Support running WireMock.Net as a sub-app in IIS (#164) (#158)

* Update examples (#158)

* IIS debug

* PathBase logic

* 1.0.4.5-preview-01

* Fix project and readme

* Fix issues

* fix picture alignment

* Add IIS publish examples

* 1.0.4.5
This commit is contained in:
Stef Heyenrath
2018-07-17 08:20:44 +02:00
committed by GitHub
parent a96c8100cf
commit a9c0c6b670
42 changed files with 474 additions and 139 deletions

View File

@@ -42,7 +42,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone.Net
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NET452", "examples\WireMock.Net.ConsoleApplication\WireMock.Net.Console.NET452.csproj", "{668F689E-57B4-422E-8846-C0FF643CA268}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication", "examples\WireMock.Net.WebApplication\WireMock.Net.WebApplication.csproj", "{049539C1-7A66-4559-AD7A-B1C73B97CBB0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication.NETCore2", "examples\WireMock.Net.WebApplication\WireMock.Net.WebApplication.NETCore2.csproj", "{049539C1-7A66-4559-AD7A-B1C73B97CBB0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Proxy.Net452", "examples\WireMock.Net.Console.Proxy.Net452\WireMock.Net.Console.Proxy.Net452.csproj", "{26433A8F-BF01-4962-97EB-81BFFBB61096}"
EndProject

View File

@@ -2,8 +2,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;netcoreapp1.1</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.0;netcoreapp1.1</TargetFrameworks>
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
<StartupObject>WireMock.Net.StandAlone.NETCoreApp.Program</StartupObject>
</PropertyGroup>
<ItemGroup>

View File

@@ -0,0 +1 @@
dotnet run --framework netcoreapp2.1

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<ProjectGuid>049539c1-7a66-4559-ad7a-b1c73b97cbb0</ProjectGuid>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>Default Web Site/wiremock1</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<ProjectGuid>049539c1-7a66-4559-ad7a-b1c73b97cbb1</ProjectGuid>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>Default Web Site/wiremock2</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>

View File

@@ -2,6 +2,10 @@
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost//wiremock",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:56513/",
"sslPort": 0
@@ -23,6 +27,12 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:56514/"
},
"IIS": {
"commandName": "IIS",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "development"
}
}
}
}

View File

@@ -1,17 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<StartupObject>WireMock.Net.WebApplication.Program</StartupObject>
<AssemblyName>WireMock.Net.WebApplication</AssemblyName>
<RootNamespace>WireMock.Net.WebApplication</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

View File

@@ -0,0 +1,21 @@
# Running in IIS
Follow these links / steps:
* https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS
* https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/development-time-iis-support?view=aspnetcore-2.1
* Create a `web.config` file
## IIS Sites
![IIS Multiple](resources/iis-wiremock1and2.png)
## App Pool settings
![IIS Multiple](resources/iis-apppool.png)
## Publish Profiles
Two example publish profiles are created:
* [IIS Localhost 1](./Properties/PublishProfiles/IIS%20Localhost%201.pubxml)
* [IIS Localhost 2](./Properties/PublishProfiles/IIS%20Localhost%202.pubxml)
## Debugging
Select the debug "IIS" if you want to debug in IIS.
![IIS Debug](resources/iis-debug.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
<Version>1.0.4.4</Version>
<Version>1.0.4.5</Version>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -26,7 +26,17 @@ namespace WireMock.Admin.Requests
public string Path { get; set; }
/// <summary>
///The absolete URL.
/// The Absolute Path.
/// </summary>
public string AbsolutePath { get; set; }
/// <summary>
/// Gets the url (relative).
/// </summary>
public string Url { get; set; }
/// <summary>
/// The absolete URL.
/// </summary>
public string AbsoluteUrl { get; set; }

View File

@@ -0,0 +1,51 @@
using System;
using WireMock.Validation;
namespace WireMock.Models
{
/// <summary>
/// UrlDetails
/// </summary>
public class UrlDetails
{
/// <summary>
/// Gets the url (relative).
/// </summary>
public Uri Url { get; }
/// <summary>
/// Gets the AbsoluteUrl.
/// </summary>
public Uri AbsoluteUrl { get; }
/// <summary>
/// Initializes a new instance of the <see cref="UrlDetails"/> class.
/// </summary>
/// <param name="url">The URL.</param>
public UrlDetails(string url) : this(new Uri(url))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UrlDetails"/> class.
/// </summary>
/// <param name="url">The URL.</param>
public UrlDetails(Uri url) : this(url, url)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UrlDetails"/> class.
/// </summary>
/// <param name="absoluteUrl">The absolute URL.</param>
/// <param name="url">The URL (relative).</param>
public UrlDetails(Uri absoluteUrl, Uri url)
{
Check.NotNull(absoluteUrl, nameof(absoluteUrl));
Check.NotNull(url, nameof(url));
AbsoluteUrl = absoluteUrl;
Url = url;
}
}
}

View File

@@ -31,10 +31,10 @@ namespace WireMock.Owin
)
{
#if !NETSTANDARD
Uri url = request.Uri;
var urldetails = UrlUtils.Parse(request.Uri, request.PathBase);
string clientIP = request.RemoteIpAddress;
#else
Uri url = new Uri(request.GetEncodedUrl());
var urldetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
var connection = request.HttpContext.Connection;
string clientIP = connection.RemoteIpAddress.IsIPv4MappedToIPv6
? connection.RemoteIpAddress.MapToIPv4().ToString()
@@ -68,7 +68,7 @@ namespace WireMock.Owin
body = await BodyParser.Parse(request.Body, request.ContentType);
}
return new RequestMessage(url, method, clientIP, body, headers, cookies) { DateTime = DateTime.Now };
return new RequestMessage(urldetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.Now };
}
private bool ShouldParseBody(string method)

