Skip to content

Commit

Permalink
Use Shouldly over FluentAssertions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsmith1968 committed Jan 15, 2025
1 parent bb5a4c3 commit 0891a24
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 411 deletions.
56 changes: 28 additions & 28 deletions tests/DNX.Extensions.Tests/Arrays/ArrayExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DNX.Extensions.Arrays;
using FluentAssertions;
using Shouldly;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -21,7 +21,7 @@ public void Test_IsNullOrEmpty(string byteArray, bool isEmpty)
.Select(x => Convert.ToByte(x))
.ToArray();

bytes.IsNullOrEmpty().Should().Be(isEmpty);
bytes.IsNullOrEmpty().ShouldBe(isEmpty);
}

[Fact]
Expand All @@ -31,13 +31,13 @@ public void Test_PadLeft_when_greater_than_existing_array_length()

var result = values.PadLeft(8);

values.Length.Should().Be(6);
result.Length.Should().Be(8);
values.Length.ShouldBe(6);
result.Length.ShouldBe(8);

for (var i = 1; i <= result.Length; ++i)
{
outputHelper.WriteLine($"Index: {i}");
result[^i].Should().Be(i > values.Length ? default : values[^i]);
result[^i].ShouldBe(i > values.Length ? default : values[^i]);
}
}

Expand All @@ -50,13 +50,13 @@ public void Test_PadLeft_when_less_than_existing_array_length()
var result = values.PadLeft(4);

// Assert
values.Length.Should().Be(6);
result.Length.Should().Be(4);
values.Length.ShouldBe(6);
result.Length.ShouldBe(4);

for (var i = 1; i <= result.Length; ++i)
{
outputHelper.WriteLine($"Index: {i}");
result[^i].Should().Be(values[^i]);
result[^i].ShouldBe(values[^i]);
}
}

Expand All @@ -72,8 +72,8 @@ public void Test_ShiftLeft_defaults_populated_array()
var result = values.ShiftLeft();

// Assert
result.Length.Should().Be(values.Length);
result.Should().BeEquivalentTo(expected);
result.Length.ShouldBe(values.Length);
result.ShouldBeEquivalentTo(expected);
}

[Fact]
Expand All @@ -86,8 +86,8 @@ public void Test_ShiftLeft_by_number_populated_array()
var result = values.ShiftLeft(by: 3);

// Assert
result.Length.Should().Be(values.Length);
result.Should().BeEquivalentTo(expected);
result.Length.ShouldBe(values.Length);
result.ShouldBeEquivalentTo(expected);
}

[Fact]
Expand All @@ -100,8 +100,8 @@ public void Test_ShiftLeft_with_fill_value_populated_array()
var result = values.ShiftLeft(by: 2, fillValue: "0");

// Assert
result.Length.Should().Be(values.Length);
result.Should().BeEquivalentTo(expected);
result.Length.ShouldBe(values.Length);
result.ShouldBeEquivalentTo(expected);
}

[Fact]
Expand All @@ -111,8 +111,8 @@ public void Test_ShiftLeft_null_array()

var result = values.ShiftLeft();

result.Should().NotBeNull();
result.Length.Should().Be(0);
result.ShouldNotBeNull();
result.Length.ShouldBe(0);
}
}

Expand All @@ -128,8 +128,8 @@ public void Test_ShiftRight_defaults_populated_array()
var result = values.ShiftRight();

// Assert
result.Length.Should().Be(values.Length);
result.Should().BeEquivalentTo(expected);
result.Length.ShouldBe(values.Length);
result.ShouldBeEquivalentTo(expected);
}

[Fact]
Expand All @@ -142,8 +142,8 @@ public void Test_ShiftRight_by_number_populated_array()
var result = values.ShiftRight(by: 3);

// Assert
result.Length.Should().Be(values.Length);
result.Should().BeEquivalentTo(expected);
result.Length.ShouldBe(values.Length);
result.ShouldBeEquivalentTo(expected);
}

[Fact]
Expand All @@ -156,8 +156,8 @@ public void Test_ShiftRight_with_fill_value_populated_array()
var result = values.ShiftRight(by: 2, fillValue: "0");

// Assert
result.Length.Should().Be(values.Length);
result.Should().BeEquivalentTo(expected);
result.Length.ShouldBe(values.Length);
result.ShouldBeEquivalentTo(expected);
}

[Fact]
Expand All @@ -167,8 +167,8 @@ public void Test_ShiftRight_null_array()

var result = values.ShiftRight();

