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
2 changes: 1 addition & 1 deletion Docs/pages/01-create-mocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var classMock = Mock.Create<MyChocolateDispenser>(
);
```

**`MockBehavior` options**
### `MockBehavior` options

- `ThrowWhenNotSetup` (bool):
- If `false` (default), the mock will return a default value (see `DefaultValue`).
Expand Down
6 changes: 3 additions & 3 deletions Docs/pages/setup/01-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Set up property getters and setters to control or verify property access on your mocks.

**Initialization**
## Initialization

You can initialize properties so they work like normal properties (setter changes the value, getter returns the last set
value):
Expand All @@ -11,7 +11,7 @@ value):
sut.SetupMock.Property.TotalDispensed.InitializeWith(42);
```

**Returns / Throws**
## Returns / Throws

Alternatively, set up properties with `Returns` and `Throws` (supports sequences):

Expand All @@ -23,7 +23,7 @@ sut.SetupMock.Property.TotalDispensed
.Returns(4);
```

**Callbacks**
## Callbacks

Register callbacks on the setter or getter:

Expand Down
8 changes: 5 additions & 3 deletions Docs/pages/setup/02-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ sut.SetupMock.Method.Dispense(It.Is("Green"), It.IsAny<int>())
- Use `.SkippingBaseClass(…)` to override the base class behavior for a specific method (only for class mocks).
- When you specify overlapping setups, the most recently defined setup takes precedence.

**Async Methods**
## Async Methods

For `Task<T>` or `ValueTask<T>` methods, use `.ReturnsAsync(…)`:
For `Task<T>` or `ValueTask<T>` methods, use `.ReturnsAsync(…)` or `ThrowsAsync(…)`:

```csharp
sut.SetupMock.Method.DispenseAsync(It.IsAny<string>(), It.IsAny<int>())
.ReturnsAsync(true);
.ReturnsAsync((_, v) => v) // First execution returns the value of the `int` parameter
.ThrowsAsync(new TimeoutException()) // Second execution throws a TimeoutException;
Comment thread
vbreuss marked this conversation as resolved.
Outdated
.ReturnsAsync(0).Forever(); // Subsequent executions return 0
Comment thread
vbreuss marked this conversation as resolved.
Outdated
```
16 changes: 8 additions & 8 deletions Docs/pages/setup/04-parameter-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Mockolate provides flexible parameter matching for method setups and verificatio

## Parameter Matchers

**Basic Matchers**
### Basic Matchers

- `It.IsAny<T>()`: Matches any value of type `T`.
- `It.Is<T>(value)`: Matches a specific value.
Expand All @@ -15,11 +15,11 @@ Mockolate provides flexible parameter matching for method setups and verificatio
minimum and maximum value.
- `It.Satisfies<T>(predicate)`: Matches values based on a predicate.

**String Matching**
### String Matching

- `It.Matches(pattern)`: Matches strings using wildcard patterns (`*` and `?`).

**Regular Expressions**
#### Regular Expressions
Use `.AsRegex()` to enable regular expression matching for `It.Matches()`:

```csharp
Expand All @@ -34,7 +34,7 @@ sut.SetupMock.Method.Process(It.Matches("^[A-Z]+$").AsRegex().CaseSensitive())
.Returns(1);
```

**Ref and Out Parameters**
### Ref and Out Parameters

- `It.IsRef<T>(setter)`: Matches any `ref` parameter and sets a new value using the setter function.
- `It.IsRef<T>(predicate, setter)`: Matches `ref` parameters that satisfy the predicate and sets a new value.
Expand Down Expand Up @@ -62,7 +62,7 @@ sut.Increment(ref value);
// value == 6
```

**Span Parameters (.NET 8+)**
### Span Parameters (.NET 8+)

- `It.IsSpan<T>(predicate)`: Matches `Span<T>` parameters that satisfy the predicate.
- `It.IsAnySpan<T>()`: Matches any `Span<T>` parameter.
Expand All @@ -83,7 +83,7 @@ bool result = sut.Process(buffer);
// result == true
```

**Custom Equality Comparers**
### Custom Equality Comparers

Use `.Using(IEqualityComparer<T>)` to provide custom equality comparison for `It.Is()` and `It.IsOneOf()`:

Expand Down Expand Up @@ -118,7 +118,7 @@ bool result = sut.Process("test123", 5);

## Parameter Interaction

**Callbacks**
### Callbacks

With `.Do`, you can register a callback for individual parameters of a method setup. This allows you to implement side
effects or checks directly when the method or indexer is called.
Expand All @@ -132,7 +132,7 @@ sut.Dispense("Dark", 42);
// lastAmount == 42
```

**Monitor**
### Monitor

With `.Monitor(out monitor)`, you can track the actual
values passed during test execution and analyze them afterward.
Expand Down
4 changes: 2 additions & 2 deletions Docs/pages/special-types/02-delegates.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Mockolate supports mocking delegates including `Action`, `Func<T>`, and custom delegates.

**Setup**
## Setup

Use `SetupMock.Delegate(…)` to configure delegate behavior.

Expand Down Expand Up @@ -46,7 +46,7 @@ processor.SetupMock.Delegate(It.IsAny<int>(), It.IsRef<int>(v => v + 1), It.IsOu
- Full [parameter matching](https://awexpect.com/docs/mockolate/setup#parameter-matching) support for delegate
parameters including `ref` and `out` parameters.

**Verification**
## Verification

You can verify that delegates were invoked with specific arguments:

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ sut.SetupMock.Method.Dispense(It.Is("Green"), It.IsAny<int>())

**Async Methods**

For `Task<T>` or `ValueTask<T>` methods, use `.ReturnsAsync(…)`:
For `Task<T>` or `ValueTask<T>` methods, use `.ReturnsAsync(…)` or `ThrowsAsync(…)`:

```csharp
sut.SetupMock.Method.DispenseAsync(It.IsAny<string>(), It.IsAny<int>())
.ReturnsAsync(true);
.ReturnsAsync((_, v) => v) // First execution returns the value of the `int` parameter
.ThrowsAsync(new TimeoutException()) // Second execution throws a TimeoutException;
Comment thread
vbreuss marked this conversation as resolved.
Outdated
.ReturnsAsync(0).Forever(); // Subsequent executions return 0
Comment thread
vbreuss marked this conversation as resolved.
Outdated
```

### Indexers
Expand Down
Loading