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


C# List.AsQueryable方法代码示例

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


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

示例1: PagingOptions_Apply_Return_Requested_Page_With_Multiple_Sort

        public void PagingOptions_Apply_Return_Requested_Page_With_Multiple_Sort()
        {
            var contacts = new List<Contact>();
            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + (i % 2), ContactTypeId = i});
            }

            const int resultingPage = 2;
            const int pageSize = 2;

            var qo = new PagingOptions<Contact>(resultingPage, pageSize, "Name", isDescending: true);
            qo.ThenSortBy("ContactTypeId", isDescending: true);

            IQueryable<Contact> queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(2);

            var contact = queryable.First();
            contact.Name.ShouldEqual("Test User 1");
            contact.ContactTypeId.ShouldEqual(1);

            var qo2 = new PagingOptions<Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);
            qo2.ThenSortBy(x => x.ContactTypeId, isDescending: true);

            queryable = qo2.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(2);

            contact = queryable.First();
            contact.Name.ShouldEqual("Test User 1");
            contact.ContactTypeId.ShouldEqual(1);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:31,代码来源:PagingOptionsTests.cs

示例2: SetUp

        public override void SetUp()
        {
            base.SetUp();

            expectedGamingGroup = new GamingGroup
            {
                Id = gamingGroupId, 
                OwningUserId = CurrentUser.Id
            };

            filter = new GamingGroupFilter
            {
                GamingGroupId = gamingGroupId
            };

            AutoMocker.Get<IDataContext>().Expect(mock => mock.FindById<GamingGroup>(gamingGroupId))
                .Return(expectedGamingGroup);

            gameDefinitionSummaries = new List<GameDefinitionSummary>
            {
                new GameDefinitionSummary()
            };

            AutoMocker.Get<IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(gamingGroupId, filter.DateRangeFilter))
                                       .Return(gameDefinitionSummaries);

            List<ApplicationUser> applicationUsers = new List<ApplicationUser>();
            applicationUsers.Add(CurrentUser);

            AutoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<ApplicationUser>())
                .Return(applicationUsers.AsQueryable());

            AutoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<ApplicationUser>())
                .Return(applicationUsers.AsQueryable());
        }
开发者ID:NemeStats,项目名称:NemeStats,代码行数:35,代码来源:GetGamingGroupDetailsTests.cs

示例3: should_query_if_query_string_is_empty

        public async void should_query_if_query_string_is_empty()
        {
            // Arrange
            const string key = "test";
            var userList = new List<User> { new User { Email = "[email protected]", FullName = "test" } };

            var userRepository = new Mock<IRepository<User>>();
            userRepository.Setup(x => x.FindAll(It.IsAny<Expression<Func<User, bool>>>()))
                          .Returns(userList.AsQueryable());

            userRepository.Setup(x => x.AsQueryable(userList.AsQueryable(), It.IsAny<Expression<Func<User, bool>>>()))
                          .Returns(userList.AsQueryable());

            // Act
            var sut = new SearchServiceBuilder().WithUserRespository(userRepository.Object)
                                                .Build();

            var nullTask = await sut.Query(string.Empty);
            var notNullResult = await sut.Query(key); 

            // Assert
            Assert.IsNull(nullTask);
            Assert.NotNull(notNullResult);
            Assert.IsInstanceOf(typeof(ISearchService), sut);
             
            userRepository.Verify(x => x.FindAll(It.IsAny<Expression<Func<User, bool>>>()), Times.AtLeastOnce);
        }
开发者ID:netexpert1983,项目名称:set-basic-aspnet-mvc,代码行数:27,代码来源:SearchServiceTests.cs

