Add unit test for Response Handlebars

This commit is contained in:
Stef Heyenrath
2017-01-20 17:52:49 +01:00
parent 1b2d20fd69
commit 6c16d45256
16 changed files with 141 additions and 121 deletions

View File

@@ -1,19 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
using WireMock.RequestBuilders;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
namespace WireMock
{
/// <summary>
@@ -24,12 +13,8 @@ namespace WireMock
/// <summary>
/// The map.
/// </summary>
/// <param name="listenerRequest">
/// The listener request.
/// </param>
/// <returns>
/// The <see cref="AndPathRequest"/>.
/// </returns>
/// <param name="listenerRequest">The listener request.</param>
/// <returns>The <see cref="RequestMessage"/>.</returns>
public RequestMessage Map(HttpListenerRequest listenerRequest)
{
Uri url = listenerRequest.Url;
@@ -45,12 +30,8 @@ namespace WireMock
/// <summary>
/// The get request body.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
/// <param name="request">The request.</param>
/// <returns>The <see cref="string"/>.</returns>
private byte[] GetRequestBody(HttpListenerRequest request)
{
if (!request.HasEntityBody)

View File

@@ -99,16 +99,16 @@ namespace WireMock.Matchers.Request
public bool IsMatch(RequestMessage requestMessage)
{
if (_matcher != null)
return _matcher.IsMatch(requestMessage.BodyAsString);
return _matcher.IsMatch(requestMessage.Body);
if (_bodyData != null)
return requestMessage.Body == _bodyData;
return requestMessage.BodyAsBytes == _bodyData;
if (_bodyFunc != null)
return _bodyFunc(requestMessage.BodyAsString);
return _bodyFunc(requestMessage.Body);
if (_bodyDataFunc != null)
return _bodyDataFunc(requestMessage.Body);
return _bodyDataFunc(requestMessage.BodyAsBytes);
return false;
}

View File

@@ -1,6 +1,9 @@
namespace WireMock.RequestBuilders
{
/// <summary>
/// IRequestBuilder
/// </summary>
public interface IRequestBuilder : IUrlAndPathRequestBuilder
{
}
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Matchers;
using WireMock.Matchers.Request;
@@ -308,4 +307,4 @@ namespace WireMock.RequestBuilders
return this;
}
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Extensions;
using WireMock.Validation;
namespace WireMock
{
@@ -14,28 +15,21 @@ namespace WireMock
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessage"/> class.
/// </summary>
/// <param name="url">
/// The original url.
/// </param>
/// <param name="verb">
/// The verb.
/// </param>
/// <param name="body">
/// The body byte[].
/// </param>
/// <param name="bodyAsString">
/// The body string.
/// </param>
/// <param name="headers">
/// The headers.
/// </param>
public RequestMessage(Uri url, string verb, byte[] body, string bodyAsString, IDictionary<string, string> headers = null)
/// <param name="url">The original url.</param>
/// <param name="verb">The verb.</param>
/// <param name="bodyAsBytes">The bodyAsBytes byte[].</param>
/// <param name="body">The body string.</param>
/// <param name="headers">The headers.</param>
public RequestMessage([NotNull] Uri url, [NotNull] string verb, [CanBeNull] byte[] bodyAsBytes, [CanBeNull] string body, [CanBeNull] IDictionary<string, string> headers = null)
{
Check.NotNull(url, nameof(url));
Check.NotNull(verb, nameof(verb));
Url = url.ToString();
Path = url.AbsolutePath;
Verb = verb.ToLower();
BodyAsBytes = bodyAsBytes;
Body = body;
BodyAsString = bodyAsString;
Headers = headers;
string query = url.Query;
@@ -108,24 +102,20 @@ namespace WireMock
public dynamic Query { get; }
/// <summary>
/// Gets the body.
/// Gets the bodyAsBytes.
/// </summary>
public byte[] Body { get; }
public byte[] BodyAsBytes { get; }
/// <summary>
/// Gets the body.
/// </summary>
public string BodyAsString { get; }
public string Body { get; }
/// <summary>
/// The get parameter.
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <returns>
/// The parameter.
/// </returns>
/// <param name="key">The key.</param>
/// <returns>The parameter.s</returns>
public List<string> GetParameter(string key)
{
return Parameters.ContainsKey(key) ? Parameters[key] : new List<string>();

View File

@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
@@ -11,6 +12,7 @@ using JetBrains.Annotations;
// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
namespace WireMock.Validation
{
[ExcludeFromCodeCoverage]
[DebuggerStepThrough]
internal static class Check
{

View File

@@ -1,10 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using JetBrains.Annotations;
// copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore/Properties/CoreStrings.resx
namespace WireMock.Validation
{
[ExcludeFromCodeCoverage]
internal static class CoreStrings
{
/// <summary>