Post() private method

private Post ( RegisterModel model ) : Task
model RegisterModel
return Task
        public void Post_Test()
        {
            #region === ARRANGE ===

            Mock <IApplicationServicesFactory>   mockApplicationServicesFactory = new Mock <IApplicationServicesFactory>();
            Mock <IUserCommandsService>          mockUserCommandsService        = new Mock <IUserCommandsService>();
            Mock <ILogger <AccountsController> > mockLoger = new Mock <ILogger <AccountsController> >();
            AccountsController usersController             = new AccountsController(mockLoger.Object, mockApplicationServicesFactory.Object);

            mockApplicationServicesFactory.Setup(x => x.CreateUserCommandsService()).Returns(mockUserCommandsService.Object);

            #endregion

            #region === ACT ===

            usersController.Post(new SignUpUser());

            #endregion

            #region === ASSERT ===

            mockUserCommandsService.Verify(mock => mock.SignUpNewUser(It.IsAny <SignUpUser>()), Times.Once());

            #endregion
        }
Ejemplo n.º 2
0
        public void TestAdd()
        {
            // arrange
            var context    = CreateDbContext();
            var controller = new AccountsController(context);

            var account = new Account()
            {
                Id   = 4,
                Name = "Dan",
            };

            // act
            var result   = controller.Post(account);
            var okResult = result as OkObjectResult;
            var data     = (okResult.Value as Account);

            // assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsNotNull(data);
            Assert.AreEqual("Dan", account.Name);
            Assert.AreEqual(4, account.Id);
        }
        public void Post()
        {
            // Arrange
            AccountsController controller = new AccountsController();

            // Act
            controller.Post("value");

            // Assert
        }
Ejemplo n.º 4
0
            public void IgnoresNonZeroUserIdForMerchantAccount()
            {
                // Arrange.
                this.account.IsUserAccount = false;
                this.account.UserId        = 123;

                // Act.
                AccountsController controller = new AccountsController(this.mockAccountsRepository.Object);
                IActionResult      result     = controller.Post(this.account);
                OkObjectResult     okResult   = result as OkObjectResult;

                // Assert.
                this.mockAccountsRepository.Verify(m => m.Add(It.Is <Account>(x => x.UserId == 123), It.IsAny <long>()), Times.Once, "The user ID for the entity should not have changed.");
            }
Ejemplo n.º 5
0
            public void AddsUserIdToBankAccountWithNullUserId()
            {
                // Arrange.
                this.account.IsUserAccount = true;
                this.account.UserId        = null;

                // Act.
                AccountsController controller = new AccountsController(this.mockAccountsRepository.Object);
                IActionResult      result     = controller.Post(this.account);
                OkObjectResult     okResult   = result as OkObjectResult;

                // Assert.
                this.mockAccountsRepository.Verify(m => m.Add(It.Is <Account>(x => x.UserId == this.userId), It.IsAny <long>()), Times.Once, "The user ID should have been added to the entity.");
            }
Ejemplo n.º 6
0
        public async void Post_Returns_Bad_Request_When_Model_Validation_Fails()
        {
            // arrange
            var controller = new AccountsController(null, null);

            controller.ModelState.AddModelError("FirstName", "Required");

            // act
            var result = await controller.Post(null);

            // assert
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.IsType <SerializableError>(badRequestResult.Value);
        }
Ejemplo n.º 7
0
            public void ReturnsRepositoryResult()
            {
                // Act.
                AccountsController controller = new AccountsController(this.mockAccountsRepository.Object);
                IActionResult      result     = controller.Post(this.account);
                OkObjectResult     okResult   = result as OkObjectResult;

                // Assert.
                this.mockAccountsRepository.Verify(m => m.Add(this.account, this.userId), Times.Once, "The add method should have been called.");
                this.mockAccountsRepository.VerifyNoOtherCalls();

                Assert.IsNotNull(okResult, "An OK response should have been returned.");
                Assert.AreEqual(200, okResult.StatusCode, "The status code from the response should have been 200.");
                Assert.AreEqual(this.stubAccount, okResult.Value, "The result from the repository should have been returned.");
            }
Ejemplo n.º 8
0
        public async Task Post()
        {
            _mediator
            .Setup(m => m.Send(
                       It.IsAny <IRequest <AccountResponse> >(),
                       default))
            .ReturnsAsync(
                Success <ErrorMsg, TryOptionAsync <AccountViewModel> >(
                    TryOptionAsync(AccountViewModel.New(
                                       AccountState.New(Guid.NewGuid())))
                    ));

            var result = await _controller.Post(new AccountTransaction());

            Assert.IsType <OkObjectResult>(result);
        }
