Skip to content

Document protected member support#418

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/add-protected-member-support-docs
Closed

Document protected member support#418
Copilot wants to merge 3 commits into
mainfrom
copilot/add-protected-member-support-docs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 30, 2026

Mockolate supports setting up and verifying protected members on class mocks, but the API was undocumented. This adds documentation for the .Protected accessor across setup and verification scenarios.

Changes

  • README.md: Added "Working with Protected Members" section under Setup, and "Protected Members" section under Verify interactions
  • Docs/pages/02-setup.md: Added protected member setup documentation
  • Docs/pages/04-verify-interactions.md: Added protected member verification documentation

Usage

public abstract class ChocolateDispenser
{
    protected virtual bool DispenseInternal(string type, int amount) => true;
    protected virtual int InternalStock { get; set; }
}

var sut = Mock.Create<ChocolateDispenser>();

// Setup
sut.SetupMock.Protected.Method.DispenseInternal(
    It.Is("Dark"), It.IsAny<int>())
    .Returns(true);

sut.SetupMock.Protected.Property.InternalStock.InitializeWith(100);

// Verify
sut.VerifyMock.Invoked.Protected.DispenseInternal(
    It.Is("Dark"), It.IsAny<int>()).Once();

sut.VerifyMock.Got.Protected.InternalStock().AtLeastOnce();

All setup options (.Returns(), .Throws(), .Do()) and verification options work with protected members. Protected indexers use .Protected.Indexer() for setup and .GotProtectedIndexer()/.SetProtectedIndexer() for verification.

Original prompt

This section details on the original issue you should resolve

<issue_title>Document protected member support</issue_title>
<issue_description>## Description

Mockolate supports setting up and verifying protected members, but this is completely undocumented.

Missing Documentation

  • SetupMock.Protected.Method() and .Property()
  • VerifyMock.Protected.Invoked(), .Got(), .Set()
  • Examples of working with protected methods and properties

Suggested Documentation

Add a new section titled "Working with Protected Members":

### Working with Protected Members

Mockolate allows you to setup and verify protected methods and properties:

```csharp
var sut = Mock.Create<MyChocolateDispenser>();

// Setup protected method
sut.SetupMock.Protected.Method(\"DispenseInternal\",
    It.Is(\"Dark\"), It.IsAny<int>())
    .Returns(true);

// Setup protected property
sut.SetupMock.Protected.Property(\"InternalStock\").InitializeWith(100);

// Verify protected method was called
sut.VerifyMock.Protected.Invoked(\"DispenseInternal\",
    It.Is(\"Dark\"), It.IsAny<int>()).Once();

// Verify protected property was accessed
sut.VerifyMock.Protected.Got(\"InternalStock\").AtLeastOnce();

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

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

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

Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Copilot AI changed the title [WIP] Add documentation for protected member support Document protected member support Jan 30, 2026
Copilot AI requested a review from vbreuss January 30, 2026 17:38
@vbreuss
Copy link
Copy Markdown
Member

vbreuss commented Jan 31, 2026

Obsolete by #432

@vbreuss vbreuss closed this Jan 31, 2026
@vbreuss vbreuss deleted the copilot/add-protected-member-support-docs 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 protected member support

2 participants