You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduced a robust callback mechanism for executing custom logic
during mock interactions. Added support for method callbacks
(`OnCall`) with or without argument matchers, and property access
callbacks (`OnPropertyAccess`, `OnGetCallback`, `OnSetCallback`)
for tracking property reads and writes.
Enhanced the `README.md` with detailed examples and documentation
on callback usage. Updated the core runtime (`RuntimeProxy`) to
include callback registration and execution. Extended the `Mock<T>`
class with new callback methods and refactored helper functions.
Added comprehensive unit tests in `MockCallbackTests` to cover
various callback scenarios, including conditional callbacks,
property access tracking, and integration workflows. Updated
project structure and documentation links to reflect the new
features. Improved code comments and adjusted invocation recording
to ensure compatibility with callbacks.
-`VerifySet<TProp>(property, matcher, times)` - Verify property setter with value matching
110
111
112
+
**Callback Methods:**
113
+
-`OnCall(expression, callback)` - Execute logic when method is called
114
+
-`OnCall(expression, matcher, callback)` - Execute logic when method is called with matching arguments
115
+
-`OnPropertyAccess<T>(property, callback)` - Execute logic on property get or set
116
+
-`OnGetCallback<T>(property, callback)` - Execute logic when property getter is accessed
117
+
-`OnSetCallback<T>(property, callback)` - Execute logic when property setter is called
118
+
-`OnSetCallback<T>(property, matcher, callback)` - Execute logic when property setter is called with matching value
119
+
111
120
**Properties:**
112
121
-`Object` - Get the mock instance
113
122
-`Invocations` - Access all recorded invocations for custom verification
114
123
124
+
## Callbacks for Custom Logic Execution
125
+
126
+
BbQ.MockLite supports callbacks that execute custom logic when methods are called or properties are accessed. This is useful for audit logging, state management, and complex verification scenarios.
127
+
128
+
```csharp
129
+
usingBbQ.MockLite;
130
+
131
+
// Track method calls with custom logic
132
+
varauditLog=newList<string>();
133
+
varbuilder=Mock.Create<IUserRepository>()
134
+
.OnCall(x=>x.GetUser(It.IsAny<string>()),
135
+
args=>auditLog.Add($"GetUser called with: {args[0]}"))
136
+
.OnCall(x=>x.SaveUser(It.IsAny<User>()),
137
+
args=>args[0] isUseru&&u.IsAdmin,
138
+
args=>auditLog.Add($"Admin user saved: {((User)args[0]).Name}"));
0 commit comments