Ejemplo n.º 9
0
        public async Task Post(CustomerRegistrationViewModel mockModel)
        {
            try
            {
                await _context.GetContext();

                var controller = new AccountsController(MockHelper.GetUserManager(new UserStore <AppUser>(_context.Context)), MockHelper.Mapper.Value, _context.Context, MockHelper.MockLogger <AccountsController>());

                var result = await controller.Post(mockModel);

                result.Should().BeOfType <OkObjectResult>().Which.Value.Should().Be("Account created");
            }
            finally
            {
                _context.Close();
            }
        }
            public async Task Returns_Created_With_Valid_Request(
                CreateAccountCommand command,
                AccountModel model,
                [Frozen] Mock <IMediator> mediator,
                AccountsController sut)
            {
                mediator.Setup(p => p.Send(It.IsAny <IRequest <AccountModel> >(), It.IsAny <CancellationToken>())).ReturnsAsync(model);

                if (await sut.Post(command) is CreatedResult message)
                {
                    var returnModel = (AccountModel)message.Value;

                    Assert.True(message.StatusCode == 201);
                    Assert.True(message.Location == $"api/accounts/{returnModel.AccountId}");
                    Assert.True((AccountModel)message.Value == model);
                }
            }
Ejemplo n.º 11
0
            public void HandlesGeneralException()
            {
                // Arrange.
                this.mockAccountsRepository
                .Setup(m => m.Add(It.IsAny <Account>(), It.IsAny <long>()))
                .Throws(new Exception());

                // Act.
                AccountsController controller   = new AccountsController(this.mockAccountsRepository.Object);
                IActionResult      result       = controller.Post(this.account);
                ObjectResult       objectResult = result as ObjectResult;

                // Assert.
                Assert.IsNotNull(objectResult, "An object result should have been returned.");
                Assert.AreEqual(500, objectResult.StatusCode, "The status code from the response should have been 500.");
                string expectedMessage = "There was an error saving the account.";

                Assert.AreEqual(expectedMessage, objectResult.Value, "The error message should have been the result.");
            }
Ejemplo n.º 12
0
            public void ReturnsBadRequestErrorWhenAccountNull()
            {
                // Arrange.
                this.account = null;

                // Act.
                AccountsController     controller       = new AccountsController(this.mockAccountsRepository.Object);
                IActionResult          result           = controller.Post(this.account);
                BadRequestObjectResult badRequestResult = result as BadRequestObjectResult;

                // Assert.
                this.mockAccountsRepository.VerifyNoOtherCalls();

                Assert.IsNotNull(badRequestResult, "A bad request response should have been returned.");
                Assert.AreEqual(400, badRequestResult.StatusCode, "The status code from the response should have been 405.");
                string expectedMessage = "An account must be passed in for it to be saved.";

                Assert.AreEqual(expectedMessage, badRequestResult.Value, "The error message should have been the result.");
            }
Ejemplo n.º 13
0
        public void Insert_New_Account()
        {
            var mockrepo = SetupAccountMockRepo();
            var acc      = new Account
            {
                Id         = 3,
                Name       = "Account Three",
                Created    = DateTime.UtcNow,
                CreatedBy  = @"AU\\Dwayne.Apostolov",
                Modified   = DateTime.UtcNow,
                ModifiedBy = @"AU\\Dwayne.Apostolov"
            };
            var controller  = new AccountsController(mockrepo.Object);
            var apiResponse = controller.Post(acc);

            var okResult = apiResponse.Should().BeOfType <OkObjectResult>().Subject;
            var account  = okResult.Value.Should().BeAssignableTo <Account>().Subject;

            account.Id.Should().Be(3);
        }
Ejemplo n.º 14
0
        public async Task ShouldReturnPresenterCorrectly()
        {
            AssumeUseCaseRun();

            var createAccountRequest = new CreateAccountRequest()
            {
                Name = "Account 1"
            };

            var result = await _sut.Post(createAccountRequest);

            Assert.NotNull(result);
            Assert.IsType <CreatedAtRouteResult>(result);

            var createdAtRouteResult = (CreatedAtRouteResult)result;

            Assert.IsType <CreateAccountOutput>(createdAtRouteResult.Value);

            var createdAccountOutput = (CreateAccountOutput)createdAtRouteResult.Value;

            Assert.Equal("Account 1", (createdAccountOutput.AccountName));
        }
Ejemplo n.º 15
0
        public async void Post_Returns_Ok_When_Use_Case_Succeeds()
        {
            // arrange
            var mockUserRepository = new Mock <IUserRepository>();

            mockUserRepository
            .Setup(repo => repo.Create(It.IsAny <User>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new CreateUserResponse("", true)));

            // fakes
            var outputPort = new RegisterUserPresenter();
            var useCase    = new RegisterUserUseCase(mockUserRepository.Object);

            var controller = new AccountsController(useCase, outputPort);

            // act
            var result = await controller.Post(new RegisterUserRequest());

            // assert
            var statusCode = ((ContentResult)result).StatusCode;

            Assert.True(statusCode.HasValue && statusCode.Value == (int)HttpStatusCode.OK);
        }