이전에 질문을 받았는지 확실하지 않은 경우 여기에 질문이 나와 있습니다. 첫째Moq를 사용하여 메서드를 조롱 할 때 메서드 인수의 속성 값이 설정되어 있는지 확인하는 방법?
코드 :
public class Customer {
public string Password { get; set; }
public string PasswordHash { get; set; }
}
public class CustomerService {
private ICustomerRepository _repo;
public CustomerService(ICustomerRepository repo) {
_repo = repo;
}
public int? AddCustomer(Customer customer) {
customer.PasswordHash = SHA1Hasher.ComputeHash(customer.Password);
return _repo.Add(customer);
}
}
public interface ICustomerRepository {
int? Add(Customer c);
}
public class CustomerRepository : ICustomerRepository {
int? AddCustomer(Customer customer) {
// call db and return identity
return 1;
}
}
[TestClass]
public class CustomerServiceTest {
[TestMethod]
public void Add_Should_Compute_Password_Hash_Before_Saving() {
var repoMock = new Mock<ICustomerRepository>();
//how do I make sure the password hash was calculated before passing the customer to repository???
}
}
가 어떻게 고객이 리포지토리에 전달하기 전에 PasswordHash를 할당하는 CustomerService를 확인합니까?