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


C# IQueryable.GetEnumerator方法代码示例

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


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

示例1: Country_Get_All

        public void Country_Get_All()
        {
            //Arrange
            data = new List<Country>() {
           new Country() { Id = 1, Name = "US" },
           new Country() { Id = 2, Name = "India" },
           new Country() { Id = 3, Name = "Russia" }
          }.AsQueryable();
            mockContext = new Mock<IContext>();
            mockSet = new Mock<IDbSet<Country>>();

           
            mockSet.Setup(m => m.Provider).Returns(data.Provider);
            mockSet.Setup(m => m.Expression).Returns(data.Expression);
            mockSet.Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            mockContext.SetupGet(c => c.Countries).Returns(mockSet.Object);

            _service = new CountryService(mockContext.Object);


            //Act
            IQueryable<Country> results = _service.GetAll() as IQueryable<Country>;

            //Assert
            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.ToList().Count);

         
        }
开发者ID:DureSameen,项目名称:RoomReservation2,代码行数:31,代码来源:CountryServiceTest.cs

示例2: Initialize

        public void Initialize()
        {

            data = new List<PaymentBy>() {
            new PaymentBy() { Id = 1,Name="Member", Enabled =true, BookingForId =(int) RoomReservationSystem.Model.Enums.BookingFor.Member     },
            new PaymentBy() { Id = 2,Name="Member", Enabled =true, BookingForId = (int) RoomReservationSystem.Model.Enums.BookingFor.Guest  , SponsorTypeId=(int) RoomReservationSystem.Model.Enums.SponsorType.Member   },
            new PaymentBy() { Id = 3,Name="Guest", Enabled =true, BookingForId = (int) RoomReservationSystem.Model.Enums.BookingFor.Guest  , SponsorTypeId=(int) RoomReservationSystem.Model.Enums.SponsorType.Member    },
            new PaymentBy() { Id = 4,Name="Club", Enabled =true, BookingForId = (int) RoomReservationSystem.Model.Enums.BookingFor.Guest  , SponsorTypeId=(int) RoomReservationSystem.Model.Enums.SponsorType.Club    },  
            new PaymentBy() { Id = 5,Name="Guest", Enabled =true, BookingForId = (int) RoomReservationSystem.Model.Enums.BookingFor.Guest  , SponsorTypeId=(int) RoomReservationSystem.Model.Enums.SponsorType.Club    }
 
 
 
          }.AsQueryable();
            mockContext = new Mock<IContext>();
            mockSet = new Mock<IDbSet<PaymentBy>>();


            mockSet.Setup(m => m.Provider).Returns(data.Provider);
            mockSet.Setup(m => m.Expression).Returns(data.Expression);
            mockSet.Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            mockContext.Setup(c => c.PaymentBy).Returns(mockSet.Object);

            _service = new PaymentByService(mockContext.Object);

          
           
        }
开发者ID:DureSameen,项目名称:RoomReservation2,代码行数:29,代码来源:PaymentByServiceTest.cs

示例3: SetupMockLogValuesSet

 private static Mock<DbSet<LogValue>> SetupMockLogValuesSet(IQueryable<LogValue> mockLogValues)
 {
     var mockLogValuesSet = new Mock<DbSet<LogValue>>();
     mockLogValuesSet.As<IQueryable<LogValue>>().Setup(m => m.Provider).Returns(mockLogValues.Provider);
     mockLogValuesSet.As<IQueryable<LogValue>>().Setup(m => m.Expression).Returns(mockLogValues.Expression);
     mockLogValuesSet.As<IQueryable<LogValue>>().Setup(m => m.ElementType).Returns(mockLogValues.ElementType);
     mockLogValuesSet.As<IEnumerable<LogValue>>().Setup(m => m.GetEnumerator()).Returns(mockLogValues.GetEnumerator());
     return mockLogValuesSet;
 }
开发者ID:giglesias,项目名称:CodeReviewExercise,代码行数:9,代码来源:LogsRepositoryFixture.cs

