本文整理汇总了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());
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}
示例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));
}
示例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();
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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();
}
示例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()));
}