Skip to content

Commit 84268ab

Browse files
refactor: remove Fluent Assertions from unit tests
- Updated all test methods to use Xunit's Assert class - Removed package dependency resolves #32 Signed-off-by: SebastienDegodez <sebastien.degodez@gmail.com>
1 parent 4ac3aff commit 84268ab

File tree

6 files changed

+65
-64
lines changed

6 files changed

+65
-64
lines changed

tests/Microcks.Testcontainers.Tests/Async/Kafka/MicrocksAsyncKafkaFunctionalityTest.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System.Linq;
2222
using Confluent.Kafka;
2323
using DotNet.Testcontainers.Builders;
24-
using FluentAssertions;
2524
using Microcks.Testcontainers.Connection;
2625
using Microcks.Testcontainers.Model;
2726
using Microsoft.Extensions.Logging;
@@ -103,7 +102,7 @@ public void ShouldReceivedKafkaMessageWhenMessageIsEmitted()
103102
message = consumeResult.Message.Value;
104103
}
105104

106-
message.Should().Be(expectedMessage);
105+
Assert.Equal(expectedMessage, message);
107106
}
108107

109108

@@ -164,17 +163,17 @@ public async Task ShouldReturnsCorrectStatusContractWhenGoodMessageIsEmitted()
164163
var testResult = await taskTestResult;
165164

166165
// Assert
167-
testResult.InProgress.Should().Be(false);
168-
testResult.Success.Should().Be(true);
169-
testResult.TestedEndpoint.Should().Be(testRequest.TestEndpoint);
166+
Assert.False(testResult.InProgress);
167+
Assert.True(testResult.Success);
168+
Assert.Equal(testRequest.TestEndpoint, testResult.TestedEndpoint);
170169

171170
var testCaseResult = testResult.TestCaseResults.First();
172171
var testStepResults = testCaseResult.TestStepResults;
173172

174173
// Minimum 1 message captured
175-
testStepResults.Should().NotBeEmpty();
174+
Assert.NotEmpty(testStepResults);
176175
// No error message
177-
testStepResults.First().Message.Should().BeNull();
176+
Assert.Null(testStepResults.First().Message);
178177
}
179178

180179

@@ -233,29 +232,30 @@ public async Task ShouldReturnsCorrectStatusContractWhenBadMessageIsEmitted()
233232
var testResult = await taskTestResult;
234233

235234
// Assert
236-
testResult.InProgress.Should().Be(false);
237-
testResult.Success.Should().Be(false);
238-
testResult.TestedEndpoint.Should().Be(testRequest.TestEndpoint);
235+
Assert.False(testResult.InProgress);
236+
Assert.False(testResult.Success);
237+
Assert.Equal(testRequest.TestEndpoint, testResult.TestedEndpoint);
239238

240239
var testCaseResult = testResult.TestCaseResults.First();
241240
var testStepResults = testCaseResult.TestStepResults;
242241

243242
// Minimum 1 message captured
244-
testStepResults.Should().NotBeEmpty();
243+
Assert.NotEmpty(testStepResults);
245244
// Error message status is missing
246-
testStepResults.First().Message.Should().Contain("object has missing required properties ([\"status\"]");
245+
Assert.Contains("object has missing required properties ([\"status\"]", testStepResults.First().Message);
247246

248247
// Retrieve event messages for the failing test case.
249248
var events = await _microcksContainerEnsemble.MicrocksContainer
250249
.GetEventMessagesForTestCaseAsync(testResult, "SUBSCRIBE pastry/orders");
251250
// We should have at least 4 events.
252-
events.Count.Should().BeGreaterOrEqualTo(4);
251+
Assert.True(events.Count >= 4);
253252

254-
events.Should().AllSatisfy(e =>
253+
// Check that all events have the correct message.
254+
Assert.All(events, e =>
255255
{
256256
// Check these are the correct message.
257-
e.EventMessage.Should().NotBeNull();
258-
e.EventMessage.Content.Should().Be(message);
257+
Assert.NotNull(e.EventMessage);
258+
Assert.Equal(message, e.EventMessage.Content);
259259
});
260260
}
261261

tests/Microcks.Testcontainers.Tests/Async/MicrocksAsyncFeatureTest.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using System.Threading;
2323
using DotNet.Testcontainers.Builders;
2424
using DotNet.Testcontainers.Containers;
25-
using FluentAssertions;
2625
using Microcks.Testcontainers.Model;
2726

