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
View File
@@ -254,3 +254,4 @@ paket-files/
./report/coverlet/ ./report/coverlet/
/test/WireMock.Net.Tests/coverage.opencover.xml /test/WireMock.Net.Tests/coverage.opencover.xml
/test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml /test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml
/test/WireMock.Net.Tests/coverage.net5.0.opencover.xml
+1
View File
@@ -30,6 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
CHANGELOG.md = CHANGELOG.md CHANGELOG.md = CHANGELOG.md
Directory.Build.props = Directory.Build.props Directory.Build.props = Directory.Build.props
GitHubReleaseNotes.txt = GitHubReleaseNotes.txt GitHubReleaseNotes.txt = GitHubReleaseNotes.txt
nuget.config = nuget.config
README.md = README.md README.md = README.md
EndProjectSection EndProjectSection
EndProject EndProject
+1 -1
View File
@@ -1,5 +1,5 @@
pool: pool:
vmImage: 'Ubuntu 16.04' vmImage: 'Ubuntu-latest'
variables: variables:
buildConfiguration: 'Release' buildConfiguration: 'Release'
+70 -99
View File
@@ -1,30 +1,20 @@
pool:
vmImage: 'windows-2019'
variables: variables:
Prerelease: 'ci' Prerelease: 'ci'
buildId: "1$(Build.BuildId)" buildId: "1$(Build.BuildId)"
buildProjects: '**/src/**/*.csproj' buildProjects: '**/src/**/*.csproj'
steps: jobs:
# Print buildId - job: Linux_Build_Test_SonarCloud
- script: |
pool:
vmImage: 'Ubuntu-latest'
steps:
- script: |
echo "BuildId = $(buildId)" echo "BuildId = $(buildId)"
displayName: 'Print buildId' displayName: 'Print buildId'
# Install Tools - task: PowerShell@2
- script: |
dotnet tool install --global dotnet-sonarscanner
displayName: Install Tools (SonarScanner)
- task: DotNetCoreCLI@2
displayName: "Install tool: dotnet-coverageconverter"
inputs:
command: 'custom'
custom: 'tool'
arguments: 'update --global dotnet-coverageconverter'
- task: PowerShell@2
displayName: "Use JDK11 by default" displayName: "Use JDK11 by default"
inputs: inputs:
targetType: 'inline' targetType: 'inline'
@@ -32,110 +22,92 @@ steps:
$jdkPath = $env:JAVA_HOME_11_X64 $jdkPath = $env:JAVA_HOME_11_X64
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath" Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
# Build tests and run tests for net452 - task: SonarCloudPrepare@1
- script: | displayName: 'Prepare analysis on SonarCloud'
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'
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis configuration'
inputs: inputs:
SonarCloud: 'SonarCloud' SonarCloud: SonarCloud
organization: 'wiremock-net' organization: wiremock-net
scannerMode: 'MSBuild'
projectKey: 'WireMock-Net_WireMock.Net' projectKey: 'WireMock-Net_WireMock.Net'
projectName: 'WireMock.Net'
extraProperties: | extraProperties: |
sonar.cs.opencover.reportsPaths=**\coverage.netcoreapp3.1.opencover.xml sonar.branch.name=$(Build.SourceBranchName)
condition: and(succeeded(), eq(variables['RUN_SONARCLOUD'], 'yes')) sonar.cs.opencover.reportsPaths=**/coverage.netcoreapp3.1.opencover.xml
# Begin SonarScanner - task: DotNetCoreCLI@2
- script: | displayName: 'Build Unit tests'
%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'))
- 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'))
# 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'))
- task: DotNetCoreCLI@2
displayName: 'Build solution'
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 netcoreapp3.1' arguments: '--configuration Debug --framework netcoreapp3.1'
- task: VSTest@2 - task: DotNetCoreCLI@2
displayName: 'VsTest' displayName: 'Execute Unit tests'
inputs: inputs:
testSelector: 'testAssemblies' command: 'test'
vsTestVersion: 16.0 projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
diagnosticsEnabled: true arguments: '--no-build --configuration Debug --framework netcoreapp3.1 --collect:"XPlat Code Coverage" --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
codeCoverageEnabled: true
testAssemblyVer2: |
**\*tests.dll
!**\obj\**
- task: CmdLine@2 - task: SonarCloudAnalyze@1
displayName: 'Convert .coverage to .coveragexml' displayName: 'SonarCloud: Run Code Analysis'
inputs:
script: 'dotnet-coverageconverter --CoverageFilesFolder "$(Agent.TempDirectory)\TestResults"'
- script: | - task: SonarCloudPublish@1
dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --framework netcoreapp3.1 --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover displayName: 'SonarCloud: Publish Quality Gate Result'
displayName: 'Build tests and run tests for netcoreapp3.1 (with coverage)'
condition: and(succeeded(), eq(variables['RUN_TESTS_NETCOREAPP31'], 'yes'))
- task: SonarCloudAnalyze@1 - task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
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' displayName: 'WhiteSource Bolt'
condition: and(succeeded(), eq(variables['RUN_WHITESOURCE'], 'yes')) condition: and(succeeded(), eq(variables['RUN_WHITESOURCE'], 'yes'))
# Upload coverage to codecov.io - script: |
- script: | bash <(curl https://codecov.io/bash) -t $(CODECOV_TOKEN) -f ./test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml
%USERPROFILE%\.nuget\packages\codecov\1.10.0\tools\codecov.exe -f "./test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml" -t $(CODECOV_TOKEN) displayName: 'codecov'
displayName: Upload coverage to codecov.io
# https://github.com/microsoft/azure-pipelines-tasks/issues/12212 - task: PublishTestResults@2
- task: PublishTestResults@2
condition: and(succeeded(), eq(variables['PUBLISH_TESTRESULTS'], 'yes')) condition: and(succeeded(), eq(variables['PUBLISH_TESTRESULTS'], 'yes'))
inputs: inputs:
testRunner: VSTest testRunner: VSTest
testResultsFiles: '**/*.trx' testResultsFiles: '**/*.trx'
# Based on https://whereslou.com/2018/09/versioning-and-publishing-nuget-packages-automatically-using-azure-devops-pipelines/ - task: PublishBuildArtifacts@1
- task: DotNetCoreCLI@2 displayName: Publish coverage file
inputs:
PathtoPublish: '/home/vsts/work/1/s/test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml'
- job: Windows_Build_Test
dependsOn: Linux_Build_Test_SonarCloud
pool:
vmImage: 'windows-2019'
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
pool:
vmImage: 'windows-2019'
steps:
- task: DotNetCoreCLI@2
displayName: Build Release displayName: Build Release
inputs: inputs:
command: 'build' command: 'build'
arguments: /p:Configuration=Release # https://github.com/MicrosoftDocs/vsts-docs/issues/1976 arguments: /p:Configuration=Release
projects: $(buildProjects) projects: $(buildProjects)
- task: DotNetCoreCLI@2 - task: DotNetCoreCLI@2
displayName: Pack displayName: Pack
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: inputs:
@@ -146,14 +118,13 @@ steps:
packDirectory: '$(Build.ArtifactStagingDirectory)/packages' packDirectory: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'normal' verbosityPack: 'normal'
- task: PublishBuildArtifacts@1 - task: PublishBuildArtifacts@1
displayName: Publish Artifacts displayName: Publish Artifacts
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: inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)' PathtoPublish: '$(Build.ArtifactStagingDirectory)'
# https://github.com/NuGet/Home/issues/8148 - task: DotNetCoreCLI@2
- task: DotNetCoreCLI@2
displayName: Push to MyGet displayName: Push to MyGet
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: inputs:
+7
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>
@@ -58,6 +58,7 @@ namespace WireMock.Owin
} }
_host = builder _host = builder
.UseSetting("suppressStatusMessages", "True") // https://andrewlock.net/suppressing-the-startup-and-shutdown-messages-in-asp-net-core/
.ConfigureAppConfigurationUsingEnvironmentVariables() .ConfigureAppConfigurationUsingEnvironmentVariables()
.ConfigureServices(services => .ConfigureServices(services =>
{ {
+1 -4
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> /// <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) protected virtual void Dispose(bool disposing)
{ {
if (_httpServer != null) _httpServer?.StopAsync();
{
_httpServer.StopAsync();
}
} }
#endregion #endregion
@@ -25,7 +25,7 @@ namespace WireMock.Settings
if (parser.GetBoolSwitchValue("help")) 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; settings = null;
return false; return false;
} }
@@ -16,9 +16,9 @@ namespace WireMock.Net.Tests.FluentAssertions
{ {
public class WireMockAssertionsTests : IDisposable public class WireMockAssertionsTests : IDisposable
{ {
private WireMockServer _server; private readonly WireMockServer _server;
private HttpClient _httpClient; private readonly HttpClient _httpClient;
private int _portUsed; private readonly int _portUsed;
public WireMockAssertionsTests() public WireMockAssertionsTests()
{ {
@@ -289,6 +289,7 @@ namespace WireMock.Net.Tests.FluentAssertions
{ {
_server?.Stop(); _server?.Stop();
_server?.Dispose(); _server?.Dispose();
_httpClient?.Dispose();
} }
} }
} }
@@ -69,6 +69,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(count).Equals(1); Check.That(count).Equals(1);
server.Dispose();
} }
[Fact] [Fact]
@@ -105,6 +107,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(countResponsesWithStatusNotOk).Equals(0); Check.That(countResponsesWithStatusNotOk).Equals(0);
Check.That(count).Equals(expectedCount); Check.That(count).Equals(expectedCount);
server.Dispose();
} }
} }
} }
@@ -41,6 +41,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
// Assert // Assert
response.Should().Contain("<hello>world</hello>"); response.Should().Contain("<hello>world</hello>");
server.Stop();
} }
[Fact] [Fact]
@@ -70,6 +72,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
// Assert // Assert
response.Should().Contain("<hello>world</hello>"); response.Should().Contain("<hello>world</hello>");
server.Stop();
} }
[Fact] [Fact]
@@ -99,6 +103,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
// Assert // Assert
response.Should().Contain("<hello>world</hello>"); response.Should().Contain("<hello>world</hello>");
server.Stop();
} }
} }
} }
@@ -82,6 +82,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
public void Dispose() public void Dispose()
{ {
_server?.Stop();
_server?.Dispose(); _server?.Dispose();
} }
} }
@@ -32,6 +32,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound); Check.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound);
server.Stop();
} }
[Fact] [Fact]
@@ -60,6 +62,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(responseNoState).Equals("No state msg"); Check.That(responseNoState).Equals("No state msg");
Check.That(responseWithState).Equals("Test state msg"); Check.That(responseWithState).Equals("Test state msg");
server.Stop();
} }
[Fact] [Fact]
@@ -94,6 +98,8 @@ namespace WireMock.Net.Tests
responseScenario1.Should().Be(body1); responseScenario1.Should().Be(body1);
responseScenario2.Should().Be(body1); responseScenario2.Should().Be(body1);
responseWithState.Should().Be(body2); responseWithState.Should().Be(body2);
server.Stop();
} }
[Fact] [Fact]
@@ -143,6 +149,8 @@ namespace WireMock.Net.Tests
t2a.Should().Be(body2); t2a.Should().Be(body2);
t2b.Should().Be(body2); t2b.Should().Be(body2);
t3.Should().Be(body3); t3.Should().Be(body3);
server.Stop();
} }
[Fact] [Fact]
@@ -171,6 +179,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(responseIntScenario).Equals("Scenario 1, Setting State 2"); Check.That(responseIntScenario).Equals("Scenario 1, Setting State 2");
Check.That(responseWithIntState).Equals("Scenario 1, State 2"); Check.That(responseWithIntState).Equals("Scenario 1, State 2");
server.Stop();
} }
[Fact] [Fact]
@@ -199,6 +209,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(responseIntScenario).Equals("string state, Setting State 2"); Check.That(responseIntScenario).Equals("string state, Setting State 2");
Check.That(responseWithIntState).Equals("string state, State 2"); Check.That(responseWithIntState).Equals("string state, State 2");
server.Stop();
} }
[Fact] [Fact]
@@ -227,6 +239,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(responseIntScenario).Equals("int state, Setting State 2"); Check.That(responseIntScenario).Equals("int state, Setting State 2");
Check.That(responseWithIntState).Equals("string state, State 2"); Check.That(responseWithIntState).Equals("string state, State 2");
server.Stop();
} }
[Fact] [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"].NextState).IsNull();
Check.That(server.Scenarios["To do list"].Started).IsTrue(); Check.That(server.Scenarios["To do list"].Started).IsTrue();
Check.That(server.Scenarios["To do list"].Finished).IsTrue(); Check.That(server.Scenarios["To do list"].Finished).IsTrue();
server.Stop();
} }
[Fact] [Fact]
@@ -326,6 +342,8 @@ namespace WireMock.Net.Tests
var responseWithState2 = await new HttpClient().GetStringAsync(url + "/foo2X"); var responseWithState2 = await new HttpClient().GetStringAsync(url + "/foo2X");
Check.That(responseWithState2).Equals("Test state msg 2"); Check.That(responseWithState2).Equals("Test state msg 2");
server.Stop();
} }
} }
} }
@@ -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();
}
}
}
@@ -2,17 +2,16 @@
<PropertyGroup> <PropertyGroup>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks> <TargetFrameworks>net452;netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<AssemblyName>WireMock.Net.Tests</AssemblyName> <AssemblyName>WireMock.Net.Tests</AssemblyName>
<PackageId>WireMock.Net.Tests</PackageId> <PackageId>WireMock.Net.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<ProjectGuid>{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}</ProjectGuid> <ProjectGuid>{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}</ProjectGuid>
<!-- https://github.com/tonerdo/coverlet/issues/6 --> <!--<SonarQubeTestProject>True</SonarQubeTestProject>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <SonarQubeExclude>True</SonarQubeExclude>-->
<SonarQubeTestProject>True</SonarQubeTestProject>
<SonarQubeExclude>True</SonarQubeExclude>
<SignAssembly>true</SignAssembly> <SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../src/WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>../../src/WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
@@ -24,9 +23,6 @@
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" /> <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.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
@@ -36,31 +32,33 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Codecov" Version="1.10.0" /> <PackageReference Include="Codecov" Version="1.10.0" />
<PackageReference Include="coverlet.msbuild" Version="2.8.1"> <PackageReference Include="coverlet.msbuild" Version="3.0.0-preview.9">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1"> <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> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.0-preview.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" /> <PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="System.Threading" Version="4.3.0" /> <PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="RestEase" Version="1.4.10" /> <PackageReference Include="RestEase" Version="1.4.10" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" /> <PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NFluent" Version="2.7.0" /> <PackageReference Include="NFluent" Version="2.7.0" />
<PackageReference Include="OpenCover" Version="4.7.922" /> <!--<PackageReference Include="OpenCover" Version="4.7.922" />-->
<PackageReference Include="ReportGenerator" Version="4.8.1" /> <!--<PackageReference Include="ReportGenerator" Version="4.8.1" />-->
<PackageReference Include="SimMetrics.Net" Version="1.0.5" /> <PackageReference Include="SimMetrics.Net" Version="1.0.5" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" /> <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" />--> <!--<PackageReference Include="StrongNamer" Version="0.0.8" />-->
</ItemGroup> </ItemGroup>
@@ -69,10 +67,6 @@
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> <PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="responsebody.json"> <None Update="responsebody.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+24 -10
View File
@@ -31,16 +31,6 @@ namespace WireMock.Net.Tests
return current; 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] [Fact]
public void WireMockServer_Admin_ResetMappings() public void WireMockServer_Admin_ResetMappings()
{ {
@@ -57,6 +47,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(server.Mappings).HasSize(0); Check.That(server.Mappings).HasSize(0);
Check.That(server.MappingModels).HasSize(0); Check.That(server.MappingModels).HasSize(0);
server.Stop();
} }
[Fact] [Fact]
@@ -106,6 +98,8 @@ namespace WireMock.Net.Tests
Check.That(mappings.First().Provider).IsNotNull(); Check.That(mappings.First().Provider).IsNotNull();
Check.That(mappings.First().Guid).Equals(guid); Check.That(mappings.First().Guid).Equals(guid);
Check.That(mappings.First().Title).Equals(title); Check.That(mappings.First().Title).Equals(title);
server.Stop();
} }
[Fact] [Fact]
@@ -124,6 +118,8 @@ namespace WireMock.Net.Tests
Check.That(mappings.First().Provider).IsNotNull(); Check.That(mappings.First().Provider).IsNotNull();
Check.That(mappings.First().Guid).Equals(Guid.Parse(guid)); Check.That(mappings.First().Guid).Equals(Guid.Parse(guid));
Check.That(mappings.First().Title).IsNullOrEmpty(); Check.That(mappings.First().Title).IsNullOrEmpty();
server.Stop();
} }
[Fact] [Fact]
@@ -136,6 +132,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray(); var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(2); Check.That(mappings).HasSize(2);
server.Stop();
} }
[Fact] [Fact]
@@ -164,6 +162,8 @@ namespace WireMock.Net.Tests
Check.That(mappings.First().Provider).IsNotNull(); Check.That(mappings.First().Provider).IsNotNull();
Check.That(mappings.First().Guid).Equals(Guid.Parse(guid)); Check.That(mappings.First().Guid).Equals(Guid.Parse(guid));
Check.That(mappings.First().Title).IsNullOrEmpty(); Check.That(mappings.First().Title).IsNullOrEmpty();
server.Stop();
} }
[Fact] [Fact]
@@ -219,6 +219,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray(); var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(6); Check.That(mappings).HasSize(6);
server.Stop();
} }
[Fact] [Fact]
@@ -257,6 +259,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray(); var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(2); Check.That(mappings).HasSize(2);
server.Stop();
} }
[Fact] [Fact]
@@ -270,6 +274,8 @@ namespace WireMock.Net.Tests
var mappings = server.Mappings.ToArray(); var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(1); Check.That(mappings).HasSize(1);
server.Stop();
} }
[Fact] [Fact]
@@ -296,6 +302,8 @@ namespace WireMock.Net.Tests
Check.That(mappings2).HasSize(1); Check.That(mappings2).HasSize(1);
Check.That(mappings2.First().Guid).Equals(guid); Check.That(mappings2.First().Guid).Equals(guid);
Check.That(mappings2.First().Provider).Equals(response2); Check.That(mappings2.First().Provider).Equals(response2);
server.Stop();
} }
[Fact] [Fact]
@@ -320,6 +328,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That((int)response.StatusCode).IsEqualTo(400); Check.That((int)response.StatusCode).IsEqualTo(400);
server.Stop();
} }
[Fact] [Fact]
@@ -336,6 +346,8 @@ namespace WireMock.Net.Tests
var requestLogged = server.LogEntries.First(); var requestLogged = server.LogEntries.First();
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("GET"); Check.That(requestLogged.RequestMessage.Method).IsEqualTo("GET");
Check.That(requestLogged.RequestMessage.BodyData).IsNull(); Check.That(requestLogged.RequestMessage.BodyData).IsNull();
server.Stop();
} }
[Fact] [Fact]
@@ -359,6 +371,8 @@ namespace WireMock.Net.Tests
var requestLoggedB = server.LogEntries.Last(); var requestLoggedB = server.LogEntries.Last();
Check.That(requestLoggedB.RequestMessage.Path).EndsWith("/foo3"); Check.That(requestLoggedB.RequestMessage.Path).EndsWith("/foo3");
server.Stop();
} }
[Fact] [Fact]
@@ -22,6 +22,8 @@ namespace WireMock.Net.Tests
Check.That(options.AuthorizationMatcher.Name).IsEqualTo("RegexMatcher"); Check.That(options.AuthorizationMatcher.Name).IsEqualTo("RegexMatcher");
Check.That(options.AuthorizationMatcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch); Check.That(options.AuthorizationMatcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
Check.That(options.AuthorizationMatcher.GetPatterns()).ContainsExactly("^(?i)BASIC eDp5$"); Check.That(options.AuthorizationMatcher.GetPatterns()).ContainsExactly("^(?i)BASIC eDp5$");
server.Stop();
} }
[Fact] [Fact]
@@ -37,6 +39,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options"); var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
Check.That(options.AuthorizationMatcher).IsNull(); Check.That(options.AuthorizationMatcher).IsNull();
server.Stop();
} }
} }
} }
@@ -73,6 +73,8 @@ namespace WireMock.Net.Tests
Check.That(server.Mappings).HasSize(1); Check.That(server.Mappings).HasSize(1);
Check.That(server.LogEntries).HasSize(1); Check.That(server.LogEntries).HasSize(1);
Check.That(content).Contains("google"); Check.That(content).Contains("google");
server.Stop();
} }
[Fact] [Fact]
@@ -486,6 +488,8 @@ namespace WireMock.Net.Tests
Check.That(content2).IsEqualTo("[]"); Check.That(content2).IsEqualTo("[]");
} }
// On Ubuntu latest it's : "Resource temporarily unavailable"
// On Windows-2019 it's : "No such host is known."
[Fact] [Fact]
public async Task WireMockServer_Proxy_WhenTargetIsNotAvailable_Should_Return_CorrectResponse() public async Task WireMockServer_Proxy_WhenTargetIsNotAvailable_Should_Return_CorrectResponse()
{ {
@@ -512,10 +516,12 @@ namespace WireMock.Net.Tests
result.StatusCode.Should().Be(500); result.StatusCode.Should().Be(500);
var content = await result.Content.ReadAsStringAsync(); 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); 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();
} }
} }
} }
@@ -32,6 +32,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
response.StatusCode.Should().Be(409); response.StatusCode.Should().Be(409);
server.Stop();
} }
} }
} }
@@ -29,6 +29,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(server.LogEntries).IsEmpty(); Check.That(server.LogEntries).IsEmpty();
server.Stop();
} }
[Fact] [Fact]
@@ -51,6 +53,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(server.Mappings).IsEmpty(); Check.That(server.Mappings).IsEmpty();
Check.ThatAsyncCode(() => new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path)).ThrowsAny(); Check.ThatAsyncCode(() => new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path)).ThrowsAny();
server.Stop();
} }
[Fact] [Fact]
@@ -82,6 +86,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(response).IsEqualTo("REDIRECT SUCCESSFUL"); Check.That(response).IsEqualTo("REDIRECT SUCCESSFUL");
server.Stop();
} }
[Fact] [Fact]
@@ -105,6 +111,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200); Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200);
server.Stop();
} }
[Fact] [Fact]
@@ -125,6 +133,8 @@ namespace WireMock.Net.Tests
// then // then
Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200); 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 //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 // Assert
Check.That(response.Headers.Contains("test")).IsTrue(); Check.That(response.Headers.Contains("test")).IsTrue();
Check.That(response.Headers.Contains("Transfer-Encoding")).IsFalse(); Check.That(response.Headers.Contains("Transfer-Encoding")).IsFalse();
server.Stop();
} }
#if !NET452 #if !NET452
@@ -189,6 +201,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(response.StatusCode).Equals(HttpStatusCode.OK); Check.That(response.StatusCode).Equals(HttpStatusCode.OK);
server.Stop();
} }
#endif #endif
@@ -221,6 +235,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(response.StatusCode).Equals(HttpStatusCode.OK); Check.That(response.StatusCode).Equals(HttpStatusCode.OK);
server.Stop();
} }
[Theory] [Theory]
@@ -254,6 +270,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(response.StatusCode).Equals(HttpStatusCode.Created); Check.That(response.StatusCode).Equals(HttpStatusCode.Created);
Check.That(await response.Content.ReadAsStringAsync()).Contains("Mapping added"); Check.That(await response.Content.ReadAsStringAsync()).Contains("Mapping added");
server.Stop();
} }
[Theory] [Theory]
@@ -284,6 +302,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(await response.Content.ReadAsStringAsync()).Contains("OK"); Check.That(await response.Content.ReadAsStringAsync()).Contains("OK");
server.Stop();
} }
} }
} }
@@ -51,6 +51,8 @@ namespace WireMock.Net.Tests.WithMapping
m.Response.Body == response && m.Response.Body == response &&
(int)m.Response.StatusCode == 201 (int)m.Response.StatusCode == 201
); );
server.Stop();
} }
[Fact] [Fact]
@@ -86,6 +88,8 @@ namespace WireMock.Net.Tests.WithMapping
m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") && m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") &&
(int)m.Response.StatusCode == 201 (int)m.Response.StatusCode == 201
); );
server.Stop();
} }
[Fact] [Fact]
@@ -120,6 +124,8 @@ namespace WireMock.Net.Tests.WithMapping
// Assert // Assert
server.MappingModels.Should().HaveCount(2); server.MappingModels.Should().HaveCount(2);
server.Stop();
} }
} }
} }