Fix SonarCloud OpenCover (coverlet-coverage) (#545)

This commit is contained in:
Stef Heyenrath
2020-11-30 14:48:17 +00:00
committed by GitHub
parent 3e0c6cce5f
commit db2caadf70
22 changed files with 409 additions and 325 deletions

1
.gitignore vendored
View File

@@ -254,3 +254,4 @@ paket-files/
./report/coverlet/
/test/WireMock.Net.Tests/coverage.opencover.xml
/test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml
/test/WireMock.Net.Tests/coverage.net5.0.opencover.xml

View File

@@ -30,6 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
CHANGELOG.md = CHANGELOG.md
Directory.Build.props = Directory.Build.props
GitHubReleaseNotes.txt = GitHubReleaseNotes.txt
nuget.config = nuget.config
README.md = README.md
EndProjectSection
EndProject

View File

@@ -1,5 +1,5 @@
pool:
vmImage: 'Ubuntu 16.04'
vmImage: 'Ubuntu-latest'
variables:
buildConfiguration: 'Release'

View File

@@ -1,162 +1,133 @@
pool:
vmImage: 'windows-2019'
variables:
Prerelease: 'ci'
buildId: "1$(Build.BuildId)"
buildProjects: '**/src/**/*.csproj'
steps:
# Print buildId
- script: |
echo "BuildId = $(buildId)"
displayName: 'Print buildId'
jobs:
- job: Linux_Build_Test_SonarCloud
# Install Tools
- script: |
dotnet tool install --global dotnet-sonarscanner
displayName: Install Tools (SonarScanner)
pool:
vmImage: 'Ubuntu-latest'
- task: DotNetCoreCLI@2
displayName: "Install tool: dotnet-coverageconverter"
inputs:
command: 'custom'
custom: 'tool'
arguments: 'update --global dotnet-coverageconverter'
steps:
- script: |
echo "BuildId = $(buildId)"
displayName: 'Print buildId'
- task: PowerShell@2
displayName: "Use JDK11 by default"
inputs:
targetType: 'inline'
script: |
$jdkPath = $env:JAVA_HOME_11_X64
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
- task: PowerShell@2
displayName: "Use JDK11 by default"
inputs:
targetType: 'inline'
script: |
$jdkPath = $env:JAVA_HOME_11_X64
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: SonarCloud
organization: wiremock-net
projectKey: 'WireMock-Net_WireMock.Net'
projectName: 'WireMock.Net'
extraProperties: |
sonar.branch.name=$(Build.SourceBranchName)
sonar.cs.opencover.reportsPaths=**/coverage.netcoreapp3.1.opencover.xml
- task: DotNetCoreCLI@2
displayName: 'Build Unit tests'
inputs:
command: 'build'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--configuration Debug --framework netcoreapp3.1'
- task: DotNetCoreCLI@2
displayName: 'Execute Unit tests'
inputs:
command: 'test'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--no-build --configuration Debug --framework netcoreapp3.1 --collect:"XPlat Code Coverage" --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
- task: SonarCloudAnalyze@1
displayName: 'SonarCloud: Run Code Analysis'
- task: SonarCloudPublish@1
displayName: 'SonarCloud: Publish Quality Gate Result'
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
displayName: 'WhiteSource Bolt'
condition: and(succeeded(), eq(variables['RUN_WHITESOURCE'], 'yes'))
- script: |
bash <(curl https://codecov.io/bash) -t $(CODECOV_TOKEN) -f ./test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml
displayName: 'codecov'
- task: PublishTestResults@2
condition: and(succeeded(), eq(variables['PUBLISH_TESTRESULTS'], 'yes'))
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
- task: PublishBuildArtifacts@1
displayName: Publish coverage file
inputs:
PathtoPublish: '/home/vsts/work/1/s/test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml'
# Build tests and run tests for net452
- script: |
dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --framework net452
condition: and(succeeded(), eq(variables['RUN_TESTS_NET452'], 'yes'))
displayName: 'Build tests and run tests for net452'
- job: Windows_Build_Test
dependsOn: Linux_Build_Test_SonarCloud
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis configuration'
inputs:
SonarCloud: 'SonarCloud'
organization: 'wiremock-net'
scannerMode: 'MSBuild'
projectKey: 'WireMock-Net_WireMock.Net'
extraProperties: |
sonar.cs.opencover.reportsPaths=**\coverage.netcoreapp3.1.opencover.xml
condition: and(succeeded(), eq(variables['RUN_SONARCLOUD'], 'yes'))
pool:
vmImage: 'windows-2019'
# Begin SonarScanner
- script: |
%USERPROFILE%\.dotnet\tools\dotnet-sonarscanner begin /k:"WireMock-Net_WireMock.Net" /o:"wiremock-net" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="$(SONAR_TOKEN)" /v:"$(buildId)" /d:sonar.cs.opencover.reportsPaths="**\coverage.netcoreapp3.1.opencover.xml"
displayName: Begin SonarScanner
condition: and(succeeded(), eq(variables['RUN_SONAR_CMD_OPENCOVER'], 'yes'))
steps:
- task: DotNetCoreCLI@2
displayName: 'Build Unit tests'
inputs:
command: 'build'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--configuration Debug --framework netcoreapp3.1'
- task: DotNetCoreCLI@2
displayName: 'Execute Unit tests'
inputs:
command: 'test'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--no-build --configuration Debug --framework netcoreapp3.1 --collect:"XPlat Code Coverage" --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
- job: Windows_Release_to_MyGet
dependsOn: Windows_Build_Test
- script: |
%USERPROFILE%\.dotnet\tools\dotnet-sonarscanner begin /k:"WireMock-Net_WireMock.Net" /o:"wiremock-net" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="$(SONAR_TOKEN)" /v:"$(buildId)"
displayName: Begin SonarScanner
condition: and(succeeded(), eq(variables['RUN_COVERAGE'], 'yes'))
pool:
vmImage: 'windows-2019'
# Build tests and run tests for netcoreapp3.1 (with coverage)
- task: DotNetCoreCLI@2
displayName: 'Build tests and run tests for netcoreapp3.1 (with coverage)'
inputs:
command: 'test'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--configuration Debug --framework netcoreapp3.1 --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
condition: and(succeeded(), eq(variables['RUN_SONARCLOUD'], 'yes'))
steps:
- task: DotNetCoreCLI@2
displayName: Build Release
inputs:
command: 'build'
arguments: /p:Configuration=Release
projects: $(buildProjects)
- task: DotNetCoreCLI@2
displayName: 'Build solution'
inputs:
command: 'build'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--configuration Debug --framework netcoreapp3.1'
- task: VSTest@2
displayName: 'VsTest'
inputs:
testSelector: 'testAssemblies'
vsTestVersion: 16.0
diagnosticsEnabled: true
codeCoverageEnabled: true
testAssemblyVer2: |
**\*tests.dll
!**\obj\**
- task: CmdLine@2
displayName: 'Convert .coverage to .coveragexml'
inputs:
script: 'dotnet-coverageconverter --CoverageFilesFolder "$(Agent.TempDirectory)\TestResults"'
- script: |
dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --framework netcoreapp3.1 --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
displayName: 'Build tests and run tests for netcoreapp3.1 (with coverage)'
condition: and(succeeded(), eq(variables['RUN_TESTS_NETCOREAPP31'], 'yes'))
- task: SonarCloudAnalyze@1
displayName: 'Run SonarCloud analysis'
condition: and(succeeded(), eq(variables['RUN_SONARCLOUD'], 'yes'))
- task: SonarCloudPublish@1
displayName: 'Publish results on build summary'
condition: and(succeeded(), eq(variables['RUN_SONARCLOUD'], 'yes'))
# End SonarScanner
- script: |
%USERPROFILE%\.dotnet\tools\dotnet-sonarscanner end /d:sonar.login="$(SONAR_TOKEN)"
displayName: End SonarScanner
condition: and(succeeded(), eq(variables['RUN_SONAR_CMD'], 'yes'))
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
displayName: 'WhiteSource Bolt'
condition: and(succeeded(), eq(variables['RUN_WHITESOURCE'], 'yes'))
# Upload coverage to codecov.io
- script: |
%USERPROFILE%\.nuget\packages\codecov\1.10.0\tools\codecov.exe -f "./test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml" -t $(CODECOV_TOKEN)
displayName: Upload coverage to codecov.io
# https://github.com/microsoft/azure-pipelines-tasks/issues/12212
- task: PublishTestResults@2
condition: and(succeeded(), eq(variables['PUBLISH_TESTRESULTS'], 'yes'))
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
# Based on https://whereslou.com/2018/09/versioning-and-publishing-nuget-packages-automatically-using-azure-devops-pipelines/
- task: DotNetCoreCLI@2
displayName: Build Release
inputs:
command: 'build'
arguments: /p:Configuration=Release # https://github.com/MicrosoftDocs/vsts-docs/issues/1976
projects: $(buildProjects)
- task: DotNetCoreCLI@2
displayName: Pack
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
command: pack
configuration: 'Release'
packagesToPack: $(buildProjects)
nobuild: true
packDirectory: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'normal'
- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
# https://github.com/NuGet/Home/issues/8148
- task: DotNetCoreCLI@2
displayName: Push to MyGet
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
command: custom
custom: nuget
arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -n true -s https://www.myget.org/F/wiremock-net/api/v3/index.json -k $(MyGetKey)
- task: DotNetCoreCLI@2
displayName: Pack
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
command: pack
configuration: 'Release'
packagesToPack: $(buildProjects)
nobuild: true
packDirectory: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'normal'
- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
- task: DotNetCoreCLI@2
displayName: Push to MyGet
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
command: custom
custom: nuget
arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -n true -s https://www.myget.org/F/wiremock-net/api/v3/index.json -k $(MyGetKey)

7
nuget.config Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="coverlet" value="https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json" />
</packageSources>
</configuration>

View File

@@ -1,74 +1,74 @@
using System.Linq;
using JetBrains.Annotations;
using WireMock.Logging;
using WireMock.Server;
using WireMock.Settings;
using WireMock.Validation;
namespace WireMock.Net.StandAlone
{
/// <summary>
/// The StandAloneApp
/// </summary>
public static class StandAloneApp
{
/// <summary>
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
/// </summary>
/// <param name="settings">The IWireMockServerSettings</param>
[PublicAPI]
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
{
Check.NotNull(settings, nameof(settings));
var server = WireMockServer.Start(settings);
settings.Logger?.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
return server;
}
/// <summary>
/// Start WireMock.Net standalone Server based on the commandline arguments.
/// </summary>
/// <param name="args">The commandline arguments</param>
/// <param name="logger">The logger</param>
[PublicAPI]
public static WireMockServer Start([NotNull] string[] args, [CanBeNull] IWireMockLogger logger = null)
{
Check.NotNull(args, nameof(args));
using System.Linq;
using JetBrains.Annotations;
using WireMock.Logging;
using WireMock.Server;
using WireMock.Settings;
using WireMock.Validation;
namespace WireMock.Net.StandAlone
{
/// <summary>
/// The StandAloneApp
/// </summary>
public static class StandAloneApp
{
/// <summary>
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
/// </summary>
/// <param name="settings">The IWireMockServerSettings</param>
[PublicAPI]
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
{
Check.NotNull(settings, nameof(settings));
var server = WireMockServer.Start(settings);
settings.Logger?.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
return server;
}
/// <summary>
/// Start WireMock.Net standalone Server based on the commandline arguments.
/// </summary>
/// <param name="args">The commandline arguments</param>
/// <param name="logger">The logger</param>
[PublicAPI]
public static WireMockServer Start([NotNull] string[] args, [CanBeNull] IWireMockLogger logger = null)
{
Check.NotNull(args, nameof(args));
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
{
settings.Logger?.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
return Start(settings);
}
return null;
}
/// <summary>
/// Try to start WireMock.Net standalone Server based on the commandline arguments.
/// </summary>
/// <param name="args">The commandline arguments</param>
/// <param name="logger">The logger</param>
/// <param name="server">The WireMockServer</param>
[PublicAPI]
public static bool TryStart([NotNull] string[] args, out WireMockServer server, [CanBeNull] IWireMockLogger logger = null)
{
Check.NotNull(args, nameof(args));
}
return null;
}
/// <summary>
/// Try to start WireMock.Net standalone Server based on the commandline arguments.
/// </summary>
/// <param name="args">The commandline arguments</param>
/// <param name="logger">The logger</param>
/// <param name="server">The WireMockServer</param>
[PublicAPI]
public static bool TryStart([NotNull] string[] args, out WireMockServer server, [CanBeNull] IWireMockLogger logger = null)
{
Check.NotNull(args, nameof(args));
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
{
settings.Logger?.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
server = Start(settings);
return true;
}
server = null;
return false;
}
}
}
server = null;
return false;
}
}
}

View File

@@ -58,6 +58,7 @@ namespace WireMock.Owin
}
_host = builder
.UseSetting("suppressStatusMessages", "True") // https://andrewlock.net/suppressing-the-startup-and-shutdown-messages-in-asp-net-core/
.ConfigureAppConfigurationUsingEnvironmentVariables()
.ConfigureServices(services =>
{

View File

@@ -80,10 +80,7 @@ namespace WireMock.Server
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (_httpServer != null)
{
_httpServer.StopAsync();
}
_httpServer?.StopAsync();
}
#endregion

View File

@@ -25,7 +25,7 @@ namespace WireMock.Settings
if (parser.GetBoolSwitchValue("help"))
{
logger.Info("See https://github.com/WireMock-Net/WireMock.Net/wiki/WireMock-commandline-parameters for details on all commandline options.");
(logger ?? new WireMockConsoleLogger()).Info("See https://github.com/WireMock-Net/WireMock.Net/wiki/WireMock-commandline-parameters for details on all commandline options.");
settings = null;
return false;
}

View File

@@ -16,9 +16,9 @@ namespace WireMock.Net.Tests.FluentAssertions
{
public class WireMockAssertionsTests : IDisposable
{
private WireMockServer _server;
private HttpClient _httpClient;
private int _portUsed;
private readonly WireMockServer _server;
private readonly HttpClient _httpClient;
private readonly int _portUsed;
public WireMockAssertionsTests()
{
@@ -289,6 +289,7 @@ namespace WireMock.Net.Tests.FluentAssertions
{
_server?.Stop();
_server?.Dispose();
_httpClient?.Dispose();
}
}
}

View File

@@ -69,6 +69,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(count).Equals(1);
server.Dispose();
}
[Fact]
@@ -105,6 +107,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(countResponsesWithStatusNotOk).Equals(0);
Check.That(count).Equals(expectedCount);
server.Dispose();
}
}
}

View File

@@ -41,6 +41,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
// Assert
response.Should().Contain("<hello>world</hello>");
server.Stop();
}
[Fact]
@@ -70,6 +72,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
// Assert
response.Should().Contain("<hello>world</hello>");
server.Stop();
}
[Fact]
@@ -99,6 +103,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
// Assert
response.Should().Contain("<hello>world</hello>");
server.Stop();
}
}
}

View File

@@ -82,6 +82,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
public void Dispose()
{
_server?.Stop();
_server?.Dispose();
}
}

View File

@@ -32,6 +32,8 @@ namespace WireMock.Net.Tests
// then
Check.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound);
server.Stop();
}
[Fact]
@@ -60,6 +62,8 @@ namespace WireMock.Net.Tests
// then
Check.That(responseNoState).Equals("No state msg");
Check.That(responseWithState).Equals("Test state msg");
server.Stop();
}
[Fact]
@@ -94,6 +98,8 @@ namespace WireMock.Net.Tests
responseScenario1.Should().Be(body1);
responseScenario2.Should().Be(body1);
responseWithState.Should().Be(body2);
server.Stop();
}
[Fact]
@@ -143,6 +149,8 @@ namespace WireMock.Net.Tests
t2a.Should().Be(body2);
t2b.Should().Be(body2);
t3.Should().Be(body3);
server.Stop();
}
[Fact]
@@ -171,6 +179,8 @@ namespace WireMock.Net.Tests
// then
Check.That(responseIntScenario).Equals("Scenario 1, Setting State 2");
Check.That(responseWithIntState).Equals("Scenario 1, State 2");
server.Stop();
}
[Fact]
@@ -199,6 +209,8 @@ namespace WireMock.Net.Tests
// then
Check.That(responseIntScenario).Equals("string state, Setting State 2");
Check.That(responseWithIntState).Equals("string state, State 2");
server.Stop();
}
[Fact]
@@ -227,6 +239,8 @@ namespace WireMock.Net.Tests
// then
Check.That(responseIntScenario).Equals("int state, Setting State 2");
Check.That(responseWithIntState).Equals("string state, State 2");
server.Stop();
}
[Fact]
@@ -281,6 +295,8 @@ namespace WireMock.Net.Tests
Check.That(server.Scenarios["To do list"].NextState).IsNull();
Check.That(server.Scenarios["To do list"].Started).IsTrue();
Check.That(server.Scenarios["To do list"].Finished).IsTrue();
server.Stop();
}
[Fact]
@@ -326,6 +342,8 @@ namespace WireMock.Net.Tests
var responseWithState2 = await new HttpClient().GetStringAsync(url + "/foo2X");
Check.That(responseWithState2).Equals("Test state msg 2");
server.Stop();
}
}
}

View File

@@ -0,0 +1,30 @@
using System.Text;
using FluentAssertions;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Util
{
public class BytesEncodingUtilsTests
{
[Fact]
public void TryGetEncoding_UTF32()
{
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff, 0xfe, 0x00, 0x00 }, out Encoding encoding);
// Assert
result.Should().BeTrue();
encoding.CodePage.Should().Be(Encoding.UTF32.CodePage);
}
[Fact]
public void TryGetEncoding_Invalid()
{
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff }, out Encoding encoding);
// Assert
result.Should().BeFalse();
encoding.Should().BeNull();
}
}
}

View File

@@ -1,107 +1,101 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>
<DebugType>full</DebugType>
<AssemblyName>WireMock.Net.Tests</AssemblyName>
<PackageId>WireMock.Net.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<ProjectGuid>{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}</ProjectGuid>
<PropertyGroup>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<DebugType>full</DebugType>
<AssemblyName>WireMock.Net.Tests</AssemblyName>
<PackageId>WireMock.Net.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<ProjectGuid>{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}</ProjectGuid>
<!-- https://github.com/tonerdo/coverlet/issues/6 -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<SonarQubeTestProject>True</SonarQubeTestProject>
<SonarQubeExclude>True</SonarQubeExclude>
<!--<SonarQubeTestProject>True</SonarQubeTestProject>
<SonarQubeExclude>True</SonarQubeExclude>-->
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../src/WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
<!--<DelaySign>true</DelaySign>-->
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../src/WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
<!--<DelaySign>true</DelaySign>-->
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<!--https://developercommunity.visualstudio.com/content/problem/26347/unit-tests-fail-with-fileloadexception-newtonsoftj-1.html-->
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<!--https://developercommunity.visualstudio.com/content/problem/26347/unit-tests-fail-with-fileloadexception-newtonsoftj-1.html-->
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Codecov" Version="1.10.0" />
<PackageReference Include="coverlet.msbuild" Version="3.0.0-preview.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.0-preview.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<ItemGroup>
<PackageReference Include="Codecov" Version="1.10.0" />
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="RestEase" Version="1.4.10" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NFluent" Version="2.7.0" />
<PackageReference Include="OpenCover" Version="4.7.922" />
<PackageReference Include="ReportGenerator" Version="4.8.1" />
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<!--<PackageReference Include="StrongNamer" Version="0.0.8" />-->
</ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="RestEase" Version="1.4.10" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NFluent" Version="2.7.0" />
<!--<PackageReference Include="OpenCover" Version="4.7.922" />-->
<!--<PackageReference Include="ReportGenerator" Version="4.8.1" />-->
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
<!--<PackageReference Include="StrongNamer" Version="0.0.8" />-->
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="3.1.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="3.1.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
</ItemGroup>
<ItemGroup>
<None Update="responsebody.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d86.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d87.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\351f0240-bba0-4bcb-93c6-1feba0fe8799.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\array.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\documentdb_root.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\MyXmlResponse.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\subdirectory\MyXmlResponse.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="responsebody.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d86.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d87.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\351f0240-bba0-4bcb-93c6-1feba0fe8799.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\array.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\documentdb_root.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\MyXmlResponse.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\subdirectory\MyXmlResponse.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

View File

@@ -31,16 +31,6 @@ namespace WireMock.Net.Tests
return current;
}
[Fact]
public void WireMockServer_Admin_StartStop()
{
var server1 = WireMockServer.Start("http://localhost:19091");
Check.That(server1.Urls[0]).Equals("http://localhost:19091");
server1.Stop();
}
[Fact]
public void WireMockServer_Admin_ResetMappings()
{
@@ -57,6 +47,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(server.Mappings).HasSize(0);
Check.That(server.MappingModels).HasSize(0);
server.Stop();
}
[Fact]
@@ -106,6 +98,8 @@ namespace WireMock.Net.Tests
Check.That(mappings.First().Provider).IsNotNull();
Check.That(mappings.First().Guid).Equals(guid);
Check.That(mappings.First().Title).Equals(title);
server.Stop();
}
[Fact]
@@ -124,6 +118,8 @@ namespace WireMock.Net.Tests
Check.That(mappings.First().Provider).IsNotNull();
Check.That(mappings.First().Guid).Equals(Guid.Parse(guid));
Check.That(mappings.First().Title).IsNullOrEmpty();
server.Stop();
}
[Fact]
@@ -136,6 +132,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(2);
server.Stop();
}
[Fact]
@@ -164,6 +162,8 @@ namespace WireMock.Net.Tests
Check.That(mappings.First().Provider).IsNotNull();
Check.That(mappings.First().Guid).Equals(Guid.Parse(guid));
Check.That(mappings.First().Title).IsNullOrEmpty();
server.Stop();
}
[Fact]
@@ -219,6 +219,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(6);
server.Stop();
}
[Fact]
@@ -257,6 +259,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(2);
server.Stop();
}
[Fact]
@@ -270,6 +274,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(1);
server.Stop();
}
[Fact]
@@ -296,6 +302,8 @@ namespace WireMock.Net.Tests
Check.That(mappings2).HasSize(1);
Check.That(mappings2.First().Guid).Equals(guid);
Check.That(mappings2.First().Provider).Equals(response2);
server.Stop();
}
[Fact]
@@ -320,6 +328,8 @@ namespace WireMock.Net.Tests
// then
Check.That((int)response.StatusCode).IsEqualTo(400);
server.Stop();
}
[Fact]
@@ -336,6 +346,8 @@ namespace WireMock.Net.Tests
var requestLogged = server.LogEntries.First();
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("GET");
Check.That(requestLogged.RequestMessage.BodyData).IsNull();
server.Stop();
}
[Fact]
@@ -359,6 +371,8 @@ namespace WireMock.Net.Tests
var requestLoggedB = server.LogEntries.Last();
Check.That(requestLoggedB.RequestMessage.Path).EndsWith("/foo3");
server.Stop();
}
[Fact]

View File

@@ -22,6 +22,8 @@ namespace WireMock.Net.Tests
Check.That(options.AuthorizationMatcher.Name).IsEqualTo("RegexMatcher");
Check.That(options.AuthorizationMatcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
Check.That(options.AuthorizationMatcher.GetPatterns()).ContainsExactly("^(?i)BASIC eDp5$");
server.Stop();
}
[Fact]
@@ -37,6 +39,8 @@ namespace WireMock.Net.Tests
// Assert
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
Check.That(options.AuthorizationMatcher).IsNull();
server.Stop();
}
}
}

View File

@@ -73,6 +73,8 @@ namespace WireMock.Net.Tests
Check.That(server.Mappings).HasSize(1);
Check.That(server.LogEntries).HasSize(1);
Check.That(content).Contains("google");
server.Stop();
}
[Fact]
@@ -486,6 +488,8 @@ namespace WireMock.Net.Tests
Check.That(content2).IsEqualTo("[]");
}
// On Ubuntu latest it's : "Resource temporarily unavailable"
// On Windows-2019 it's : "No such host is known."
[Fact]
public async Task WireMockServer_Proxy_WhenTargetIsNotAvailable_Should_Return_CorrectResponse()
{
@@ -512,10 +516,12 @@ namespace WireMock.Net.Tests
result.StatusCode.Should().Be(500);
var content = await result.Content.ReadAsStringAsync();
content.Should().Contain("known"); // On Linux it's "Name or service not known". On Windows it's "No such host is known.".
content.Should().NotBeEmpty();
server.LogEntries.Should().HaveCount(1);
((StatusModel)server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known");
var status = ((StatusModel)server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status;
server.Stop();
}
}
}

View File

@@ -32,6 +32,8 @@ namespace WireMock.Net.Tests
// Assert
response.StatusCode.Should().Be(409);
server.Stop();
}
}
}

View File

@@ -29,6 +29,8 @@ namespace WireMock.Net.Tests
// then
Check.That(server.LogEntries).IsEmpty();
server.Stop();
}
[Fact]
@@ -51,6 +53,8 @@ namespace WireMock.Net.Tests
// then
Check.That(server.Mappings).IsEmpty();
Check.ThatAsyncCode(() => new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path)).ThrowsAny();
server.Stop();
}
[Fact]
@@ -82,6 +86,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(response).IsEqualTo("REDIRECT SUCCESSFUL");
server.Stop();
}
[Fact]
@@ -105,6 +111,8 @@ namespace WireMock.Net.Tests
// then
Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200);
server.Stop();
}
[Fact]
@@ -125,6 +133,8 @@ namespace WireMock.Net.Tests
// then
Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200);
server.Stop();
}
//Leaving commented as this requires an actual certificate with password, along with a service that expects a client certificate
@@ -161,6 +171,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(response.Headers.Contains("test")).IsTrue();
Check.That(response.Headers.Contains("Transfer-Encoding")).IsFalse();
server.Stop();
}
#if !NET452
@@ -189,6 +201,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(response.StatusCode).Equals(HttpStatusCode.OK);
server.Stop();
}
#endif
@@ -221,6 +235,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(response.StatusCode).Equals(HttpStatusCode.OK);
server.Stop();
}
[Theory]
@@ -254,6 +270,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(response.StatusCode).Equals(HttpStatusCode.Created);
Check.That(await response.Content.ReadAsStringAsync()).Contains("Mapping added");
server.Stop();
}
[Theory]
@@ -284,6 +302,8 @@ namespace WireMock.Net.Tests
// Assert
Check.That(await response.Content.ReadAsStringAsync()).Contains("OK");
server.Stop();
}
}
}

View File

@@ -51,6 +51,8 @@ namespace WireMock.Net.Tests.WithMapping
m.Response.Body == response &&
(int)m.Response.StatusCode == 201
);
server.Stop();
}
[Fact]
@@ -86,6 +88,8 @@ namespace WireMock.Net.Tests.WithMapping
m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") &&
(int)m.Response.StatusCode == 201
);
server.Stop();
}
[Fact]
@@ -120,6 +124,8 @@ namespace WireMock.Net.Tests.WithMapping
// Assert
server.MappingModels.Should().HaveCount(2);
server.Stop();
}
}
}