test.clone

Development Guide

This guide covers coding standards, testing conventions, and the contribution workflow for the TestClone project.

Coding Standards

Language and Framework Versions

Naming Conventions

Construct Convention Example
Types, methods, public members PascalCase CreateOrder, OrderId
Interfaces I prefix + PascalCase IFacade
Private fields _camelCase _facade
Local variables, parameters camelCase createOrderRequest

Formatting

Null Safety

XML Documentation

Every public API surface (classes, interfaces, methods, properties) must have an XML <summary> comment. Include <param>, <returns>, and optionally <example> / <code> where appropriate.

/// <summary>
/// Creates a new product order based on the provided request.
/// </summary>
/// <param name="request">The order creation request containing product name and quantity.</param>
/// <returns>A task that returns the created order response with order ID and status.</returns>
Task<CreateOrderResponse> CreateOrder(CreateOrderRequest request);

Code Quality

Testing

Frameworks

Library Purpose
TUnit Unit testing framework
Moq Mocking / test-double creation

Test Project Layout

Project What it tests
src/WebApi.UnitTests Controllers (mocked IFacade)
src/DomainApi.UnitTests Facade business logic (no mocking needed)

Test Naming Convention

ClassNameMethodNameExpectedBehavior

Example: TestCloneControllerGetTestOperationReturnsOkWithFacadeResult

Test Structure

Use // Arrange, // Act, // Assert comments to clearly separate the three phases:

[Test]
public async Task TestCloneControllerGetTestOperationReturnsOkWithFacadeResult()
{
    // Arrange
    var mockFacade = new Mock<IFacade>();
    mockFacade.Setup(f => f.TestOperation()).ReturnsAsync("Hello from the Facade!");
    var controller = new TestCloneController(mockFacade.Object);

    // Act
    var result = await controller.GetTestOperation();

    // Assert
    var okResult = result as OkObjectResult;
    await Assert.That(okResult).IsNotNull();
    await Assert.That(okResult!.Value).IsEqualTo("Hello from the Facade!");
}

Conventions

Running Tests

# All tests
dotnet test

# Single test project
dotnet test src/WebApi.UnitTests
dotnet test src/DomainApi.UnitTests

Adding a New Endpoint

  1. DomainModel — Add request/response DTOs in src/DomainModel/Requests/ and src/DomainModel/Responses/.
  2. DomainApi — Add the operation signature to IFacade and implement it in Facade.
  3. WebApi — Add a new action method to TestCloneController (or a new controller if the domain warrants it).
  4. Tests — Add unit tests for both the controller action (mock IFacade) and the Facade implementation.

Contribution Workflow

  1. Fork or branch from main.
  2. Implement your changes following the coding standards above.
  3. Ensure dotnet build produces zero warnings.
  4. Ensure dotnet test passes with all tests green.
  5. Open a Pull Request using the provided PR template (.github/pull_request_template.md).
  6. Address review feedback and update your branch as needed.

Useful Commands

# Build (warnings treated as errors)
dotnet build

# Run the API locally
dotnet run --project src/WebApi

# Run all unit tests
dotnet test

# Restore NuGet packages
dotnet restore