diff --git a/.gitignore b/.gitignore index 96149d09..761a9dbe 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/WireMock.Net Solution.sln b/WireMock.Net Solution.sln index 319c92a1..9b0243e0 100644 --- a/WireMock.Net Solution.sln +++ b/WireMock.Net Solution.sln @@ -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 diff --git a/azure-pipelines-ci-linux.yml b/azure-pipelines-ci-linux.yml index aadfe4d4..f2e5ef09 100644 --- a/azure-pipelines-ci-linux.yml +++ b/azure-pipelines-ci-linux.yml @@ -1,5 +1,5 @@ pool: - vmImage: 'Ubuntu 16.04' + vmImage: 'Ubuntu-latest' variables: buildConfiguration: 'Release' diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index 0be942f1..ecd7c793 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -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) \ No newline at end of file + - 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) \ No newline at end of file diff --git a/nuget.config b/nuget.config new file mode 100644 index 00000000..00c9bbb8 --- /dev/null +++ b/nuget.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net.StandAlone/StandAloneApp.cs b/src/WireMock.Net.StandAlone/StandAloneApp.cs index 26cb4521..63388638 100644 --- a/src/WireMock.Net.StandAlone/StandAloneApp.cs +++ b/src/WireMock.Net.StandAlone/StandAloneApp.cs @@ -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 -{ - /// - /// The StandAloneApp - /// - public static class StandAloneApp - { - /// - /// Start WireMock.Net standalone Server based on the IWireMockServerSettings. - /// - /// The IWireMockServerSettings - [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; - } - - /// - /// Start WireMock.Net standalone Server based on the commandline arguments. - /// - /// The commandline arguments - /// The logger - [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 +{ + /// + /// The StandAloneApp + /// + public static class StandAloneApp + { + /// + /// Start WireMock.Net standalone Server based on the IWireMockServerSettings. + /// + /// The IWireMockServerSettings + [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; + } + + /// + /// Start WireMock.Net standalone Server based on the commandline arguments. + /// + /// The commandline arguments + /// The logger + [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; - } - - /// - /// Try to start WireMock.Net standalone Server based on the commandline arguments. - /// - /// The commandline arguments - /// The logger - /// The WireMockServer - [PublicAPI] - public static bool TryStart([NotNull] string[] args, out WireMockServer server, [CanBeNull] IWireMockLogger logger = null) - { - Check.NotNull(args, nameof(args)); - + } + + return null; + } + + /// + /// Try to start WireMock.Net standalone Server based on the commandline arguments. + /// + /// The commandline arguments + /// The logger + /// The WireMockServer + [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; + } + } } \ No newline at end of file diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs index ef647d3e..1fe2e9a7 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs @@ -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 => { diff --git a/src/WireMock.Net/Server/WireMockServer.cs b/src/WireMock.Net/Server/WireMockServer.cs index a58adde8..02c51568 100644 --- a/src/WireMock.Net/Server/WireMockServer.cs +++ b/src/WireMock.Net/Server/WireMockServer.cs @@ -80,10 +80,7 @@ namespace WireMock.Server /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool disposing) { - if (_httpServer != null) - { - _httpServer.StopAsync(); - } + _httpServer?.StopAsync(); } #endregion diff --git a/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs b/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs index b5ab5c39..67a0f0df 100644 --- a/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs +++ b/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs @@ -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; } diff --git a/test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs b/test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs index 86c42499..58374707 100644 --- a/test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs +++ b/test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs @@ -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(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/ObservableLogEntriesTest.cs b/test/WireMock.Net.Tests/ObservableLogEntriesTest.cs index be93fcec..9ded3032 100644 --- a/test/WireMock.Net.Tests/ObservableLogEntriesTest.cs +++ b/test/WireMock.Net.Tests/ObservableLogEntriesTest.cs @@ -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(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithBodyFromFileTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithBodyFromFileTests.cs index b841fda3..b9f2bf3b 100644 --- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithBodyFromFileTests.cs +++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithBodyFromFileTests.cs @@ -41,6 +41,8 @@ namespace WireMock.Net.Tests.ResponseBuilders // Assert response.Should().Contain("world"); + + server.Stop(); } [Fact] @@ -70,6 +72,8 @@ namespace WireMock.Net.Tests.ResponseBuilders // Assert response.Should().Contain("world"); + + server.Stop(); } [Fact] @@ -99,6 +103,8 @@ namespace WireMock.Net.Tests.ResponseBuilders // Assert response.Should().Contain("world"); + + server.Stop(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs index c5eae9f6..14f357f1 100644 --- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs +++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs @@ -82,6 +82,7 @@ namespace WireMock.Net.Tests.ResponseBuilders public void Dispose() { + _server?.Stop(); _server?.Dispose(); } } diff --git a/test/WireMock.Net.Tests/StatefulBehaviorTests.cs b/test/WireMock.Net.Tests/StatefulBehaviorTests.cs index ad23eb5e..f9e37161 100644 --- a/test/WireMock.Net.Tests/StatefulBehaviorTests.cs +++ b/test/WireMock.Net.Tests/StatefulBehaviorTests.cs @@ -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(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Util/BytesEncodingUtilsTests.cs b/test/WireMock.Net.Tests/Util/BytesEncodingUtilsTests.cs new file mode 100644 index 00000000..bbd0d5d0 --- /dev/null +++ b/test/WireMock.Net.Tests/Util/BytesEncodingUtilsTests.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj index 763ece4e..744f3656 100644 --- a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj +++ b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj @@ -1,107 +1,101 @@  - - Stef Heyenrath - net452;netcoreapp3.1 - full - WireMock.Net.Tests - WireMock.Net.Tests - true - {31DC2EF8-C3FE-467D-84BE-FB5D956E612E} + + Stef Heyenrath + net452;netcoreapp3.1;net5.0 + false + full + WireMock.Net.Tests + WireMock.Net.Tests + true + {31DC2EF8-C3FE-467D-84BE-FB5D956E612E} - - true - True - True + - true - ../../src/WireMock.Net/WireMock.Net.snk - - true + true + ../../src/WireMock.Net/WireMock.Net.snk + + true - - true - true - + + true + true + - - + + + + + + - - - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - + + + + + + + + + + + + + + - - - - + + + + - - - + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - - + + + \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WireMockServer.Admin.cs b/test/WireMock.Net.Tests/WireMockServer.Admin.cs index fea69f2e..8b72a6bb 100644 --- a/test/WireMock.Net.Tests/WireMockServer.Admin.cs +++ b/test/WireMock.Net.Tests/WireMockServer.Admin.cs @@ -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] diff --git a/test/WireMock.Net.Tests/WireMockServer.Authentication.cs b/test/WireMock.Net.Tests/WireMockServer.Authentication.cs index 7990cda5..2dc023f1 100644 --- a/test/WireMock.Net.Tests/WireMockServer.Authentication.cs +++ b/test/WireMock.Net.Tests/WireMockServer.Authentication.cs @@ -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("_options"); Check.That(options.AuthorizationMatcher).IsNull(); + + server.Stop(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WireMockServer.Proxy.cs b/test/WireMock.Net.Tests/WireMockServer.Proxy.cs index 35584213..6bbc68b6 100644 --- a/test/WireMock.Net.Tests/WireMockServer.Proxy.cs +++ b/test/WireMock.Net.Tests/WireMockServer.Proxy.cs @@ -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(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WireMockServerTests.WithCallback.cs b/test/WireMock.Net.Tests/WireMockServerTests.WithCallback.cs index 04c853f8..a0b7b1fb 100644 --- a/test/WireMock.Net.Tests/WireMockServerTests.WithCallback.cs +++ b/test/WireMock.Net.Tests/WireMockServerTests.WithCallback.cs @@ -32,6 +32,8 @@ namespace WireMock.Net.Tests // Assert response.StatusCode.Should().Be(409); + + server.Stop(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WireMockServerTests.cs b/test/WireMock.Net.Tests/WireMockServerTests.cs index 48c537cd..d4fffd7a 100644 --- a/test/WireMock.Net.Tests/WireMockServerTests.cs +++ b/test/WireMock.Net.Tests/WireMockServerTests.cs @@ -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(); } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WithMapping/WireMockServerWithMappingTests.cs b/test/WireMock.Net.Tests/WithMapping/WireMockServerWithMappingTests.cs index 089dd7b7..c6b93c66 100644 --- a/test/WireMock.Net.Tests/WithMapping/WireMockServerWithMappingTests.cs +++ b/test/WireMock.Net.Tests/WithMapping/WireMockServerWithMappingTests.cs @@ -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(); } } } \ No newline at end of file