Skip to content

Commit 6708718

Browse files
authored
coverage: add missing tests for It.* (#736)
This pull request adds new unit tests to improve coverage and ensure correct behavior of the `It.IsNull`, `It.IsNotNull`, and `It.SequenceEquals` parameter matchers in the Mockolate testing framework. The most important changes include verifying the use of shared instances, correct string representations, handling of nulls in sequences, and support for multiple callbacks. **Parameter matcher instance behavior:** * Added tests to verify that `It.IsNull<string>()` and `It.IsNotNull<string>()` return shared instances when `ToString()` is not called, ensuring consistent identity semantics. **String representation and null handling:** * Added a test to `It.SequenceEquals<object?>` to ensure that the string representation correctly renders `null` elements as `null` tokens in the output. **Callback registration and invocation:** * Added a test to verify that multiple callbacks registered with `ISequenceEqualsParameter<int>` are all invoked when the matcher is triggered, improving confidence in the callback mechanism.
1 parent b0a4f6c commit 6708718

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

Tests/Mockolate.Tests/ItTests.IsNotNullTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public async Task NotNull_ShouldMatchWhenNotNull(int? value, int expectedCount)
3030
await That(sut.Mock.Verify.DoSomething(It.IsNotNull<int?>(), It.Is(true))).Exactly(expectedCount);
3131
}
3232

33+
[Fact]
34+
public async Task ShouldReturnSharedInstance_WhenToStringIsOmitted()
35+
{
36+
IParameter<string> first = It.IsNotNull<string>();
37+
IParameter<string> second = It.IsNotNull<string>();
38+
39+
await That(first).IsSameAs(second);
40+
}
41+
3342
[Fact]
3443
public async Task ToString_ShouldReturnExpectedValue()
3544
{

Tests/Mockolate.Tests/ItTests.IsNullTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public async Task Null_ShouldMatchWhenNull(int? value, int expectedCount)
3030
await That(sut.Mock.Verify.DoSomething(null, It.Is(true))).Exactly(expectedCount);
3131
}
3232

33+
[Fact]
34+
public async Task ShouldReturnSharedInstance_WhenToStringIsOmitted()
35+
{
36+
IParameter<string> first = It.IsNull<string>();
37+
IParameter<string> second = It.IsNull<string>();
38+
39+
await That(first).IsSameAs(second);
40+
}
41+
3342
[Fact]
3443
public async Task ToString_ShouldReturnExpectedValue()
3544
{

Tests/Mockolate.Tests/ItTests.SequenceEqualsTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ public async Task ToString_Using_ShouldReturnExpectedValue()
161161
await That(result).IsEqualTo(expectedValue);
162162
}
163163

164+
[Fact]
165+
public async Task ToString_WithNullElement_ShouldRenderNullToken()
166+
{
167+
IParameter<object?[]> sut = It.SequenceEquals<object?>("foo", null, 3);
168+
string expectedValue = "It.SequenceEquals(\"foo\", null, 3)";
169+
170+
string? result = sut.ToString();
171+
172+
await That(result).IsEqualTo(expectedValue);
173+
}
174+
164175
[Fact]
165176
public async Task ToString_WithStringValues_ShouldReturnExpectedValue()
166177
{
@@ -184,6 +195,22 @@ public async Task WithComparer_ShouldUseComparer()
184195

185196
public sealed class DoTests
186197
{
198+
[Fact]
199+
public async Task Do_MultipleRegistrations_ShouldAllInvoke()
200+
{
201+
It.ISequenceEqualsParameter<int> sut = It.SequenceEquals(1, 2, 3);
202+
int firstCount = 0;
203+
int secondCount = 0;
204+
((IParameterWithCallback<int[]>)sut).Do(_ => firstCount++);
205+
((IParameterWithCallback<int[]>)sut).Do(_ => secondCount++);
206+
207+
int[] source = [1, 2, 3,];
208+
((IParameterMatch<int[]>)sut).InvokeCallbacks(source);
209+
210+
await That(firstCount).IsEqualTo(1);
211+
await That(secondCount).IsEqualTo(1);
212+
}
213+
187214
[Fact]
188215
public async Task Do_RegistersCallbackForArray()
189216
{

0 commit comments

Comments
 (0)