示例4: CreateDbSet

        public static DbSet<Perfomance> CreateDbSet(IQueryable<Perfomance> perfomances)
        {
            var mockSet = new Mock<DbSet<Perfomance>>();
            mockSet.As<IQueryable<Perfomance>>().Setup(m => m.Provider).Returns(perfomances.Provider);
            mockSet.As<IQueryable<Perfomance>>().Setup(m => m.Expression).Returns(perfomances.Expression);
            mockSet.As<IQueryable<Perfomance>>().Setup(m => m.ElementType).Returns(perfomances.ElementType);
            mockSet.As<IQueryable<Perfomance>>().Setup(m => m.GetEnumerator()).Returns(perfomances.GetEnumerator());

            return mockSet.Object;
        }
开发者ID:Madster9000,项目名称:MF.Theater,代码行数:10,代码来源:PerfomanceStubs.cs

示例5: SetupMocks

        private Mock<TestContext> SetupMocks(IQueryable<Blog> blogs)
        {
            var mockSet = new Mock<DbSet<Blog>>();
            mockSet.As<IDbAsyncEnumerable<Blog>>()
                .Setup(m => m.GetAsyncEnumerator())
                .Returns(new TestDbAsyncQueryProvider<Blog>.TestDbAsyncEnumerator<Blog>(blogs.GetEnumerator()));

            mockSet.As<IQueryable<Blog>>()
                .Setup(m => m.Provider)
                .Returns(new TestDbAsyncQueryProvider<Blog>(blogs.Provider));

            mockSet.As<IQueryable<Blog>>().Setup(m => m.Expression).Returns(blogs.Expression);
            mockSet.As<IQueryable<Blog>>().Setup(m => m.ElementType).Returns(blogs.ElementType);
            mockSet.As<IQueryable<Blog>>().Setup(m => m.GetEnumerator()).Returns(blogs.GetEnumerator());

            var mockContext = new Mock<TestContext>();
            mockContext.Setup(c => c.Blogs).Returns(mockSet.Object);

            return mockContext;
        }
开发者ID:bosxixi,项目名称:X.PagedList,代码行数:20,代码来源:AsyncPagedListExtensionsTheories.cs

示例6: InitializeUnitTests

        public void InitializeUnitTests()
        {
            // create some mock products to play with
            _isValid = true;

            _userObj = new User
                           {
                               Name = "Chris Smith",
                               Password = "pass",
                               Role = "Developer",
                               IsEnabled = true,
                               id = 2
                           };

            _userList =
                new List<User>
                    {
                        _userObj,
                        new User
                            {
                                Name = "Awin George",
                                Password = "pass",
                                Role = "Developer",
                                IsEnabled = false,
                                id = 3
                            },
                        new User
                            {
                                Name = "Richard Child",
                                Password = "pass",
                                Role = "Developer",
                                IsEnabled = true,
                                id = 4
                            }
                    }.AsQueryable();

            _dbContextMock = new Mock<dbContext>();

            _dbSetMock = new Mock<IDbSet<User>>();

            _dbSetMock.Setup(m => m.Provider).Returns(_userList.Provider);
            _dbSetMock.Setup(m => m.Expression).Returns(_userList.Expression);
            _dbSetMock.Setup(m => m.ElementType).Returns(_userList.ElementType);
            _dbSetMock.Setup(m => m.GetEnumerator()).Returns(_userList.GetEnumerator());
        }
开发者ID:dshutinovski,项目名称:MvcRefactorTest,代码行数:45,代码来源:UserRepositoryFixture.cs

