I'm new to NSubstitute, I'm trying to make fun of the void method with 2 out parameters, and I'm sure I'm doing it wrong.
I have a CustomerDataAccess class that has a method with the following signature:
void GetCustomerWithAddresses(int customerId, out List<Customer> customers, out List<Address> addresses);
CustomerRepository calls its GetCustomer method, which then calls the CustomerDataAccess.GetCustomerWithAddresses DAL method. The DAL method then outputs two out parameters, one for the client and one for the addresses. The repository method then uses AutoMapper to map the two objects from the DAL method to the business domain, which then returns the repository.
Here is the code that I have and it does not work. My research did not help me determine what I need to do to fix this problem. How to set the value of my out parameters?
// Arange ICustomerDataAccess customerDataAccess = Substitute.For<ICustomerDataAccess>(); IList<Customer> customers; IList<Address> addresses; customerDataAccess.When(x => x.GetCustomerWithAddresses( 1, out customers, out addresses)) .Do(x => { customers = new List<Customer>() { new Customer() { CustomerId = 1, CustomerName = "John Doe" } }; addresses = new List<Address>() { new Address() { AddressId = 1, AddressLine1 = "123 Main St", City = "Atlanta" } }; }); CustomerRepository sut = new CustomerRepository(customerDataAccess); // Act Customer customer = sut.GetCustomer(1); // Assert Assert.IsNotNull(customer);
source share