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


C# List.GetEnumerator方法代码示例

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


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

示例1: GetAllShouldReturnTodos

        public void GetAllShouldReturnTodos()
        {
            var data = new List<Todo>
            {
                new Todo {Id = 1},
                new Todo {Id = 2},
                new Todo {Id = 3},
            }.AsQueryable();

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

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

            var service = new TodoRepository(mockContext.Object);
            var todos = service.GetAll().ToList();

            Assert.AreEqual(3, todos.Count);
            Assert.AreEqual(1, todos[0].Id);
            Assert.AreEqual(2, todos[1].Id);
            Assert.AreEqual(3, todos[2].Id);
        }
开发者ID:harumburum,项目名称:todolist-mvc5,代码行数:26,代码来源:TodoRepositoryTests.cs

示例2: GetApplicationDbContextMock

        private Mock<ApplicationDbContext> GetApplicationDbContextMock()
        {
            // single user
            var appUser = new ApplicationUser();
            appUser.Id = "1";

            var data = new List<ToDo>  {
                    new ToDo { Id = 0, Title = "Todo 1", Completed = false, User = appUser },
                    new ToDo { Id = 1, Title = "Todo 2", Completed = true, User = appUser },
                  }.AsQueryable();

            var mockSet = new Mock<DbSet<ToDo>>();

            mockSet.As<IDbAsyncEnumerable<ToDo>>()
               .Setup(m => m.GetAsyncEnumerator())
               .Returns(new TestDbAsyncEnumerator<ToDo>(data.GetEnumerator()));

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

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

            var applicationDbContext = new Mock<ApplicationDbContext>();
            applicationDbContext.Setup(c => c.ToDos).Returns(mockSet.Object);

            return applicationDbContext;
        }
开发者ID:sdurandeu,项目名称:todomvc-aspnet,代码行数:30,代码来源:TodoControllerFixture.cs

示例3: GetAllTasks_Order_By_Username

        public void GetAllTasks_Order_By_Username()
        {
            var taskData = new List<TaskModel>
            {
                Build_Task_For_Testing("B's Task", new DateTime(2015, 7, 3, 5, 5, 5), "B's Test Task", "B"),
                Build_Task_For_Testing("C's Task", new DateTime(2015, 7, 5, 5, 5, 5), "C's Test Task", "C"),
                Build_Task_For_Testing("D's Task", new DateTime(2015, 7, 6, 5, 5, 5), "D's Test Task", "D")
            }.AsQueryable();

            var taskData2 = new List<TaskModel> { }.AsQueryable();

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

            var mockDbContext = new Mock<TaskDBContext>();
            mockDbContext.Setup(t => t.Tasks).Returns(mockSet.Object);

            var testClass = new TestClass(mockDbContext.Object);
            var allTasks = testClass.GetAllTasks();

            Assert.AreEqual(3, allTasks.Count);
            Assert.AreEqual("B", allTasks[0].Username);
            Assert.AreEqual("C", allTasks[1].Username);
            Assert.AreEqual("D", allTasks[2].Username);
        }
开发者ID:charlesjw,项目名称:ToDo_App,代码行数:28,代码来源:HomeControllerTest.cs

示例4: Get_Object_fromPager_User_Match_To_DB

        public void Get_Object_fromPager_User_Match_To_DB()
        {
            var users = new List<staff>{new staff{
                Email = "[email protected]",
                FirstName = "andrew",
                LastName = "nick",
                ID = 3
            },
            new staff{
                Email = "[email protected]",
                FirstName = "aasdndrew",
                LastName = "nicasdk",
                ID = 30}
            };

            Mock<IStaffDAO> mockStaffDAO = new Mock<IStaffDAO>();
            mockStaffDAO.Setup(m => m.Get()).Returns(users);
            StaffBL staffBL = new StaffBL(mockStaffDAO.Object);
            var result = staffBL.Get(5, 0, "");
            Assert.AreEqual(users.Count(), result.staffMembers.Count());
            IEnumerator<staff> e1 = users.GetEnumerator();
            IEnumerator<staff> e2 = result.staffMembers.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                Assert.AreEqual(e1.Current, e2.Current);
            }
        }
开发者ID:anicoll,项目名称:training,代码行数:28,代码来源:StaffBL_Tests.cs

