public CustomerRegistrationServiceTests() { _repo = Substitute.For <ICustomerRepository>(); _gateway = Substitute.For <IGateway>(); _repo.RegisterCustomerTwo(Arg.Any <string>()).Returns(Result.Ok(new Customer())); _gateway.SendMailTwo(Arg.Any <string>()).Returns(Result.Ok(new Customer())); }
private CustomerCreatedResponse ImplementationTwo(CreateCustomerRequest request) { return(_repository.RegisterCustomerTwo("name") .OnSuccess(customer => _gateway.SendMailTwo(customer.Name)) .OnBoth(x => x.IsSuccess ? new CustomerCreatedResponse { CustomerId = x.Value.Id } : new CustomerCreatedResponse { IsSuccess = false, ErrorMessage = x.Error })); }
public void RegisterCustomer_with_failing_gateway_returns_failure_response() { var sut = new CustomerRegistrationService(_repo, _gateway); Dtos.CreateCustomerRequest request = new Dtos.CreateCustomerRequest { Name = "Foo" }; _gateway.SendMailTwo(Arg.Any <string>()).Returns(Result.Fail <Customer>("send mail new Customer()")); var response = sut.RegisterCustomer(request); response.IsSuccess.Should().BeFalse("because we are NOT in the happy case"); }