Skip to content

Document advanced callback control features#429

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/document-advanced-callback-features
Closed

Document advanced callback control features#429
Copilot wants to merge 3 commits into
mainfrom
copilot/document-advanced-callback-features

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

Four advanced callback control features (.When(), .For(), .Only(), .InParallel(), and invocation counter access) were implemented and tested but undocumented.

Changes

Added documentation for:

  • Conditional Callbacks - .When(predicate) filters callback execution based on 0-indexed invocation count
  • Frequency Control - .For(n) executes exactly n times, .Only(n) executes up to n times
  • Parallel Callbacks - .InParallel() runs callback on every invocation regardless of setup order
  • Invocation Counter - Callbacks can accept int count parameter to access invocation index

Example

// Conditional execution
mock.SetupMock.Method.Process(It.IsAny<string>())
    .Do(() => Console.WriteLine("Called!"))
    .When(count => count < 3);  // Only first 3 invocations (0-indexed)

// Frequency control
mock.SetupMock.Method.Process(It.IsAny<string>())
    .Do(() => Console.WriteLine("Limited"))
    .For(5);  // Exactly 5 times

// Invocation counter access
mock.SetupMock.Property.Value
    .OnGet.Do((int count, int value) => 
        Console.WriteLine($"Read #{count}, value: {value}"));

Documentation added to both README.md and Docs/pages/02-setup.md.

Original prompt

This section details on the original issue you should resolve

<issue_title>Document advanced callback features</issue_title>
<issue_description>## Description

Several advanced callback control features are missing from the callback documentation.

Missing Documentation

  • .When(Func<int, bool>) - Conditional callback execution
  • .For(int times) - Execute callback N times
  • .Only(int times) - Execute callback up to N times
  • .InParallel() - Execute callback in parallel
  • Invocation counter in callbacks (Action<int>)

Suggested Documentation

Expand the callback sections with subsections for:

  1. Conditional Callbacks (.When())
  2. Frequency Control (.For(), .Only())
  3. Parallel Callbacks (.InParallel())
  4. Invocation Counter

Conditional Callbacks

Execute callbacks conditionally based on invocation count:

sut.SetupMock.Method.Dispense(It.Is("Dark"), It.IsAny<int>())
    .Do(() => Console.WriteLine("Called!"))
    .When(count => count <= 3);  // Only first 3 invocations

Frequency Control

Control how many times a callback executes:

// Execute exactly 5 times
sut.SetupMock.Method.Dispense(It.IsAny<string>(), It.IsAny<int>())
    .Do(() => Console.WriteLine("First 5 calls"))
    .For(5);

// Execute up to 3 times
sut.SetupMock.Method.Dispense(It.IsAny<string>(), It.IsAny<int>())
    .Do(() => Console.WriteLine("Up to 3 calls"))
    .Only(3);

Parallel Callbacks

Execute callbacks in parallel:

sut.SetupMock.Method.Dispense(It.IsAny<string>(), It.IsAny<int>())
    .Do(() => { /* parallel work */ })
    .InParallel();

Invocation Counter

Access the invocation counter in callbacks:

sut.SetupMock.Method.Dispense(It.IsAny<string>(), It.IsAny<int>())
    .Do((int count) => Console.WriteLine($"Call #{count}"));

sut.SetupMock.Property.TotalDispensed
    .OnGet.Do((int count, int value) => 
        Console.WriteLine($"Read #{count}, value: {value}"));
```</issue_description>

## 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 31, 2026 05:26
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Copilot AI changed the title [WIP] Document advanced callback features for callbacks Document advanced callback control features Jan 31, 2026
Copilot AI requested a review from vbreuss January 31, 2026 05:29
@vbreuss
Copy link
Copy Markdown
Member

vbreuss commented Jan 31, 2026

Obsolete by #430

@vbreuss vbreuss closed this Jan 31, 2026
@vbreuss vbreuss deleted the copilot/document-advanced-callback-features 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 advanced callback features

2 participants