示例5: generateSensorDataSet

        private legion_service_api generateSensorDataSet()
        {
            Random rnd = new Random();

            IQueryable<sensor_data> data = new List<sensor_data>
            {
                new sensor_data { Id = 1, userGuid = "teste.teste.teste", sensor_name = "sensor1", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))},
                new sensor_data { Id = 3, userGuid = "teste.teste.teste", sensor_name = "sensor2", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))},
                new sensor_data { Id = 4, userGuid = "teste.teste.teste", sensor_name = "sensor2", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))},
                new sensor_data { Id = 5, userGuid = "teste.teste.teste", sensor_name = "sensor3", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))},
                new sensor_data { Id = 6, userGuid = "teste.teste.teste2", sensor_name = "sensor2", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))},
                new sensor_data { Id = 7, userGuid = "teste.teste.teste2", sensor_name = "sensor2", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))},
                new sensor_data { Id = 2, userGuid = "teste.teste.teste2", sensor_name = "sensor1", timestamp = DateTime.Now.AddMilliseconds(rnd.Next(1000, 10000))}

            }.AsQueryable();
            var mockset = new Mock<DbSet<sensor_data>>();
            mockset.As<IQueryable<sensor_data>>().Setup(m => m.Provider).Returns(data.Provider);
            mockset.As<IQueryable<sensor_data>>().Setup(m => m.Expression).Returns(data.Expression);
            mockset.As<IQueryable<sensor_data>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockset.As<IQueryable<sensor_data>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock<legion_serviceContext>();
            mockContext.Setup(s => s.sensor_data).Returns(mockset.Object);

               return new legion_service_api(mockContext.Object);
        }
开发者ID:Dronetech,项目名称:legion_network,代码行数:26,代码来源:UnitTest1.cs

示例6: GetUserStocks_must_return_all_stocks_of_user_from_context

        public void GetUserStocks_must_return_all_stocks_of_user_from_context()
        {
            var data = new List<UserStock>
            {
                new UserStock {ID = 0, Name = "DAX", User = Thread.CurrentPrincipal.Identity.GetUserName()},
                new UserStock {ID = 1, Name = "NYSE", User = "user2"},
                new UserStock {ID = 1, Name = "NASDAQ", User = Thread.CurrentPrincipal.Identity.GetUserName()},
            }.AsQueryable();

            var mockSet = new Mock<DbSet<UserStock>>();

            mockSet.As<IQueryable<UserStock>>().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As<IQueryable<UserStock>>().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As<IQueryable<UserStock>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As<IQueryable<UserStock>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

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

            var service = new UserStocksController(mockContext.Object);
            var result = service.GetUserStocks();

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("DAX", result.Single(us => us.ID == 0).Name);
            Assert.AreEqual("NASDAQ", result.Single(us => us.ID == 1).Name);
        }
开发者ID:MGTSr,项目名称:StockExchange,代码行数:26,代码来源:UserStocksControllerTests.cs

示例7: TestInitalise

        public void TestInitalise()
        {
            var Urls = new List<ShortUrlEntity>();

            Urls.Add(new ShortUrlEntity
            {
                Id = 0,
                Nsfw = false,
                RedirectionUrl = "http://www.google.com/",
                ShortCode = "google",
                Views = 0
            });

            Urls.Add(new ShortUrlEntity
            {
                Id = 1,
                Nsfw = true,
                RedirectionUrl = "http://www.google2.com/",
                ShortCode = "google2",
                Views = 20
            });

            var dbSet = new Mock<IEntitySet<ShortUrlEntity>>();
            dbSet.Setup(s => s.GetEnumerator()).Returns(Urls.GetEnumerator());

            var context = new Mock<IShortUrlContext>();
            context.Setup(r => r.EntitySet<ShortUrlEntity>()).Returns(dbSet.Object);

            repo = new ShortUrlRepository(context.Object);
        }
开发者ID:harrymilnes,项目名称:PersonalWebsite,代码行数:30,代码来源:UnitTest1.cs

