Skip to content

Commit c50e2a5

Browse files
Improve README examples to show both traditional and strongly-typed approaches
Co-authored-by: JeanMarcMbouma <16613177+JeanMarcMbouma@users.noreply.github.com>
1 parent 4828b21 commit c50e2a5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,16 @@ using BbQ.MockLite;
203203
// Track method calls with custom logic using strongly-typed handlers
204204
var auditLog = new List<string>();
205205
var builder = Mock.Create<IUserRepository>()
206+
// Traditional approach with object array
206207
.OnCall(x => x.GetUser(It.IsAny<string>()),
207-
(string userId) => auditLog.Add($"GetUser called with: {userId}"))
208+
args => auditLog.Add($"GetUser called with: {args[0]}"))
209+
// Strongly-typed approach (new)
208210
.OnCall(x => x.SaveUser(It.IsAny<User>()),
209-
args => args[0] is User u && u.IsAdmin,
210-
args => auditLog.Add($"Admin user saved: {((User)args[0]).Name}"));
211+
(User user) => auditLog.Add($"SaveUser called with: {user.Name}"))
212+
// Conditional callback with matcher
213+
.OnCall(x => x.DeleteUser(It.IsAny<string>()),
214+
args => args[0] is string id && id.StartsWith("admin"),
215+
args => auditLog.Add($"Admin user deleted: {args[0]}"));
211216

212217
var mock = builder.Object;
213218

0 commit comments

Comments
 (0)