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


C# System.Linq.AsQueryable方法代码示例

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


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

示例1: Handle_should_update_correct_size

        public void Handle_should_update_correct_size()
        {
            var widget = new Product { Name = "widget"};
            var gadget = new Product { Name = "gadget"};

            var sizes = new[]
            {
                new Size {Product = widget, Name = "Small", IsActive = false, IsInStock = false},
                new Size {Product = widget, Name = "Medium", IsActive = true, IsInStock = false},
                new Size {Product = widget, Name = "Small", IsActive = true, IsInStock = false}, // should update this one
                new Size {Product = gadget, Name = "Small", IsActive = true, IsInStock = false},
            };

            sizeRepository.GetAllDelegate = () => sizes.AsQueryable();

            var @event = new StockItemInStockChanged("Small", "widget", true);

            handler.Handle(@event);

            sizes[2].IsInStock.ShouldBeTrue();

            sizes[0].IsInStock.ShouldBeFalse();
            sizes[1].IsInStock.ShouldBeFalse();
            sizes[3].IsInStock.ShouldBeFalse();
        }
开发者ID:somlea-george,项目名称:sutekishop,代码行数:25,代码来源:ChangeInStockStatusOnStockItemInStockChangedTests.cs

示例2: FindPackagesOverloadLooksForSearchTermsInSpecificFields

        public void FindPackagesOverloadLooksForSearchTermsInSpecificFields()
        {
            // Arrange
            var packages = new[] {
                PackageUtility.CreatePackage("Foo.Qux", description: "Some desc"),
                PackageUtility.CreatePackage("X-Package", tags: " lib qux "),
                PackageUtility.CreatePackage("Filtered"),
                PackageUtility.CreatePackage("B", description: "This is a package for qux and not one for baz"),
            };

            // Act
            var result1 = packages.AsQueryable().Find(new[] { "Description", "Tags" }, "Qux");
            var result2 = packages.AsQueryable().Find(new[] { "Id" }, "Filtered");

            // Assert
            Assert.Equal(new[] { packages[1], packages[3] }, result1.ToArray());
            Assert.Equal(new[] { packages[2], }, result2.ToArray());
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:18,代码来源:PackageExtensionsTest.cs

示例3: SetUpPagedList

 public void SetUpPagedList(int pageIndex, int pageSize, int? totalCount)
 {
     var collection = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     if (totalCount < 0)
     {
         pagedList = new PagedList<int>(collection.AsQueryable(), pageIndex, pageSize);
     }
     else
     {
         pagedList = new PagedList<int>(collection.AsQueryable(), pageIndex, pageSize, totalCount);
     }
 }
开发者ID:CuriositySoftware,项目名称:curiosity-common,代码行数:12,代码来源:PagedListTests.cs

示例4: GetByName_VirtualMachineDoesNotExist_ReturnsNull

        public void GetByName_VirtualMachineDoesNotExist_ReturnsNull()
        {
            // Arrange
            var machineList = new[]
            {
                new VirtualMachine {Name = "Machine1"},
                new VirtualMachine {Name = "Machine2"},
                new VirtualMachine {Name = "Machine3"}
            };

            var repository = MockRepository.GenerateMock<IVirtualMachineRepository>();
            repository.Expect(x => x.Read())
                .Repeat.Once()
                .Return(machineList.AsQueryable());

            var messenger = MockRepository.GenerateStub<IMessenger>();

            var controller = new VirtualMachinesController(repository, messenger);

            // Act
            var result = controller.Get("FakeMachine");

            // Assert
            Assert.That(result, Is.Null);
        }
开发者ID:jamesology,项目名称:AzureVmFarmer,代码行数:25,代码来源:VirtualMachinesControllerTest.cs

示例5: GetByName_VirtualMachineExists_RepositoryIsCalled

        public void GetByName_VirtualMachineExists_RepositoryIsCalled()
        {
            // Arrange
            var machineList = new[]
            {
                new VirtualMachine {Name = "Machine1"},
                new VirtualMachine {Name = "Machine2"},
                new VirtualMachine {Name = "Machine3"}
            };

            var repository = MockRepository.GenerateMock<IVirtualMachineRepository>();
            repository.Expect(x => x.Read())
                .Repeat.Once()
                .Return(machineList.AsQueryable());

            var messenger = MockRepository.GenerateStub<IMessenger>();

            var controller = new VirtualMachinesController(repository, messenger);

            // Act
            controller.Get("Machine2");

            // Assert
            repository.VerifyAllExpectations();
        }
开发者ID:jamesology,项目名称:AzureVmFarmer,代码行数:25,代码来源:VirtualMachinesControllerTest.cs

示例6: CanExecute

        public void CanExecute()
        {
            //arrange
            var gameRecords = new[] {
                new GameRecord
                {
                    Moves = new[] { new GameMoveRecord{ Value = 0 } },
                },
                new GameRecord
                {
                    Moves = new[] { new GameMoveRecord() },
                },
            };

            var repoMock = new Mock<IRepository>();
            repoMock.Setup(x => x.Query<GameRecord>()).Returns(gameRecords.AsQueryable());

            var query = new FindGames();
            var handler = new FindGamesHandler(repoMock.Object);

            //act
            var result = handler.Execute(query);

            //assert
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(100, result.First().PercentageComplete);
            Assert.AreEqual(0, result.Last().PercentageComplete);
        }
开发者ID:bumblebeetuna,项目名称:Sudoku,代码行数:28,代码来源:FindGamesHandlerFixture.cs

示例7: Main

 static void Main()
 {
     var languages = new[] { "C#", "J#", "VB", "Delphi", "F#", "COBOL", "Python" };
     var queryable = languages.AsQueryable().Where(l => l.EndsWith("#") && l != "j#")
         .Take(3).Select(l => new { Name = l, IsSelected = true });
     new VisualizerDevelopmentHost(queryable.Expression, typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeObjectSource)).ShowVisualizer();
 }