示例8: GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase

        public void GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase()
        {
            // Arrange
            var stubContext = new Mock<Context>();

            var stubRecipients = new List<Recipient>
            {
                new Recipient("[email protected]"),
                new Recipient("[email protected]"),
                new Recipient("[email protected]"),
            }.AsQueryable();
            stubRecipients.ElementAt(0).MarkAsSent(DateTime.Now);
            stubRecipients.ElementAt(1).MarkAsSent(DateTime.Now);
            stubRecipients.ElementAt(2).MarkAsFailed("sending failed", DateTime.Now);

            var stubDbSet = new Mock<DbSet<Recipient>>();
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Provider).Returns(stubRecipients.Provider);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Expression).Returns(stubRecipients.Expression);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.ElementType).Returns(stubRecipients.ElementType);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.GetEnumerator()).Returns(stubRecipients.GetEnumerator());

            stubContext.Setup(c => c.Recipients).Returns(stubDbSet.Object);

            // Act
            var repository = new Repository(stubContext.Object);
            var recipient = repository.GetFirstUnsentAddress();

            // Assert
            Assert.IsNull(recipient);
        }
开发者ID:bpashkovskyi,项目名称:BulkMailSender,代码行数:30,代码来源:RepositoryTests.cs

示例9: GetAllBlogsAsync_orders_by_name

            public async Task GetAllBlogsAsync_orders_by_name()
            {

                var data = new List<Blog>
                {
                    new Blog { Name = "BBB" },
                    new Blog { Name = "ZZZ" },
                    new Blog { Name = "AAA" },
                }.AsQueryable();

                var mockSet = new Mock<DbSet<Blog>>();
                mockSet.As<IDbAsyncEnumerable<Blog>>()
                    .Setup(m => m.GetAsyncEnumerator())
                    .Returns(new TestDbAsyncEnumerator<Blog>(data.GetEnumerator()));

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

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

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

                var service = new BlogService(mockContext.Object);
                var blogs = await service.GetAllBlogsAsync();

                Assert.AreEqual(3, blogs.Count);
                Assert.AreEqual("AAA", blogs[0].Name);
                Assert.AreEqual("BBB", blogs[1].Name);
                Assert.AreEqual("ZZZ", blogs[2].Name);
            }
开发者ID:hobe,项目名称:entityframework,代码行数:34,代码来源:MockUnitTests.cs

示例10: Delete

        public async Task Delete()
        {
            var data = new List<Department>
            {
                new Department {DepartmentID = 1, Name = "Test1", Budget = 1001, StartDate = DateTime.Today.AddDays(1)},
                new Department {DepartmentID = 2, Name = "Test2", Budget = 1002, StartDate = DateTime.Today.AddDays(2)},
                new Department {DepartmentID = 3, Name = "Test3", Budget = 1003, StartDate = DateTime.Today.AddDays(3)},
                new Department {DepartmentID = 4, Name = "Test4", Budget = 1004, StartDate = DateTime.Today.AddDays(4)}
            }.AsQueryable();

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

            var mockContext = new Mock<SchoolContext>();
            mockContext.Setup(m => m.Departments).Returns(mockSet.Object);

            var controller = new DepartmentController(mockContext.Object);

            Department departmentToDelete = controller.GetAllDepartments().First();
            await controller.Delete(departmentToDelete);

            mockContext.Verify(m => m.SaveChangesAsync(), Times.Once());

            //Assert.AreEqual(3, controller.GetAllDepartments().Count);

        }
开发者ID:pleasereleaseme,项目名称:ContosoUniversity,代码行数:29,代码来源:DepartmentTests.cs

示例11: RepositoryGetArtistById

        public void RepositoryGetArtistById()
        {
            const int expectedId = 3;
            var expected = new Artist { Id = expectedId, Name = "WWWW", Country = "WEE", Identifier = "dfr" };

            var data = new List<Artist>{
                expected,
                new Artist{Id = 1, Name = "Ronald", Country = "ZW", Identifier = "abc", Eliases = new List<Elias>{new Elias {Id = 1, EliasName = "Ron", ArtistId = 1}}},
                new Artist{Id = 2, Name = "Zebra", Country = "SA", Identifier = "bvf", Eliases = new List<Elias>{new Elias {Id = 2, EliasName = "Zeb", ArtistId = 2}}}
            }.AsQueryable();

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

            var mockContext = new Mock<BEContext>();
            mockContext.Setup(m => m.Artists).Returns(mockSet.Object);
            mockContext.Setup(m => m.Set<Artist>()).Returns(mockSet.Object);

            var repo = new Repository<Artist>(mockContext.Object);

            var list = repo.GetArtistById(expectedId);

            Assert.AreEqual(1, list.Id);
        }
