我正在编写一些代码,这些代码遵循将方法的所有参数封装为“请求”对象并返回“响应”对象的模式。但是,这在使用 MOQ 进行模拟时产生了一些问题。例如:
public class Query : IQuery
{
public QueryResponse Execute(QueryRequest request)
{
// get the customer...
return new QueryResponse { Customer = customer };
}
}
public class QueryRequest
{
public string Key { get; set; }
}
public class QueryResponse
{
public Customer Customer { get; set; }
}
...在我的测试中,我想存根查询以在给出密钥时返回客户
var customer = new Customer();
var key = "something";
var query = new Mock<ICustomerQuery>();
// I want to do something like this (but this does not work)
// i.e. I dont care what the request object that get passed is in but it must have the key value I want to give it
query.Setup(q => q.Execute(It.IsAny<QueryRequest>().Key = key))
.Returns(new QueryResponse {Customer = customer});
我想要的最小起订量是可能的吗?