c# - 此函数只能在单元测试期间从 LINQ to Entities 错误中调用
问题描述
嗨,我在测试我的方法时遇到问题。我将我的存储库模拟为 DbSet。我的单元测试方法看起来是:
public void Can_change_quantity_of_product()
{
//przygotowanie
var repo = CreateDbSetMock(new List<Processor>
{
new Processor{Product_ID = 1, Quantity = 20},
new Processor{Product_ID = 2, Quantity = 5}
});
var target = new ProductContext();
target.context.Processors = repo.Object;
//działanie
target.SellProduct(new OrderDetails { Product_ID = 1, Quantity = 5 });
//Asercje
Assert.AreEqual(target.TakeProcessors.ToList()[0].Quantity, 15);
}
我在这里得到这个错误:
public IEnumerable<Product> TakeProcessors //Zwraca repozutorium procesorów jako lista klas Product.
{
get
{
return (from x in context.Processors
select new Product
{
ProductID = x.Product_ID,
Title = x.Title,
Price = x.Price,
Quantity = x.Quantity,
FDetail = SqlFunctions.StringConvert(x.Clock, 5, 1),
SDetail = SqlFunctions.StringConvert((double)x.Cores),
TDetail = SqlFunctions.StringConvert((decimal)x.Cache),
OrderDetails = x.OrderDetails,
Promoted = x.Promoted,
SoldPieces = x.OrderDetails.Count() == 0 ? 0 : x.OrderDetails.Sum(y => y.Quantity),
Category = "Procesory"
}).ToList();
}
}
我怎么了?
解决方案
推荐阅读
- c# - 正在发送 HTTP 标头,但 Request.Headers 中不存在
- c# - 如何从 IniFile 加载 Combobox.SelectedItem?
- python - 如何让 python websocket 服务器返回东西?
- dialogflow-es - 如何在 Dialogflow 中处理用户名?
- php - 我的 GET 请求在本地正确重定向但不在线..:/
- html - 限制用户使用 Angular 输入特殊字符
- python - 如何从 redirect_uri 获取访问令牌?
- python - 如何处理包含的数据 \n 而无需在 Python 中为 CSV 输入新单元格?
- authentication - 如何在服务器上对身份验证服务进行本地调用?
- python - Python 是否评估前向引用的类型提示?