示例4: Init

        public void Init()
        {
            AutoMapperConfiguration.Configure();
            var mockSiteRepository = new Mock<ISiteRepository>();
            var items = new List<Hatfield.EnviroData.Core.Site> { 
                            new Hatfield.EnviroData.Core.Site{
                                SiteTypeCV = "Stream",
                                Latitude = 49.2827,
                                Longitude = 123.1207,
                                SpatialReferenceID = 1
                            },
                            new Hatfield.EnviroData.Core.Site{
                                SiteTypeCV = "Stream",
                                Latitude = 49.2827,
                                Longitude = 123.1207,
                                SpatialReferenceID = 1
                            }};
            mockSiteRepository.Setup(x => x.GetAll())
                          .Returns(items.AsQueryable());

            var mockActionRepository = new Mock<IWQDataRepository>();
            var actions = new List<Hatfield.EnviroData.Core.Action> { 
             new Hatfield.EnviroData.Core.Action{
                                ActionID = 2,
                                BeginDateTime = new DateTime(2015, 2, 2)
                            },
                            new Hatfield.EnviroData.Core.Action{
                                ActionID = 3,
                                BeginDateTime = new DateTime(2015, 2, 3)
                            }               
            };
            mockSiteRepository.Setup(x => x.GetAll())
                          .Returns(items.AsQueryable());

            var mockVariableRepository = new Mock<IWQVariableRepository>();
            var variables = new List<Hatfield.EnviroData.Core.Variable> { 
                            new Hatfield.EnviroData.Core.Variable{
                                VariableTypeCV = "Chemistry",
                                VariableCode = "108-88-3",
                                VariableNameCV = "1,1,1-Trichloroethane",
                                VariableDefinition = "",
                                NoDataValue = -9999,
                            },
                            new Hatfield.EnviroData.Core.Variable{
                                VariableTypeCV = "Chemistry",
                                VariableCode = "528-78-3",
                                VariableNameCV = "1,1,1-Trichloroethane",
                                VariableDefinition = "",
                                NoDataValue = -9999,
                            }};
            mockVariableRepository.Setup(x => x.GetAllChemistryVariables())
                          .Returns(variables.AsQueryable());

            var mockDefaultValueProvider = new Mock<IWQDefaultValueProvider>();

            this.controller = new StationQueryAPIController(mockDefaultValueProvider.Object, mockSiteRepository.Object, mockVariableRepository.Object, mockActionRepository.Object);
        }
开发者ID:gvassas,项目名称:Hatfield.EnviroData.MVC,代码行数:57,代码来源:StationQueryAPIControllerTest.cs

示例5: TheWidgetShouldBeReturned

        public void TheWidgetShouldBeReturned()
        {
            //Arrange
            List<DomainWidget> values = new List<DomainWidget>
            {
                new DomainWidget
                {
                    Name = "Test Widget",
                    Description = "A test widget",
                    Manufacturer = "Radix2"
                },
                new DomainWidget
                {
                    Name = "Second Widget",
                    Description = "A second widget",
                    Manufacturer = "Radix2"
                }

            };
            IQueryable<DomainWidget> valuesQueryable = values.AsQueryable();

            var mockRepository = new Mock<IRepository>();
            mockRepository
                .Setup(x => x.All<DomainWidget>(It.IsAny<String[]>()))
                .Returns(()=> valuesQueryable);

            var widgetService = new WidgetService(mockRepository.Object);

            //Act
            var widgets = widgetService.Get();

            //Assert
            Assert.IsInstanceOf<List<DomainWidget>>(widgets);
        }
开发者ID:inmWill,项目名称:api.core,代码行数:34,代码来源:WIdgetServiceFixture.cs

示例6: BuildsAListOfNameValueObjectsBasedOnOrigins

        public void BuildsAListOfNameValueObjectsBasedOnOrigins()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order = new Order();
            
            var origins = new List<string>
            {
                "Test Origin 1",
                "Test Origin 2"
            };

            Mock.Arrange(() => _mockOriginRepository.GetAllOrigins()).Returns(origins.AsQueryable()).OccursOnce();
            Mock.Arrange(() => _mockDestinationRepository.GetAllDestinations()).Returns(new string[0].AsQueryable());

            var builder = new OrderViewDataBuilder(_mockOriginRepository, _mockDestinationRepository, _mockPackageTypeSelectListBuilder);

            builder.BuildViewData(viewDataDictionary, order);

            Mock.AssertAll(_mockOriginRepository);
            var result = viewDataDictionary["Origins"];
            Assert.IsNotNull(result);
            var resultList = ((IEnumerable<dynamic>) result).ToList();
            Assert.AreEqual(2, resultList.Count());

            Assert.AreEqual("Test Origin 1", resultList[0].Name);
            Assert.AreEqual("Test Origin 1", resultList[0].Value);
            
            Assert.AreEqual("Test Origin 2", resultList[1].Name);
            Assert.AreEqual("Test Origin 2", resultList[1].Value);
        }
开发者ID:turtlechalk,项目名称:ui-for-aspnet-mvc-examples,代码行数:30,代码来源:BuildViewDataShould.cs

