205 lines
5.0 KiB
C#
205 lines
5.0 KiB
C#
using StellaOps.TestKit;
|
|
namespace StellaOps.Router.Config.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for <see cref="ConfigValidationResult"/>.
|
|
/// </summary>
|
|
public sealed class ConfigValidationResultTests
|
|
{
|
|
#region Default Values Tests
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Constructor_Errors_DefaultsToEmptyList()
|
|
{
|
|
// Arrange & Act
|
|
var result = new ConfigValidationResult();
|
|
|
|
// Assert
|
|
result.Errors.Should().NotBeNull();
|
|
result.Errors.Should().BeEmpty();
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Constructor_Warnings_DefaultsToEmptyList()
|
|
{
|
|
// Arrange & Act
|
|
var result = new ConfigValidationResult();
|
|
|
|
// Assert
|
|
result.Warnings.Should().NotBeNull();
|
|
result.Warnings.Should().BeEmpty();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IsValid Tests
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void IsValid_NoErrors_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
|
|
// Act & Assert
|
|
result.IsValid.Should().BeTrue();
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void IsValid_WithErrors_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
result.Errors.Add("Some error");
|
|
|
|
// Act & Assert
|
|
result.IsValid.Should().BeFalse();
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void IsValid_WithOnlyWarnings_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
result.Warnings.Add("Some warning");
|
|
|
|
// Act & Assert
|
|
result.IsValid.Should().BeTrue();
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void IsValid_WithErrorsAndWarnings_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
result.Errors.Add("Some error");
|
|
result.Warnings.Add("Some warning");
|
|
|
|
// Act & Assert
|
|
result.IsValid.Should().BeFalse();
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void IsValid_MultipleErrors_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
result.Errors.Add("Error 1");
|
|
result.Errors.Add("Error 2");
|
|
result.Errors.Add("Error 3");
|
|
|
|
// Act & Assert
|
|
result.IsValid.Should().BeFalse();
|
|
result.Errors.Should().HaveCount(3);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static Success Tests
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Success_ReturnsValidResult()
|
|
{
|
|
// Arrange & Act
|
|
var result = ConfigValidationResult.Success;
|
|
|
|
// Assert
|
|
result.IsValid.Should().BeTrue();
|
|
result.Errors.Should().BeEmpty();
|
|
result.Warnings.Should().BeEmpty();
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Success_ReturnsNewInstance()
|
|
{
|
|
// Arrange & Act
|
|
var result1 = ConfigValidationResult.Success;
|
|
var result2 = ConfigValidationResult.Success;
|
|
|
|
// Assert - Should be different instances to allow mutation without affecting shared state
|
|
result1.Should().NotBeSameAs(result2);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Errors Collection Tests
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Errors_CanBeModified()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
|
|
// Act
|
|
result.Errors.Add("Error 1");
|
|
result.Errors.Add("Error 2");
|
|
|
|
// Assert
|
|
result.Errors.Should().HaveCount(2);
|
|
result.Errors.Should().Contain("Error 1");
|
|
result.Errors.Should().Contain("Error 2");
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Errors_CanBeInitialized()
|
|
{
|
|
// Arrange & Act
|
|
var result = new ConfigValidationResult
|
|
{
|
|
Errors = ["Error 1", "Error 2"]
|
|
};
|
|
|
|
// Assert
|
|
result.Errors.Should().HaveCount(2);
|
|
result.IsValid.Should().BeFalse();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Warnings Collection Tests
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Warnings_CanBeModified()
|
|
{
|
|
// Arrange
|
|
var result = new ConfigValidationResult();
|
|
|
|
// Act
|
|
result.Warnings.Add("Warning 1");
|
|
result.Warnings.Add("Warning 2");
|
|
|
|
// Assert
|
|
result.Warnings.Should().HaveCount(2);
|
|
result.Warnings.Should().Contain("Warning 1");
|
|
result.Warnings.Should().Contain("Warning 2");
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void Warnings_CanBeInitialized()
|
|
{
|
|
// Arrange & Act
|
|
var result = new ConfigValidationResult
|
|
{
|
|
Warnings = ["Warning 1", "Warning 2"]
|
|
};
|
|
|
|
// Assert
|
|
result.Warnings.Should().HaveCount(2);
|
|
result.IsValid.Should().BeTrue(); // Warnings don't affect validity
|
|
}
|
|
|
|
#endregion
|
|
}
|