diff --git a/MainProject.Tests/JsonData/emptyAppsettings.json b/MainProject.Tests/JsonData/emptyAppsettings.json new file mode 100644 index 0000000..16867f6 --- /dev/null +++ b/MainProject.Tests/JsonData/emptyAppsettings.json @@ -0,0 +1,7 @@ +{ + "AppSettings" : + { + + } + +} \ No newline at end of file diff --git a/MainProject.Tests/Program_Tests.cs b/MainProject.Tests/Program_Tests.cs index e2eb38f..dd0d694 100644 --- a/MainProject.Tests/Program_Tests.cs +++ b/MainProject.Tests/Program_Tests.cs @@ -73,4 +73,5 @@ public class Program_Tests Assert.Fail($"An exception was thrown: {ex.Message}"); } } + } diff --git a/MainProject.Tests/Utils/ProgramUtils_Tests.cs b/MainProject.Tests/Utils/ProgramUtils_Tests.cs index 2cfc572..f4df5ec 100644 --- a/MainProject.Tests/Utils/ProgramUtils_Tests.cs +++ b/MainProject.Tests/Utils/ProgramUtils_Tests.cs @@ -56,6 +56,59 @@ public class ProgramUtils_Tests } } + [TestMethod] + public void CreateOpenApiInfo_EmptyAppSettings() + { + try + { + OpenApiInfo expectedOpenApiInfo = new OpenApiInfo() + { + Title = "", + Description = "", + Version = "", + Contact = null, + TermsOfService = null, + License = null, + Extensions = new Dictionary() + }; + + WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty()); + AppSettings realAppSettings = ProgramUtils.AddConfiguration(ref builder, "D:\\Users\\Simona\\Documents\\Projects\\BasicDotnetTemplate\\MainProject.Tests\\JsonData", "emptyAppsettings.json"); + OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(realAppSettings); + + var areEquals = expectedOpenApiInfo.Title == realOpenApiInfo.Title && + expectedOpenApiInfo.Description == realOpenApiInfo.Description && + expectedOpenApiInfo.Version == realOpenApiInfo.Version && + expectedOpenApiInfo.Contact == realOpenApiInfo.Contact && + expectedOpenApiInfo.TermsOfService == realOpenApiInfo.TermsOfService && + expectedOpenApiInfo.License == realOpenApiInfo.License; + + Assert.IsTrue(areEquals); + } + catch (Exception ex) + { + Console.WriteLine(ex.InnerException); + Assert.Fail($"An exception was thrown: {ex.Message}"); + } + } + + [TestMethod] + public void CreateOpenApiInfo_NullSettings() + { + try + { + + AppSettings appSettings = new AppSettings(); + OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(appSettings); + Assert.IsTrue(realOpenApiInfo != null); + } + catch (Exception ex) + { + Console.WriteLine(ex.InnerException); + Assert.Fail($"An exception was thrown: {ex.Message}"); + } + } + [TestMethod] public void OpenApiConfig_NotNull() { diff --git a/MainProject/Utils/ProgramUtils.cs b/MainProject/Utils/ProgramUtils.cs index 4d35c56..701e0e0 100644 --- a/MainProject/Utils/ProgramUtils.cs +++ b/MainProject/Utils/ProgramUtils.cs @@ -42,7 +42,7 @@ public static class ProgramUtils public static OpenApiInfo CreateOpenApiInfo(AppSettings appSettings) { - OpenApiInfo openApiInfo = new() + OpenApiInfo openApiInfo = new OpenApiInfo { Version = appSettings.Settings?.Version, Title = appSettings.Settings?.Name,