diff options
4 files changed, 9 insertions, 7 deletions
diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs index 9372517..700010c 100644 --- a/src/DevHive.Services/Interfaces/IUserService.cs +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -15,7 +15,7 @@ namespace DevHive.Services.Interfaces Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel); - Task DeleteUser(Guid id); + Task<bool> DeleteUser(Guid id); Task<bool> ValidJWT(Guid id, string rawTokenData); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index f8fe2ed..ec74b5f 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -120,7 +120,7 @@ namespace DevHive.Services.Services #endregion #region Delete - public async Task DeleteUser(Guid id) + public async Task<bool> DeleteUser(Guid id) { if (!await this._userRepository.DoesUserExistAsync(id)) throw new ArgumentException("User does not exist!"); @@ -128,8 +128,7 @@ namespace DevHive.Services.Services User user = await this._userRepository.GetByIdAsync(id); bool result = await this._userRepository.DeleteAsync(user); - if (!result) - throw new InvalidOperationException("Unable to delete user!"); + return result; } #endregion diff --git a/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs index 32f2c56..1abc0f1 100644 --- a/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs +++ b/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs @@ -333,9 +333,9 @@ namespace DevHive.Services.Tests this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(user)); this.UserRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny<User>())).Returns(Task.FromResult(shouldPass)); - //bool result = await this.UserService.DeleteUser(id); + bool result = await this.UserService.DeleteUser(id); - Assert.Pass(); + Assert.AreEqual(shouldPass, result); } [Test] diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index e409eea..f9fb083 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -100,7 +100,10 @@ namespace DevHive.Web.Controllers if (!await this._userService.ValidJWT(id, authorization)) return new UnauthorizedResult(); - await this._userService.DeleteUser(id); + bool result = await this._userService.DeleteUser(id); + if (!result) + return new BadRequestObjectResult("Could not delete User"); + return new OkResult(); } #endregion |
