refactor(tests): migrate Database.Tests from FluentAssertions to Shouldly
Replace FluentAssertions with Shouldly across all 6 test files (94 tests). Add ShouldlyExtensions for BeCloseTo and BeEquivalentTo patterns.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Shouldly;
|
||||
|
||||
namespace JdeScoping.Database.Tests.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for Shouldly to support patterns from FluentAssertions.
|
||||
/// </summary>
|
||||
public static class ShouldlyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Asserts that a nullable DateTime is close to the expected value within a tolerance.
|
||||
/// Equivalent to FluentAssertions' BeCloseTo.
|
||||
/// </summary>
|
||||
public static void ShouldBeCloseTo(this DateTime? actual, DateTime expected, TimeSpan tolerance)
|
||||
{
|
||||
actual.ShouldNotBeNull();
|
||||
Math.Abs((actual.Value - expected).TotalMilliseconds)
|
||||
.ShouldBeLessThanOrEqualTo(tolerance.TotalMilliseconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that a DateTime is close to the expected value within a tolerance.
|
||||
/// Equivalent to FluentAssertions' BeCloseTo.
|
||||
/// </summary>
|
||||
public static void ShouldBeCloseTo(this DateTime actual, DateTime expected, TimeSpan tolerance)
|
||||
{
|
||||
Math.Abs((actual - expected).TotalMilliseconds)
|
||||
.ShouldBeLessThanOrEqualTo(tolerance.TotalMilliseconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that two collections contain equivalent items (same items, order independent).
|
||||
/// Equivalent to FluentAssertions' BeEquivalentTo for simple types.
|
||||
/// </summary>
|
||||
public static void ShouldBeEquivalentTo<T>(this IEnumerable<T> actual, IEnumerable<T> expected)
|
||||
{
|
||||
var actualList = actual.ToList();
|
||||
var expectedList = expected.ToList();
|
||||
actualList.Count.ShouldBe(expectedList.Count, "Collections should have the same count");
|
||||
foreach (var item in expectedList)
|
||||
{
|
||||
actualList.ShouldContain(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user