Code refactoring + tests

This commit is contained in:
2025-03-04 00:42:20 +01:00
parent a0c93ea587
commit f73fe748ed
8 changed files with 299 additions and 86 deletions

View File

@@ -44,7 +44,7 @@ public class JwtService_Tests
}
[TestMethod]
public async Task GenerateToken()
public void GenerateToken()
{
try
{
@@ -52,7 +52,7 @@ public class JwtService_Tests
var testString = "test";
if(jwtService != null)
{
var jwt = jwtService.GenerateToken(testString, testString);
var jwt = jwtService.GenerateToken(testString);
Assert.IsTrue(jwt != null);
Assert.IsInstanceOfType(jwt, typeof(string));
}
@@ -68,6 +68,31 @@ public class JwtService_Tests
}
}
[TestMethod]
public void ValidateToken_Null()
{
try
{
var jwtService = TestUtils.CreateJwtService();
var testString = "test";
if(jwtService != null)
{
var jwt = jwtService.GenerateToken(testString);
var user = jwtService.ValidateToken($"Bearer {jwt}");
Assert.IsTrue(user == null);
}
else
{
Assert.Fail($"JwtService is null");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex.Message}");
}
}
}

View File

@@ -46,7 +46,7 @@ public class UserService_Tests
}
[TestMethod]
public async Task GetUsers()
public async Task GetUserByUsernameAndPassword_Null()
{
try
{
@@ -69,6 +69,33 @@ public class UserService_Tests
}
}
// TODO
// [TestMethod]
public async Task GetUserByUsernameAndPassword_Success()
{
try
{
var userService = TestUtils.CreateUserService();
var testUsername = "test@email.it";
var testPassword = "password";
if(userService != null)
{
var user = await userService.GetUserByUsernameAndPassword(testUsername, testPassword);
Assert.IsTrue(user != null);
Assert.IsTrue(user.Username == testUsername);
}
else
{
Assert.Fail($"UserService is null");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex.Message}");
}
}
}