示例7: MockedGetAll

		private IQueryable<User> MockedGetAll()
		{
			List<User> users = new List<User>();
			users.Add(new User(Guid.NewGuid(), "komil.patel", "[email protected]", "Komil", "Patel", false, true));
			users.Add(new User(Guid.NewGuid(), "nikki.patel", "[email protected]", "Nikki", "Patel", false, true));
			return users.AsQueryable();
		}
开发者ID:komilp13,项目名称:Abstractools.KB,代码行数:7,代码来源:UserControllerTests.cs

示例8: Given_a_consultant_all_checklists_that_are_visited_by_consultant_are_returned

        public void Given_a_consultant_all_checklists_that_are_visited_by_consultant_are_returned()
        {
            //given
            var consultantToFind = "Mr H&S";
            var expectedIdOfFoundChecklist = Guid.NewGuid();
            var checklists = new List<Checklist>
                                 {
                                     new Checklist() {ClientId = 14145135, QaAdvisor = new QaAdvisor{Id = Guid.NewGuid(), Forename = "Test", Surname = "Test"}}
                                     , new Checklist() {Id= expectedIdOfFoundChecklist, ClientId = 14145135, VisitBy = consultantToFind, ChecklistCreatedBy = consultantToFind, QaAdvisor = new QaAdvisor{Id = Guid.NewGuid(), Forename = "Test", Surname = "Test"}}
                                     , new Checklist() {ClientId = 23452435, QaAdvisor = new QaAdvisor{Id = Guid.NewGuid(), Forename = "Test", Surname = "Test"}}
                                 };

           
            _queryableWrapper.Setup(x => x.Queryable())
                .Returns(() => checklists.AsQueryable());


            var target = new GetChecklistsQuery(_queryableWrapper.Object);

            //when
            var result = target.WithConsultantName(consultantToFind)
                .Execute();

            //then
            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result.First().Id, Is.EqualTo(expectedIdOfFoundChecklist));
        }
开发者ID:mnasif786,项目名称:Business-Safe,代码行数:27,代码来源:GetChecklistsQueryTests.cs

示例9: UnsuccessfulMatchReturnsNotFound

        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();
            var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var list = new List<PersonMapping>();
            repository.Setup(x => x.Queryable<PersonMapping>()).Returns(list.AsQueryable());

            var message = new GetRequest
            {
                EntityId = 0,
            };

            // Act
            var contract = service.Request(message);

            // Assert
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers");
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:25,代码来源:PersonRequestFixture.cs

示例10: Queryable_FirstOne_Should_Return_First_Item

        public void Queryable_FirstOne_Should_Return_First_Item()
        {
            var list = new List<string> { "First", "Second", "Third" };
            var first = list.AsQueryable().FirstOne();

            Assert.AreEqual(first, "First");
        }
开发者ID:remyblok,项目名称:BetterModules,代码行数:7,代码来源:QueryableExtensionsTests.cs

示例11: ItReturnsOnlyGameDefinitionsInTheSpecifiedGamingGroup

        public void ItReturnsOnlyGameDefinitionsInTheSpecifiedGamingGroup()
        {
            const int VALID_GAME_DEFINITION_ID = 1;
            var gameDefinitionList = new List<GameDefinition>
            {
                new GameDefinition
                {
                    Id = VALID_GAME_DEFINITION_ID,
                    Active = true,
                    GamingGroupId = currentUser.CurrentGamingGroupId
                },
                new GameDefinition
                {
                    Id = VALID_GAME_DEFINITION_ID + 1,
                    Active = true,
                    GamingGroupId = currentUser.CurrentGamingGroupId + 1
                }
            };

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<GameDefinition>()).Return(gameDefinitionList.AsQueryable());

            var results = autoMocker.ClassUnderTest.GetAllGameDefinitionNames(this.currentUser.CurrentGamingGroupId);

            Assert.That(results.Count, Is.EqualTo(1));
            Assert.That(results[0].Id, Is.EqualTo(VALID_GAME_DEFINITION_ID));
        }
开发者ID:NemeStats,项目名称:NemeStats,代码行数:26,代码来源:GetAllGameDefinitionNamesTests.cs

