From 6543751dcb97a64b115bdb68a594a767a676ee14 Mon Sep 17 00:00:00 2001 From: Vanderlan Gomes Date: Thu, 27 Jul 2023 16:43:58 -0300 Subject: [PATCH] Fix unit tests naming (#15) * Update packages * Namming adjustments and minor fixes --- VBaseProject.Api/Controllers/AuthController.cs | 4 ++-- VBaseProject.Api/Controllers/UsersController.cs | 2 +- VBaseProject.Api/VBaseProject.Api.csproj | 14 +++++++------- VBaseProject.Api/ValidateModelStateAttribute .cs | 16 ---------------- VBaseProject.Data/VBaseProject.Data.csproj | 6 +++--- .../Implementation/UserService.cs | 12 ++++++------ VBaseProject.Domain/Interfaces/IUserService.cs | 6 +++--- VBaseProject.Resources/Messages/MessagesKeys.cs | 2 +- .../VBaseProject.Resources.csproj | 2 +- VBaseProject.Test/API/HealthCheckApiTest.cs | 2 +- .../Controllers/AuthControllerTest.cs | 12 ++++++------ .../Controllers/CustomersControllerTest.cs | 11 +++++------ .../Controllers/UsersControllerTest.cs | 2 +- VBaseProject.Test/Services/UserServiceTest.cs | 14 +++++++------- VBaseProject.Test/VBaseProject.Test.csproj | 12 ++++++------ 15 files changed, 50 insertions(+), 67 deletions(-) delete mode 100644 VBaseProject.Api/ValidateModelStateAttribute .cs diff --git a/VBaseProject.Api/Controllers/AuthController.cs b/VBaseProject.Api/Controllers/AuthController.cs index e9fc70a..d858407 100644 --- a/VBaseProject.Api/Controllers/AuthController.cs +++ b/VBaseProject.Api/Controllers/AuthController.cs @@ -45,7 +45,7 @@ public async Task Login([FromBody] UserLoginModel model) [HttpPost] public async Task RefreshToken([FromBody] RefreshTokenModel refreshTokenModel) { - var userOutput = _mapper.Map(await _userService.GetUserByRefreshToken(refreshTokenModel.RefreshToken)); + var userOutput = _mapper.Map(await _userService.GetUserByRefreshTokenAsync(refreshTokenModel.RefreshToken)); return await AuthorizeUser(userOutput); } @@ -56,7 +56,7 @@ private async Task AuthorizeUser(UserOutput userOutput) { var token = CreateToken(userOutput); - var refreshToken = await _userService.AddRefreshToken(new RefreshToken { Email = userOutput.Email, Refreshtoken = Guid.NewGuid().ToString().ToSha512()}); + var refreshToken = await _userService.AddRefreshTokenAsync(new RefreshToken { Email = userOutput.Email, Refreshtoken = Guid.NewGuid().ToString().ToSha512()}); return Ok( new UserApiTokenModel diff --git a/VBaseProject.Api/Controllers/UsersController.cs b/VBaseProject.Api/Controllers/UsersController.cs index 35b70c7..cf99ce8 100644 --- a/VBaseProject.Api/Controllers/UsersController.cs +++ b/VBaseProject.Api/Controllers/UsersController.cs @@ -30,7 +30,7 @@ public UsersController(IUserService userService, IMapper mapper) : base(mapper) [ProducesResponseType((int)HttpStatusCode.OK)] public async Task Get([FromQuery] UserFilter filter) { - var user = await _userService.ListPaginate(filter); + var user = await _userService.ListPaginateAsync(filter); var userOutputList = _mapper.Map>(user); diff --git a/VBaseProject.Api/VBaseProject.Api.csproj b/VBaseProject.Api/VBaseProject.Api.csproj index 128fe8b..d982564 100644 --- a/VBaseProject.Api/VBaseProject.Api.csproj +++ b/VBaseProject.Api/VBaseProject.Api.csproj @@ -14,7 +14,7 @@ all - + @@ -23,14 +23,14 @@ - + - - - - - + + + + + diff --git a/VBaseProject.Api/ValidateModelStateAttribute .cs b/VBaseProject.Api/ValidateModelStateAttribute .cs deleted file mode 100644 index 7727e05..0000000 --- a/VBaseProject.Api/ValidateModelStateAttribute .cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace VBaseProject.Api -{ - public class ValidateModelStateAttribute : ActionFilterAttribute - { - public override void OnActionExecuting(ActionExecutingContext context) - { - if (!context.ModelState.IsValid) - { - context.Result = new BadRequestObjectResult(context.ModelState); - } - } - } -} diff --git a/VBaseProject.Data/VBaseProject.Data.csproj b/VBaseProject.Data/VBaseProject.Data.csproj index e70b995..5e697f5 100644 --- a/VBaseProject.Data/VBaseProject.Data.csproj +++ b/VBaseProject.Data/VBaseProject.Data.csproj @@ -11,9 +11,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/VBaseProject.Domain/Implementation/UserService.cs b/VBaseProject.Domain/Implementation/UserService.cs index 5df0f6f..684972e 100644 --- a/VBaseProject.Domain/Implementation/UserService.cs +++ b/VBaseProject.Domain/Implementation/UserService.cs @@ -79,12 +79,12 @@ public async Task UpdateAsync(User user) await _unitOfWork.CommitAsync(); } - public async Task AddRefreshToken(RefreshToken refreshToken) + public async Task AddRefreshTokenAsync(RefreshToken refreshToken) { - var existentRt = await _unitOfWork.RefreshTokenRepository.GetBy(x => x.Email == refreshToken.Email); + var existantRt = await _unitOfWork.RefreshTokenRepository.GetBy(x => x.Email == refreshToken.Email); - if (existentRt.Any()) - return existentRt.First(); + if (existantRt.Any()) + return existantRt.First(); var added = await _unitOfWork.RefreshTokenRepository.AddAsync(refreshToken); await _unitOfWork.CommitAsync(); @@ -92,7 +92,7 @@ public async Task AddRefreshToken(RefreshToken refreshToken) return added; } - public async Task GetUserByRefreshToken(string refreshToken) + public async Task GetUserByRefreshTokenAsync(string refreshToken) { if (string.IsNullOrEmpty(refreshToken)) { @@ -120,7 +120,7 @@ public async Task GetUserByRefreshToken(string refreshToken) throw new UnauthorizedUserException(_messages[UserMessages.InvalidRefreshToken], _messages[ExceptionsTitles.AuthenticationError]); } - public async Task> ListPaginate(UserFilter filter) + public async Task> ListPaginateAsync(UserFilter filter) { return await _unitOfWork.UserRepository.ListPaginate(filter); } diff --git a/VBaseProject.Domain/Interfaces/IUserService.cs b/VBaseProject.Domain/Interfaces/IUserService.cs index 54e0768..9dce54b 100644 --- a/VBaseProject.Domain/Interfaces/IUserService.cs +++ b/VBaseProject.Domain/Interfaces/IUserService.cs @@ -9,8 +9,8 @@ namespace VBaseProject.Domain.Interfaces public interface IUserService : IBaseService { Task LoginAsync(string email, string password); - Task AddRefreshToken(RefreshToken refreshToken); - Task GetUserByRefreshToken(string refreshToken); - Task> ListPaginate(UserFilter filter); + Task AddRefreshTokenAsync(RefreshToken refreshToken); + Task GetUserByRefreshTokenAsync(string refreshToken); + Task> ListPaginateAsync(UserFilter filter); } } diff --git a/VBaseProject.Resources/Messages/MessagesKeys.cs b/VBaseProject.Resources/Messages/MessagesKeys.cs index 3bf3393..c1e8f52 100644 --- a/VBaseProject.Resources/Messages/MessagesKeys.cs +++ b/VBaseProject.Resources/Messages/MessagesKeys.cs @@ -1,7 +1,7 @@ namespace VBaseProject.Resources.Messages { /// - /// Update All Resoure Files to matain the globalization support + /// Update all Resource Files to mantain the globalization support /// public static class MessagesKeys { diff --git a/VBaseProject.Resources/VBaseProject.Resources.csproj b/VBaseProject.Resources/VBaseProject.Resources.csproj index 0910863..dfdf966 100644 --- a/VBaseProject.Resources/VBaseProject.Resources.csproj +++ b/VBaseProject.Resources/VBaseProject.Resources.csproj @@ -11,7 +11,7 @@ - + diff --git a/VBaseProject.Test/API/HealthCheckApiTest.cs b/VBaseProject.Test/API/HealthCheckApiTest.cs index 6f4ef53..bfb32e9 100644 --- a/VBaseProject.Test/API/HealthCheckApiTest.cs +++ b/VBaseProject.Test/API/HealthCheckApiTest.cs @@ -8,7 +8,7 @@ namespace VBaseProject.Test.Api public class HealthCheckApiTest: ApiTestInitializer { [Fact] - public async Task HealthCheckConfigurationTest() + public async Task GetAsync_HealthCheck_ReturnsHealthy() { Setup(); diff --git a/VBaseProject.Test/Controllers/AuthControllerTest.cs b/VBaseProject.Test/Controllers/AuthControllerTest.cs index 55bc797..6ce4673 100644 --- a/VBaseProject.Test/Controllers/AuthControllerTest.cs +++ b/VBaseProject.Test/Controllers/AuthControllerTest.cs @@ -24,7 +24,7 @@ public AuthControllerTest() } [Fact] - public async Task LoginValidTest() + public async Task Login_WithValidCredentials_ReturnsOk() { var result = await authController.Login( new UserLoginModel @@ -46,7 +46,7 @@ public async Task LoginValidTest() } [Fact] - public async Task LoginInvalidTest() + public async Task Login_WithInvalidCredentials_RetunsUnauthorized() { var result = await authController.Login( new UserLoginModel @@ -63,7 +63,7 @@ public async Task LoginInvalidTest() } [Fact] - public async Task RefreshTokenValidTest() + public async Task RefreshToken_WithValidRefreshToken_ReturnsNewToken() { var result = await authController.RefreshToken( RefreshTokenMotherObject.ValidRefreshTokenModel() @@ -80,7 +80,7 @@ public async Task RefreshTokenValidTest() Assert.True(userApiToken.Expiration > DateTime.Now); } [Fact] - public async Task RefreshTokenInValidTest() + public async Task RefreshToken_WithInvalidRefreshToken_ReturnsUnauthorized() { var result = await authController.RefreshToken( new RefreshTokenModel { RefreshToken = null} @@ -99,8 +99,8 @@ private void SetupServiceMock() userServiceMock.Setup(x => x.LoginAsync(UserMotherObject.ValidAdminUser().Email, UserMotherObject.ValidAdminUser().Password)) .ReturnsAsync(UserMotherObject.ValidAdminUser()); - userServiceMock.Setup(x => x.AddRefreshToken(It.IsAny())).ReturnsAsync(RefreshTokenMotherObject.ValidRefreshToken()); - userServiceMock.Setup(x => x.GetUserByRefreshToken(RefreshTokenMotherObject.ValidRefreshToken().Refreshtoken)).ReturnsAsync(UserMotherObject.ValidAdminUser()); + userServiceMock.Setup(x => x.AddRefreshTokenAsync(It.IsAny())).ReturnsAsync(RefreshTokenMotherObject.ValidRefreshToken()); + userServiceMock.Setup(x => x.GetUserByRefreshTokenAsync(RefreshTokenMotherObject.ValidRefreshToken().Refreshtoken)).ReturnsAsync(UserMotherObject.ValidAdminUser()); //Arrange var inMemorySettings = new Dictionary { diff --git a/VBaseProject.Test/Controllers/CustomersControllerTest.cs b/VBaseProject.Test/Controllers/CustomersControllerTest.cs index 4875387..7f1c9a7 100644 --- a/VBaseProject.Test/Controllers/CustomersControllerTest.cs +++ b/VBaseProject.Test/Controllers/CustomersControllerTest.cs @@ -24,7 +24,7 @@ public CustomersControllerTestTest() } [Fact] - public async Task GetCustomerValidTest() + public async Task GetCustomerById_WithValidId_ReturnsValidCustomer() { var result = await _customersController.Get(CustomerMotherObject.ValidCustomer().PublicId); @@ -39,7 +39,7 @@ public async Task GetCustomerValidTest() } [Fact] - public async Task CreateCustomerValidTest() + public async Task PostCustomer_WithValidData_CreateNewCustomer() { var result = await _customersController.Post(CustomerMotherObject.ValidCustomerInput()); @@ -53,7 +53,7 @@ public async Task CreateCustomerValidTest() } [Fact] - public async Task EditCustomerValidTest() + public async Task PutCustomer_WithValidData_EditCustomer() { var result = await _customersController.Put(CustomerMotherObject.ValidCustomer().PublicId, CustomerMotherObject.ValidCustomerInput()); @@ -64,7 +64,7 @@ public async Task EditCustomerValidTest() } [Fact] - public async Task DeleteCustomerValidTest() + public async Task DeleteCustomer_WithValidId_DeleteCustomer() { var result = await _customersController.Delete(CustomerMotherObject.ValidCustomer().PublicId); @@ -75,7 +75,7 @@ public async Task DeleteCustomerValidTest() } [Fact] - public async Task ListCustomersTest() + public async Task GetCustomers_WithPagination_ReturnsAllCustomers() { var result = await _customersController.Get(new CustomerFilter()); @@ -86,7 +86,6 @@ public async Task ListCustomersTest() Assert.Equal(200, contentResult.StatusCode); } - private void SetupServiceMock() { var customerServiceMock = new Mock(); diff --git a/VBaseProject.Test/Controllers/UsersControllerTest.cs b/VBaseProject.Test/Controllers/UsersControllerTest.cs index e6acc06..6ef4f55 100644 --- a/VBaseProject.Test/Controllers/UsersControllerTest.cs +++ b/VBaseProject.Test/Controllers/UsersControllerTest.cs @@ -103,7 +103,7 @@ private void SetupServiceMock() userServiceMock.Setup(x => x.AddAsync(It.IsAny())).ReturnsAsync(UserMotherObject.ValidAdminUser()); userServiceMock.Setup(x => x.UpdateAsync(It.IsAny())).Verifiable(); userServiceMock.Setup(x => x.DeleteAsync(UserMotherObject.ValidAdminUser().PublicId)).Verifiable(); - userServiceMock.Setup(x => x.ListPaginate(It.IsAny())). + userServiceMock.Setup(x => x.ListPaginateAsync(It.IsAny())). ReturnsAsync(userListPaginated); _usersController = new UsersController(userServiceMock.Object, _mapper); diff --git a/VBaseProject.Test/Services/UserServiceTest.cs b/VBaseProject.Test/Services/UserServiceTest.cs index e21b173..41c9a39 100644 --- a/VBaseProject.Test/Services/UserServiceTest.cs +++ b/VBaseProject.Test/Services/UserServiceTest.cs @@ -69,7 +69,7 @@ public async Task ListUserPaginatedFilterTest() var userSaved = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userSaved.PublicId); - var userPaginated = await _userService.ListPaginate( + var userPaginated = await _userService.ListPaginateAsync( new UserFilter { Query = UserMotherObject.ValidAdminUser().Name, Entity = new User @@ -192,9 +192,9 @@ public async Task AddRefreshTokenValidTest() var refreshToken = Guid.NewGuid().ToString(); - var refreshTokenAdded = await _userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); + var refreshTokenAdded = await _userService.AddRefreshTokenAsync(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); - var userByRefreshToken = await _userService.GetUserByRefreshToken(refreshTokenAdded.Refreshtoken); + var userByRefreshToken = await _userService.GetUserByRefreshTokenAsync(refreshTokenAdded.Refreshtoken); Assert.NotNull(userByRefreshToken); @@ -219,9 +219,9 @@ public async Task RefreshTokenNullTest() var refreshToken = Guid.NewGuid().ToString(); - await _userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); + await _userService.AddRefreshTokenAsync(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); - var exeption = await Assert.ThrowsAsync(() => _userService.GetUserByRefreshToken(null)); + var exeption = await Assert.ThrowsAsync(() => _userService.GetUserByRefreshTokenAsync(null)); Assert.Equal(exeption.Message, messages[UserMessages.InvalidRefreshToken]); @@ -242,9 +242,9 @@ public async Task RefreshTokenInvalidTest() var refreshToken = Guid.NewGuid().ToString(); - await _userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); + await _userService.AddRefreshTokenAsync(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); - var exeption = await Assert.ThrowsAsync(() => _userService.GetUserByRefreshToken("wrong refresh token")); + var exeption = await Assert.ThrowsAsync(() => _userService.GetUserByRefreshTokenAsync("wrong refresh token")); Assert.Equal(exeption.Message, messages[UserMessages.InvalidRefreshToken]); diff --git a/VBaseProject.Test/VBaseProject.Test.csproj b/VBaseProject.Test/VBaseProject.Test.csproj index 8502080..a5536e6 100644 --- a/VBaseProject.Test/VBaseProject.Test.csproj +++ b/VBaseProject.Test/VBaseProject.Test.csproj @@ -16,18 +16,18 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - +