From 79ecff971b59ba431dd4aaba7492ee9d00417138 Mon Sep 17 00:00:00 2001 From: Andrei Tudor Date: Mon, 20 Nov 2023 13:43:43 +0200 Subject: [PATCH] Playing with tests --- PluginManager/Others/Logger/Logger.cs | 4 +- SethDiscordBot.sln | 6 +++ .../PluginManagerTests/AppSettingsTests.cs | 46 +++++++++++++++++++ SethTests/SethTests.csproj | 33 +++++++++++++ SethTests/Usings.cs | 1 + 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 SethTests/PluginManagerTests/AppSettingsTests.cs create mode 100644 SethTests/SethTests.csproj create mode 100644 SethTests/Usings.cs diff --git a/PluginManager/Others/Logger/Logger.cs b/PluginManager/Others/Logger/Logger.cs index 2a9e2c7..33462f7 100644 --- a/PluginManager/Others/Logger/Logger.cs +++ b/PluginManager/Others/Logger/Logger.cs @@ -10,8 +10,8 @@ public sealed class Logger : ILogger { public bool IsEnabled { get; init; } public bool OutputToFile { get; init; } - - public LogType LowestLogLevel { get; set; } + + private LogType LowestLogLevel { get; } private bool UseShortVersion { get; } public Logger(bool useShortVersion, bool outputToFile, LogType lowestLogLevel = LogType.INFO) diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index a8d9f43..d355007 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LevelingSystem", "..\SethPl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCompatibilityLayer", "..\SethPlugins\PythonCompatibilityLayer\PythonCompatibilityLayer.csproj", "{81ED4953-13E5-4950-96A8-8CEF5FD59559}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SethTests", "SethTests\SethTests.csproj", "{B3044E3C-2F68-4556-9E87-3772702B4CE7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,10 @@ Global {81ED4953-13E5-4950-96A8-8CEF5FD59559}.Debug|Any CPU.Build.0 = Debug|Any CPU {81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.ActiveCfg = Release|Any CPU {81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.Build.0 = Release|Any CPU + {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SethTests/PluginManagerTests/AppSettingsTests.cs b/SethTests/PluginManagerTests/AppSettingsTests.cs new file mode 100644 index 0000000..ed18d62 --- /dev/null +++ b/SethTests/PluginManagerTests/AppSettingsTests.cs @@ -0,0 +1,46 @@ +using PluginManager; +using Xunit.Abstractions; + +namespace SethTests.PluginManagerTests; + +public class AppSettingsTests +{ + private readonly ITestOutputHelper _testOutputHelper; + + public AppSettingsTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + + [Fact] + public void TestAppSettings_ConstructorInitializeTheClassAndFile() + { + var appSettings = new PluginManager.Others.SettingsDictionary("settings.txt"); + + Assert.NotNull(appSettings); + } + + [Theory] + [InlineData("key1", "value1")] + [InlineData("key2", true)] + public void TestAppSettings_InsertingValueIntoSettings(string keyName, object value) + { + var appSettings = new PluginManager.Others.SettingsDictionary("settings.txt"); + + appSettings[keyName] = value; + Assert.True(appSettings.ContainsKey(keyName)); + } + + [Theory] + //[InlineData("key2", 32)] // fails + [InlineData("key1", "value1")] + public void TestAppSettings_GettingTheValueFromSettings(string keyName, object value) + { + var appSettings = new PluginManager.Others.SettingsDictionary("settings.txt"); + + appSettings[keyName] = value; + + Assert.Same(appSettings[keyName], value); + } + +} \ No newline at end of file diff --git a/SethTests/SethTests.csproj b/SethTests/SethTests.csproj new file mode 100644 index 0000000..f55c2d1 --- /dev/null +++ b/SethTests/SethTests.csproj @@ -0,0 +1,33 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + diff --git a/SethTests/Usings.cs b/SethTests/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/SethTests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file