开发者ID:rob3c,项目名称:exprtreevisualizer,代码行数:7,代码来源:Program.cs

示例8: It_gets_an_expression_to_map_A_to_B

        public void It_gets_an_expression_to_map_A_to_B()
        {
            mapper.Map<A, B>();
            var expr = mapper.GetMapExpression<A, B>();

            var objects = new[]{new A{String="hello world", Int=42}, new A{String="Magic", Int=8}};
            var mapped = objects.AsQueryable().Select(expr);

            Assert.False (mapped.Any (x => x.String == null));
        }
开发者ID:tkellogg,项目名称:Cortez,代码行数:10,代码来源:MapperTests.cs

示例9: When

        public override void When()
        {
            this.matchingUserConfiguration = new UserConfiguration { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = TestValues.CONFIGURATION_ROW_KEY };
            var nonMatchingUserConfiguration1 = new UserConfiguration { PartitionKey = "Non-matchingPartitionKey", RowKey = TestValues.CONFIGURATION_ROW_KEY };
            var nonMatchingUserConfiguration2 = new UserConfiguration { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = "Non-matchingRowKey" };
            var userConfigurations = new[] { this.matchingUserConfiguration, nonMatchingUserConfiguration1, nonMatchingUserConfiguration2 };
            this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(userConfigurations.AsQueryable());

            this.userConfiguration = this.UserConfigurationRepository.GetByNameIdentifier();
        }
开发者ID:aenmeyk,项目名称:BrainThud,代码行数:10,代码来源:When_GetByNameIdentifier_is_called.cs

