Adding tests

This commit is contained in:
2025-05-19 00:03:27 +02:00
parent ec0847e95c
commit 58b7e75e77

View File

@@ -5,60 +5,45 @@ using BasicDotnetTemplate.MainProject.Models.Common;
namespace BasicDotnetTemplate.MainProject.Tests; namespace BasicDotnetTemplate.MainProject.Tests;
[TestClass] [TestClass]
public static class FileUtils_Tests public class FileUtils_Tests
{ {
[TestMethod] [TestMethod]
public static void ConvertFileToObject_NoFilePath() public void ConvertFileToObject_NoFilePath()
{ {
try try
{ {
try PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(String.Empty);
{ Assert.Fail($"Expected exception instead of response: {permissionsFile}");
PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(String.Empty);
Assert.Fail($"Expected exception instead of response: {permissionsFile}");
}
catch (ArgumentException argumentException)
{
Assert.IsInstanceOfType(argumentException, typeof(ArgumentException));
}
catch (Exception exception)
{
Assert.Fail($"An exception was thrown: {exception}");
}
} }
catch (Exception ex) catch (ArgumentException argumentException)
{ {
Console.WriteLine(ex.InnerException); Assert.IsInstanceOfType(argumentException, typeof(ArgumentException));
Assert.Fail($"An exception was thrown: {ex}"); }
catch (Exception exception)
{
Assert.Fail($"An exception was thrown: {exception}");
} }
} }
[TestMethod] [TestMethod]
public static void ConvertFileToObject_NoFile() public void ConvertFileToObject_NoFile()
{ {
try try
{ {
try PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(System.AppDomain.CurrentDomain.BaseDirectory + "Config/no-permissions.json");
{ Assert.Fail($"Expected exception instead of response: {permissionsFile}");
PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(System.AppDomain.CurrentDomain.BaseDirectory + "Config/no-permissions.json");
Assert.Fail($"Expected exception instead of response: {permissionsFile}");
}
catch (FileNotFoundException fileNotFoundException)
{
Assert.IsInstanceOfType(fileNotFoundException, typeof(FileNotFoundException));
}
catch (Exception exception)
{
Assert.Fail($"An exception was thrown: {exception}");
}
} }
catch (Exception ex) catch (FileNotFoundException fileNotFoundException)
{ {
Console.WriteLine(ex.InnerException); Assert.IsInstanceOfType(fileNotFoundException, typeof(FileNotFoundException));
Assert.Fail($"An exception was thrown: {ex}"); }
catch (Exception exception)
{
Assert.Fail($"An exception was thrown: {exception}");
} }
} }
} }