Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
Prev Previous commit
Next Next commit
refactor(mocks): rename Invocations to GetInvocations for consistency
All static accessors now use Get prefix: GetBehavior, GetDiagnostics,
GetDefaultValueProvider, GetInvocations. Makes it clear these are
method calls with potential cost (GetInvocations allocates an array).
  • Loading branch information
thomhurst committed Feb 25, 2026
commit 8f1d84bb053fc935685800ec18292beafc687fd5
12 changes: 6 additions & 6 deletions 12 TUnit.Mocks.Tests/AdditionalCoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ public async Task Invocations_Are_In_Call_Order()
mock.Object.GetName();
mock.Object.Add(3, 4);

await Assert.That(Mock.Invocations(mock)).HasCount().EqualTo(4);
await Assert.That(Mock.Invocations(mock)[0].MemberName).IsEqualTo("Add");
await Assert.That(Mock.Invocations(mock)[1].MemberName).IsEqualTo("Log");
await Assert.That(Mock.Invocations(mock)[2].MemberName).IsEqualTo("GetName");
await Assert.That(Mock.Invocations(mock)[3].MemberName).IsEqualTo("Add");
await Assert.That(Mock.GetInvocations(mock)).HasCount().EqualTo(4);
await Assert.That(Mock.GetInvocations(mock)[0].MemberName).IsEqualTo("Add");
await Assert.That(Mock.GetInvocations(mock)[1].MemberName).IsEqualTo("Log");
await Assert.That(Mock.GetInvocations(mock)[2].MemberName).IsEqualTo("GetName");
await Assert.That(Mock.GetInvocations(mock)[3].MemberName).IsEqualTo("Add");
}

[Test]
Expand All @@ -282,7 +282,7 @@ public async Task Invocations_Sequence_Numbers_Are_Monotonically_Increasing()
mock.Object.GetName();
mock.Object.Log("msg");

var invocations = Mock.Invocations(mock);
var invocations = Mock.GetInvocations(mock);
for (int i = 1; i < invocations.Count; i++)
{
await Assert.That(invocations[i].SequenceNumber)
Expand Down
12 changes: 6 additions & 6 deletions 12 TUnit.Mocks.Tests/InvocationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Invocations_Returns_All_Calls()
svc.GetValue("key2");
svc.Process(42);

await Assert.That(Mock.Invocations(mock).Count).IsEqualTo(3);
await Assert.That(Mock.GetInvocations(mock).Count).IsEqualTo(3);
}

[Test]
Expand All @@ -32,8 +32,8 @@ public async Task Invocations_Contains_Correct_Method_Names()
svc.GetValue("key1");
svc.Process(99);

await Assert.That(Mock.Invocations(mock)[0].MemberName).IsEqualTo("GetValue");
await Assert.That(Mock.Invocations(mock)[1].MemberName).IsEqualTo("Process");
await Assert.That(Mock.GetInvocations(mock)[0].MemberName).IsEqualTo("GetValue");
await Assert.That(Mock.GetInvocations(mock)[1].MemberName).IsEqualTo("Process");
}

[Test]
Expand All @@ -45,14 +45,14 @@ public async Task Invocations_Contains_Correct_Arguments()
var svc = mock.Object;
svc.GetValue("hello");

await Assert.That(Mock.Invocations(mock)[0].Arguments[0]).IsEqualTo("hello");
await Assert.That(Mock.GetInvocations(mock)[0].Arguments[0]).IsEqualTo("hello");
}

[Test]
public async Task Invocations_Is_Empty_When_No_Calls_Made()
{
var mock = Mock.Of<IService>();
await Assert.That(Mock.Invocations(mock).Count).IsEqualTo(0);
await Assert.That(Mock.GetInvocations(mock).Count).IsEqualTo(0);
}

[Test]
Expand All @@ -66,6 +66,6 @@ public async Task Invocations_Is_Empty_After_Reset()

Mock.Reset(mock);

await Assert.That(Mock.Invocations(mock).Count).IsEqualTo(0);
await Assert.That(Mock.GetInvocations(mock).Count).IsEqualTo(0);
}
}
4 changes: 2 additions & 2 deletions 4 TUnit.Mocks.Tests/MockRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public async Task Repository_Reset_Clears_All_Mocks()

// Assert — setups and history are cleared
await Assert.That(serviceMock.Object.GetData(1)).IsEmpty(); // no setup, returns smart default
await Assert.That(Mock.Invocations(serviceMock)).Count().IsEqualTo(1); // only the new call
await Assert.That(Mock.Invocations(loggerMock)).Count().IsEqualTo(0); // history cleared
await Assert.That(Mock.GetInvocations(serviceMock)).Count().IsEqualTo(1); // only the new call
await Assert.That(Mock.GetInvocations(loggerMock)).Count().IsEqualTo(0); // history cleared
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions 4 TUnit.Mocks.Tests/MultipleInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task Multi_Mock_Shares_Single_Engine()
((IMultiDisposable)mock.Object).Dispose();

// Assert — all calls recorded in invocations
await Assert.That(Mock.Invocations(mock)).Count().IsEqualTo(2);
await Assert.That(Mock.GetInvocations(mock)).Count().IsEqualTo(2);
}

[Test]
Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task Mock_Of_Four_Interfaces_Tracks_All_Calls()
((IMultiCloneable)mock.Object).Clone();

// Assert — all 4 calls tracked
await Assert.That(Mock.Invocations(mock)).Count().IsEqualTo(4);
await Assert.That(Mock.GetInvocations(mock)).Count().IsEqualTo(4);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion 2 TUnit.Mocks.Tests/ProtectedMemberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task Protected_Method_Calls_Are_Recorded_In_Invocations()
mock.Object.ProcessAndFormat(7);

// Assert — both ComputeValue (base call) and FormatResult are recorded
await Assert.That(Mock.Invocations(mock)).Count().IsGreaterThanOrEqualTo(2);
await Assert.That(Mock.GetInvocations(mock)).Count().IsGreaterThanOrEqualTo(2);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion 2 TUnit.Mocks/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public static void VerifyInOrder(Action verificationActions)
// ──────────────────────────────────────────────────────────

/// <summary>All calls made to this mock, in order.</summary>
public static IReadOnlyList<CallRecord> Invocations<T>(Mock<T> mock) where T : class
public static IReadOnlyList<CallRecord> GetInvocations<T>(Mock<T> mock) where T : class
=> mock.Engine.GetAllCalls();

/// <summary>Returns the mock behavior (Loose or Strict).</summary>
Expand Down
2 changes: 1 addition & 1 deletion 2 docs/docs/test-authoring/mocking/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ svc.GetUser(1);
Mock.Reset(mock);

svc.GetUser(1); // returns default (setup cleared)
Mock.Invocations(mock).Count; // 0 (history cleared)
Mock.GetInvocations(mock).Count; // 0 (history cleared)
```

The `SetupAllProperties()` flag is preserved across resets.
2 changes: 1 addition & 1 deletion 2 docs/docs/test-authoring/mocking/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ This integrates with TUnit's assertion engine — failures appear as assertion e
Access the raw call history for custom inspection:

```csharp
var calls = Mock.Invocations(mock);
var calls = Mock.GetInvocations(mock);

await Assert.That(calls).HasCount().EqualTo(3);
await Assert.That(calls[0].MemberName).IsEqualTo("GetUser");
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.