result.Should().NotBeNull();
result.Length.Should().Be(0);
result.ShouldNotBeNull();
result.Length.ShouldBe(0);
}
}

Expand All @@ -182,8 +182,8 @@ public void Reduce_can_produce_an_appropriate_output_for_bytes(byte[] input, int
var result = input.Reduce(targetSize, method);

// Assert
result.Length.Should().BeLessThanOrEqualTo(targetSize);
result.Should().BeEquivalentTo(expectedResult);
result.Length.ShouldBeLessThanOrEqualTo(targetSize);
result.ShouldBeEquivalentTo(expectedResult);
}

[Theory]
Expand All @@ -194,8 +194,8 @@ public void Reduce_can_produce_an_appropriate_output_for_strings(string[] input,
var result = input.Reduce(targetSize, method);

// Assert
result.Length.Should().BeLessThanOrEqualTo(targetSize);
result.Should().BeEquivalentTo(expectedResult);
result.Length.ShouldBeLessThanOrEqualTo(targetSize);
result.ShouldBeEquivalentTo(expectedResult);
}

// Useful : https://www.compscilib.com/calculate/binaryxor?variation=default
Expand Down
6 changes: 3 additions & 3 deletions tests/DNX.Extensions.Tests/Arrays/ByteArrayExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DNX.Extensions.Arrays;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace DNX.Extensions.Tests.Arrays;
Expand All @@ -19,7 +19,7 @@ public void Test_GetAsciiString(string byteText, string expectedResult)

var result = bytes.GetAsciiString();

result.Should().Be(expectedResult);
result.ShouldBe(expectedResult);
}

[Theory]
Expand All @@ -34,6 +34,6 @@ public void Test_ToHexString(string byteText, string expectedResult)

var result = bytes.ToHexString();

result.Should().Be(expectedResult);
result.ShouldBe(expectedResult);
}
}
12 changes: 6 additions & 6 deletions tests/DNX.Extensions.Tests/Assemblies/AssemblyExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Resources;
using DNX.Extensions.Assemblies;
using FluentAssertions;
using Shouldly;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -21,7 +21,7 @@ public void GetEmbeddedResourceText_can_read_resource_successfully()
testOutputHelper.WriteLine("Result: {0}", result);

// Assert
result.Should().NotBeNull();
result.ShouldNotBeNull();
}

[Fact]
Expand All @@ -38,8 +38,8 @@ public void GetEmbeddedResourceText_throws_on_unknown_resource_name()
testOutputHelper.WriteLine("Exception Message: {0}", ex?.Message);

// Assert
ex.Should().NotBeNull();
ex.Message.Should().Contain(name);
ex.ShouldNotBeNull();
ex.Message.ShouldContain(name);
}

[Fact]
Expand All @@ -55,6 +55,6 @@ public void GetEmbeddedResourceText_can_read_resource_with_specific_namespace_su
testOutputHelper.WriteLine("Result: {0}", result);

// Assert
result.Should().NotBeNull();
result.ShouldNotBeNull();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DNX.Extensions.Comparers;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace DNX.Extensions.Tests.Comparers;
Expand All @@ -14,7 +14,7 @@ public void DefaultConstructor_works_as_expected()
{
var sut = new StringComparisonEqualityComparer();

sut.StringComparisonMethod.Should().Be(StringComparison.CurrentCulture);
sut.StringComparisonMethod.ShouldBe(StringComparison.CurrentCulture);
}

[Theory]
Expand All @@ -23,7 +23,7 @@ public void Constructor_for_StringComparison_works_as_expected(StringComparison
{
var sut = new StringComparisonEqualityComparer(stringComparison);

sut.StringComparisonMethod.Should().Be(stringComparison);
sut.StringComparisonMethod.ShouldBe(stringComparison);
}

[Theory]
Expand All @@ -37,7 +37,7 @@ public void Equals_compares_as_expected(string x, string y, StringComparison str
var result = Sut.Equals(x, y);

// Assert
result.Should().Be(expectedResult);
result.ShouldBe(expectedResult);
}

[Theory]
Expand All @@ -52,7 +52,7 @@ public void GetHashCode_compares_as_expected(string x, string y, StringCompariso
var resultY = Sut.GetHashCode(y);

// Assert
(resultX == resultY).Should().Be(expectedResult);
(resultX == resultY).ShouldBe(expectedResult);
}

#region TestData
Expand Down
Loading

0 comments on commit 0891a24

Please sign in to comment.