mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Hardens test assertions and adds missing test coverage.
This commit is contained in:
1 parent
6b86fd5805
commit
1189bbaf36
489 files changed
+39982
-512
No files matched your search
+97
@@ -0,0 +1,97 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||
using Lumina.Plugins.Contracts.Fixtures.Common.Models.DTO.Settings;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.UnitTests.Common.Models.DTO.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PluginSettingDescriptorDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginSettingDescriptorDtoTests
|
||||
{
|
||||
private readonly PluginSettingDescriptorDtoFixture _pluginSettingDescriptorDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenConstructedWithValues_ShouldPreserveAllValues()
|
||||
{
|
||||
// Arrange
|
||||
IReadOnlyList<string> allowedValues = ["Fiction", "Non-Fiction"];
|
||||
|
||||
// Act
|
||||
PluginSettingDescriptorDto result = _pluginSettingDescriptorDtoFixture.Create(
|
||||
key: "Theme",
|
||||
label: "Theme",
|
||||
type: PluginSettingType.Select,
|
||||
defaultValue: "Fiction",
|
||||
allowedValues: allowedValues);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Theme", result.Key);
|
||||
Assert.Equal("Theme", result.Label);
|
||||
Assert.Equal(PluginSettingType.Select, result.Type);
|
||||
Assert.Equal("Fiction", result.DefaultValue);
|
||||
Assert.Same(allowedValues, result.AllowedValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenDefaultValuesAreNotProvided_ShouldDefaultToNull()
|
||||
{
|
||||
// Act
|
||||
PluginSettingDescriptorDto result = _pluginSettingDescriptorDtoFixture.Create(defaultValue: null, allowedValues: null);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.DefaultValue);
|
||||
Assert.Null(result.AllowedValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoDescriptorsHaveTheSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
IReadOnlyList<string> allowedValues = ["A"];
|
||||
|
||||
// Act
|
||||
PluginSettingDescriptorDto first = _pluginSettingDescriptorDtoFixture.Create(key: "Key", label: "Label", type: PluginSettingType.Text, defaultValue: "value", allowedValues: allowedValues);
|
||||
PluginSettingDescriptorDto second = _pluginSettingDescriptorDtoFixture.Create(key: "Key", label: "Label", type: PluginSettingType.Text, defaultValue: "value", allowedValues: allowedValues);
|
||||
bool result = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
Assert.Equal(first, second);
|
||||
Assert.Equal(first.GetHashCode(), second.GetHashCode());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenDescriptorsHaveDifferentAllowedValueInstances_ShouldNotBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorDto first = _pluginSettingDescriptorDtoFixture.Create(key: "Key", label: "Label", type: PluginSettingType.Text, defaultValue: "value", allowedValues: ["A"]);
|
||||
PluginSettingDescriptorDto second = _pluginSettingDescriptorDtoFixture.Create(key: "Key", label: "Label", type: PluginSettingType.Text, defaultValue: "value", allowedValues: ["A"]);
|
||||
|
||||
// Act
|
||||
bool result = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoDescriptorsHaveDifferentKeys_ShouldNotBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorDto first = _pluginSettingDescriptorDtoFixture.Create(key: "KeyOne", label: "Label", type: PluginSettingType.Text);
|
||||
PluginSettingDescriptorDto second = _pluginSettingDescriptorDtoFixture.Create(key: "KeyTwo", label: "Label", type: PluginSettingType.Text);
|
||||
|
||||
// Act
|
||||
bool result = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
Assert.NotEqual(first, second);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user