2827
namespace Microcks.Testcontainers.Tests.Async;
@@ -84,9 +83,8 @@ public async Task InitializeAsync()
8483
[Fact]
8584
public void ShouldDetermineCorrectImageMessage()
8685
{
87-
this._microcksContainerEnsemble.AsyncMinionContainer.Image.FullName
88-
.Should()
89-
.Be("quay.io/microcks/microcks-uber-async-minion:1.10.1");
86+
Assert.Equal("quay.io/microcks/microcks-uber-async-minion:1.10.1",
87+
this._microcksContainerEnsemble.AsyncMinionContainer.Image.FullName);
9088
}
9189

9290
/// <summary>
@@ -116,7 +114,7 @@ await webSocketClient.CloseAsync(
116114
"Test done",
117115
CancellationToken.None);
118116

119-
message.Should().Be(expectedMessage);
117+
Assert.Equal(expectedMessage, message);
120118
}
121119

122120
/// <summary>
@@ -140,13 +138,13 @@ public async Task ShouldReturnsCorrectStatusContractWhenBadMessageIsEmitted()
140138
var testResult = await taskTestResult;
141139

142140
// Assert
143-
testResult.InProgress.Should().Be(false);
144-
testResult.Success.Should().Be(false);
145-
testResult.TestedEndpoint.Should().Be(testRequest.TestEndpoint);
141+
Assert.False(testResult.InProgress);
142+
Assert.False(testResult.Success);
143+
Assert.Equal(testRequest.TestEndpoint, testResult.TestedEndpoint);
146144

147-
testResult.TestCaseResults.First().TestStepResults.Should().NotBeEmpty();
145+
Assert.NotEmpty(testResult.TestCaseResults.First().TestStepResults);
148146
var testStepResult = testResult.TestCaseResults.First().TestStepResults.First();
149-
testStepResult.Message.Should().Contain("object has missing required properties ([\"status\"]");
147+
Assert.Contains("object has missing required properties ([\"status\"]", testStepResult.Message);
150148
}
151149

152150
/// <summary>
@@ -170,11 +168,11 @@ public async Task ShouldReturnsCorrectStatusContractWhenGoodMessageIsEmitted()
170168
var testResult = await taskTestResult;
171169

172170
// Assert
173-
testResult.InProgress.Should().Be(false);
174-
testResult.Success.Should().Be(true);
175-
testResult.TestedEndpoint.Should().Be(testRequest.TestEndpoint);
171+
Assert.False(testResult.InProgress);
172+
Assert.True(testResult.Success);
173+
Assert.Equal(testRequest.TestEndpoint, testResult.TestedEndpoint);
176174

177-
testResult.TestCaseResults.First().TestStepResults.Should().NotBeEmpty();
178-
testResult.TestCaseResults.First().TestStepResults.First().Message.Should().BeNullOrEmpty();
175+
Assert.NotEmpty(testResult.TestCaseResults.First().TestStepResults);
176+
Assert.True(string.IsNullOrEmpty(testResult.TestCaseResults.First().TestStepResults.First().Message));
179177
}
180178
}

tests/Microcks.Testcontainers.Tests/Microcks.Testcontainers.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<NoWarn>$(NoWarn);CS1591</NoWarn>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="FluentAssertions" Version="7.0.0" />
109
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
1110
<PackageReference Include="coverlet.collector" Version="6.0.2" />
1211
<PackageReference Include="RestAssured.Net" Version="4.5.1" />

tests/Microcks.Testcontainers.Tests/MicrocksContractTestingFunctionalityTests.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// you may not use this file except in compliance with the License.
66
// You may obtain a copy of the License at
77
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
8+
// http://www.apache.org/licenses/LICENSE-2.0
99
//
1010
// Unless required by applicable law or agreed to in writing, software
1111
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,7 +18,6 @@
1818
using DotNet.Testcontainers.Builders;
1919
using DotNet.Testcontainers.Containers;
2020
using DotNet.Testcontainers.Networks;
21-
using FluentAssertions;
2221
using Microcks.Testcontainers;
2322
using Microcks.Testcontainers.Model;
2423
using System;
@@ -109,10 +108,10 @@ public async Task ShouldReturnSuccess_WhenGoodImplementation()
109108

