Esempio n. 1
0
        public void Contains_Ok_Status_Code_When_Use_Case_Succeeds()
        {
            // arrange
            var presenter = new UpdateUserByIdPresenter();

            // act
            presenter.Handle(new UpdateUserByIdResponse(1, true));

            // assert
            Assert.Equal((int)HttpStatusCode.OK, presenter.ContentResult.StatusCode);
        }
Esempio n. 2
0
        public void Contains_Errors_When_Use_Case_Fails()
        {
            // arrange
            var presenter = new UpdateUserByIdPresenter();

            // act
            presenter.Handle(new UpdateUserByIdResponse(new[] { "UserId not exists" }, true));

            // assert
            dynamic data = JsonConvert.DeserializeObject(presenter.ContentResult.Content);

            Assert.False(data.success.Value);
            Assert.Equal("missing first name", data.errors.First.Value);
        }
Esempio n. 3
0
        public void Contains_Id_When_Use_Case_Succeeds()
        {
            // arrange
            var presenter = new UpdateUserByIdPresenter();

            // act
            presenter.Handle(new UpdateUserByIdResponse(1, true));

            // assert
            dynamic data = JsonConvert.DeserializeObject(presenter.ContentResult.Content);

            Assert.True(data.success.Value);
            Assert.Equal("2", data.id.Value);
        }
Esempio n. 4
0
 public UserController(IAddAsyncUserUseCase addUserUseCase, AddUserPresenter addUserPresenter,
                       IGetAsyncUserByIdUseCase getUserByIdUseCase, GetUserByIdPresenter getUserByIdPresenter,
                       IGetAsyncUsersUseCase getUsersUseCase, GetUsersPresenter getUsersPresenter,
                       IUpdateAsyncUserByIdUseCase updateUserUseCase, UpdateUserByIdPresenter updateUserPresenter,
                       IDeleteAsyncUserByIdUseCase deleteUserByIdUseCase, DeleteUserByIdPresenter deleteUserByIdPresenter)
 {
     _addAsyncUserUseCase        = addUserUseCase;
     _addUserPresenter           = addUserPresenter;
     _getAsyncUserByIdUseCase    = getUserByIdUseCase;
     _getUserByIdPresenter       = getUserByIdPresenter;
     _getAsyncUsersUseCase       = getUsersUseCase;
     _getUsersPresenter          = getUsersPresenter;
     _updateAsyncUserUseCase     = updateUserUseCase;
     _updateUserPresenter        = updateUserPresenter;
     _deleteAsyncUserByIdUseCase = deleteUserByIdUseCase;
     _deleteUserByIdPresenter    = deleteUserByIdPresenter;
 }
Esempio n. 5
0
        public async void Post_Returns_Ok_When_Update_User_By_Id_Use_Case_Succeeds()
        {
            // arrange
            var mockUserRepository = new Mock <IUserRepository>();

            mockUserRepository
            .Setup(repo => repo.Update("", It.IsAny <User>()))
            .Returns(Task.FromResult(new Core.Dto.GatewayResponses.Repositories.UpdateUserByIdResponse(1, true)));

            // fakes
            var outputAddUserPort        = new AddUserPresenter();
            var outputGetUsersPort       = new GetUsersPresenter();
            var outputGetUserByIdPort    = new GetUserByIdPresenter();
            var outputUpdateUserPort     = new UpdateUserByIdPresenter();
            var outputDeleteUserByIdPort = new DeleteUserByIdPresenter();

            var addUserUseCase        = new AddAsyncUserUseCase(mockUserRepository.Object);
            var getUsersUseCase       = new GetAsyncUsersUseCase(mockUserRepository.Object);
            var getUserByIdUseCase    = new GetAsyncUserByIdUseCase(mockUserRepository.Object);
            var updateUserByIdUseCase = new UpdateAsyncUserByIdUseCase(mockUserRepository.Object);
            var deleteUserByIdUseCase = new DeleteAsyncUserByIdUseCase(mockUserRepository.Object);

            var controller = new UserController(addUserUseCase, outputAddUserPort,
                                                getUserByIdUseCase, outputGetUserByIdPort,
                                                getUsersUseCase, outputGetUsersPort,
                                                updateUserByIdUseCase, outputUpdateUserPort,
                                                deleteUserByIdUseCase, outputDeleteUserByIdPort);

            // act
            var result = await controller.UpdateUserByIdAsync("userIdToUpdate", new UpdateUserRequest()
            {
                Updated_id = 999, Updated_name = "newName", Updated_birthdate = DateTime.Now, Updated_password = "******"
            });

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

            Assert.True(statusCode.HasValue && statusCode.Value == (int)HttpStatusCode.OK);
        }
Esempio n. 6
0
        public async void Post_Returns_Ok_When_Add_User_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(1, true)));

            // fakes
            var outputAddUserPort        = new AddUserPresenter();
            var outputGetUsersPort       = new GetUsersPresenter();
            var outputGetUserByIdPort    = new GetUserByIdPresenter();
            var outputUpdateUserPort     = new UpdateUserByIdPresenter();
            var outputDeleteUserByIdPort = new DeleteUserByIdPresenter();

            var addUserUseCase        = new AddAsyncUserUseCase(mockUserRepository.Object);
            var getUsersUseCase       = new GetAsyncUsersUseCase(mockUserRepository.Object);
            var getUserByIdUseCase    = new GetAsyncUserByIdUseCase(mockUserRepository.Object);
            var updateUserByIdUseCase = new UpdateAsyncUserByIdUseCase(mockUserRepository.Object);
            var deleteUserByIdUseCase = new DeleteAsyncUserByIdUseCase(mockUserRepository.Object);

            var controller = new UserController(addUserUseCase, outputAddUserPort,
                                                getUserByIdUseCase, outputGetUserByIdPort,
                                                getUsersUseCase, outputGetUsersPort,
                                                updateUserByIdUseCase, outputUpdateUserPort,
                                                deleteUserByIdUseCase, outputDeleteUserByIdPort);

            // act
            var result = await controller.AddUserAsync(new Models.Request.AddUserRequest());

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

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