View File

@@ -4,13 +4,14 @@ using System.Linq;
using System.Text;
using System.Net;
using JetBrains.Annotations;
using WireMock.Models;
using WireMock.Util;
using WireMock.Validation;
namespace WireMock
{
/// <summary>
/// The request.
/// The RequestMessage.
/// </summary>
public class RequestMessage
{
@@ -20,25 +21,40 @@ namespace WireMock
public string ClientIP { get; }
/// <summary>
/// Gets the url.
/// Gets the url (relative).
/// </summary>
public string Url { get; }
/// <summary>
/// Gets the AbsoluteUrl.
/// </summary>
public string AbsoluteUrl { get; }
/// <summary>
/// Gets the DateTime.
/// </summary>
public DateTime DateTime { get; set; }
/// <summary>
/// Gets the path.
/// Gets the path (relative).
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the AbsolutePath.
/// </summary>
public string AbsolutePath { get; }
/// <summary>
/// Gets the path segments.
/// </summary>
public string[] PathSegments { get; }
/// <summary>
/// Gets the absolute path segments.
/// </summary>
public string[] AbsolutePathSegments { get; }
/// <summary>
/// Gets the method.
/// </summary>
@@ -107,25 +123,30 @@ namespace WireMock
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessage"/> class.
/// </summary>
/// <param name="url">The original url.</param>
/// <param name="urlDetails">The original url details.</param>
/// <param name="method">The HTTP method.</param>
/// <param name="clientIP">The client IP Address.</param>
/// <param name="body">The body.</param>
/// <param name="headers">The headers.</param>
/// <param name="cookies">The cookies.</param>
public RequestMessage([NotNull] Uri url, [NotNull] string method, [NotNull] string clientIP, [CanBeNull] BodyData body = null, [CanBeNull] IDictionary<string, string[]> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
public RequestMessage([NotNull] UrlDetails urlDetails, [NotNull] string method, [NotNull] string clientIP, [CanBeNull] BodyData body = null, [CanBeNull] IDictionary<string, string[]> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
{
Check.NotNull(url, nameof(url));
Check.NotNull(urlDetails, nameof(urlDetails));
Check.NotNull(method, nameof(method));
Check.NotNull(clientIP, nameof(clientIP));
Url = url.ToString();
Protocol = url.Scheme;
Host = url.Host;
Port = url.Port;
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
Path = WebUtility.UrlDecode(url.AbsolutePath);
AbsoluteUrl = urlDetails.AbsoluteUrl.ToString();
Url = urlDetails.Url.ToString();
Protocol = urlDetails.Url.Scheme;
Host = urlDetails.Url.Host;
Port = urlDetails.Url.Port;
Origin = $"{Protocol}://{Host}:{Port}";
AbsolutePath = WebUtility.UrlDecode(urlDetails.AbsoluteUrl.AbsolutePath);
Path = WebUtility.UrlDecode(urlDetails.Url.AbsolutePath);
PathSegments = Path.Split('/').Skip(1).ToArray();
AbsolutePathSegments = AbsolutePath.Split('/').Skip(1).ToArray();
Method = method.ToLower();
ClientIP = clientIP;
@@ -136,7 +157,7 @@ namespace WireMock
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
Cookies = cookies;
RawQuery = WebUtility.UrlDecode(url.Query);
RawQuery = WebUtility.UrlDecode(urlDetails.Url.Query);
Query = ParseQuery(RawQuery);
}

View File

@@ -17,7 +17,9 @@ namespace WireMock.Serialization
DateTime = logEntry.RequestMessage.DateTime,
ClientIP = logEntry.RequestMessage.ClientIP,
Path = logEntry.RequestMessage.Path,
AbsoluteUrl = logEntry.RequestMessage.Url,
AbsolutePath = logEntry.RequestMessage.AbsolutePath,
Url = logEntry.RequestMessage.Url,
AbsoluteUrl = logEntry.RequestMessage.AbsoluteUrl,
Query = logEntry.RequestMessage.Query,
Method = logEntry.RequestMessage.Method,
Body = logEntry.RequestMessage.Body,

View File

@@ -273,8 +273,7 @@ namespace WireMock.Server
public void Stop()
{
var result = _httpServer?.StopAsync();
if (result != null)
result.Wait(); //wait for stop to actually happen
result?.Wait(); // wait for stop to actually happen
}
#endregion

View File

@@ -0,0 +1,38 @@
using System;
using JetBrains.Annotations;
using WireMock.Models;
#if !NETSTANDARD
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif
namespace WireMock.Util
{
internal static class UrlUtils
{
public static UrlDetails Parse([NotNull] Uri uri, PathString pathBase)
{
if (!pathBase.HasValue)
{
return new UrlDetails(uri, uri);
}
var builder = new UriBuilder(uri);
builder.Path = RemoveFirst(builder.Path, pathBase.Value);
return new UrlDetails(uri, builder.Uri);
}
private static string RemoveFirst(string text, string search)
{
int pos = text.IndexOf(search);
if (pos < 0)
{
return text;
}
return text.Substring(0, pos) + text.Substring(pos + search.Length);
}
}
}

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
<AssemblyTitle>WireMock.Net</AssemblyTitle>
<Version>1.0.4.4</Version>
<Version>1.0.4.5</Version>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using NFluent;
using WireMock.Http;
using WireMock.Models;
using WireMock.Util;
using Xunit;
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -38,7 +39,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsBytes = Encoding.UTF8.GetBytes("hi")
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -55,7 +56,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsJson = new { x = 42 }
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -73,7 +74,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsJson = new { x = 42 }
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -92,7 +93,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -110,7 +111,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -128,7 +129,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using NFluent;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using Xunit;
@@ -18,7 +19,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyMethod().WithCookie("session", "a*");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, new Dictionary<string, string> { { "session", "abc" } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, null, new Dictionary<string, string> { { "session", "abc" } });
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -3,6 +3,7 @@ using Moq;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Util;
using Xunit;
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -48,7 +49,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -75,7 +76,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -102,7 +103,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -128,7 +129,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var objectMatcherMock = new Mock<IObjectMatcher>();
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
@@ -154,7 +155,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var objectMatcherMock = new Mock<IObjectMatcher>();
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Moq;
using NFluent;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageCompositeMatcher_GetMatchingScore_EmptyArray()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new Helper(Enumerable.Empty<IRequestMatcher>());
// Act
@@ -41,7 +42,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var requestMatcher2Mock = new Mock<IRequestMatcher>();
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object });
// Act
@@ -65,7 +66,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var requestMatcher2Mock = new Mock<IRequestMatcher>();
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object }, CompositeMatcherType.Or);
// Act

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -13,7 +14,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", "x");
// Act
@@ -28,7 +29,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", "x");
// Act
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "c", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "no-match", "123");
// Act
@@ -59,7 +60,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "h", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "no-match", "123");
// Act
@@ -75,7 +76,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "h", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", "x");
// Act
@@ -91,7 +92,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "h", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", "x");
// Act
@@ -107,7 +108,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "cook", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher("cook", new ExactMatcher("x"));
// Act
@@ -123,7 +124,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "cook", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(x => x.ContainsKey("cook"));
// Act

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -13,7 +14,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageHeaderMatcher_GetMatchingScore_AcceptOnMatch_HeaderDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "h", "x", true);
// Act
@@ -28,7 +29,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageHeaderMatcher_GetMatchingScore_RejectOnMatch_HeaderDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "h", "x", true);
// Act
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "no-match", "123", true);
// Act
@@ -59,7 +60,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "no-match", "123", true);
// Act
@@ -75,7 +76,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "h", "x", true);
// Act
@@ -91,7 +92,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "h", "x", true);
// Act
@@ -107,7 +108,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher("h", new ExactMatcher("x"));
// Act
@@ -123,7 +124,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(x => x.ContainsKey("h"));
// Act

