public async Task CreateAccount_WithCorrectRequest_ReturnStatusCodeOK() { // Arrange var accountRequest = new AccountRequest { AccountIban = "CCCC", FirstName = "test", LastName = "test", Balance = 1000, Email = "*****@*****.**", Address = "123456" }; customerAccountsService .AccountExistsAsync(Arg.Any <AccountRequest>()) .Returns(false); customerAccountsService .CreateAccountAsync(Arg.Any <AccountRequest>()) .Returns(Task.FromResult(new AccountResponse())); // Act var actionResult = await accountsController.CreateAccount(accountRequest); // Assert var requestResult = Assert.IsType <OkObjectResult>(actionResult); Assert.Equal((int)System.Net.HttpStatusCode.OK, requestResult.StatusCode); }
public async Task <IActionResult> CreateAccount([FromBody] AccountRequest accountRequest) { if (accountRequest == null) { return(BadRequest(ModelState)); } var accountExists = await customerAccountsService.AccountExistsAsync(accountRequest); if (accountExists) { ModelState.AddModelError("", "Account exists"); return(BadRequest(ModelState)); } var accountResponse = await customerAccountsService.CreateAccountAsync(accountRequest); return(Ok(accountResponse)); }