110109
// First test should fail with validation failure messages.
111110
TestResult badTestResult = await _microcksContainer.TestEndpointAsync(badTestRequest);
112-
badTestResult.Success.Should().BeFalse();
113-
badTestResult.TestedEndpoint.Should().Be("http://bad-impl:3001");
114-
badTestResult.TestCaseResults.Should().HaveCount(3);
115-
badTestResult.TestCaseResults[0].TestStepResults[0].Message.Should().Contain("object has missing required properties");
111+
Assert.False(badTestResult.Success);
112+
Assert.Equal("http://bad-impl:3001", badTestResult.TestedEndpoint);
113+
Assert.Equal(3, badTestResult.TestCaseResults.Count);
114+
Assert.Contains("object has missing required properties", badTestResult.TestCaseResults[0].TestStepResults[0].Message);
116115

117116
// Switch endpoint to good implementation
118117
var goodTestRequest = new TestRequest
@@ -123,10 +122,10 @@ public async Task ShouldReturnSuccess_WhenGoodImplementation()
123122
Timeout = TimeSpan.FromMilliseconds(2000)
124123
};
125124
TestResult goodTestResult = await _microcksContainer.TestEndpointAsync(goodTestRequest);
126-
goodTestResult.Success.Should().BeTrue();
127-
goodTestResult.TestedEndpoint.Should().Be("http://good-impl:3002");
128-
goodTestResult.TestCaseResults.Should().HaveCount(3);
129-
goodTestResult.TestCaseResults[0].TestStepResults[0].Message.Should().BeEmpty();
125+
Assert.True(goodTestResult.Success);
126+
Assert.Equal("http://good-impl:3002", goodTestResult.TestedEndpoint);
127+
Assert.Equal(3, goodTestResult.TestCaseResults.Count);
128+
Assert.Empty(goodTestResult.TestCaseResults[0].TestStepResults[0].Message);
130129

131130
// Test avec un header
132131
var goodTestRequestWithHeader = new TestRequest
@@ -151,15 +150,22 @@ public async Task ShouldReturnSuccess_WhenGoodImplementation()
151150
};
152151

153152
TestResult goodTestResultWithHeader = await _microcksContainer.TestEndpointAsync(goodTestRequestWithHeader);
154-
goodTestResultWithHeader.Success.Should().BeTrue();
155-
goodTestResultWithHeader.TestedEndpoint.Should().Be("http://good-impl:3002");
156-
goodTestResultWithHeader.TestCaseResults.Should().HaveCount(3);
157-
goodTestResultWithHeader.TestCaseResults[0].TestStepResults[0].Message.Should().BeEmpty();
158-
goodTestResultWithHeader.OperationsHeaders.Should().HaveCount(1);
159-
goodTestResultWithHeader.OperationsHeaders.Should().ContainKey("GET /pastries");
160-
goodTestResultWithHeader.OperationsHeaders["GET /pastries"].Should().HaveCount(1);
153+
Assert.True(goodTestResultWithHeader.Success);
154+
Assert.Equal("http://good-impl:3002", goodTestResultWithHeader.TestedEndpoint);
155+
Assert.Equal(3, goodTestResultWithHeader.TestCaseResults.Count);
156+
Assert.Empty(goodTestResultWithHeader.TestCaseResults[0].TestStepResults[0].Message);
157+
Assert.Single(goodTestResultWithHeader.OperationsHeaders);
158+
Assert.True(goodTestResultWithHeader.OperationsHeaders.ContainsKey("GET /pastries"));
159+
Assert.Single(goodTestResultWithHeader.OperationsHeaders["GET /pastries"]);
161160
var header = goodTestResultWithHeader.OperationsHeaders["GET /pastries"][0];
162-
header.Name.Should().Be("X-Custom-Header-1");
163-
header.Values.Split(",").Should().BeEquivalentTo(["value1", "value2", "value3"]);
161+
Assert.Equal("X-Custom-Header-1", header.Name);
162+
163+
var actualItems = header.Values.Split(",");
164+
var expectedItems = new[] { "value1", "value2", "value3" };
165+
166+
foreach (var expectedItem in expectedItems)
167+
{
168+
Assert.Contains(expectedItem, actualItems);
169+
}
164170
}
165171
}

