Pracuję nad kodem, który jest wzorowany na enkapsulacji wszystkich argumentów metody jako obiektu "request" i zwracaniu obiektu "response". Jednak spowodowało to pewne problemy, jeśli chodzi o drwi z MOQ. Na przykład:Wartość właściwości stubbowania MOQ na obiekcie "Any"
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; }
}
... w moim teście Chcę skrótową zapytanie do zwrotu klientowi, gdy klucz jest podany
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});
jest to, co chcemy w MOQ możliwe?
Niezła, dzięki! – nashwan