示例10: WhenCreatingSelectExpressionFromXmlMemberOnPropertyThenGetsPropertyValue

		public void WhenCreatingSelectExpressionFromXmlMemberOnPropertyThenGetsPropertyValue()
		{
			var nameResolver = new MemberNameResolver();
			var factory = new SelectExpressionFactory<FakeItem>(nameResolver, new RuntimeTypeProvider(nameResolver));
			var items = new[] { new FakeItem { IntValue = 2 } };

			var expression = factory.Create("Number");

			dynamic result = items.AsQueryable().Select(expression).First();

			Assert.AreEqual(2, result.Number);
		}
开发者ID:calebjenkins,项目名称:Highway.Data,代码行数:12,代码来源:SelectExpressionFactoryTests.cs

示例11: WhenCreatingSelectExpressionFromDataMemberOnFieldThenGetsFieldValue

		public void WhenCreatingSelectExpressionFromDataMemberOnFieldThenGetsFieldValue()
		{
			var nameResolver = new MemberNameResolver();
			var factory = new SelectExpressionFactory<FakeItem>(nameResolver, new RuntimeTypeProvider(nameResolver));
			var items = new[] { new FakeItem { StringValue = "test" } };

			var expression = factory.Create("Text");

			dynamic result = items.AsQueryable().Select(expression).First();

			Assert.AreEqual("test", result.Text);
		}
开发者ID:calebjenkins,项目名称:Highway.Data,代码行数:12,代码来源:SelectExpressionFactoryTests.cs

示例12: TestFindLatest

        public void TestFindLatest()
        {
            var context = new Mock<Context>();
            var rates = new[] { new Rate { CurrencyCode = "EUR" }, new Rate { CurrencyCode = "USD" } };
            var contextRates = DbSetMockBuilder.Build(rates.AsQueryable());

            context.Setup(c => c.Rates).Returns(contextRates.Object);

            var currencyRatesService = new CurrencyRatesService(context.Object);
            var latestRates = currencyRatesService.FindLatest();

            Assert.That(latestRates, Is.EqualTo(rates));
        }
开发者ID:Lc5,项目名称:CurrencyRates,代码行数:13,代码来源:CurrencyRatesServiceTest.cs

示例13: It_gets_an_expression_to_map_aggregate_to_aggregate

        public void It_gets_an_expression_to_map_aggregate_to_aggregate()
        {
            mapper.Map<AggregateA, AggregateB> ();
            var expr = mapper.GetMapExpression<AggregateA, AggregateB> ();

            var objects = new[] {
                new AggregateA {Prop=new A{String="hello world", Int=42}},
                new AggregateA{Prop=new A{String="Magic", Int=8}}
            };
            var mapped = objects.AsQueryable ().Select (expr);

            Assert.False (mapped.Any (x => x.Prop == null || x.Prop.String == null));
        }
开发者ID:tkellogg,项目名称:Cortez,代码行数:13,代码来源:MapperTests.cs

示例14: Because_of

        protected override void Because_of()
        {
            var sourceList = new[]
            {
                new Source
                {
                    Child1 = new ChildSource(),
                    Child2 = new ChildSource(),
                    Child3 = new ChildSource()
                }
            };

            _dests = sourceList.AsQueryable().ProjectTo<Dest>(d => d.Child2).ToArray();
        }
开发者ID:mwpowellhtx,项目名称:MicroMapper,代码行数:14,代码来源:ExplicitExpansion.cs

示例15: TestFind

        public void TestFind()
        {
            var context = new Mock<Context>();
            var rates = new[] { new Rate { Id = 123, CurrencyCode = "EUR" } };
            var contextRates = DbSetMockBuilder.Build(rates.AsQueryable());

            contextRates.Setup(cr => cr.Include("File")).Returns(contextRates.Object);
            context.Setup(c => c.Rates).Returns(contextRates.Object);

            var currencyRatesService = new CurrencyRatesService(context.Object);
            var rate = currencyRatesService.Find(123);

            Assert.That(rate, Is.EqualTo(rates.First()));
        }
开发者ID:Lc5,项目名称:CurrencyRates,代码行数:14,代码来源:CurrencyRatesServiceTest.cs


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