Skip to content

Commit 9733080

Browse files
author
Bart Koelman
committed
Setup code coverage
1 parent 31d6e76 commit 9733080

File tree

12 files changed

+58
-22
lines changed

12 files changed

+58
-22
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
"commands": [
1414
"regitlint"
1515
]
16+
},
17+
"codecov.tool": {
18+
"version": "1.13.0",
19+
"commands": [
20+
"codecov"
21+
]
22+
},
23+
"dotnet-reportgenerator-globaltool": {
24+
"version": "4.8.7",
25+
"commands": [
26+
"reportgenerator"
27+
]
1628
}
1729
}
1830
}

Build.ps1

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# Gets the version suffix from the repo tag
22
# example: v1.0.0-preview1-final => preview1-final
33
function Get-Version-Suffix-From-Tag {
4-
$tag=$env:APPVEYOR_REPO_TAG_NAME
5-
$split=$tag -split "-"
6-
$suffix=$split[1..2]
7-
$final=$suffix -join "-"
8-
return $final
4+
$tag = $env:APPVEYOR_REPO_TAG_NAME
5+
$split = $tag -split "-"
6+
$suffix = $split[1..2]
7+
$final = $suffix -join "-"
8+
return $final
99
}
1010

1111
function CheckLastExitCode {
1212
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)
1313

1414
if ($SuccessCodes -notcontains $LastExitCode) {
15-
$msg = "EXE RETURNED EXIT CODE $LastExitCode"
16-
throw $msg
15+
throw "EXE RETURNED EXIT CODE $LastExitCode"
1716
}
1817
}
1918

@@ -63,6 +62,17 @@ function RunCleanupCode {
6362
}
6463
}
6564

65+
function ReportCodeCoverage {
66+
if ($env:APPVEYOR) {
67+
dotnet codecov -f "**\coverage.cobertura.xml"
68+
}
69+
else {
70+
dotnet reportgenerator -reports:**\coverage.cobertura.xml -targetdir:artifacts\coverage
71+
}
72+
73+
CheckLastExitCode
74+
}
75+
6676
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
6777
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
6878

@@ -72,12 +82,15 @@ CheckLastExitCode
7282
dotnet build -c Release
7383
CheckLastExitCode
7484

75-
RunInspectCode
76-
RunCleanupCode
85+
# TODO: Uncomment after testing has completed.
86+
#RunInspectCode
87+
#RunCleanupCode
7788

78-
dotnet test -c Release --no-build
89+
dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
7990
CheckLastExitCode
8091

92+
ReportCodeCoverage
93+
8194
Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
8295

8396
if ($env:APPVEYOR_REPO_TAG -eq $true) {

Directory.Build.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
<!-- Test Project Dependencies -->
2323
<PropertyGroup>
24-
<XUnitVersion>2.4.1</XUnitVersion>
25-
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
2624
<BogusVersion>33.0.2</BogusVersion>
25+
<CoverletVersion>3.0.3</CoverletVersion>
26+
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
2727
<MoqVersion>4.16.1</MoqVersion>
28+
<XUnitVersion>2.4.1</XUnitVersion>
2829
</PropertyGroup>
2930
</Project>

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# JsonApiDotNetCore
66
A framework for building [JSON:API](http://jsonapi.org/) compliant REST APIs using .NET Core and Entity Framework Core.
77

8-
[![Build status](https://ci.appveyor.com/api/projects/status/5go47hrm0iik0ls3/branch/master?svg=true)](https://ci.appveyor.com/project/jaredcnance/jsonapidotnetcore/branch/master)
9-
[![Travis](https://travis-ci.org/json-api-dotnet/JsonApiDotNetCore.svg?branch=master)](https://travis-ci.org/json-api-dotnet/JsonApiDotNetCore)
8+
[![Build](https://ci.appveyor.com/api/projects/status/t8noo6rjtst51kga/branch/master?svg=true)](https://ci.appveyor.com/project/json-api-dotnet/jsonapidotnetcore/branch/master)
9+
[![Coverage](https://codecov.io/gh/json-api-dotnet/JsonApiDotNetCore/branch/master/graph/badge.svg?token=pn036tWV8T)](https://codecov.io/gh/json-api-dotnet/JsonApiDotNetCore)
1010
[![NuGet](https://img.shields.io/nuget/v/JsonApiDotNetCore.svg)](https://www.nuget.org/packages/JsonApiDotNetCore/)
11-
[![Join the chat at https://gitter.im/json-api-dotnet-core/Lobby](https://badges.gitter.im/json-api-dotnet-core/Lobby.svg)](https://gitter.im/json-api-dotnet-core/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
11+
[![Chat](https://badges.gitter.im/json-api-dotnet-core/Lobby.svg)](https://gitter.im/json-api-dotnet-core/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1212
[![FIRST-TIMERS](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](http://www.firsttimersonly.com/)
1313

1414
The ultimate goal of this library is to eliminate as much boilerplate as possible by offering out-of-the-box features such as sorting, filtering and pagination. You just need to focus on defining the resources and implementing your custom business logic. This library has been designed around dependency injection, making extensibility incredibly easy.

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ after_build:
2424
if ($lastexitcode -ne 0) {
2525
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
2626
}
27-
27+
2828
git config --global credential.helper store
2929
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:ACCESS_TOKEN):x-oauth-basic@github.com`n"
3030
git config --global user.email "jaredcnance@gmail.com"
@@ -61,7 +61,7 @@ nuget:
6161
init:
6262
- SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%
6363

64-
services:
64+
services:
6565
- postgresql96
6666

6767
build_script:

test/DiscoveryTests/DiscoveryTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
1819
<PackageReference Include="Moq" Version="$(MoqVersion)" />
1920
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />
2021
</ItemGroup>

test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
1819
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCoreVersion)" />
1920
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />
2021
</ItemGroup>

test/MultiDbContextTests/MultiDbContextTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
1819
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCoreVersion)" />
1920
<PackageReference Include="Moq" Version="$(MoqVersion)" />
2021
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />

test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
1213
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCoreVersion)" />
1314
<PackageReference Include="Moq" Version="$(MoqVersion)" />
1415
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
// https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#excluding-from-coverage
4+
[assembly: ExcludeFromCodeCoverage]
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>$(NetCoreAppVersion)</TargetFramework>
44
</PropertyGroup>
55

6+
<ItemGroup>
7+
<ProjectReference Include="..\..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
8+
</ItemGroup>
9+
610
<ItemGroup>
711
<PackageReference Include="Bogus" Version="$(BogusVersion)" />
12+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
813
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
914
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCoreVersion)" />
1015
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="$(AspNetCoreVersion)" />
@@ -13,8 +18,4 @@
1318
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
1419
</ItemGroup>
1520

16-
<ItemGroup>
17-
<ProjectReference Include="..\..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
18-
</ItemGroup>
19-
2021
</Project>

test/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
1819
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(EFCoreVersion)" />
1920
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="$(EFCoreVersion)" />
2021
<PackageReference Include="Moq" Version="$(MoqVersion)" />

0 commit comments

Comments
 (0)