Adding JwtService tests + fixed issues

This commit is contained in:
2025-03-03 21:54:03 +01:00
parent 433e97938d
commit a0c93ea587
3 changed files with 88 additions and 3 deletions

View File

@@ -0,0 +1,76 @@
using BasicDotnetTemplate.MainProject.Models.Settings;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using BasicDotnetTemplate.MainProject.Utils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Moq;
using Newtonsoft.Json;
using BasicDotnetTemplate.MainProject.Core.Database;
using BasicDotnetTemplate.MainProject.Services;
using BasicDotnetTemplate.MainProject.Models.Api.Response;
using BasicDotnetTemplate.MainProject.Models.Api.Request.Auth;
using BasicDotnetTemplate.MainProject.Models.Api.Data.Auth;
using BasicDotnetTemplate.MainProject.Models.Api.Response.Auth;
using DatabaseSqlServer = BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
namespace BasicDotnetTemplate.MainProject.Tests;
[TestClass]
public class JwtService_Tests
{
[TestMethod]
public void Inizialize()
{
try
{
var jwtService = TestUtils.CreateJwtService();
if(jwtService != null)
{
Assert.IsInstanceOfType(jwtService, typeof(JwtService));
}
else
{
Assert.Fail($"JwtService is null");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex.Message}");
}
}
[TestMethod]
public async Task GenerateToken()
{
try
{
var jwtService = TestUtils.CreateJwtService();
var testString = "test";
if(jwtService != null)
{
var jwt = jwtService.GenerateToken(testString, testString);
Assert.IsTrue(jwt != null);
Assert.IsInstanceOfType(jwt, typeof(string));
}
else
{
Assert.Fail($"JwtService is null");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex.Message}");
}
}
}