示例7: EmployerControllerTest

        public EmployerControllerTest()
        {
            _data = new List<Employee>
            {
                new Employee {EmployeeID = 1,  Name = "Aimen", Address = "Address" , Age = 1, Employment = 1, Active = 1},
                new Employee {EmployeeID = 2,  Name = "Max", Address = "Address" , Age = 1, Employment = 1, Active = 1},
                new Employee {EmployeeID = 3,  Name = "Alex", Address = "Address" , Age = 1, Employment = 1, Active = 1},
            }.AsQueryable();

            _mockSet = new Mock<DbSet<Employee>>();
            _mockSet.As<IQueryable<Employee>>().Setup(m => m.Provider).Returns(_data.Provider);
            _mockSet.As<IQueryable<Employee>>().Setup(m => m.Expression).Returns(_data.Expression);
            _mockSet.As<IQueryable<Employee>>().Setup(m => m.ElementType).Returns(_data.ElementType);
            _mockSet.As<IQueryable<Employee>>().Setup(m => m.GetEnumerator()).Returns(_data.GetEnumerator());

            _mockER = new Mock<IEmployeeRepository>();
            _mockER.Setup(t => t.Get()).Returns(_mockSet.Object);
            _mockER.Setup(t => t.Get(x => x.EmployeeID == It.IsAny<int>())).Returns(_mockSet.Object);
            _mockER.Setup(t => t.Add(It.IsAny<Employee>())).Callback((Employee employee) =>
            {
                var newListEmployee = new List<Employee> { employee };
                _data = _data.Concat(newListEmployee);
            }).Verifiable();
            _mockER.Setup(t => t.Delete(It.IsAny<Employee>())).Callback((Employee employee) =>
            {
                //var newListEmployee = new List<Employee> { employee };
                var list = new List<Employee>();
                list = _data.ToList();
                list.Remove(employee);
                _data = list.AsQueryable();
            }).Verifiable();
            //_mockER.Verify(mr => mr.Update(It.IsAny<Employee>()), Times.Once());
            //_mockER.Setup(t => t.Delete(It.IsAny<int>()));
            //_mockER.Setup(t => t.Delete(It.IsAny<Employee>()));
            _mockER.Setup(t => t.Update(It.IsAny<Employee>()));

            _mockUW = new Mock<IUnitOfWork>();
            _mockUW.Setup(t => t.SaveChanges());

            _mockHttpContext = new Mock<HttpContextBase>();
            _mockRequest = new Mock<HttpRequestBase>();
            _FormKeys = new NameValueCollection();
            _mockHttpContext.Setup(ctxt => ctxt.Request).Returns(_mockRequest.Object);
            _mockRequest.Setup(r => r.Form).Returns(_FormKeys);
        }
开发者ID:iqbal001001,项目名称:Business,代码行数:45,代码来源:EmployerControllerTest.cs

示例8: Setup

        public void Setup()
        {
            var products = new List<Product>();
            products.Add(new Product() { Description="Product A Description", Price = 9.99M, ProductCode="PA001", ProductId=1, ProductName="Product A", ReleaseDate = DateTime.Now });
            products.Add(new Product() { Description = "Product B Description", Price = 6.75M, ProductCode = "PB001", ProductId = 2, ProductName = "Product B", ReleaseDate = DateTime.Now });
            products.Add(new Product() { Description = "Product C Description", Price = 19.50M, ProductCode = "PC001", ProductId = 3, ProductName = "Product C", ReleaseDate = DateTime.Now });
            _products = products.AsQueryable();

            var mockSet = new Mock<DbSet<Product>>();
            mockSet.As<IQueryable<Product>>().Setup(m => m.Provider).Returns(_products.Provider);
            mockSet.As<IQueryable<Product>>().Setup(m => m.Expression).Returns(_products.Expression);
            mockSet.As<IQueryable<Product>>().Setup(m => m.ElementType).Returns(_products.ElementType);
            mockSet.As<IQueryable<Product>>().Setup(m => m.GetEnumerator()).Returns(_products.GetEnumerator());
            mockSet.As<IDbSet<Product>>().Setup(m => m.Add(It.IsAny<Product>())).Returns(new Product());

            _mockContext = new Mock<ProductContext>();
            _mockContext.Setup(m => m.Products).Returns(mockSet.Object);
        }
开发者ID:damianevans,项目名称:AngularWebAPI,代码行数:18,代码来源:ProductRepositoryTests.cs

示例9: Initialize

        public void Initialize()
        {
            listCountry = new List<Country>() {
             new Country() { Id = 1, Name = "US" },
             new Country() { Id = 2, Name = "India" },
             new Country() { Id = 3, Name = "Russia" }
            }.AsQueryable();

            _mockSet = new Mock<DbSet<Country>>();
            _mockSet.As<IQueryable<Country>>().Setup(m => m.Provider).Returns(listCountry.Provider);
            _mockSet.As<IQueryable<Country>>().Setup(m => m.Expression).Returns(listCountry.Expression);
            _mockSet.As<IQueryable<Country>>().Setup(m => m.ElementType).Returns(listCountry.ElementType);
            _mockSet.As<IQueryable<Country>>().Setup(m => m.GetEnumerator()).Returns(listCountry.GetEnumerator());

            _mockContext = new Mock<IContext>();
            _mockContext.Setup(c => c.Set<Country>()).Returns(_mockSet.Object);
            //_mockContext.Setup(c => c.Countries).Returns(_mockSet.Object);

            _service = new CountryService(_mockContext.Object);
        }
