mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-25 18:41:01 +01:00
* Lower priority from Proxy mappings * Fix codefactor * extra tests * #205 * Fix test for linux * `c:\temp\x.json` fix * Extra tests * more tests * more tests * codefactor * #200 * refactor * refactor * tests
This commit is contained in:
@@ -104,12 +104,12 @@ namespace WireMock.Net.Tests
|
||||
var api = RestClient.For<IFluentMockServerAdmin>(serverUrl);
|
||||
|
||||
// when
|
||||
var requests = await api.FindRequestsAsync(new RequestModel { Methods = new[] { "get" } });
|
||||
var requests = await api.FindRequestsAsync(new RequestModel { Methods = new[] { "GET" } });
|
||||
|
||||
// then
|
||||
Check.That(requests).HasSize(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("get");
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("GET");
|
||||
Check.That(requestLogged.Request.Body).IsNull();
|
||||
Check.That(requestLogged.Request.Path).IsEqualTo("/foo");
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace WireMock.Net.Tests
|
||||
// then
|
||||
Check.That(requests).HasSize(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("get");
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("GET");
|
||||
Check.That(requestLogged.Request.Body).IsNull();
|
||||
Check.That(requestLogged.Request.Path).IsEqualTo("/foo");
|
||||
}
|
||||
@@ -168,7 +168,7 @@ namespace WireMock.Net.Tests
|
||||
// then
|
||||
Check.That(requests).HasSize(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("post");
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("POST");
|
||||
Check.That(requestLogged.Request.Body).IsNotNull();
|
||||
Check.That(requestLogged.Request.Body).Contains("T000001");
|
||||
}
|
||||
@@ -202,7 +202,7 @@ namespace WireMock.Net.Tests
|
||||
// then
|
||||
Check.That(requests).HasSize(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("post");
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("POST");
|
||||
Check.That(requestLogged.Request.Body).IsNotNull();
|
||||
Check.That(requestLogged.Request.Body).Contains("T000001");
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ namespace WireMock.Net.Tests
|
||||
// then
|
||||
Check.That(_server.LogEntries).HasSize(1);
|
||||
var requestLogged = _server.LogEntries.First();
|
||||
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("get");
|
||||
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("GET");
|
||||
Check.That(requestLogged.RequestMessage.BodyAsBytes).IsNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class FluentMockServerAuthenticationTests
|
||||
{
|
||||
[Fact]
|
||||
public void FluentMockServer_Authentication_SetBasicAuthentication()
|
||||
{
|
||||
// Assign
|
||||
var server = FluentMockServer.Start();
|
||||
|
||||
// Act
|
||||
server.SetBasicAuthentication("x", "y");
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<WireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AuthorizationMatcher.Name).IsEqualTo("RegexMatcher");
|
||||
Check.That(options.AuthorizationMatcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
|
||||
Check.That(options.AuthorizationMatcher.GetPatterns()).ContainsExactly("^(?i)BASIC eDp5$");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_Authentication_RemoveBasicAuthentication()
|
||||
{
|
||||
// Assign
|
||||
var server = FluentMockServer.Start();
|
||||
server.SetBasicAuthentication("x", "y");
|
||||
|
||||
// Act
|
||||
server.RemoveBasicAuthentication();
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<WireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AuthorizationMatcher).IsNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,6 +290,52 @@ namespace WireMock.Net.Tests
|
||||
Check.That(response.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Proxy_Should_Not_overrule_AdminMappings()
|
||||
{
|
||||
// Assign
|
||||
string path = $"/prx_{Guid.NewGuid().ToString()}";
|
||||
var serverForProxyForwarding = FluentMockServer.Start();
|
||||
serverForProxyForwarding
|
||||
.Given(Request.Create().WithPath(path))
|
||||
.RespondWith(Response.Create().WithBody("ok"));
|
||||
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = serverForProxyForwarding.Urls[0],
|
||||
SaveMapping = false,
|
||||
SaveMappingToFile = false
|
||||
}
|
||||
});
|
||||
|
||||
// Act 1
|
||||
var requestMessage1 = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri($"{server.Urls[0]}{path}")
|
||||
};
|
||||
var response1 = await new HttpClient().SendAsync(requestMessage1);
|
||||
|
||||
// Assert 1
|
||||
string content1 = await response1.Content.ReadAsStringAsync();
|
||||
Check.That(content1).IsEqualTo("ok");
|
||||
|
||||
// Act 2
|
||||
var requestMessage2 = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri($"{server.Urls[0]}/__admin/mappings")
|
||||
};
|
||||
var response2 = await new HttpClient().SendAsync(requestMessage2);
|
||||
|
||||
// Assert 2
|
||||
string content2 = await response2.Content.ReadAsStringAsync();
|
||||
Check.That(content2).IsEqualTo("[]");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
97
test/WireMock.Net.Tests/FluentMockServerTests.Settings.cs
Normal file
97
test/WireMock.Net.Tests/FluentMockServerTests.Settings.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class FluentMockServerSettingsTests
|
||||
{
|
||||
[Fact]
|
||||
public void FluentMockServer_FluentMockServerSettings_StartAdminInterfaceTrue_BasicAuthenticationIsSet()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
AdminUsername = "u",
|
||||
AdminPassword = "p"
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<WireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AuthorizationMatcher).IsNotNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_FluentMockServerSettings_StartAdminInterfaceFalse_BasicAuthenticationIsNotSet()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
StartAdminInterface = false,
|
||||
AdminUsername = "u",
|
||||
AdminPassword = "p"
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<WireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AuthorizationMatcher).IsNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_FluentMockServerSettings_PriorityFromAllAdminMappingsIsLow_When_StartAdminInterface_IsTrue()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
var mappings = server.Mappings;
|
||||
Check.That(mappings.Count()).IsEqualTo(19);
|
||||
Check.That(mappings.All(m => m.Priority == int.MinValue)).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_FluentMockServerSettings_ProxyAndRecordSettings_ProxyPriority_Is1000_When_StartAdminInterface_IsTrue()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "www.google.com"
|
||||
}
|
||||
});
|
||||
|
||||
// Assert
|
||||
var mappings = server.Mappings;
|
||||
Check.That(mappings.Count()).IsEqualTo(20);
|
||||
Check.That(mappings.Count(m => m.Priority == int.MinValue)).IsEqualTo(19);
|
||||
Check.That(mappings.Count(m => m.Priority == 1000)).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_FluentMockServerSettings_ProxyAndRecordSettings_ProxyPriority_Is0_When_StartAdminInterface_IsFalse()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "www.google.com"
|
||||
}
|
||||
});
|
||||
|
||||
// Assert
|
||||
var mappings = server.Mappings.ToArray();
|
||||
Check.That(mappings.Count()).IsEqualTo(1);
|
||||
Check.That(mappings[0].Priority).IsEqualTo(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace WireMock.Net.Tests
|
||||
.RespondWith(Response.Create().WithBody("hello patch"));
|
||||
|
||||
// when
|
||||
var msg = new HttpRequestMessage(new HttpMethod("patch"), new Uri("http://localhost:" + _server.Ports[0] + path))
|
||||
var msg = new HttpRequestMessage(new HttpMethod("PATCH"), new Uri("http://localhost:" + _server.Ports[0] + path))
|
||||
{
|
||||
Content = new StringContent("{\"data\": {\"attr\":\"value\"}}")
|
||||
};
|
||||
@@ -43,7 +43,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
Check.That(_server.LogEntries).HasSize(1);
|
||||
var requestLogged = _server.LogEntries.First();
|
||||
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("patch");
|
||||
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("PATCH");
|
||||
Check.That(requestLogged.RequestMessage.Body).IsNotNull();
|
||||
Check.That(requestLogged.RequestMessage.Body).IsEqualTo("{\"data\": {\"attr\":\"value\"}}");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestBuilderUsingMethodTests
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
||||
{
|
||||
// Assign
|
||||
var requestBuilder = (Request)Request.Create().UsingGet();
|
||||
|
||||
// Assert 1
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageMethodMatcher));
|
||||
|
||||
// Act
|
||||
requestBuilder.UsingAnyMethod();
|
||||
|
||||
// Assert 2
|
||||
matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestBuilderWithCookieTests
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_String_String_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie("c", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_String_IExactMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie("c", new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_FuncIDictionary()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie((IDictionary<string, string> x) => true);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestBuilderWithHeaderTests
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_String_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_String_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_Strings_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_Strings_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, true, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_IExactMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_FuncIDictionary()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader((IDictionary<string, string[]> x) => true);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestBuilderWithParamTests
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_Strings()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new[] { "v1", "v2" });
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_IExactMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_MatchBehaviour_IExactMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch, new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count()).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,16 @@ namespace WireMock.Net.Tests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Method_Should_BeSame()
|
||||
{
|
||||
// given
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "posT", ClientIp);
|
||||
|
||||
// then
|
||||
Check.That(request.Method).IsEqualTo("posT");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_ParseQuery_NoKeys()
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "whatever"
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("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}}")
|
||||
@@ -61,7 +61,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
var responseMessage = await response.ProvideResponseAsync(request);
|
||||
|
||||
// Assert
|
||||
Check.That(responseMessage.Body).Equals("test http://localhost/foo /foo post");
|
||||
Check.That(responseMessage.Body).Equals("test http://localhost/foo /foo POSt");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
14
test/WireMock.Net.Tests/TestUtils.cs
Normal file
14
test/WireMock.Net.Tests/TestUtils.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public static class TestUtils
|
||||
{
|
||||
public static T GetPrivateFieldValue<T>(this object obj, string fieldName)
|
||||
{
|
||||
var field = obj.GetType().GetTypeInfo().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
return (T)field.GetValue(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
test/WireMock.Net.Tests/Util/PortUtilsTests.cs
Normal file
73
test/WireMock.Net.Tests/Util/PortUtilsTests.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using NFluent;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
{
|
||||
public class PortUtilsTests
|
||||
{
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_InvalidUrl_Returns_False()
|
||||
{
|
||||
// Assign
|
||||
string url = "test";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out string proto, out string host, out int port);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsFalse();
|
||||
Check.That(proto).IsNull();
|
||||
Check.That(host).IsNull();
|
||||
Check.That(port).IsEqualTo(default(int));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_UrlIsMissingPort_Returns_False()
|
||||
{
|
||||
// Assign
|
||||
string url = "http://0.0.0.0";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out string proto, out string host, out int port);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsFalse();
|
||||
Check.That(proto).IsNull();
|
||||
Check.That(host).IsNull();
|
||||
Check.That(port).IsEqualTo(default(int));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_ValidUrl1_Returns_True()
|
||||
{
|
||||
// Assign
|
||||
string url = "https://wiremock.net:5000";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out string proto, out string host, out int port);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsTrue();
|
||||
Check.That(proto).IsEqualTo("https");
|
||||
Check.That(host).IsEqualTo("wiremock.net");
|
||||
Check.That(port).IsEqualTo(5000);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_ValidUrl2_Returns_True()
|
||||
{
|
||||
// Assign
|
||||
string url = "https://0.0.0.0:5000";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out string proto, out string host, out int port);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsTrue();
|
||||
Check.That(proto).IsEqualTo("https");
|
||||
Check.That(host).IsEqualTo("0.0.0.0");
|
||||
Check.That(port).IsEqualTo(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user