From cfe877a066c78a069721d7e33db925839eddc57b Mon Sep 17 00:00:00 2001 From: csimonapastore Date: Thu, 20 Mar 2025 22:42:19 +0100 Subject: [PATCH] Fixing coverage --- .../Services/UserService_Tests.cs | 90 ++++++++++--------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/MainProject.Tests/Services/UserService_Tests.cs b/MainProject.Tests/Services/UserService_Tests.cs index 6d6800b..c332fd0 100644 --- a/MainProject.Tests/Services/UserService_Tests.cs +++ b/MainProject.Tests/Services/UserService_Tests.cs @@ -9,7 +9,7 @@ namespace BasicDotnetTemplate.MainProject.Tests; [TestClass] public class UserService_Tests { - private static User? _user; + private static User _user = ModelsInit.CreateUser(); private static Role? _role; [TestMethod] @@ -114,30 +114,31 @@ public class UserService_Tests // } // } - // [TestMethod] - // public async Task CheckIfEmailIsValid_EmailNotExists() - // { - // try - // { - // if (_userService != null) - // { - // var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty); - // Assert.IsTrue(valid); - // } - // else - // { - // Assert.Fail($"UserService is null"); - // } - // } - // catch (Exception ex) - // { - // Console.WriteLine(ex.InnerException); - // Assert.Fail($"An exception was thrown: {ex}"); - // } - // } + [TestMethod] + public async Task CheckIfEmailIsValid_EmailNotExists() + { + try + { + var userService = TestUtils.CreateUserService(); + if (userService != null) + { + var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty); + Assert.IsTrue(valid); + } + else + { + Assert.Fail($"UserService is null"); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.InnerException); + Assert.Fail($"An exception was thrown: {ex}"); + } + } [TestMethod] - public async Task CreateUserData() + public async Task CreateUserAsync_Success() { try { @@ -176,27 +177,28 @@ public class UserService_Tests } } - // [TestMethod] - // public async Task CheckIfEmailIsValid_EmailCurrentUser() - // { - // try - // { - // if (_userService != null) - // { - // var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty, _user?.Guid ?? String.Empty); - // Assert.IsTrue(valid); - // } - // else - // { - // Assert.Fail($"UserService is null"); - // } - // } - // catch (Exception ex) - // { - // Console.WriteLine(ex.InnerException); - // Assert.Fail($"An exception was thrown: {ex}"); - // } - // } + [TestMethod] + public async Task CheckIfEmailIsValid_EmailCurrentUser() + { + try + { + var userService = TestUtils.CreateUserService(); + if (userService != null) + { + var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty, _user.Guid ?? String.Empty); + Assert.IsTrue(valid); + } + else + { + Assert.Fail($"UserService is null"); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.InnerException); + Assert.Fail($"An exception was thrown: {ex}"); + } + } // [TestMethod] // public async Task CheckIfEmailIsValid_EmailAlreadyExists()