开发者ID:tonvantruongbk,项目名称:DANN,代码行数:20,代码来源:CountryServiceTest.cs

示例10: Initilize

        public void Initilize()
        {
            _listUser = new List<User>()
            {
                new User() {Email = "[email protected]", UserName = "paulwild", Authenticated = true},
                new User() {Email = "[email protected]", UserName = "Iamcool1234", Authenticated = true}
            }.AsQueryable();

            _mockSet = new Mock<DbSet<User>>();
            _mockSet.As<IQueryable<User>>().Setup(m => m.Provider).Returns(_listUser.Provider);
            _mockSet.As<IQueryable<User>>().Setup(m => m.Expression).Returns(_listUser.Expression);
            _mockSet.As<IQueryable<User>>().Setup(m => m.ElementType).Returns(_listUser.ElementType);
            _mockSet.As<IQueryable<User>>().Setup(m => m.GetEnumerator()).Returns(_listUser.GetEnumerator());

            _mockContext = new Mock<IPhotoArkContext>();
            _mockContext.Setup(c => c.Set<User>()).Returns(_mockSet.Object);
            _mockContext.Setup(c => c.Users).Returns(_mockSet.Object);

            _service = new UserService(_mockContext.Object);
        }
开发者ID:PaulWild,项目名称:PhotoArk,代码行数:20,代码来源:UserServiceTests.cs

示例11: Init

        public void Init()
        {
            data = new List<Category>
            {
                new Category(){ Id = 1, IsActive = true,  Title = "Wooden",   Date = DateTime.Now.AddDays(-20)},
                new Category(){ Id = 2, IsActive = false, Title = "Modern",   Date = DateTime.Now.AddDays(-10)},
                new Category(){ Id = 3, IsActive = true,  Title = "Metal",    Date = DateTime.Now.AddDays(-15)}
            }.AsQueryable();

            mockSet = new Mock<DbSet<Category>>();
            mockSet.As<IQueryable<Category>>().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As<IQueryable<Category>>().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As<IQueryable<Category>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As<IQueryable<Category>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            mockContext = new Mock<ProjectContext>();
            mockContext.Setup(x => x.Categories).Returns(mockSet.Object);

            service = new EFCategoryDAO(mockContext.Object);
        }
开发者ID:Mechtatel-student,项目名称:CS1_Project,代码行数:20,代码来源:EfTest.cs

示例12: Initialize

        public void Initialize()
        {
            listRestaurant = new List<Restaurant>() {
              new Restaurant() { Id = 1, Name = "Apple Bees", CityID = 1 },
              new Restaurant() { Id = 2, Name = "TGI Fridays", CityID = 1 },
              new Restaurant() { Id = 3, Name = "Olive Garden", CityID = 2 }
             }.AsQueryable();

            _mockSet = new Mock<DbSet<Restaurant>>();
            _mockSet.As<IQueryable<Restaurant>>().Setup(m => m.Provider).Returns(listRestaurant.Provider);
            _mockSet.As<IQueryable<Restaurant>>().Setup(m => m.Expression).Returns(listRestaurant.Expression);
            _mockSet.As<IQueryable<Restaurant>>().Setup(m => m.ElementType).Returns(listRestaurant.ElementType);
            _mockSet.As<IQueryable<Restaurant>>().Setup(m => m.GetEnumerator()).Returns(listRestaurant.GetEnumerator());

            _mockContext = new Mock<IRRContext>();
            _mockContext.Setup(c => c.Set<Restaurant>()).Returns(_mockSet.Object);
            _mockContext.Setup(c => c.Restaurants).Returns(_mockSet.Object);

            _service = new RestaurantService(_mockContext.Object);
        }
开发者ID:rickv1003,项目名称:RestaurantReviews,代码行数:20,代码来源:RestaurantBase.cs

