Skip to content

Commit

Permalink
test: To FluentAssertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jul 15, 2021
1 parent 9509042 commit deb1c91
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 61 deletions.
4 changes: 2 additions & 2 deletions src/tests/H.Engine.IO.IntegrationTests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using H.WebSockets.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace H.Engine.IO.IntegrationTests
{
Expand Down Expand Up @@ -45,7 +45,7 @@ public static async Task ConnectToChatBaseTestAsync(string url, CancellationToke

foreach (var pair in results)
{
Assert.IsNotNull(pair.Value, $"Client event(\"{pair.Key}\") did not happen");
pair.Value.Should().NotBeNull(because: $"Client event(\"{pair.Key}\") did not happen");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/tests/H.Engine.IO.UnitTests/EngineIoClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace H.Engine.IO.Tests
{
Expand All @@ -8,9 +9,8 @@ public class EngineIoClientTests
{
private static void ToWebSocketUriBaseTest(string expected, string url, string framework = "engine.io")
{
Assert.AreEqual(
new Uri(expected),
EngineIoClient.ToWebSocketUri(new Uri(url), framework));
EngineIoClient.ToWebSocketUri(new Uri(url), framework)
.Should().Be(new Uri(expected));
}

[TestMethod]
Expand Down
7 changes: 4 additions & 3 deletions src/tests/H.Engine.IO.UnitTests/EngineIoPacketTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace H.Engine.IO.Tests
{
Expand All @@ -9,8 +10,8 @@ private static EngineIoPacket BaseDecodeTest(string message, EngineIoPacket expe
{
var packet = EngineIoPacket.Decode(message);

Assert.AreEqual(expectedPacket.Prefix, packet.Prefix, $"{nameof(BaseDecodeTest)}.{nameof(packet.Prefix)}: {message}");
Assert.AreEqual(expectedPacket.Value, packet.Value, $"{nameof(BaseDecodeTest)}.{nameof(packet.Value)}: {message}");
packet.Prefix.Should().Be(expectedPacket.Prefix);
packet.Value.Should().Be(expectedPacket.Value);

return packet;
}
Expand All @@ -19,7 +20,7 @@ private static string BaseEncodeTest(EngineIoPacket packet, string expectedMessa
{
var message = packet.Encode();

Assert.AreEqual(expectedMessage, message, $"{nameof(BaseEncodeTest)}.{nameof(message)}: {message}");
message.Should().Be(expectedMessage);

return message;
}
Expand Down
7 changes: 4 additions & 3 deletions src/tests/H.Engine.IO.UnitTests/H.Engine.IO.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/tests/H.Socket.IO.IntegrationTests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using H.Socket.IO.EventsArgs;
using H.WebSockets.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static async Task BaseTestAsync(

foreach (var pair in results)
{
Assert.IsNotNull(pair.Value, $"Client event(\"{pair.Key}\") did not happen");
pair.Value.Should().NotBeNull(because: $"Client event(\"{pair.Key}\") did not happen");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/tests/H.Socket.IO.UnitTests/H.Socket.IO.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/tests/H.Socket.IO.UnitTests/SocketIoPacketTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace H.Socket.IO.Tests
{
Expand All @@ -9,9 +10,9 @@ private static SocketIoPacket BaseDecodeTest(string message, SocketIoPacket expe
{
var packet = SocketIoPacket.Decode(message);

Assert.AreEqual(expectedPacket.Prefix, packet.Prefix, $"{nameof(BaseDecodeTest)}.{nameof(packet.Prefix)}: {message}");
Assert.AreEqual(expectedPacket.Namespace, packet.Namespace, $"{nameof(BaseDecodeTest)}.{nameof(packet.Namespace)}: {message}");
Assert.AreEqual(expectedPacket.Value, packet.Value, $"{nameof(BaseDecodeTest)}.{nameof(packet.Value)}: {message}");
packet.Prefix.Should().Be(expectedPacket.Prefix);
packet.Namespace.Should().Be(expectedPacket.Namespace);
packet.Value.Should().Be(expectedPacket.Value);

return packet;
}
Expand All @@ -20,7 +21,7 @@ private static string BaseEncodeTest(SocketIoPacket packet, string expectedMessa
{
var message = packet.Encode();

Assert.AreEqual(expectedMessage, message, $"{nameof(BaseEncodeTest)}.{nameof(message)}: {message}");
message.Should().Be(expectedMessage);

return message;
}
Expand Down
42 changes: 12 additions & 30 deletions src/tests/H.Socket.IO.UnitTests/SocketIoUtilitiesTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using H.Socket.IO.Utilities;
using H.Socket.IO.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace H.Socket.IO.Tests
{
Expand All @@ -11,33 +10,16 @@ public class SocketIoUtilitiesTests
[TestMethod]
public void GetEventValuesTest()
{
CollectionAreEqual(
new[] { "messages", "[{},{},{}]" },
"[\"messages\",[{},{},{}]]".GetJsonArrayValues());

CollectionAreEqual(
new [] { "message", "value" },
"[\"message\",\"value\"]".GetJsonArrayValues());

CollectionAreEqual(
new[] { "message" },
"[\"message\"]".GetJsonArrayValues());

CollectionAreEqual(
new[] { "message", "{}" },
"[\"message\",{}]".GetJsonArrayValues());

CollectionAreEqual(
new[] { "new message", "{\"username\":\"1\",\"message\":\"1\"}" },
"[\"new message\",{\"username\":\"1\",\"message\":\"1\"}]".GetJsonArrayValues());
}

private static void CollectionAreEqual<T>(IEnumerable<T> first, IEnumerable<T> second)
{
foreach (var (a, b) in first.Zip(second, (a, b) => (a, b)))
{
Assert.AreEqual(a, b);
}
"[\"messages\",[{},{},{}]]".GetJsonArrayValues()
.Should().BeEquivalentTo(new[] { "messages", "[{},{},{}]" });
"[\"message\",\"value\"]".GetJsonArrayValues()
.Should().BeEquivalentTo(new[] { "message", "value" });
"[\"message\"]".GetJsonArrayValues()
.Should().BeEquivalentTo(new[] { "message" });
"[\"message\",{}]".GetJsonArrayValues()
.Should().BeEquivalentTo(new[] { "message", "{}" });
"[\"new message\",{\"username\":\"1\",\"message\":\"1\"}]".GetJsonArrayValues()
.Should().BeEquivalentTo(new[] { "new message", "{\"username\":\"1\",\"message\":\"1\"}" });
}
}
}
6 changes: 3 additions & 3 deletions src/tests/H.Socket.IO.UnitTests/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using H.Socket.IO.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace H.Socket.IO.Tests
{
Expand All @@ -23,9 +24,8 @@ public void SplitByIndexesTest()
}
} while (index >= 0);

CollectionAssert.AreEqual(
new[] { "[\"message\"", "\"value\"", "\"value\"", "\"value\"]" },
text.SplitByIndexes(indexes.ToArray()));
text.SplitByIndexes(indexes.ToArray())
.Should().BeEquivalentTo(new[] { "[\"message\"", "\"value\"", "\"value\"", "\"value\"]" });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit deb1c91

Please sign in to comment.