From 0f73560cd91c791ee6bf9deed967b66b0f4d08ba Mon Sep 17 00:00:00 2001 From: csimonapastore Date: Sun, 18 May 2025 23:23:24 +0200 Subject: [PATCH] Adding tests --- MainProject.Tests/Config/permissions.json | 32 +++++++++++ MainProject.Tests/Utils/FileUtils_Tests.cs | 66 ++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 MainProject.Tests/Config/permissions.json create mode 100644 MainProject.Tests/Utils/FileUtils_Tests.cs diff --git a/MainProject.Tests/Config/permissions.json b/MainProject.Tests/Config/permissions.json new file mode 100644 index 0000000..aeabb85 --- /dev/null +++ b/MainProject.Tests/Config/permissions.json @@ -0,0 +1,32 @@ +{ + "PermissionInfos": [ + { + "System": "base", + "RolePermissionModuleOperations": [ + { + "Module": "roles", + "Operations": [ + { "Operation": "create", "Roles": [] }, + { "Operation": "read", "Roles": [] }, + { "Operation": "update", "Roles": [] }, + { "Operation": "delete", "Roles": [] }, + { "Operation": "list", "Roles": [] }, + { "Operation": "use", "Roles": [] } + ] + }, + { + "Module": "users", + "Operations": [ + { "Operation": "create", "Roles": [] }, + { "Operation": "read", "Roles": [] }, + { "Operation": "update", "Roles": [] }, + { "Operation": "delete", "Roles": [] }, + { "Operation": "list", "Roles": [] }, + { "Operation": "use", "Roles": [] } + ] + } + ] + } + + ] +} \ No newline at end of file diff --git a/MainProject.Tests/Utils/FileUtils_Tests.cs b/MainProject.Tests/Utils/FileUtils_Tests.cs new file mode 100644 index 0000000..a689650 --- /dev/null +++ b/MainProject.Tests/Utils/FileUtils_Tests.cs @@ -0,0 +1,66 @@ +using BasicDotnetTemplate.MainProject.Utils; +using BasicDotnetTemplate.MainProject.Models.Common; + + +namespace BasicDotnetTemplate.MainProject.Tests; + +[TestClass] +public static class FileUtils_Tests +{ + [TestMethod] + public static void ConvertFileToObject_NoFilePath() + { + try + { + try + { + PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject(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) + { + Console.WriteLine(ex.InnerException); + Assert.Fail($"An exception was thrown: {ex}"); + } + } + + [TestMethod] + public static void ConvertFileToObject_NoFile() + { + try + { + try + { + PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject(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) + { + Console.WriteLine(ex.InnerException); + Assert.Fail($"An exception was thrown: {ex}"); + } + } + +} + + + +