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}");
}
}
}