public void Contains_Ok_Status_Code_When_Use_Case_Succeeds() { // arrange var presenter = new GetUserByIdPresenter(); // act presenter.Handle(new GetUserByIdResponse(new User(1, "name", DateTime.Now, "password"), true)); // assert Assert.Equal((int)HttpStatusCode.OK, presenter.ContentResult.StatusCode); }
public void Contains_Errors_When_Use_Case_Fails() { // arrange var presenter = new GetUserByIdPresenter(); // act presenter.Handle(new GetUserByIdResponse(new Core.Dto.Error[] { new Core.Dto.Error("ERR404", "Error Description") }, true)); // assert dynamic data = JsonConvert.DeserializeObject(presenter.ContentResult.Content); Assert.False(data.success.Value); Assert.Equal("missing first name", data.errors.First.Value); }
public void Contains_Id_When_Use_Case_Succeeds() { // arrange var presenter = new GetUserByIdPresenter(); // act presenter.Handle(new GetUserByIdResponse(new User(2, "name", DateTime.Now, "password"), true)); // assert dynamic data = JsonConvert.DeserializeObject(presenter.ContentResult.Content); Assert.True(data.success.Value); Assert.Equal("2", data.id.Value); }
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; }
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); }
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); }