Playing with tests

This commit is contained in:
2023-11-20 13:43:43 +02:00
parent 1f0e6516fd
commit 79ecff971b
5 changed files with 88 additions and 2 deletions

View File

@@ -10,8 +10,8 @@ public sealed class Logger : ILogger
{ {
public bool IsEnabled { get; init; } public bool IsEnabled { get; init; }
public bool OutputToFile { get; init; } public bool OutputToFile { get; init; }
public LogType LowestLogLevel { get; set; } private LogType LowestLogLevel { get; }
private bool UseShortVersion { get; } private bool UseShortVersion { get; }
public Logger(bool useShortVersion, bool outputToFile, LogType lowestLogLevel = LogType.INFO) public Logger(bool useShortVersion, bool outputToFile, LogType lowestLogLevel = LogType.INFO)

View File

@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LevelingSystem", "..\SethPl
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCompatibilityLayer", "..\SethPlugins\PythonCompatibilityLayer\PythonCompatibilityLayer.csproj", "{81ED4953-13E5-4950-96A8-8CEF5FD59559}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCompatibilityLayer", "..\SethPlugins\PythonCompatibilityLayer\PythonCompatibilityLayer.csproj", "{81ED4953-13E5-4950-96A8-8CEF5FD59559}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SethTests", "SethTests\SethTests.csproj", "{B3044E3C-2F68-4556-9E87-3772702B4CE7}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -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<string, string>("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<string, object>("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<string, object>("settings.txt");
appSettings[keyName] = value;
Assert.Same(appSettings[keyName], value);
}
}

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="DiscordBot\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiscordBot\DiscordBot.csproj" />
<ProjectReference Include="..\PluginManager\PluginManager.csproj" />
</ItemGroup>
</Project>

1
SethTests/Usings.cs Normal file
View File

@@ -0,0 +1 @@
global using Xunit;