Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions Docs/pages/01-create-mocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,25 @@ var sut2 = factory.Create<ILemonadeDispenser>();

Using a factory allows you to create multiple mocks with identical, centrally configured behavior. This is especially
useful when you need consistent mock setups across multiple tests or for different types.

## Wrapping Existing Instances

You can wrap an existing instance with mock tracking using `Mock.Wrap<T>()`. This allows you to track interactions with a real object:

```csharp
var realDispenser = new ChocolateDispenser();
var wrappedDispenser = Mock.Wrap<IChocolateDispenser>(realDispenser);

// Calls are forwarded to the real instance
wrappedDispenser.Dispense("Dark", 5);

// But you can still verify interactions
wrappedDispenser.VerifyMock.Invoked.Dispense(It.Is("Dark"), It.Is(5)).Once();
```

**Notes:**

- Only interface types can be wrapped with `Mock.Wrap<T>()`.
- All calls are forwarded to the wrapped instance.
- You can still set up custom behavior that overrides the wrapped instance's behavior.
- Verification works the same as with regular mocks.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,28 @@ var sut2 = factory.Create<ILemonadeDispenser>();
Using a factory allows you to create multiple mocks with identical, centrally configured behavior. This is especially
useful when you need consistent mock setups across multiple tests or for different types.

### Wrapping Existing Instances

You can wrap an existing instance with mock tracking using `Mock.Wrap<T>()`. This allows you to track interactions with a real object:

```csharp
var realDispenser = new ChocolateDispenser();
var wrappedDispenser = Mock.Wrap<IChocolateDispenser>(realDispenser);

// Calls are forwarded to the real instance
wrappedDispenser.Dispense("Dark", 5);

// But you can still verify interactions
wrappedDispenser.VerifyMock.Invoked.Dispense(It.Is("Dark"), It.Is(5)).Once();
```

**Notes:**

- Only interface types can be wrapped with `Mock.Wrap<T>()`.
- All calls are forwarded to the wrapped instance.
- You can still set up custom behavior that overrides the wrapped instance's behavior.
- Verification works the same as with regular mocks.

## Setup

Set up return values or behaviors for methods, properties, and indexers on your mock. Control how the mock responds to
Expand Down