當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。