Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Source/Mockolate/Setup/Callback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ public bool Invoke(bool wasInvoked, ref int index, Action<int, TDelegate> callba

return !RunInParallel;
}

_forIterationCount++;
_matchingCount++;
}

_invocationCount++;
Expand Down Expand Up @@ -177,9 +174,6 @@ public bool Invoke(ref int index, Action<int, TDelegate> callback)
callback(_invocationCount - 1, @delegate);
return true;
}

_forIterationCount++;
_matchingCount++;
}

_invocationCount++;
Expand Down Expand Up @@ -212,9 +206,6 @@ public bool Invoke<TReturn>(ref int index, Func<int, TDelegate, TReturn> callbac
returnValue = callback(_invocationCount - 1, @delegate)!;
return true;
}

_forIterationCount++;
_matchingCount++;
}

_invocationCount++;
Expand Down
40 changes: 40 additions & 0 deletions Tests/Mockolate.Internal.Tests/CallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,46 @@ public async Task ShouldIncrementIndexOnceWhenCallbackIsExhausted(
await That(indexValues).IsEqualTo(expectResult);
}

[Theory]
[InlineData(2, 2, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2)]
[InlineData(2, 3, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3)]
public async Task ShouldIncrementIndexWheneverForIsExhausted(
int @for, int only, params int[] expectResult)
{
bool wasInvoked = false;
List<int> indexValues = [];
Callback<Action> sut = new(() => { });
sut.For(@for);
sut.Only(only);

int index = 0;
for (int iteration = 1; iteration <= 10; iteration++)
{
sut.Invoke(wasInvoked, ref index, (_, _) => { });
indexValues.Add(index);
}

await That(indexValues).IsEqualTo(expectResult);
}

[Fact]
public async Task ShouldLimitExecutionWhenRunningInParallel()
{
bool wasInvoked = false;
List<int> values = [];
Callback<Action> sut = new(() => { });
sut.Only(2);
sut.InParallel();

int index = 0;
for (int i = 0; i < 5; i++)
{
sut.Invoke(wasInvoked, ref index, (v, _) => values.Add(v));
}

await That(values).IsEqualTo([0, 1,]);
Comment thread
vbreuss marked this conversation as resolved.
}

[Fact]
public async Task WhenCheck_ShouldOnlyBeCalledWhenOnlyLimitIsNotReached()
{
Expand Down
Loading