Tutorial: .NET Web API
What This Tutorial Will Cover
Section titled “What This Tutorial Will Cover”When .NET support lands, this tutorial will walk through:
- Creating a minimal ASP.NET Core Web API with
GET /healthandGET /greetendpoints - Writing xUnit tests and configuring Coverlet to produce a
coverage.jsonreport - Running
nolapse init --repo . --lang dotnetto create the baseline - Simulating a coverage regression by removing a test
- Running
nolapse run --repo . --lang dotnetand seeing it exit 1 - Adding a GitHub Actions workflow that gates PRs on coverage
Expected Project Structure
Section titled “Expected Project Structure”hello-dotnet/├── HelloApi/│ ├── Controllers/│ │ └── HelloController.cs│ └── HelloApi.csproj├── HelloApi.Tests/│ ├── HelloControllerTests.cs│ └── HelloApi.Tests.csproj├── HelloApi.sln├── .audit/│ └── coverage/│ └── baseline.md└── nolapse.yamlExpected Commands (Once Available)
Section titled “Expected Commands (Once Available)”Run tests with Coverlet
Section titled “Run tests with Coverlet”dotnet test --collect:"XPlat Code Coverage" --results-directory ./coverageCoverlet generates coverage/*/coverage.cobertura.xml. nolapse will read this format.
Initialise
Section titled “Initialise”nolapse init --repo . --lang dotnetRun a check
Section titled “Run a check”nolapse run --repo . --lang dotnetGitHub Actions workflow
Section titled “GitHub Actions workflow”name: Coverage check
on: pull_request:
jobs: coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0
- name: Set up .NET uses: actions/setup-dotnet@v4 with: dotnet-version: "8.0.x"
- name: Restore and build run: dotnet build
- name: Run nolapse uses: nolapse/nolapse-action@v1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} lang: dotnet warn-threshold: "0.5" fail-threshold: "1.0"Coverlet Configuration
Section titled “Coverlet Configuration”nolapse will invoke dotnet test internally with Coverlet. To configure the coverage format, add a coverlet.runsettings file or pass arguments in the nolapse action (exact interface TBD at implementation time).
A minimal coverlet.runsettings:
<?xml version="1.0" encoding="utf-8" ?><RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="XPlat code coverage"> <Configuration> <Format>json</Format> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings></RunSettings>Get Notified
Section titled “Get Notified”Watch the nolapse changelog for the .NET runner release. Once available, this tutorial will be updated with full working commands and example output.
See Also
Section titled “See Also”- Tutorial: Go Microservice — a fully working tutorial available today
- Tutorial: Python Django App — a fully working tutorial available today
- Languages: .NET — .NET language reference page