Skip to content

Document delegate mocking feature #413

@vbreuss

Description

@vbreuss

Description

While delegates are mentioned in the main example, delegate mocking is not properly documented as a standalone feature.

Missing Documentation

  • Mock Action<T>, Func<T>, and custom delegates
  • SetupMock.Delegate() for setup
  • VerifyMock.Invoked() for delegate verification
  • Full parameter matching support for delegates

Suggested Documentation

Add a new section titled "Mocking Delegates":

### Mocking Delegates

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

```csharp
// Create a mock delegate
var myDelegate = Mock.Create<Action<string, int>>();

// Setup the delegate
myDelegate.SetupMock.Delegate(It.Is(\"Dark\"), It.IsAny<int>())
    .Do((type, amount) => Console.WriteLine($\"Dispensed {amount} {type}\"));

// Invoke the delegate
myDelegate(\"Dark\", 5);

// Verify invocation
myDelegate.VerifyMock.Invoked(It.Is(\"Dark\"), It.Is(5)).Once();

Custom delegates are also supported:

var customDelegate = Mock.Create<ChocolateDispensedDelegate>();
customDelegate.SetupMock.Delegate(It.IsAny<string>(), It.IsAny<int>())
    .Do((type, amount) => { /* handler */ });

Metadata

Metadata

Labels

documentationImprovements or additions to documentationstate: releasedThe issue is released

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions