コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }