mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 00:38:28 +02:00
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
This commit is contained in:
@@ -14,53 +14,45 @@ jobs:
|
|||||||
echo "BuildId = $(buildId)"
|
echo "BuildId = $(buildId)"
|
||||||
displayName: 'Print buildId'
|
displayName: 'Print buildId'
|
||||||
|
|
||||||
- task: UseDotNet@2
|
- script: |
|
||||||
displayName: Use .NET 8.0
|
dotnet tool install --global dotnet-sonarscanner
|
||||||
inputs:
|
dotnet tool install --global dotnet-coverage
|
||||||
packageType: 'sdk'
|
dotnet tool install --global coverlet.console
|
||||||
version: '8.0.x'
|
displayName: 'Install dotnet tools'
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
displayName: "Use JDK11 by default"
|
displayName: "Use JDK17 by default"
|
||||||
inputs:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: 'inline'
|
||||||
script: |
|
script: |
|
||||||
$jdkPath = $env:JAVA_HOME_11_X64
|
$jdkPath = $env:JAVA_HOME_17_X64
|
||||||
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
|
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
|
||||||
|
|
||||||
- script: |
|
- script: |
|
||||||
dotnet dev-certs https --trust || true
|
dotnet dev-certs https --trust || true
|
||||||
displayName: 'dotnet dev-certs https'
|
displayName: 'dotnet dev-certs https'
|
||||||
|
|
||||||
- task: SonarCloudPrepare@1
|
# See: https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/dotnet-test-coverage
|
||||||
displayName: 'Prepare analysis on SonarCloud'
|
- script: |
|
||||||
|
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
|
||||||
|
displayName: 'Begin analysis on SonarCloud'
|
||||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
inputs:
|
|
||||||
SonarCloud: SonarCloud
|
|
||||||
organization: wiremock-net
|
|
||||||
projectKey: 'WireMock-Net_WireMock.Net'
|
|
||||||
projectName: 'WireMock.Net'
|
|
||||||
extraProperties: |
|
|
||||||
sonar.cs.opencover.reportsPaths=**/coverage.net8.0.opencover.xml
|
|
||||||
|
|
||||||
- task: DotNetCoreCLI@2
|
- task: DotNetCoreCLI@2
|
||||||
displayName: 'Build Unit tests'
|
displayName: 'Build Unit tests'
|
||||||
inputs:
|
inputs:
|
||||||
command: 'build'
|
command: 'build'
|
||||||
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
|
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
|
||||||
arguments: '--configuration Debug --framework net8.0'
|
arguments: '--configuration Debug --framework net8.0 --no-incremental'
|
||||||
|
|
||||||
- task: CmdLine@2
|
- task: CmdLine@2
|
||||||
inputs:
|
inputs:
|
||||||
script: 'dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --no-build --configuration Debug --framework net8.0'
|
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"'
|
||||||
displayName: 'Execute Unit Tests with Coverage'
|
displayName: 'Execute Unit Tests with Coverage'
|
||||||
|
|
||||||
- task: SonarCloudAnalyze@1
|
|
||||||
displayName: 'SonarCloud: Run Code Analysis'
|
|
||||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
|
||||||
|
|
||||||
- task: SonarCloudPublish@1
|
- script: |
|
||||||
displayName: 'SonarCloud: Publish Quality Gate Result'
|
dotnet sonarscanner end /d:sonar.token="$(SONAR_TOKEN)"
|
||||||
|
displayName: 'End analysis on SonarCloud'
|
||||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
|
|
||||||
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
|
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
|
||||||
|
|||||||
40
test/WireMock.Net.Tests/Extensions/EnumExtensionsTests.cs
Normal file
40
test/WireMock.Net.Tests/Extensions/EnumExtensionsTests.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using FluentAssertions;
|
||||||
|
using WireMock.Extensions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.Extensions;
|
||||||
|
|
||||||
|
public class EnumExtensionsTests
|
||||||
|
{
|
||||||
|
private enum TestEnum
|
||||||
|
{
|
||||||
|
Value1
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EnumExtensions_GetFullyQualifiedEnumValue_ShouldReturnCorrectValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var enumValue = TestEnum.Value1;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = enumValue.GetFullyQualifiedEnumValue();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("WireMock.Net.Tests.Extensions.TestEnum.Value1");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EnumExtensions_GetFullyQualifiedEnumValue_ShouldThrowArgumentException_WhenTypeIsNotEnum()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
int nonEnumValue = 42;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Action act = () => nonEnumValue.GetFullyQualifiedEnumValue();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
act.Should().Throw<ArgumentException>().WithMessage("T must be an enum");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user