public async Task Calling_CreateUser_With_Existing_PaymentCustomerId_And_PaymentService_Throws_Exception_Should_Be_Catched_And_Logged() { const string paymentCustomerId = "testPaymentCustomerId"; var exception = new PaymentServiceException("Unable to find the customer"); var user = new UserDao { Id = Guid.NewGuid().ToString(), Email = "*****@*****.**", FirstName = "Test First Name", LastName = "Test Last Name", PaymentCustomerId = paymentCustomerId, SetupIntentId = "TestSetupIntentId", Address = new AddressDao() }; _userRepositoryMock.Setup(s => s.GetUserById(user.Id, _cancellationToken)).Returns(Task.FromResult((UserDao)null)); _paymentServiceMock.Setup(s => s.CreatePaymentCustomer(It.IsAny <UserDao>(), _cancellationToken)).Throws(exception); _pricePlanRepositoryMock.Setup(s => s.GetPricePlanByTitle(Constants.FreePricePlanTitle, _cancellationToken)).Returns(Task.FromResult(new PricePlanDao { Id = "freePricePlanTestId", Title = Constants.FreePricePlanTitle, Price = 0 })); await _userService.CreateUser(user, _cancellationToken); _loggerMock.Verify(s => s.Warning(exception, exception.Message), Times.Once); _userRepositoryMock.Verify(s => s.CreateUser(It.Is <UserDao>(t => t.CurrentPricePlanId.Equals("freePricePlanTestId")), _cancellationToken), Times.Once); }
public async Task Calling_CreateUser_With_Mismatch_User_And_PaymentService_Email_Should_Throw_An_Exception() { var userId = Guid.NewGuid().ToString(); const string paymentCustomerId = "testPaymentCustomerId"; var exception = new PaymentServiceException("Unable to find the customer"); _userRepositoryMock.Setup(s => s.GetUserById(userId, _cancellationToken)).Returns(Task.FromResult(new UserDao())); _paymentServiceMock.Setup(s => s.GetCustomerById(paymentCustomerId, _cancellationToken)).Returns(Task.FromResult(new PaymentCustomerDao { Id = paymentCustomerId, Email = "*****@*****.**" })); _pricePlanRepositoryMock.Setup(s => s.GetPricePlanByTitle(Constants.FreePricePlanTitle, _cancellationToken)).Returns(Task.FromResult(new PricePlanDao { Id = "freePricePlanTestId", Title = Constants.FreePricePlanTitle, Price = 0 })); await _userService .CreateUser( new UserDao { Id = userId, Email = "*****@*****.**", FirstName = "Test First Name", LastName = "Test Last Name", PaymentCustomerId = paymentCustomerId, SetupIntentId = "TestSetupIntentId", Address = new AddressDao() }, _cancellationToken); }