当前位置: 首页>>代码示例>>C#>>正文


C# List.AsQueryable方法代码示例

本文整理汇总了C#中Data.List.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# List.AsQueryable方法的具体用法?C# List.AsQueryable怎么用?C# List.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Data.List的用法示例。


在下文中一共展示了List.AsQueryable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        public static IRepository<Book> Create()
        {
            var listOfBooks = new List<Book>();
            for (int i = 0; i < 20; i++)
            {
                listOfBooks.Add(new Book
                {
                    Id = i,
                    Title = "Book " + i,
                    Description = "Description" + i,
                    Author = new Author
                    {
                        FirstName = "FirstName " + i,
                        LastName = "LastName " + i
                    }
                });
            }

            var repository = new Mock<IRepository<Book>>();
            repository.Setup(r => r.All()).Returns(listOfBooks.AsQueryable());
            repository.Setup(r => r.Add(It.IsAny<Book>())).Callback<Book>(b =>
            {
                b.Id = 1;
            });
            repository.Setup(r => r.SaveChanges()).Verifiable();

            return repository.Object;
        }
开发者ID:rahulchrty,项目名称:MyTested.WebApi,代码行数:28,代码来源:BooksRepositoryMock.cs

示例2: DummyContractsRepository

        internal static IRepository<Contract> DummyContractsRepository()
        {
            var repo = new Mock<IRepository<Contract>>();

            var contracts = new List<Contract>();

            for (int i = 0; i < NumberOfTestObjects; i++)
            {
                contracts.Add(new Contract
                {
                    ClientId = (i % 2 == 0 ? i : 3).ToString(),
                    HitmanId = (i % 2 == 0 ? i : 3).ToString() + "hitman",
                    Deadline = DateTime.Now,
                    Status = ConnectionStatus.Pending,
                    Id = i
                });
            }

            repo.Setup(r => r.GetById(It.Is<int>(x => x == 4))).Returns(() =>
            {
                return contracts.Where(c => c.Id == 4).FirstOrDefault();
            });

            repo.Setup(r => r.All()).Returns(() =>
            {
                return contracts.AsQueryable();
            });

            return repo.Object;
        }
开发者ID:ERIS-Team-TelerikAcademy,项目名称:ERIS-App,代码行数:30,代码来源:DummyRepositories.cs

示例3: Create

        public static IRepository<Author> Create()
        {
            var listOfAuthors = new List<Author>
            {
                new Author
                {
                    UserName = "Valid"
                }
            };

            var repository = new Mock<IRepository<Author>>();
            repository.Setup(r => r.All()).Returns(listOfAuthors.AsQueryable());

            return repository.Object;
        }
开发者ID:rahulchrty,项目名称:MyTested.WebApi,代码行数:15,代码来源:AuthorsRepositoryMock.cs

示例4: DummyCountriesRepository

        internal static IRepository<Country> DummyCountriesRepository()
        {
            var repo = new Mock<IRepository<Country>>();

            repo.Setup(r => r.All()).Returns(() =>
            {
                var countries = new List<Country>();

                for (int i = 0; i < NumberOfTestObjects; i++)
                {
                    countries.Add(new Country
                    {
                        Id = i,
                        Name = "TestCountry" + i
                    });
                }

                return countries.AsQueryable();
            });

            return repo.Object;
        }
开发者ID:ERIS-Team-TelerikAcademy,项目名称:ERIS-App,代码行数:22,代码来源:DummyRepositories.cs

示例5: DummyHitmenRepository

        internal static IRepository<User> DummyHitmenRepository()
        {
            var repo = new Mock<IRepository<User>>();

            var users = new List<User>();

            for (int i = 0; i < NumberOfTestObjects; i++)
            {
                users.Add(new User
                {
                    Id = i.ToString(),
                    RegistrationDate = DateTime.Now,
                    AboutMe = "Test About Me" + i,
                    DateOfBirth = DateTime.Now.AddYears(i),
                    Gender = true,
                    IsWorking = i % 2 == 0
                });
            }

            repo.Setup(r => r.All()).Returns(() =>
            {
                return users.AsQueryable();
            });

            return repo.Object;
        }
开发者ID:ERIS-Team-TelerikAcademy,项目名称:ERIS-App,代码行数:26,代码来源:DummyRepositories.cs

示例6: DummyUserRatingsRepository

        internal static IRepository<UserRating> DummyUserRatingsRepository()
        {
            var repo = new Mock<IRepository<UserRating>>();
            var ratings = new List<UserRating>();

            for (int i = 0; i < NumberOfTestObjects; i++)
            {
                ratings.Add(new UserRating
                {
                    Id = i,
                    ClientId = "TestId" + i,
                    HitmanId = "TestId" + (i % 2 == 0 ? i : 3),
                    Rating = i % 6
                });
            }

            repo.Setup(r => r.All()).Returns(() =>
            {
                return ratings.AsQueryable();
            });

            repo.Setup(r => r.SaveChanges()).Returns(ratings.Last().Id);

            repo.Setup(r => r.Add(It.IsAny<UserRating>())).Callback<UserRating>(ur =>
            {
                ur.Id = ratings.LastOrDefault().Id + 1;
                ratings.Add(ur);
            });

            return repo.Object;
        }
开发者ID:ERIS-Team-TelerikAcademy,项目名称:ERIS-App,代码行数:31,代码来源:DummyRepositories.cs

示例7: DummyImagesRepository

        internal static IRepository<Image> DummyImagesRepository()
        {
            var repository = new Mock<IRepository<Image>>();
            var images = new List<Image>();

            for (int i = 0; i < NumberOfTestObjects; i++)
            {
                var user = DummyHitmenRepository()
                    .All()
                    .FirstOrDefault(u => u.Id == i.ToString());

                images.Add(new Image()
                {
                    Id = i,
                    Name = "Image #" + i,
                    Extension = ".png",
                    UserId = user.Id,
                    User = user
                });
            }

            repository.Setup(r => r.All()).Returns(() =>
            {
                return images.AsQueryable();
            });

            repository
                .Setup(r => r.Add(It.IsAny<Image>()))
                .Callback<Image>(i =>
                {
                    i.Id = images.LastOrDefault().Id + 1;
                    images.Add(i);
                });

            repository.Setup(r => r.SaveChanges()).Returns(images.Last().Id);

            repository
                .Setup(r => r.Delete(It.IsAny<Image>()))
                .Callback<Image>(i =>
                {
                    images.RemoveAt(i.Id);
                });

            return repository.Object;
        }
开发者ID:ERIS-Team-TelerikAcademy,项目名称:ERIS-App,代码行数:45,代码来源:DummyRepositories.cs


注:本文中的Data.List.AsQueryable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。