Skip to content

Commit

Permalink
🚧Refactor unit test assertions (#273)
Browse files Browse the repository at this point in the history
* Start work for issue #109

* deps: FluentAssertions v6.11.0 nuget package added to test project

* tests: refactor assertion code to use fluent assertions
  • Loading branch information
CalvinWilkinson authored Aug 8, 2023
1 parent d662802 commit 88efa4b
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 215 deletions.
1 change: 1 addition & 0 deletions Testing/CASLTests/CASLTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
9 changes: 5 additions & 4 deletions Testing/CASLTests/NativeInterop/ExtensionMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace CASLTests.NativeInterop;
using System;
using System.Runtime.InteropServices;
using CASL.NativeInterop;
using FluentAssertions;
using Xunit;

public class ExtensionMethodTests
Expand All @@ -19,21 +20,21 @@ public void ToManagedUTF8String_WithNullPointer_ReturnsEmptyString()
var actual = IntPtr.Zero.ToManagedUtf8String();

// Assert
Assert.Equal(string.Empty, actual);
actual.Should().BeEmpty();
}

[Fact]
public void ToManagedUTF8String_WhenInvoked_ReturnsCorrectResult()
{
// Arrange
var testString = "hello world";
const string testString = "hello world";
var stringDataPtr = Marshal.StringToHGlobalAnsi(testString);

// Act
var actual = stringDataPtr.ToManagedUtf8String();

// Assert
Assert.Equal("hello world", actual);
actual.Should().Be("hello world");
}

[Fact]
Expand All @@ -46,7 +47,7 @@ public void ToReadOnlyCollection_WhenInvoked_ReturnsCorrectResult()
var actual = testItems.ToReadOnlyCollection();

// Assert
Assert.Equal(new[] { "item-1", "item-2" }, actual);
actual.Should().BeEquivalentTo("item-1", "item-2");
}
#endregion
}
17 changes: 9 additions & 8 deletions Testing/CASLTests/OpenAL/ALContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CASLTests.OpenAL;

using CASL.OpenAL;
using FluentAssertions;
using Xunit;

/// <summary>
Expand All @@ -23,7 +24,7 @@ public void Ctr_WhenInvoked_SetHandleProperty()
var context = new ALContext(handle);

// Assert
Assert.Equal(1234, context.Handle);
context.Handle.Should().Be(1234);
}
#endregion

Expand All @@ -39,7 +40,7 @@ public void ImplicitCast_WhenInvoked_SuccessfullyCastsContextToPointer()
nint actual = context;

// Assert
Assert.Equal(1234, actual);
actual.Should().Be(1234);
}

[Fact]
Expand All @@ -53,7 +54,7 @@ public void EqualsOperator_WithEqualOperands_ReturnsTrue()
var actual = left == right;

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}

[Fact]
Expand All @@ -67,7 +68,7 @@ public void NotEqualsOperator_WithNonEqualOperands_ReturnsFalse()
var actual = left != right;

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}
#endregion

Expand All @@ -79,7 +80,7 @@ public void Null_WhenInvoked_ReturnsEmptyContext()
var actual = ALContext.Null();

// Assert
Assert.Equal(0, actual.Handle);
actual.Handle.Should().Be(0);
}

[Fact]
Expand All @@ -93,7 +94,7 @@ public void Equals_WithContextParamOverloadAndEqualContext_ReturnsTrue()
var actual = contextA.Equals(contextB);

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}

[Fact]
Expand All @@ -107,7 +108,7 @@ public void Equals_WithObjectParamOverloadAndNonContextType_ReturnsFalse()
var actual = contextA.Equals(contextB);

// Assert
Assert.False(actual);
actual.Should().BeFalse();
}

[Fact]
Expand All @@ -121,7 +122,7 @@ public void Equals_WithObjectParamOverloadAndEqualContext_ReturnsTrue()
var actual = contextA.Equals(contextB);

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}
#endregion
}
11 changes: 6 additions & 5 deletions Testing/CASLTests/OpenAL/ALDeviceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CASLTests.OpenAL;

using CASL.OpenAL;
using FluentAssertions;
using Xunit;

/// <summary>
Expand Down Expand Up @@ -53,7 +54,7 @@ public void EqualsOperator_WithEqualOperands_ReturnsTrue()
var actual = left == right;

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}

[Fact]
Expand All @@ -67,7 +68,7 @@ public void NotEqualsOperator_WithNonEqualOperands_ReturnsFalse()
var actual = left != right;

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}
#endregion

Expand All @@ -93,7 +94,7 @@ public void Equals_WithDeviceParamOverloadAndEquALDevice_ReturnsTrue()
var actual = deviceA.Equals(deviceB);

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}

[Fact]
Expand All @@ -107,7 +108,7 @@ public void Equals_WithObjectParamOverloadAndNonDeviceType_ReturnsFalse()
var actual = deviceA.Equals(deviceB);

// Assert
Assert.False(actual);
actual.Should().BeFalse();
}

[Fact]
Expand All @@ -121,7 +122,7 @@ public void Equals_WithObjectParamOverloadAndEquALDevice_ReturnsTrue()
var actual = deviceA.Equals(deviceB);

// Assert
Assert.True(actual);
actual.Should().BeTrue();
}
#endregion
}
Loading

0 comments on commit 88efa4b

Please sign in to comment.