with one click
nunit-constraint-documentation
// Create and update documentation for NUnit constraints following the established template structure
// Create and update documentation for NUnit constraints following the established template structure
| name | NUnit Constraint Documentation |
| description | Create and update documentation for NUnit constraints following the established template structure |
This skill describes how to create and update documentation for NUnit constraints.
Each constraint documentation file in docs/articles/nunit/writing-tests/constraints/ should follow this structure:
---
uid: constraint-<name>
---
# <Name> Constraint
Brief description (2-3 sentences) explaining what the constraint tests and when to use it.
## Usage
```csharp
Is.<Method>(args) // Primary syntax
Does.<Method>(args) // If applicable
Has.<Method>(args) // If applicable
```
## Modifiers
```csharp
.IgnoreCase // Makes comparison case-insensitive
.Using(IComparer comparer) // Uses custom comparison logic
.Within(tolerance) // Allows approximate matching
```
> [!NOTE]
> Only include this section if the constraint has modifiers.
## Examples
Inline one-liners showing common patterns:
```csharp
Assert.That(actual, Is.<Method>(expected));
Assert.That(actual, Is.Not.<Method>(expected));
Assert.That(actual, Is.<Method>(expected).IgnoreCase);
```
### [Scenario Section - only if complex setup needed]
Brief explanation of the scenario.
[!code-csharp[ScenarioExample](~/snippets/Snippets.NUnit/ConstraintExamples.cs#ScenarioExample)]
## Notes
1. Important behavioral notes
2. Edge cases
3. Compatibility information
## See Also
* [Related Constraint](related.md)
* [Another Related](another.md)
| Section | Purpose |
|---|---|
| Usage (first) | Users interact with fluent API (Is.*, Does.*), not constructors |
| Modifiers | Use .ModifierName format (shows method chaining) |
| Examples | Inline one-liners for common patterns |
| Notes | Edge cases and important behaviors |
| See Also | Links to related constraints |
Inline examples (in the markdown itself):
## Usage
```csharp
Is.Null
Is.Not.Null
```
## Examples
```csharp
Assert.That(myObject, Is.Null);
Assert.That(myString, Is.Not.Null);
Assert.That(GetResult(), Is.Null.Or.Empty); // Combined with other constraints
```
External snippets (from Snippets.NUnit):
### Using Custom Comparers
[!code-csharp[EqualWithComparer](~/snippets/Snippets.NUnit/ConstraintExamples.cs#EqualWithComparer)]
Never inline:
[Test] public void... methods - those go in external snippetsAll constraint UIDs should follow the pattern: constraint-<lowercase-name>
Examples:
equalconstraint → constraint-equalnullconstraint → constraint-nullgreaterthanconstraint → constraint-greaterthanRepository Layout Assumption: This workflow assumes you have cloned both repositories as siblings:
<workspace>/nunit/- The NUnit framework source code (nunit/nunit)<workspace>/docs/- This documentation repository (nunit/docs)Adjust paths below to match your local setup.
Search for the constraint class in the NUnit framework:
# Find the constraint source file (adjust path to your nunit repo location)
grep -r "class <Name>Constraint" ../nunit/src/NUnitFramework/framework/Constraints --include="*.cs"
The source is typically at:
<nunit-repo>/src/NUnitFramework/framework/Constraints/<Name>Constraint.cs
From the source file, extract:
Is.cs, Does.cs, Has.cs, Contains.cs)# Find unit tests for the constraint (adjust path to your nunit repo location)
grep -r "<Name>Constraint" ../nunit/src/NUnitFramework/tests --include="*.cs"
Unit tests provide good examples of usage patterns and edge cases.
Follow the template structure above. Key points:
If complex scenarios need external snippets, add them to:
docs/snippets/Snippets.NUnit/ConstraintExamples.cs
Use regions to organize:
#region <Name>ConstraintExamples
[Test]
public void <Name>Constraint_WithCustomComparer()
{
// Example with setup that's too complex for inline
var comparer = new MyCustomComparer();
Assert.That(actual, Is.<Method>(expected).Using(comparer));
}
#endregion
Always verify the snippets compile and tests pass. From the docs repository root:
# Build
dotnet build docs/snippets/Snippets.slnx
# Run all tests
dotnet test docs/snippets/Snippets.slnx --no-build
# Run specific constraint tests
dotnet test docs/snippets/Snippets.slnx --no-build --filter "FullyQualifiedName~ConstraintExamples" --verbosity normal
Before marking a constraint as done:
constraint-<name> patternExamples: NullConstraint, TrueConstraint, FalseConstraint, NaNConstraint
These need minimal documentation but should still have:
Is.<Name> and Is.Not.<Name>Examples: EqualConstraint, GreaterThanConstraint, LessThanConstraint
These need:
.Using() and .Within() variantsExamples: CollectionEquivalentConstraint, UniqueItemsConstraint, AllItemsConstraint
These need:
.IgnoreCase, .Using(), .UsingPropertiesComparer()Examples: StartsWithConstraint, SubstringConstraint, RegexConstraint
These need:
.IgnoreCase, .Using(StringComparison), .Using(CultureInfo)