tests/Microcks.Testcontainers.Tests/MicrocksMockingFunctionalityTest.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// you may not use this file except in compliance with the License.
66
// You may obtain a copy of the License at
77
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
8+
// http://www.apache.org/licenses/LICENSE-2.0
99
//
1010
// Unless required by applicable law or agreed to in writing, software
1111
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,7 +15,6 @@
1515
//
1616
//
1717

18-
using FluentAssertions;
1918
using NHamcrest;
2019
using NHamcrest.Core;
2120
using RestAssured.Logging;
@@ -50,16 +49,16 @@ public Task InitializeAsync()
5049
public void ShouldConfigureMockEndpoints()
5150
{
5251
string baseWsUrl = $"{_microcksContainer.GetSoapMockEndpoint("Pastries Service", "1.0")}";
53-
baseWsUrl.Should().Be($"{_microcksContainer.GetHttpEndpoint()}soap/Pastries Service/1.0");
52+
Assert.Equal($"{_microcksContainer.GetHttpEndpoint()}soap/Pastries Service/1.0", baseWsUrl);
5453

5554
string baseApiUrl = $"{_microcksContainer.GetRestMockEndpoint("API Pastries", "0.0.1")}";
56-
baseApiUrl.Should().Be($"{_microcksContainer.GetHttpEndpoint()}rest/API Pastries/0.0.1");
55+
Assert.Equal($"{_microcksContainer.GetHttpEndpoint()}rest/API Pastries/0.0.1", baseApiUrl);
5756

5857
string baseGraphUrl = $"{_microcksContainer.GetGraphQLMockEndpoint("Pastries Graph", "1")}";
59-
baseGraphUrl.Should().Be($"{_microcksContainer.GetHttpEndpoint()}graphql/Pastries Graph/1");
58+
Assert.Equal($"{_microcksContainer.GetHttpEndpoint()}graphql/Pastries Graph/1", baseGraphUrl);
6059

6160
string baseGrpcUrl = $"{_microcksContainer.GetGrpcMockEndpoint()}";
62-
baseGrpcUrl.Should().Be($"grpc://{_microcksContainer.Hostname}:{_microcksContainer.GetMappedPublicPort(MicrocksBuilder.MicrocksGrpcPort)}/");
61+
Assert.Equal($"grpc://{_microcksContainer.Hostname}:{_microcksContainer.GetMappedPublicPort(MicrocksBuilder.MicrocksGrpcPort)}/", baseGrpcUrl);
6362
}
6463

6564
[Fact]
@@ -98,8 +97,7 @@ public async Task ShouldAvailableServices()
9897
.Response().Content.ReadAsStringAsync();
9998

10099
var document = JsonDocument.Parse(services);
101-
document.RootElement.EnumerateArray().Should().HaveCount(7);
102-
100+
Assert.Equal(7, document.RootElement.GetArrayLength());
103101

104102
verifiableResponse.Body("$[0:].name", Has.Items(
105103
Is.EqualTo("Petstore API"),

tests/Microcks.Testcontainers.Tests/MicrocksSecretCreationTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// you may not use this file except in compliance with the License.
66
// You may obtain a copy of the License at
77
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
8+
// http://www.apache.org/licenses/LICENSE-2.0
99
//
1010
// Unless required by applicable law or agreed to in writing, software
1111
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,7 +15,6 @@
1515
//
1616
//
1717

18-
using FluentAssertions;
1918
using Microcks.Testcontainers;
2019
using NHamcrest;
2120
using System;
@@ -59,7 +58,7 @@ public async Task ShouldFindSecrets()
5958
.Response().Content.ReadAsStringAsync();
6059

6160
var document = JsonDocument.Parse(result);
62-
document.RootElement.EnumerateArray().Should().HaveCount(1);
61+
Assert.Equal(1, document.RootElement.GetArrayLength());
6362
}
6463

6564
[Fact]
@@ -68,8 +67,9 @@ public void ShouldNotThrowExceptionWhenNameDefined()
6867
var secret = new SecretBuilder()
6968
.WithName("my-secret")
7069
.Build();
71-
secret.Should().NotBeNull();
72-
secret.Name.Should().Be("my-secret");
70+
71+
Assert.NotNull(secret);
72+
Assert.Equal("my-secret", secret.Name);
7373
}
7474

7575
[Fact]

0 commit comments

Comments
 (0)