View File

@@ -2,6 +2,7 @@
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -12,7 +13,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchExactOnStringValues()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
@@ -27,7 +28,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchExactOnExactMatchers()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new IStringMatcher[] { new ExactMatcher("test1"), new ExactMatcher("test2") });
// Act
@@ -42,7 +43,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchOnKeyWithValues_PartialMatch()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
@@ -57,7 +58,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithValues_Fails()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
@@ -72,7 +73,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKey()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key");
// Act
@@ -87,7 +88,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithEmptyArray()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new string[] { });
// Act
@@ -102,7 +103,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuePresentInUrl_MatchOnKey()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key");
// Act

View File

@@ -1,5 +1,6 @@
using System;
using NFluent;
using WireMock.Models;
using WireMock.Util;
using Xunit;
@@ -13,7 +14,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_NoKeys()
{
// given
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp);
// then
Check.That(request.GetParameter("not_there")).IsNull();
@@ -23,7 +24,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_SingleKey_SingleValue()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost?foo=bar"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost?foo=bar"), "POST", ClientIp);
// Assert
Check.That(request.GetParameter("foo")).ContainsExactly("bar");
@@ -33,7 +34,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_MultipleKeys_MultipleValues()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost?key=1&key=2"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost?key=1&key=2"), "POST", ClientIp);
// Assert
Check.That(request.GetParameter("key")).Contains("1");
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_SingleKey_MultipleValues()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost?key=1,2&foo=bar&key=3"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost?key=1,2&foo=bar&key=3"), "POST", ClientIp);
// Assert
Check.That(request.GetParameter("key")).Contains("1");
@@ -56,7 +57,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_Constructor1_PathSegments()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/a/b/c"), "POST", ClientIp);
// Assert
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
@@ -66,7 +67,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_Constructor2_PathSegments()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
var request = new RequestMessage(new UrlDetails("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
// Assert
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");

View File

@@ -5,6 +5,7 @@ using NFluent;
using Xunit;
using WireMock.RequestBuilders;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Util;
namespace WireMock.Net.Tests
@@ -20,7 +21,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/bar").UsingPut();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -38,7 +39,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -56,7 +57,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "ABC" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "ABC" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -74,7 +75,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -92,7 +93,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "Hello world!"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -110,7 +111,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "xxx"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -124,7 +125,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithParam("bar", "1", "2");
// when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -138,7 +139,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyMethod().WithParam(p => p.ContainsKey("bar"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -152,7 +153,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithParam("bar", "1");
// when
var request = new RequestMessage(new Uri("http://localhost/test=7"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/test=7"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -4,6 +4,7 @@ using Newtonsoft.Json;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using WireMock.Util;
using Xunit;
@@ -25,7 +26,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "b"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -43,7 +44,7 @@ namespace WireMock.Net.Tests
{
BodyAsJson = 123
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -61,7 +62,7 @@ namespace WireMock.Net.Tests
{
BodyAsBytes = new byte[0]
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -79,7 +80,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "cat"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -97,7 +98,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "Hello world!"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -120,7 +121,7 @@ namespace WireMock.Net.Tests
<todo-item id='a3'>xyz</todo-item>
</todo-list>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -143,7 +144,7 @@ namespace WireMock.Net.Tests
<todo-item id='a3'>xyz</todo-item>
</todo-list>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -161,7 +162,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -179,7 +180,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -201,7 +202,7 @@ namespace WireMock.Net.Tests
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// then
var requestMatchResult = new RequestMatchResult();
@@ -223,7 +224,7 @@ namespace WireMock.Net.Tests
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// then
var requestMatchResult = new RequestMatchResult();
@@ -245,7 +246,7 @@ namespace WireMock.Net.Tests
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// then
var requestMatchResult = new RequestMatchResult();
@@ -266,7 +267,7 @@ namespace WireMock.Net.Tests
};
// Act
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -286,7 +287,7 @@ namespace WireMock.Net.Tests
};
// Act
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// Assert
var requestMatchResult = new RequestMatchResult();

View File

@@ -2,6 +2,7 @@ using System;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using Xunit;
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP("127.0.0.2", "1.1.1.1");
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.2");
// then
var requestMatchResult = new RequestMatchResult();
@@ -30,7 +31,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP("127.0.0.2");
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "192.1.1.1");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "192.1.1.1");
// then
var requestMatchResult = new RequestMatchResult();
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP(new WildcardMatcher("127.0.0.2"));
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.2");
// then
var requestMatchResult = new RequestMatchResult();
@@ -58,7 +59,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP(c => c.Contains("."));
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.2");
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -5,6 +5,7 @@ using WireMock.Matchers;
using Xunit;
using WireMock.RequestBuilders;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Util;
namespace WireMock.Net.Tests
@@ -24,7 +25,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -38,7 +39,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -50,8 +51,8 @@ namespace WireMock.Net.Tests
{
var requestBuilder = Request.Create().WithPath("/x1", "/x2");
var request1 = new RequestMessage(new Uri("http://localhost/x1"), "blabla", ClientIp);
var request2 = new RequestMessage(new Uri("http://localhost/x2"), "blabla", ClientIp);
var request1 = new RequestMessage(new UrlDetails("http://localhost/x1"), "blabla", ClientIp);
var request2 = new RequestMessage(new UrlDetails("http://localhost/x2"), "blabla", ClientIp);
var requestMatchResult = new RequestMatchResult();
Check.That(requestBuilder.GetMatchingScore(request1, requestMatchResult)).IsEqualTo(1.0);
@@ -65,7 +66,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath(url => url.EndsWith("/foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -79,7 +80,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath(new RegexMatcher("^/foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo/bar"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo/bar"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -93,7 +94,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo");
// when
var request = new RequestMessage(new Uri("http://localhost/bar"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -111,7 +112,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "Delete", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "Delete", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -125,7 +126,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingGet();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -139,7 +140,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingHead();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "HEAD", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -153,7 +154,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPost();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -167,7 +168,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPut();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -181,7 +182,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPatch();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PATCH", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PATCH", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -195,7 +196,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPut();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "HEAD", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -2,6 +2,7 @@
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using Xunit;
@@ -18,7 +19,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithUrl("*/foo");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -32,7 +33,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithUrl(new WildcardMatcher("*/foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -46,7 +47,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithUrl(url => url.Contains("foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using Xunit;
@@ -15,7 +16,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
// Assign
var responseMessage = new ResponseMessage { StatusCode = 500 };
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create(() => responseMessage);

View File

@@ -2,6 +2,7 @@
using System.Text;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
@@ -20,7 +21,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.String, Encoding.ASCII);
@@ -41,7 +42,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.SameAsSource, Encoding.ASCII);
@@ -62,7 +63,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create().WithBody("test", null, Encoding.ASCII);
@@ -82,7 +83,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
object x = new { value = "test" };
var response = Response.Create().WithBodyAsJson(x, Encoding.ASCII);
@@ -100,7 +101,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithBody_String_SameAsSource_Encoding()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create().WithBody("r", BodyDestinationFormat.SameAsSource, Encoding.ASCII);
@@ -118,7 +119,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithBody_String_Bytes_Encoding()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create().WithBody("r", BodyDestinationFormat.Bytes, Encoding.ASCII);
@@ -136,7 +137,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithBody_String_Json_Encoding()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create().WithBody("{ \"value\": 42 }", BodyDestinationFormat.Json, Encoding.ASCII);

View File

@@ -2,15 +2,17 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Newtonsoft.Json;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
{
public class ResponseWithBodyHandlebarsTests
public class ResponseWithHandlebarsTests
{
private const string ClientIp = "::1";
@@ -24,7 +26,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData);
var response = Response.Create()
.WithBodyAsJson(new { x = "test {{request.url}}" })
@@ -45,7 +47,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("test {{request.url}} {{request.path}} {{request.method}}")
@@ -58,6 +60,42 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
Check.That(responseMessage.Body).Equals("test http://localhost/foo /foo post");
}
[Fact]
public async Task Response_ProvideResponse_Handlebars_UrlPath()
{
// given
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
var request = new RequestMessage(urlDetails, "POST", ClientIp);
var response = Response.Create()
.WithBody("{{request.url}} {{request.absoluteurl}} {{request.path}} {{request.absolutepath}}")
.WithTransformer();
// act
var responseMessage = await response.ProvideResponseAsync(request);
// then
Check.That(responseMessage.Body).Equals("http://localhost/a/b http://localhost/wiremock/a/b /a/b /wiremock/a/b");
}
[Fact]
public async Task Response_ProvideResponse_Handlebars_PathSegments()
{
// given
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
var request = new RequestMessage(urlDetails, "POST", ClientIp);
var response = Response.Create()
.WithBody("{{request.pathsegments.[0]}} {{request.absolutepathsegments.[0]}}")
.WithTransformer();
// act
var responseMessage = await response.ProvideResponseAsync(request);
// then
Check.That(responseMessage.Body).Equals("a wiremock");
}
[Fact]
public async Task Response_ProvideResponse_Handlebars_Query()
{
@@ -66,7 +104,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("test keya={{request.query.a}} idx={{request.query.a.[0]}} idx={{request.query.a.[1]}} keyb={{request.query.b}}")
@@ -87,7 +125,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}").WithBody("test").WithTransformer();
@@ -108,7 +146,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}", "{{request.url}}").WithBody("test").WithTransformer();
@@ -130,7 +168,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost:1234"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("test {{request.origin}} {{request.port}} {{request.protocol}} {{request.host}}")

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithHeaders_SingleValue()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var headers = new Dictionary<string, string> { { "h", "x" } };
var response = Response.Create().WithHeaders(headers);
@@ -31,7 +32,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithHeaders_MultipleValues()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var response = Response.Create().WithHeaders(headers);
@@ -46,7 +47,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithHeaders_WiremockList()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var headers = new Dictionary<string, WireMockList<string>> { { "h", new WireMockList<string>("x") } };
var response = Response.Create().WithHeaders(headers);

View File

@@ -1,5 +1,6 @@
using System;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using Xunit;
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests
public async void Response_Create_WithHeader(string headerName, string headerValue)
{
// Assign
var requestMock = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
var requestMock = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
IResponseBuilder builder = Response.Create().WithHeader(headerName, headerValue);
// Act

View File

@@ -0,0 +1,53 @@
using System;
using Microsoft.Owin;
using NFluent;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Util
{
public class UrlUtilsTests
{
[Fact]
public void UriUtils_CreateUri_WithValidPathString()
{
// Assign
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
// Act
var result = UrlUtils.Parse(uri, new PathString("/a"));
// Assert
Check.That(result.Url.ToString()).Equals("https://localhost:1234/b?x=0");
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
}
[Fact]
public void UriUtils_CreateUri_WithEmptyPathString()
{
// Assign
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
// Act
var result = UrlUtils.Parse(uri, new PathString());
// Assert
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
}
[Fact]
public void UriUtils_CreateUri_WithDifferentPathString()
{
// Assign
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
// Act
var result = UrlUtils.Parse(uri, new PathString("/test"));
// Assert
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
}
}
}