namespace MoqSample.Test
{
[TestFixture]
public class GivenCustomerServiceTest
{
private ICustomerService customerService;
private CustomerModel customer;
// Defining the mock object.
private Mock<ICustomerRepository> mockCustomerRepository;
[SetUp]
public void SetUp()
{
//Creating the mock object.
mockCustomerRepository = new Mock<ICustomerRepository>();
customerService = new CustomerService(mockCustomerRepository.Object);
}
[Test]
public void GetCustomerByIdTest()
{
customer = new CustomerModel { Id = 1, Name = "TEST-CUSTOMER", Address = "abc" };
mockCustomerRepository.Setup(customerRepository => customerRepository.GetCustomerById(1)).Returns(customer);
var customerReturned = customerService.GetCustomerById(1);
//Verifying values.
Assert.AreEqual(customer.Id, customerReturned.Id);
Assert.AreEqual(customer.Name, customerReturned.Name);
Assert.AreEqual(customer.Address, customerReturned.Address);
}
}
}
当我尝试调试上述类中的代码时,它没有达到断点。 我无法调试代码。 欢迎任何建议。