示例13: Initialize

        public void Initialize()
        {
            listReview = new List<Review>() {
            new Review() { Id = 1, RestaurantID = 0, UserID = 0, Rating = 1, Comments = "test", DateCreated = DateTime.Now },
            new Review() { Id = 2, RestaurantID = 0, UserID = 0, Rating = 1, Comments = "test", DateCreated = DateTime.Now },
            new Review() { Id = 3, RestaurantID = 0, UserID = 0, Rating = 1, Comments = "test", DateCreated = DateTime.Now },
             }.AsQueryable();

            _mockSet = new Mock<DbSet<Review>>();
            _mockSet.As<IQueryable<Review>>().Setup(m => m.Provider).Returns(listReview.Provider);
            _mockSet.As<IQueryable<Review>>().Setup(m => m.Expression).Returns(listReview.Expression);
            _mockSet.As<IQueryable<Review>>().Setup(m => m.ElementType).Returns(listReview.ElementType);
            _mockSet.As<IQueryable<Review>>().Setup(m => m.GetEnumerator()).Returns(listReview.GetEnumerator());

            _mockContext = new Mock<IRRContext>();
            _mockContext.Setup(c => c.Set<Review>()).Returns(_mockSet.Object);
            _mockContext.Setup(c => c.Reviews).Returns(_mockSet.Object);

            _service = new ReviewService(_mockContext.Object);
        }
开发者ID:rickv1003,项目名称:RestaurantReviews,代码行数:20,代码来源:ReviewBase.cs

示例14: Initialize

        public void Initialize()
        {
            _listaAvisos = new List<Aviso>
                           {
                               new Aviso() {Id = 1, Texto = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."},
                               new Aviso() {Id = 2, Texto = "Duis aute irure dolor in reprehenderit in voluptate velit."},
                               new Aviso() {Id = 3, Texto = "Excepteur sint occaecat cupidatat non proident, sunt in culpa."}
                           }.AsQueryable();

            _setMock = new Mock<DbSet<Aviso>>();
            _setMock.As<IQueryable<Aviso>>().Setup(m => m.Provider).Returns(_listaAvisos.Provider);
            _setMock.As<IQueryable<Aviso>>().Setup(m => m.Expression).Returns(_listaAvisos.Expression);
            _setMock.As<IQueryable<Aviso>>().Setup(m => m.ElementType).Returns(_listaAvisos.ElementType);
            _setMock.As<IQueryable<Aviso>>().Setup(m => m.GetEnumerator()).Returns(_listaAvisos.GetEnumerator());

            _contextoMock = new Mock<IContexto>();
            _contextoMock.Setup(c => c.Set<Aviso>()).Returns(_setMock.Object);
            _contextoMock.Setup(c => c.Avisos).Returns(_setMock.Object);

            _servicoAvisoMock = new ServicoAviso(_contextoMock.Object);
        }
开发者ID:pierobrito,项目名称:AppConsig,代码行数:21,代码来源:ServicoAvisoTeste.cs

示例15: Create

        /// <summary>
        /// Loads a DataTable from a sequence of objects.
        /// </summary>
        /// <param name="source">The sequence of objects to load into the DataTable.</param>
        /// <param name="table">The input table. The schema of the table must match that 
        /// the type T.  If the table is null, a new table is created with a schema 
        /// created from the public properties and fields of the type T.</param>
        /// <param name="options">Specifies how values from the source sequence will be applied to 
        /// existing rows in the table.</param>
        /// <returns>A DataTable created from the source sequence.</returns>
        public DataTable Create(IQueryable source)
        {
            var entityType = source.ElementType;
            var entityTypeProperties = entityType.GetProperties();

            var table = new DataTable(entityType.Namespace + "." + entityType.Name);
            var cols = entityTypeProperties.Select(p => new DataColumn(p.Name, Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType));
            table.Columns.AddRange(cols.ToArray());

            table.BeginLoadData();
            var entityEnumerator = source.GetEnumerator();

            while (entityEnumerator.MoveNext())
            {
                var values = entityTypeProperties.Select(p => p.GetValue(entityEnumerator.Current, null) ?? DBNull.Value);
                table.LoadDataRow(values.ToArray(), true);
            }

            table.EndLoadData();

            return table;
        }
开发者ID:vagwada,项目名称:SqlCopy,代码行数:32,代码来源:EntityTableFactory.cs


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