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