Skip to content

Document delegate mocking feature#414

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/document-delegate-mocking-feature
Closed

Document delegate mocking feature#414
Copilot wants to merge 3 commits into
mainfrom
copilot/document-delegate-mocking-feature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 30, 2026

Delegate mocking (Action, Func, custom delegates) was implemented but undocumented as a standalone feature.

Changes

  • Setup documentation - Added "Delegate Setup" section covering SetupMock.Delegate() with examples for Action, Func, and custom delegates including ref/out parameters
  • Verification documentation - Added "Delegates" section covering VerifyMock.Invoked() for delegate verification with parameter matching
  • Documentation consistency - Applied changes to both README.md and Docs/pages/ to maintain sync

Example

// Mock and setup a custom delegate
public delegate int Calculate(int x, string operation);
Calculate calculator = Mock.Create<Calculate>();
calculator.SetupMock.Delegate(It.IsAny<int>(), It.Is("add"))
    .Returns((x, operation) => x + 10);

// Use and verify
int result = calculator(5, "add");  // returns 15
calculator.VerifyMock.Invoked(It.IsAny<int>(), It.Is("add")).Once();
Original prompt

This section details on the original issue you should resolve

<issue_title>Document delegate mocking feature</issue_title>
<issue_description>## 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 */ });

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 30, 2026 17:31
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
…tions

Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Copilot AI changed the title [WIP] Document delegate mocking feature Document delegate mocking feature Jan 30, 2026
Copilot AI requested a review from vbreuss January 30, 2026 17:37
@vbreuss
Copy link
Copy Markdown
Member

vbreuss commented Jan 30, 2026

Obsolete by #428

@vbreuss vbreuss closed this Jan 30, 2026
@vbreuss vbreuss deleted the copilot/document-delegate-mocking-feature branch January 31, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document delegate mocking feature

2 participants