示例12: PerfomancesCount_ContextHasPerfomances_ReturnsExpectedCount

        public void PerfomancesCount_ContextHasPerfomances_ReturnsExpectedCount()
        {
            //Arrange
            var expectation = new List<Perfomance>
            {
                new Perfomance{Id = Guid.NewGuid(), Name = "Test"},
                new Perfomance{Id = Guid.NewGuid(), Name = "Test"},
                new Perfomance{Id = Guid.NewGuid(), Name = "Test"}
            };
            var perfomanceDbSet = PerfomanceStubs.CreateDbSet(expectation.AsQueryable());

            var contextMock = new Mock<DbContext>();
            contextMock
                .Setup(x => x.Set<Perfomance>())
                .Returns(perfomanceDbSet);
            mDbContextFactoryMock
                .Setup(x => x.CreateContext())
                .Returns(contextMock.Object);

            //Act
            var executionResult = mClassUnderTest.PerfomancesCount();

            //Assert
            executionResult.ShouldBeEquivalentTo(expectation.Count);
        }
开发者ID:Madster9000,项目名称:MF.Theater,代码行数:25,代码来源:PerfomanceQueriesTests.cs

示例13: TestAsFacade

        public void TestAsFacade()
        {
            var l1 = new List<C0>();
            l1.Add(new C0 { X = 1 });
            l1.Add(new C1 { X = 1, Y = "hello", Z = "goodbye" });
            l1.Add(new C0 { X = 2 });
            l1.Add(new C0 { X = 0 });

            var l2 = new List<C1>();
            l2.Add(new C1 { X = 0, Y = "xyz", Z = "zzz" });
            l2.Add(new C1 { X = 2, Y = "mmm", Z = "nnn" });
            l2.Add(new C1 { X = 1, Y = null, Z = "qqq" });

            var l3 = new List<IHasZ>();
            l3.Add(new C1 { X = 2, Y = "000", Z = "abc" });
            l3.Add(new CX0 { Z = "yyy" });
            l3.Add(new CX0 { Z = "abc" });

            var l4 = new List<IHasZ>();

            IQueryable l1Q = l1.AsQueryable();
            IQueryable l2Q = l2.AsQueryable();
            var out0 = l1Q.AsFacade<C0>().Where(x => x.X == 1).ToList();
            Assert.AreEqual(out0.Count, 2);
            var out1 = l2Q.AsFacade<C0>().Where(x => x.X == 1).ToList();
            Assert.AreEqual(out1.Count, 1);

            IQueryable l3Q = l3.AsQueryable();
            var out3 = l3Q.AsFacade<IHasZ>().Where(x => x.Z == "abc").ToList();
            Assert.AreEqual(out3.Count, 2);
        }
开发者ID:jamesej,项目名称:lynicon,代码行数:31,代码来源:FacadeTest.cs

示例14: Index

        public void Index()
        {
            // Arrange
            var controller = GetHomeController();

            var stores = new List<Store>
                {
                    new Store()
                };

            storeRepositoryMock.Setup( s => s.GetAll() )
                .Returns( stores.AsQueryable() )
                .Verifiable();

            // Act
            var result = controller.Index();

            // Assert
            storeRepositoryMock.Verify();

            Assert.IsInstanceOf<ViewResult>( result );

            var view = (ViewResult)result;

            Assert.IsInstanceOf<List<Store>>( view.Model );
        }
开发者ID:Pajamaman,项目名称:Castle-Fluent-NHibernate-MVC-3,代码行数:26,代码来源:HomeControllerTest.cs

示例15: ItOnlyIncludesRecordsForTheGivenPlayer

        public void ItOnlyIncludesRecordsForTheGivenPlayer()
        {
            //--the player's minion was never their nemesis
            var expectedNemesisRecords = new List<Nemesis>
            {
                new Nemesis
                {
                    NemesisPlayerId = _playerId + 1,
                    MinionPlayerId = _playerId + 2,
                    DateCreated = DateTime.UtcNow,
                    NemesisPlayer = new Player
                    {
                        CurrentAndPriorNemeses = new List<Nemesis>
                        {
                            new Nemesis
                            {
                                NemesisPlayerId = _playerId + 2,
                                MinionPlayerId = _playerId + 1,
                                DateCreated = DateTime.UtcNow.AddDays(-1)
                            }
                        }
                    }
                }
            };
            _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Nemesis>()).Return(expectedNemesisRecords.AsQueryable());

            //--act
            var results = _autoMocker.ClassUnderTest.IsAwardedForThisPlayer(_playerId);

            //--assert
            Assert.That(results.LevelAwarded, Is.Null);
        }
开发者ID:NemeStats,项目名称:NemeStats,代码行数:32,代码来源:PunisherAchievementTests.cs


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