开发者ID:ronaldpasipanodya,项目名称:backend-developer-assessment,代码行数:27,代码来源:IPlatformBEUnitTest.cs

示例12: GetAll_retrieveallitems_allitemsretrieved

        public void GetAll_retrieveallitems_allitemsretrieved()
        {
            // Arrange
            var data = new List<Warehouse>
            {
                new Warehouse(1, 10, 10),
                new Warehouse(2, 15, 20),
                new Warehouse(3, 25, 30),
            }.AsQueryable();

            var mockContext = new Mock<PDSDatabase>();
            var mockSet = new Mock<MockableDbSetWithIQueryable<Warehouse>>();
            mockContext.Setup(c => c.Warehouses).Returns(mockSet.Object);

            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());

            var repostitory = new InDatabaseWarehouseRepository(mockContext.Object);

            // Act
            var warehouses = (List<Warehouse>)repostitory.GetAll();

            // Assert
            Assert.AreEqual(3, warehouses.Count);
        }
开发者ID:JueZ,项目名称:SKS,代码行数:27,代码来源:InDataBaseWarehouseRepositoryTest.cs

示例13: ClassInit

        public void ClassInit()
        {
            // Installing mock DbSet.
            var data = new List<MockCatalog>
            {
                new MockCatalog(false) { Name = "BBB" },
                new MockCatalog(false) { Name = "ZZZ" },
                new MockCatalog(false) { Name = "AAA" },
            }.AsQueryable();

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

            // Installing mock Context.
            var mockContext = new Mock<MetadataEFContext>();
            mockContext.Setup(m => m.Set<MockCatalog>()).Returns(mockDbSet.Object);

            // Installing repository.
            var catalogRepository = new EFCatalogRepository<MockCatalog>(mockContext.Object);

            // Installing shared tests.
            SharedTests = new SharedTests<MockCatalog>(mockDbSet, mockContext, catalogRepository, CreateCatalogItem);
        }
开发者ID:slootsky-oleg,项目名称:EFRepositoryForMetadata,代码行数:26,代码来源:TestCatalogRepository.cs

示例14: can_mock_convict_context_SpeedTest

        public void can_mock_convict_context_SpeedTest()
        {
            /// Arrange Objects:

            var convicts = new List<Convict> {
                new Convict { ConvictCode = "1234",
                                Email = "[email protected]"
                },
                new Convict { ConvictCode = "1233",
                                Email = "[email protected]"
                },
                new Convict { ConvictCode = "1232",
                                Email = "[email protected]"
                }
            }.AsQueryable();

            var mockSet = Substitute.For<IDbSet<Convict>>();
            mockSet.Provider.Returns(convicts.Provider);
            mockSet.Expression.Returns(convicts.Expression);
            mockSet.ElementType.Returns(convicts.ElementType);
            mockSet.GetEnumerator().Returns(convicts.GetEnumerator());

            var context = Substitute.For<IConvictsContext>();
            context.Convicts.Returns(mockSet);

            Assert.AreEqual(3, context.Convicts.Count());
            Assert.AreEqual("1234", context.Convicts.First().ConvictCode);
        }
开发者ID:tiang,项目名称:Convicts-For-A-Cause,代码行数:28,代码来源:TestingTheTests.cs

示例15: TestCacheableGetAllProductsSync

        public void TestCacheableGetAllProductsSync()
        {
            var data = new List<Product>
            {
                new Product { ProductName = "BBB"},
                new Product { ProductName = "ZZZ" },
                new Product { ProductName = "AAA" }
            }.AsQueryable();

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

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

            // public List<Product> GetAllProductsOrderedByName()
            var products = mockContext.Object.Products
                                             .OrderBy(product => product.ProductName)
                                             .Cacheable()
                                             .ToList();

            Assert.AreEqual(3, products.Count);
            Assert.AreEqual("AAA", products[0].ProductName);
            Assert.AreEqual("BBB", products[1].ProductName);
            Assert.AreEqual("ZZZ", products[2].ProductName);
        }
开发者ID:yao-yi,项目名称:EFSecondLevelCache,代码行数:29,代码来源:MockingTests.cs


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