Skip to content

Commit 90e017b

Browse files
authored
Use dotnet sonar scanner (part 2) (#1125)
* ddd * ---ddd * f * revert * /d:sonar.branch.name=$(Build.SourceBranchName) * FIX * coverlet * coverlet - 1 line * dotnet-coverage * --configuration Debug --no-build --framework net8.0 * script * /d: * collect? * "wiremock-coverage.xml" * see * tests
1 parent 2602db5 commit 90e017b

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

azure-pipelines-ci.yml

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,45 @@ jobs:
1414
echo "BuildId = $(buildId)"
1515
displayName: 'Print buildId'
1616
17-
- task: UseDotNet@2
18-
displayName: Use .NET 8.0
19-
inputs:
20-
packageType: 'sdk'
21-
version: '8.0.x'
17+
- script: |
18+
dotnet tool install --global dotnet-sonarscanner
19+
dotnet tool install --global dotnet-coverage
20+
dotnet tool install --global coverlet.console
21+
displayName: 'Install dotnet tools'
2222
2323
- task: PowerShell@2
24-
displayName: "Use JDK11 by default"
24+
displayName: "Use JDK17 by default"
2525
inputs:
2626
targetType: 'inline'
2727
script: |
28-
$jdkPath = $env:JAVA_HOME_11_X64
28+
$jdkPath = $env:JAVA_HOME_17_X64
2929
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
3030
3131
- script: |
3232
dotnet dev-certs https --trust || true
3333
displayName: 'dotnet dev-certs https'
34-
35-
- task: SonarCloudPrepare@1
36-
displayName: 'Prepare analysis on SonarCloud'
34+
35+
# See: https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/dotnet-test-coverage
36+
- script: |
37+
dotnet sonarscanner begin /k:"WireMock-Net_WireMock.Net" /o:"wiremock-net" /d:sonar.branch.name=$(Build.SourceBranchName) /d:sonar.host.url="https://sonarcloud.io" /d:sonar.token="$(SONAR_TOKEN)" /d:sonar.dotnet.excludeTestProjects=true /d:sonar.cs.vscoveragexml.reportsPaths=**/wiremock-coverage.xml /d:sonar.verbose=true
38+
displayName: 'Begin analysis on SonarCloud'
3739
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
38-
inputs:
39-
SonarCloud: SonarCloud
40-
organization: wiremock-net
41-
projectKey: 'WireMock-Net_WireMock.Net'
42-
projectName: 'WireMock.Net'
43-
extraProperties: |
44-
sonar.cs.opencover.reportsPaths=**/coverage.net8.0.opencover.xml
4540
4641
- task: DotNetCoreCLI@2
4742
displayName: 'Build Unit tests'
4843
inputs:
4944
command: 'build'
5045
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
51-
arguments: '--configuration Debug --framework net8.0'
46+
arguments: '--configuration Debug --framework net8.0 --no-incremental'
5247

5348
- task: CmdLine@2
5449
inputs:
55-
script: 'dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --no-build --configuration Debug --framework net8.0'
50+
script: 'dotnet-coverage collect "dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --no-build --framework net8.0" -f xml -o "wiremock-coverage.xml"'
5651
displayName: 'Execute Unit Tests with Coverage'
57-
58-
- task: SonarCloudAnalyze@1
59-
displayName: 'SonarCloud: Run Code Analysis'
60-
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
6152

62-
- task: SonarCloudPublish@1
63-
displayName: 'SonarCloud: Publish Quality Gate Result'
53+
- script: |
54+
dotnet sonarscanner end /d:sonar.token="$(SONAR_TOKEN)"
55+
displayName: 'End analysis on SonarCloud'
6456
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
6557
6658
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using FluentAssertions;
3+
using WireMock.Extensions;
4+
using Xunit;
5+
6+
namespace WireMock.Net.Tests.Extensions;
7+
8+
public class EnumExtensionsTests
9+
{
10+
private enum TestEnum
11+
{
12+
Value1
13+
}
14+
15+
[Fact]
16+
public void EnumExtensions_GetFullyQualifiedEnumValue_ShouldReturnCorrectValue()
17+
{
18+
// Arrange
19+
var enumValue = TestEnum.Value1;
20+
21+
// Act
22+
var result = enumValue.GetFullyQualifiedEnumValue();
23+
24+
// Assert
25+
result.Should().Be("WireMock.Net.Tests.Extensions.TestEnum.Value1");
26+
}
27+
28+
[Fact]
29+
public void EnumExtensions_GetFullyQualifiedEnumValue_ShouldThrowArgumentException_WhenTypeIsNotEnum()
30+
{
31+
// Arrange
32+
int nonEnumValue = 42;
33+
34+
// Act
35+
Action act = () => nonEnumValue.GetFullyQualifiedEnumValue();
36+
37+
// Assert
38+
act.Should().Throw<ArgumentException>().WithMessage("T must be an enum");
39+
}
40+
}

0 commit comments

Comments
 (0)