本文整理汇总了C#中System.Collections.Generic.List.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.AsQueryable方法的具体用法?C# System.Collections.Generic.List.AsQueryable怎么用?C# System.Collections.Generic.List.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.AsQueryable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverlappingIdentifierFails
public void OverlappingIdentifierFails()
{
// Assert
var start = new DateTime(1999, 1, 1);
var finish = new DateTime(2020, 12, 31);
var validity = new DateRange(start, finish);
var system = new SourceSystem { Name = "Test" };
var expected = new SourceSystemMapping { System = system, MappingValue = "1", Validity = validity };
var list = new System.Collections.Generic.List<SourceSystemMapping> { expected };
var repository = new Mock<IRepository>();
repository.Setup(x => x.Queryable<SourceSystemMapping>()).Returns(list.AsQueryable());
var identifier = new EnergyTrading.Mdm.Contracts.MdmId
{
SystemName = "Test",
Identifier = "1",
StartDate = start.AddHours(5),
EndDate = start.AddHours(10)
};
var request = new AmendMappingRequest() { EntityId = 1, Mapping = identifier, MappingId = 1 };
var rule = new AmendMappingNoOverlappingRule<SourceSystemMapping>(repository.Object);
// Act
var result = rule.IsValid(request);
// Assert
repository.Verify(x => x.Queryable<SourceSystemMapping>());
Assert.IsFalse(result, "Rule failed");
}
示例2: Can_Remove_Product_From_Cart
public void Can_Remove_Product_From_Cart()
{
// Arrange: Set up a mock repository with two products
var mockProductsRepos = new Moq.Mock<IProductsRepository>();
var products = new System.Collections.Generic.List<Product> {
new Product { ProductID = 14, Name = "Much Ado About Nothing" },
new Product { ProductID = 27, Name = "The Comedy of Errors" },
};
mockProductsRepos.Setup(x => x.Products)
.Returns(products.AsQueryable());
var cart = new Cart();
cart.AddItem(products[1], 2); // 2x Comedy of Errors
cart.AddItem(products[0], 3); // 3x Much Ado
var controller = new CartController(mockProductsRepos.Object, null);
// Act: Try removing Much Ado
RedirectToRouteResult result =
controller.RemoveFromCart(cart, 14, "someReturnUrl");
// Assert
Assert.AreEqual(1, cart.Lines.Count);
Assert.AreEqual("The Comedy of Errors", cart.Lines[0].Product.Name);
Assert.AreEqual(2, cart.Lines[0].Quantity);
// Check that the visitor was redirected to the cart display screen
Assert.AreEqual("Index", result.RouteValues["action"]);
Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
}
示例3: Handle_should_update_product_names_on_stockItems
public void Handle_should_update_product_names_on_stockItems()
{
var dateCreated = new DateTime(2011, 2, 15);
var stockItems = new System.Collections.Generic.List<StockItem>()
{
StockItem.Create("Widget", "Small", dateCreated, "[email protected]"),
StockItem.Create("Widget", "Medium", dateCreated, "[email protected]"),
StockItem.Create("Widget", "Large", dateCreated, "[email protected]"),
StockItem.Create("Gadget", "Small", dateCreated, "[email protected]"),
};
stockItemRepository.GetAllDelegate = () => stockItems.AsQueryable();
var @event = new ProductNameChangedEvent("Widget", "Widget_Plus");
handler.Handle(@event);
stockItems[0].ProductName.ShouldEqual("Widget_Plus");
stockItems[1].ProductName.ShouldEqual("Widget_Plus");
stockItems[2].ProductName.ShouldEqual("Widget_Plus");
stockItems[3].ProductName.ShouldEqual("Gadget");
stockItems[2].History[1].Description.ShouldEqual("Product name changed from 'Widget' to 'Widget_Plus'");
}
示例4: OrderDispatchedEvent_should_work_with_default_sizes
public void OrderDispatchedEvent_should_work_with_default_sizes()
{
// create the event
var order = new Order(345);
order.Lines.Add(new OrderLine("Widget", "-", 2));
var @event = new OrderDispatchedEvent(order);
// create existing stock items
var dateCreated = new DateTime(2011, 2, 15);
var stockItems = new System.Collections.Generic.List<StockItem>()
{
StockItem.Create("Widget", "-", dateCreated, "[email protected]"),
};
// create some initial stock
stockItems[0].ReceiveStock(10, dateCreated, user);
stockItems[0].Deactivate(dateCreated, user);
stockItemRepository.GetAllDelegate = () => stockItems.AsQueryable();
// execute
decrementStockLevelOnOrderDispatchedEvent.Handle(@event);
// assert
stockItems[0].Level.ShouldEqual(8); // 10-2 = 8
}
示例5: SizesDeactivatedEvent_should_deactivate_all_stockItems
public void SizesDeactivatedEvent_should_deactivate_all_stockItems()
{
var dateCreated = new DateTime(2011, 2, 15);
var stockItems = new System.Collections.Generic.List<StockItem>()
{
StockItem.Create("Widget", "Small", dateCreated, "[email protected]"),
StockItem.Create("Widget", "Small", dateCreated, "[email protected]"),
StockItem.Create("Widget", "Small", dateCreated, "[email protected]"),
StockItem.Create("Gadget", "Small", dateCreated, "[email protected]"),
};
stockItemRepository.GetAllDelegate = () => stockItems.AsQueryable();
var @event = new SizesDeactivatedEvent("Widget");
deactiveStockItemsOnSizesDeactivatedEvent.Handle(@event);
stockItems[0].IsActive.ShouldBeFalse();
stockItems[0].History[1].DateTime.ShouldEqual(now);
stockItems[0].History[1].User.ShouldEqual(user);
stockItems[1].IsActive.ShouldBeFalse();
stockItems[2].IsActive.ShouldBeFalse();
stockItems[3].IsActive.ShouldBeTrue();
}
示例6: BindTo_should_return_the_correct_select_list
public void BindTo_should_return_the_correct_select_list()
{
var ids = new[] {2, 3};
var loopups = new System.Collections.Generic.List<ComboForLookup>()
{
new ComboForLookup {Id = 1, Name = "one"},
new ComboForLookup {Id = 2, Name = "two"},
new ComboForLookup {Id = 3, Name = "three"},
new ComboForLookup {Id = 4, Name = "four"},
};
repository.Stub(x => x.GetAll()).Return(loopups.AsQueryable());
var result = comboFor.Multiple().BoundTo("PropertyName", ids);
//Console.Out.WriteLine("result = {0}", result);
result.ShouldEqual(expectedSelectList);
}
示例7: SystemMissingFails
public void SystemMissingFails()
{
// Assert
var systemList = new System.Collections.Generic.List<SourceSystem>();
var repository = new Mock<IRepository>();
repository.Setup(x => x.Queryable<SourceSystem>()).Returns(systemList.AsQueryable());
var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1" };
var rule = new MdmIdSystemExistsRule(repository.Object);
// Act
var result = rule.IsValid(identifier);
// Assert
repository.Verify(x => x.Queryable<SourceSystem>());
Assert.IsFalse(result, "Rule failed");
}