Initial code (copy)

This commit is contained in:
Stef Heyenrath
2017-01-17 22:44:21 +01:00
parent 4ab93896d7
commit eeaeeb2c61
47 changed files with 3311 additions and 1 deletions

View File

@@ -1,2 +1,2 @@
# WireMock.Net
A C# .NET version based on http://wiremock.org
A C# .NET version based on https://github.com/alexvictoor/mock4net which tries to mimic the functionality from http://WireMock.org

56
WireMock.Net Solution.sln Normal file
View File

@@ -0,0 +1,56 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EF242EDF-7133-4277-9A0C-18744DE08707}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{197A0EE3-94E5-4807-BBCF-2F1BCA28A6AE}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WireMock", "src\WireMock\WireMock.xproj", "{D3804228-91F4-4502-9595-39584E5A01AD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{F0C22C47-DF71-463C-9B04-B4E0F3B8708A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.ConsoleApplication", "examples\WireMock.Net.ConsoleApplication\WireMock.Net.ConsoleApplication.csproj", "{668F689E-57B4-422E-8846-C0FF643CA268}"
ProjectSection(ProjectDependencies) = postProject
{D3804228-91F4-4502-9595-39584E5A01AD} = {D3804228-91F4-4502-9595-39584E5A01AD}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{890A1DED-C229-4FA1-969E-AAC3BBFC05E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Tests", "test\WireMock.Net.Tests\WireMock.Net.Tests.csproj", "{D8B56D28-33CE-4BEF-97D4-7DD546E37F25}"
ProjectSection(ProjectDependencies) = postProject
{D3804228-91F4-4502-9595-39584E5A01AD} = {D3804228-91F4-4502-9595-39584E5A01AD}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D3804228-91F4-4502-9595-39584E5A01AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3804228-91F4-4502-9595-39584E5A01AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3804228-91F4-4502-9595-39584E5A01AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3804228-91F4-4502-9595-39584E5A01AD}.Release|Any CPU.Build.0 = Release|Any CPU
{668F689E-57B4-422E-8846-C0FF643CA268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{668F689E-57B4-422E-8846-C0FF643CA268}.Debug|Any CPU.Build.0 = Debug|Any CPU
{668F689E-57B4-422E-8846-C0FF643CA268}.Release|Any CPU.ActiveCfg = Release|Any CPU
{668F689E-57B4-422E-8846-C0FF643CA268}.Release|Any CPU.Build.0 = Release|Any CPU
{D8B56D28-33CE-4BEF-97D4-7DD546E37F25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8B56D28-33CE-4BEF-97D4-7DD546E37F25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8B56D28-33CE-4BEF-97D4-7DD546E37F25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8B56D28-33CE-4BEF-97D4-7DD546E37F25}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D3804228-91F4-4502-9595-39584E5A01AD} = {EF242EDF-7133-4277-9A0C-18744DE08707}
{668F689E-57B4-422E-8846-C0FF643CA268} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
{D8B56D28-33CE-4BEF-97D4-7DD546E37F25} = {890A1DED-C229-4FA1-969E-AAC3BBFC05E5}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WireMock.Net.ConsoleApp
{
public class Program
{
public static void Main(string[] args)
{
int port;
if (args.Length == 0 || !int.TryParse(args[0], out port))
port = 8080;
var server = FluentMockServer.Start(port);
Console.WriteLine("FluentMockServer running at {0}", server.Port);
server
.Given(
Requests
.WithUrl("/*")
.UsingGet()
)
.RespondWith(
Responses
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""msg"": ""Hello world!""}")
);
Console.WriteLine("Press any key to stop the server");
Console.ReadKey();
Console.WriteLine("Displaying all requests");
var allRequests = server.RequestLogs;
Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented));
Console.WriteLine("Press any key to quit");
Console.ReadKey();
}
}
}

View File

@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WireMock.Net.ConsoleApp")]
[assembly: AssemblyTrademark("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bb7ad978-5c03-4d76-a903-3865802b45eb")]

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>bb7ad978-5c03-4d76-a903-3865802b45eb</ProjectGuid>
<RootNamespace>WireMock.Net.ConsoleApp</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@@ -0,0 +1,42 @@
using System;
using Newtonsoft.Json;
namespace WireMock.Net.ConsoleApplication
{
static class Program
{
static void Main(string[] args)
{
int port;
if (args.Length == 0 || !int.TryParse(args[0], out port))
port = 8080;
var server = FluentMockServer.Start(port);
Console.WriteLine("FluentMockServer running at {0}", server.Port);
server
.Given(
Requests
.WithUrl("/*")
.UsingGet()
)
.RespondWith(
Responses
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""msg"": ""Hello world!""}")
);
Console.WriteLine("Press any key to stop the server");
Console.ReadKey();
Console.WriteLine("Displaying all requests");
var allRequests = server.RequestLogs;
Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented));
Console.WriteLine("Press any key to quit");
Console.ReadKey();
}
}
}

View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Mock4Net.Core.ConsoleApplication")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Mock4Net.Core.ConsoleApplication")]
[assembly: AssemblyCopyright("Copyright © Stef Heyenrath 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("668f689e-57b4-422e-8846-c0ff643ca268")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{668F689E-57B4-422E-8846-C0FF643CA268}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WireMock.Net.ConsoleApplication</RootNamespace>
<AssemblyName>WireMock.Net.ConsoleApplication</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="WireMock">
<HintPath>..\..\src\WireMock\bin\$(Configuration)\net45\WireMock.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
</packages>

View File

@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The composite request spec.
/// </summary>
public class CompositeRequestSpec : ISpecifyRequests
{
/// <summary>
/// The _request specs.
/// </summary>
private readonly IEnumerable<ISpecifyRequests> _requestSpecs;
/// <summary>
/// Initializes a new instance of the <see cref="CompositeRequestSpec"/> class.
/// The constructor.
/// </summary>
/// <param name="requestSpecs">
/// The <see cref="IEnumerable&lt;ISpecifyRequests&gt;"/> request specs.
/// </param>
public CompositeRequestSpec(IEnumerable<ISpecifyRequests> requestSpecs)
{
_requestSpecs = requestSpecs;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return _requestSpecs.All(spec => spec.IsSatisfiedBy(request));
}
}
}

View File

@@ -0,0 +1,311 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using WireMock.Http;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The fluent mock server.
/// </summary>
public class FluentMockServer
{
/// <summary>
/// The _http server.
/// </summary>
private readonly TinyHttpServer _httpServer;
/// <summary>
/// The _routes.
/// </summary>
private readonly IList<Route> _routes = new List<Route>();
/// <summary>
/// The _request logs.
/// </summary>
private readonly IList<Request> _requestLogs = new List<Request>();
/// <summary>
/// The _request mapper.
/// </summary>
private readonly HttpListenerRequestMapper _requestMapper = new HttpListenerRequestMapper();
/// <summary>
/// The _response mapper.
/// </summary>
private readonly HttpListenerResponseMapper _responseMapper = new HttpListenerResponseMapper();
/// <summary>
/// The _sync root.
/// </summary>
private readonly object _syncRoot = new object();
/// <summary>
/// The _request processing delay.
/// </summary>
private TimeSpan _requestProcessingDelay = TimeSpan.Zero;
/// <summary>
/// Initializes a new instance of the <see cref="FluentMockServer"/> class.
/// </summary>
/// <param name="port">
/// The port.
/// </param>
/// <param name="ssl">
/// The SSL support.
/// </param>
private FluentMockServer(int port, bool ssl)
{
string protocol = ssl ? "https" : "http";
_httpServer = new TinyHttpServer(protocol + "://localhost:" + port + "/", HandleRequest);
Port = port;
_httpServer.Start();
}
/// <summary>
/// The RespondWithAProvider interface.
/// </summary>
public interface IRespondWithAProvider
{
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
void RespondWith(IProvideResponses provider);
}
/// <summary>
/// Gets the port.
/// </summary>
public int Port { get; }
/// <summary>
/// Gets the request logs.
/// </summary>
public IEnumerable<Request> RequestLogs
{
get
{
lock (((ICollection)_requestLogs).SyncRoot)
{
return new ReadOnlyCollection<Request>(_requestLogs);
}
}
}
/// <summary>
/// The start.
/// </summary>
/// <param name="port">
/// The port.
/// </param>
/// <param name="ssl">
/// The SSL support.
/// </param>
/// <returns>
/// The <see cref="FluentMockServer"/>.
/// </returns>
public static FluentMockServer Start(int port = 0, bool ssl = false)
{
if (port == 0)
{
port = Ports.FindFreeTcpPort();
}
return new FluentMockServer(port, ssl);
}
/// <summary>
/// The reset.
/// </summary>
public void Reset()
{
lock (((ICollection)_requestLogs).SyncRoot)
{
_requestLogs.Clear();
}
lock (((ICollection)_routes).SyncRoot)
{
_routes.Clear();
}
}
/// <summary>
/// The search logs for.
/// </summary>
/// <param name="spec">
/// The spec.
/// </param>
/// <returns>
/// The <see cref="IEnumerable"/>.
/// </returns>
public IEnumerable<Request> SearchLogsFor(ISpecifyRequests spec)
{
lock (((ICollection)_requestLogs).SyncRoot)
{
return _requestLogs.Where(spec.IsSatisfiedBy);
}
}
/// <summary>
/// The add request processing delay.
/// </summary>
/// <param name="delay">
/// The delay.
/// </param>
public void AddRequestProcessingDelay(TimeSpan delay)
{
lock (_syncRoot)
{
_requestProcessingDelay = delay;
}
}
/// <summary>
/// The stop.
/// </summary>
public void Stop()
{
_httpServer.Stop();
}
/// <summary>
/// The given.
/// </summary>
/// <param name="requestSpec">
/// The request spec.
/// </param>
/// <returns>
/// The <see cref="IRespondWithAProvider"/>.
/// </returns>
public IRespondWithAProvider Given(ISpecifyRequests requestSpec)
{
return new RespondWithAProvider(RegisterRoute, requestSpec);
}
/// <summary>
/// The register route.
/// </summary>
/// <param name="route">
/// The route.
/// </param>
private void RegisterRoute(Route route)
{
lock (((ICollection)_routes).SyncRoot)
{
_routes.Add(route);
}
}
/// <summary>
/// The log request.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
private void LogRequest(Request request)
{
lock (((ICollection)_requestLogs).SyncRoot)
{
_requestLogs.Add(request);
}
}
/// <summary>
/// The handle request.
/// </summary>
/// <param name="ctx">
/// The context.
/// </param>
private async void HandleRequest(HttpListenerContext ctx)
{
lock (_syncRoot)
{
Task.Delay(_requestProcessingDelay).Wait();
}
var request = _requestMapper.Map(ctx.Request);
LogRequest(request);
var targetRoute = _routes.FirstOrDefault(route => route.IsRequestHandled(request));
if (targetRoute == null)
{
ctx.Response.StatusCode = 404;
var content = Encoding.UTF8.GetBytes("<html><body>Mock Server: page not found</body></html>");
ctx.Response.OutputStream.Write(content, 0, content.Length);
}
else
{
var response = await targetRoute.ResponseTo(request);
_responseMapper.Map(response, ctx.Response);
}
ctx.Response.Close();
}
/// <summary>
/// The respond with a provider.
/// </summary>
private class RespondWithAProvider : IRespondWithAProvider
{
/// <summary>
/// The _registration callback.
/// </summary>
private readonly RegistrationCallback _registrationCallback;
/// <summary>
/// The _request spec.
/// </summary>
private readonly ISpecifyRequests _requestSpec;
/// <summary>
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
/// </summary>
/// <param name="registrationCallback">
/// The registration callback.
/// </param>
/// <param name="requestSpec">
/// The request spec.
/// </param>
public RespondWithAProvider(RegistrationCallback registrationCallback, ISpecifyRequests requestSpec)
{
_registrationCallback = registrationCallback;
_requestSpec = requestSpec;
}
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
public void RespondWith(IProvideResponses provider)
{
_registrationCallback(new Route(_requestSpec, provider));
}
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Sockets;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1650:ElementDocumentationMustBeSpelledCorrectly",
Justification = "Reviewed. Suppression is OK here.")]
namespace WireMock.Http
{
/// <summary>
/// The ports.
/// </summary>
public static class Ports
{
/// <summary>
/// The find free TCP port.
/// </summary>
/// <returns>
/// The <see cref="int"/>.
/// </returns>
/// <remarks>see http://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net. </remarks>
// ReSharper disable once StyleCop.SA1650
public static int FindFreeTcpPort()
{
TcpListener l = new TcpListener(IPAddress.Loopback, 0);
l.Start();
int port = ((IPEndPoint)l.LocalEndpoint).Port;
l.Stop();
return port;
}
}
}

View File

@@ -0,0 +1,98 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock.Http
{
/// <summary>
/// The tiny http server.
/// </summary>
public class TinyHttpServer
{
/// <summary>
/// The _http handler.
/// </summary>
private readonly Action<HttpListenerContext> _httpHandler;
/// <summary>
/// The _listener.
/// </summary>
private readonly HttpListener _listener;
/// <summary>
/// The cancellation token source.
/// </summary>
private CancellationTokenSource _cts;
/// <summary>
/// Initializes a new instance of the <see cref="TinyHttpServer"/> class.
/// </summary>
/// <param name="urlPrefix">
/// The url prefix.
/// </param>
/// <param name="httpHandler">
/// The http handler.
/// </param>
public TinyHttpServer(string urlPrefix, Action<HttpListenerContext> httpHandler)
{
_httpHandler = httpHandler;
// .Net Framework is not supportted on XP or Server 2003, so no need for the check
/*if (!HttpListener.IsSupported)
{
Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
return;
}*/
// Create a listener.
_listener = new HttpListener();
_listener.Prefixes.Add(urlPrefix);
}
/// <summary>
/// The start.
/// </summary>
public void Start()
{
_listener.Start();
_cts = new CancellationTokenSource();
Task.Run(
async () =>
{
using (_listener)
{
while (!_cts.Token.IsCancellationRequested)
{
HttpListenerContext context = await _listener.GetContextAsync();
_httpHandler(context);
}
}
},
_cts.Token);
}
/// <summary>
/// The stop.
/// </summary>
public void Stop()
{
_cts.Cancel();
}
}
}

View File

@@ -0,0 +1,68 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
[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>
/// The http listener request mapper.
/// </summary>
public class HttpListenerRequestMapper
{
/// <summary>
/// The map.
/// </summary>
/// <param name="listenerRequest">
/// The listener request.
/// </param>
/// <returns>
/// The <see cref="Request"/>.
/// </returns>
public Request Map(HttpListenerRequest listenerRequest)
{
var path = listenerRequest.Url.AbsolutePath;
var query = listenerRequest.Url.Query;
var verb = listenerRequest.HttpMethod;
var body = GetRequestBody(listenerRequest);
var listenerHeaders = listenerRequest.Headers;
var headers = listenerHeaders.AllKeys.ToDictionary(k => k, k => listenerHeaders[k]);
return new Request(path, query, verb, body, headers);
}
/// <summary>
/// The get request body.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
private string GetRequestBody(HttpListenerRequest request)
{
if (!request.HasEntityBody)
{
return null;
}
using (var body = request.InputStream)
{
using (var reader = new StreamReader(body, request.ContentEncoding))
{
return reader.ReadToEnd();
}
}
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Text;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The http listener response mapper.
/// </summary>
public class HttpListenerResponseMapper
{
/// <summary>
/// The map.
/// </summary>
/// <param name="response">
/// The response.
/// </param>
/// <param name="result">
/// The result.
/// </param>
public void Map(Response response, HttpListenerResponse result)
{
result.StatusCode = response.StatusCode;
response.Headers.ToList().ForEach(pair => result.AddHeader(pair.Key, pair.Value));
if (response.Body != null)
{
var content = Encoding.UTF8.GetBytes(response.Body);
result.OutputStream.Write(content, 0, content.Length);
}
}
}
}

View File

@@ -0,0 +1,27 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The ProvideResponses interface.
/// </summary>
public interface IProvideResponses
{
/// <summary>
/// The provide response.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<Response> ProvideResponse(Request request);
}
}

View File

@@ -0,0 +1,26 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The SpecifyRequests interface.
/// </summary>
public interface ISpecifyRequests
{
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
bool IsSatisfiedBy(Request request);
}
}

138
src/WireMock/Request.cs Normal file
View File

@@ -0,0 +1,138 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1650:ElementDocumentationMustBeSpelledCorrectly",
Justification = "Reviewed. Suppression is OK here.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request.
/// </summary>
public class Request
{
/// <summary>
/// The _params.
/// </summary>
private readonly Dictionary<string, List<string>> _params = new Dictionary<string, List<string>>();
/// <summary>
/// Initializes a new instance of the <see cref="Request"/> class.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <param name="query">
/// The query.
/// </param>
/// <param name="verb">
/// The verb.
/// </param>
/// <param name="body">
/// The body.
/// </param>
/// <param name="headers">
/// The headers.
/// </param>
public Request(string path, string query, string verb, string body, IDictionary<string, string> headers)
{
if (!string.IsNullOrEmpty(query))
{
if (query.StartsWith("?"))
{
query = query.Substring(1);
}
_params = query.Split('&').Aggregate(
new Dictionary<string, List<string>>(),
(dict, term) =>
{
var key = term.Split('=')[0];
if (!dict.ContainsKey(key))
{
dict.Add(key, new List<string>());
}
dict[key].Add(term.Split('=')[1]);
return dict;
});
}
Path = path;
Headers = headers.ToDictionary(kv => kv.Key.ToLower(), kv => kv.Value.ToLower());
Verb = verb.ToLower();
Body = body?.Trim() ?? string.Empty;
}
/// <summary>
/// Gets the url.
/// </summary>
public string Url
{
get
{
if (!_params.Any())
{
return Path;
}
return Path + "?" + string.Join("&", _params.SelectMany(kv => kv.Value.Select(value => kv.Key + "=" + value)));
}
}
/// <summary>
/// Gets the path.
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the verb.
/// </summary>
public string Verb { get; }
/// <summary>
/// Gets the headers.
/// </summary>
public IDictionary<string, string> Headers { get; }
/// <summary>
/// Gets the body.
/// </summary>
public string Body { get; }
/// <summary>
/// The get parameter.
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <returns>
/// The parameter.
/// </returns>
public List<string> GetParameter(string key)
{
if (_params.ContainsKey(key))
{
return _params[key];
}
return new List<string>();
}
}
}

View File

@@ -0,0 +1,54 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request body spec.
/// </summary>
public class RequestBodySpec : ISpecifyRequests
{
/// <summary>
/// The _body.
/// </summary>
private readonly string _body;
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// </summary>
/// <param name="body">
/// The body.
/// </param>
public RequestBodySpec(string body)
{
_body = body.Trim();
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return WildcardPatternMatcher.MatchWildcardString(_body, request.Body.Trim());
}
}
}

View File

@@ -0,0 +1,64 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request header spec.
/// </summary>
public class RequestHeaderSpec : ISpecifyRequests
{
/// <summary>
/// The _name.
/// </summary>
private readonly string _name;
/// <summary>
/// The _pattern.
/// </summary>
private readonly string _pattern;
/// <summary>
/// Initializes a new instance of the <see cref="RequestHeaderSpec"/> class.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="pattern">
/// The pattern.
/// </param>
public RequestHeaderSpec(string name, string pattern)
{
_name = name.ToLower();
_pattern = pattern.ToLower();
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
string headerValue = request.Headers[_name];
return WildcardPatternMatcher.MatchWildcardString(_pattern, headerValue);
}
}
}

View File

@@ -0,0 +1,65 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request parameters spec.
/// </summary>
public class RequestParamSpec : ISpecifyRequests
{
/// <summary>
/// The _key.
/// </summary>
private readonly string _key;
/// <summary>
/// The _values.
/// </summary>
private readonly List<string> _values;
/// <summary>
/// Initializes a new instance of the <see cref="RequestParamSpec"/> class.
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <param name="values">
/// The values.
/// </param>
public RequestParamSpec(string key, List<string> values)
{
_key = key;
_values = values;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return request.GetParameter(_key).Intersect(_values).Count() == _values.Count;
}
}
}

View File

@@ -0,0 +1,54 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request path spec.
/// </summary>
public class RequestPathSpec : ISpecifyRequests
{
/// <summary>
/// The _path.
/// </summary>
private readonly string _path;
/// <summary>
/// Initializes a new instance of the <see cref="RequestPathSpec"/> class.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
public RequestPathSpec(string path)
{
_path = path;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return WildcardPatternMatcher.MatchWildcardString(_path, request.Path);
}
}
}

View File

@@ -0,0 +1,123 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The VerbRequestBuilder interface.
/// </summary>
public interface IVerbRequestBuilder : ISpecifyRequests, IHeadersRequestBuilder
{
/// <summary>
/// The using get.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder UsingGet();
/// <summary>
/// The using post.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder UsingPost();
/// <summary>
/// The using put.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder UsingPut();
/// <summary>
/// The using head.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder UsingHead();
/// <summary>
/// The using any verb.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder UsingAnyVerb();
/// <summary>
/// The using verb.
/// </summary>
/// <param name="verb">
/// The verb.
/// </param>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder UsingVerb(string verb);
}
/// <summary>
/// The HeadersRequestBuilder interface.
/// </summary>
public interface IHeadersRequestBuilder : IBodyRequestBuilder, ISpecifyRequests, IParamsRequestBuilder
{
/// <summary>
/// The with header.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="value">
/// The value.
/// </param>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
IHeadersRequestBuilder WithHeader(string name, string value);
}
/// <summary>
/// The BodyRequestBuilder interface.
/// </summary>
public interface IBodyRequestBuilder
{
/// <summary>
/// The with body.
/// </summary>
/// <param name="body">
/// The body.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// </returns>
ISpecifyRequests WithBody(string body);
}
/// <summary>
/// The ParametersRequestBuilder interface.
/// </summary>
public interface IParamsRequestBuilder
{
/// <summary>
/// The with parameters.
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <param name="values">
/// The values.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// </returns>
ISpecifyRequests WithParam(string key, params string[] values);
}
}

View File

@@ -0,0 +1,54 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request url spec.
/// </summary>
public class RequestUrlSpec : ISpecifyRequests
{
/// <summary>
/// The _url.
/// </summary>
private readonly string _url;
/// <summary>
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
/// </summary>
/// <param name="url">
/// The url.
/// </param>
public RequestUrlSpec(string url)
{
_url = url;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return WildcardPatternMatcher.MatchWildcardString(_url, request.Url);
}
}
}

View File

@@ -0,0 +1,54 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request verb spec.
/// </summary>
internal class RequestVerbSpec : ISpecifyRequests
{
/// <summary>
/// The _verb.
/// </summary>
private readonly string _verb;
/// <summary>
/// Initializes a new instance of the <see cref="RequestVerbSpec"/> class.
/// </summary>
/// <param name="verb">
/// The verb.
/// </param>
public RequestVerbSpec(string verb)
{
_verb = verb.ToLower();
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return request.Verb == _verb;
}
}
}

205
src/WireMock/Requests.cs Normal file
View File

@@ -0,0 +1,205 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1126:PrefixCallsCorrectly",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The requests.
/// </summary>
public class Requests : CompositeRequestSpec, IVerbRequestBuilder, IHeadersRequestBuilder, IParamsRequestBuilder
{
/// <summary>
/// The _request specs.
/// </summary>
private readonly IList<ISpecifyRequests> _requestSpecs;
/// <summary>
/// Initializes a new instance of the <see cref="Requests"/> class.
/// </summary>
/// <param name="requestSpecs">
/// The request specs.
/// </param>
private Requests(IList<ISpecifyRequests> requestSpecs) : base(requestSpecs)
{
_requestSpecs = requestSpecs;
}
/// <summary>
/// The with url.
/// </summary>
/// <param name="url">
/// The url.
/// </param>
/// <returns>
/// The <see cref="IVerbRequestBuilder"/>.
/// </returns>
public static IVerbRequestBuilder WithUrl(string url)
{
var specs = new List<ISpecifyRequests>();
var requests = new Requests(specs);
specs.Add(new RequestUrlSpec(url));
return requests;
}
/// <summary>
/// The with path.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <returns>
/// The <see cref="IVerbRequestBuilder"/>.
/// </returns>
public static IVerbRequestBuilder WithPath(string path)
{
var specs = new List<ISpecifyRequests>();
var requests = new Requests(specs);
specs.Add(new RequestPathSpec(path));
return requests;
}
/// <summary>
/// The using get.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder UsingGet()
{
_requestSpecs.Add(new RequestVerbSpec("get"));
return this;
}
/// <summary>
/// The using post.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder UsingPost()
{
_requestSpecs.Add(new RequestVerbSpec("post"));
return this;
}
/// <summary>
/// The using put.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder UsingPut()
{
_requestSpecs.Add(new RequestVerbSpec("put"));
return this;
}
/// <summary>
/// The using head.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder UsingHead()
{
_requestSpecs.Add(new RequestVerbSpec("head"));
return this;
}
/// <summary>
/// The using any verb.
/// </summary>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder UsingAnyVerb()
{
return this;
}
/// <summary>
/// The using verb.
/// </summary>
/// <param name="verb">
/// The verb.
/// </param>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder UsingVerb(string verb)
{
_requestSpecs.Add(new RequestVerbSpec(verb));
return this;
}
/// <summary>
/// The with body.
/// </summary>
/// <param name="body">
/// The body.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// </returns>
public ISpecifyRequests WithBody(string body)
{
_requestSpecs.Add(new RequestBodySpec(body));
return this;
}
/// <summary>
/// The with parameters.
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <param name="values">
/// The values.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// </returns>
public ISpecifyRequests WithParam(string key, params string[] values)
{
_requestSpecs.Add(new RequestParamSpec(key, values.ToList()));
return this;
}
/// <summary>
/// The with header.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="value">
/// The value.
/// </param>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </returns>
public IHeadersRequestBuilder WithHeader(string name, string value)
{
_requestSpecs.Add(new RequestHeaderSpec(name, value));
return this;
}
}
}

92
src/WireMock/Response.cs Normal file
View File

@@ -0,0 +1,92 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The response.
/// </summary>
public class Response
{
/// <summary>
/// The _headers.
/// </summary>
private readonly IDictionary<string, string> _headers = new ConcurrentDictionary<string, string>();
/// <summary>
/// The status code.
/// </summary>
private volatile int statusCode = 200;
/// <summary>
/// The body.
/// </summary>
private volatile string body;
/// <summary>
/// Gets the headers.
/// </summary>
public IDictionary<string, string> Headers => _headers;
/// <summary>
/// Gets or sets the status code.
/// </summary>
public int StatusCode
{
get
{
return statusCode;
}
set
{
statusCode = value;
}
}
/// <summary>
/// Gets or sets the body.
/// </summary>
public string Body
{
get
{
return body;
}
set
{
body = value;
}
}
/// <summary>
/// The add header.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="value">
/// The value.
/// </param>
public void AddHeader(string name, string value)
{
_headers.Add(name, value);
}
}
}

View File

@@ -0,0 +1,64 @@
using System;
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The HeadersResponseBuilder interface.
/// </summary>
public interface IHeadersResponseBuilder : IBodyResponseBuilder
{
/// <summary>
/// The with header.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="value">
/// The value.
/// </param>
/// <returns>
/// The <see cref="IHeadersResponseBuilder"/>.
/// </returns>
IHeadersResponseBuilder WithHeader(string name, string value);
}
/// <summary>
/// The BodyResponseBuilder interface.
/// </summary>
public interface IBodyResponseBuilder : IDelayResponseBuilder
{
/// <summary>
/// The with body.
/// </summary>
/// <param name="body">
/// The body.
/// </param>
/// <returns>
/// The <see cref="IDelayResponseBuilder"/>.
/// </returns>
IDelayResponseBuilder WithBody(string body);
}
/// <summary>
/// The DelayResponseBuilder interface.
/// </summary>
public interface IDelayResponseBuilder : IProvideResponses
{
/// <summary>
/// The after delay.
/// </summary>
/// <param name="delay">
/// The delay.
/// </param>
/// <returns>
/// The <see cref="IProvideResponses"/>.
/// </returns>
IProvideResponses AfterDelay(TimeSpan delay);
}
}

143
src/WireMock/Responses.cs Normal file
View File

@@ -0,0 +1,143 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The responses.
/// </summary>
public class Responses : IHeadersResponseBuilder
{
/// <summary>
/// The _response.
/// </summary>
private readonly Response _response;
/// <summary>
/// The _delay.
/// </summary>
private TimeSpan _delay = TimeSpan.Zero;
/// <summary>
/// Initializes a new instance of the <see cref="Responses"/> class.
/// </summary>
/// <param name="response">
/// The response.
/// </param>
public Responses(Response response)
{
_response = response;
}
/// <summary>
/// The with Success status code.
/// </summary>
/// <returns>The <see cref="IHeadersResponseBuilder"/>.</returns>
public static IHeadersResponseBuilder WithSuccess()
{
return WithStatusCode(200);
}
/// <summary>
/// The with NotFound status code.
/// </summary>
/// <returns>The <see cref="IHeadersResponseBuilder"/>.</returns>
public static IHeadersResponseBuilder WithNotFound()
{
return WithStatusCode(404);
}
/// <summary>
/// The with status code.
/// </summary>
/// <param name="code">
/// The code.
/// </param>
/// <returns>
/// The <see cref="IHeadersResponseBuilder"/>.
/// </returns>
public static IHeadersResponseBuilder WithStatusCode(int code)
{
var response = new Response { StatusCode = code };
return new Responses(response);
}
/// <summary>
/// The provide response.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public async Task<Response> ProvideResponse(Request request)
{
await Task.Delay(_delay);
return _response;
}
/// <summary>
/// The with header.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="value">
/// The value.
/// </param>
/// <returns>
/// The <see cref="IHeadersResponseBuilder"/>.
/// </returns>
public IHeadersResponseBuilder WithHeader(string name, string value)
{
_response.AddHeader(name, value);
return this;
}
/// <summary>
/// The with body.
/// </summary>
/// <param name="body">
/// The body.
/// </param>
/// <returns>
/// The <see cref="IDelayResponseBuilder"/>.
/// </returns>
public IDelayResponseBuilder WithBody(string body)
{
_response.Body = body;
return this;
}
/// <summary>
/// The after delay.
/// </summary>
/// <param name="delay">
/// The delay.
/// </param>
/// <returns>
/// The <see cref="IProvideResponses"/>.
/// </returns>
public IProvideResponses AfterDelay(TimeSpan delay)
{
_delay = delay;
return this;
}
}
}

78
src/WireMock/Route.cs Normal file
View File

@@ -0,0 +1,78 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
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
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The route.
/// </summary>
public class Route
{
/// <summary>
/// The _request spec.
/// </summary>
private readonly ISpecifyRequests _requestSpec;
/// <summary>
/// The _provider.
/// </summary>
private readonly IProvideResponses _provider;
/// <summary>
/// Initializes a new instance of the <see cref="Route"/> class.
/// </summary>
/// <param name="requestSpec">
/// The request spec.
/// </param>
/// <param name="provider">
/// The provider.
/// </param>
public Route(ISpecifyRequests requestSpec, IProvideResponses provider)
{
_requestSpec = requestSpec;
_provider = provider;
}
/// <summary>
/// The response to.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public Task<Response> ResponseTo(Request request)
{
return _provider.ProvideResponse(request);
}
/// <summary>
/// The is request handled.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsRequestHandled(Request request)
{
return _requestSpec.IsSatisfiedBy(request);
}
}
}

View File

@@ -0,0 +1,17 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The registration callback.
/// </summary>
/// <param name="route">
/// The route.
/// </param>
public delegate void RegistrationCallback(Route route);
}

View File

@@ -0,0 +1,74 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1650:ElementDocumentationMustBeSpelledCorrectly",
Justification = "Reviewed. Suppression is OK here.")]
namespace WireMock
{
/// <summary>
/// The wildcard pattern matcher.
/// </summary>
public static class WildcardPatternMatcher
{
/// <summary>
/// The match wildcard string.
/// </summary>
/// <param name="pattern">
/// The pattern.
/// </param>
/// <param name="input">
/// The input.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
/// <remarks>
/// Copy/paste from http://www.codeproject.com/Tips/57304/Use-wildcard-characters-and-to-compare-strings
/// </remarks>
public static bool MatchWildcardString(string pattern, string input)
{
if (string.CompareOrdinal(pattern, input) == 0)
{
return true;
}
if (string.IsNullOrEmpty(input))
{
return string.IsNullOrEmpty(pattern.Trim('*'));
}
if (pattern.Length == 0)
{
return false;
}
if (pattern[0] == '?')
{
return MatchWildcardString(pattern.Substring(1), input.Substring(1));
}
if (pattern[pattern.Length - 1] == '?')
{
return MatchWildcardString(pattern.Substring(0, pattern.Length - 1), input.Substring(0, input.Length - 1));
}
if (pattern[0] == '*')
{
return MatchWildcardString(pattern.Substring(1), input) || MatchWildcardString(pattern, input.Substring(1));
}
if (pattern[pattern.Length - 1] == '*')
{
return MatchWildcardString(pattern.Substring(0, pattern.Length - 1), input) || MatchWildcardString(pattern, input.Substring(0, input.Length - 1));
}
return pattern[0] == input[0] && MatchWildcardString(pattern.Substring(1), input.Substring(1));
}
}
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>d3804228-91f4-4502-9595-39584e5a01ad</ProjectGuid>
<RootNamespace>WireMock</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -0,0 +1,15 @@
,
"netstandard1.3": {
"buildOptions": { "define": [ "NETSTANDARD" ] },
"imports": [
"dotnet5.4"
],
"dependencies": {
"System.Collections.Concurrent": "4.3.0",
"System.Diagnostics.Tools": "4.3.0",
"System.Linq": "4.3.0",
"System.Net.Http": "4.3.0",
"System.Net.Sockets": "4.3.0",
"System.Threading.Tasks": "4.3.0"
}
}

37
src/WireMock/project.json Normal file
View File

@@ -0,0 +1,37 @@
{
"version": "1.0.0.9",
"title": "WireMock.Net",
"description": "xxxx",
"authors": [ "Alexandre Victoor", "Stef Heyenrath" ],
"packOptions": {
"summary": "This is a .NET Core port of the the Microsoft assembly for the .Net 4.0 Dynamic language functionality.",
"tags": [ "system", "linq", "dynamic", "core" ],
"owners": [ "Stef Heyenrath" ],
"repository": {
"type": "git",
"url": "https://github.com/StefH/WireMock.Net"
},
"projectUrl": "https://github.com/StefH/WireMock.Net",
"licenseUrl": "https://github.com/StefH/WireMock.Net/blob/master/licence.txt",
"releaseNotes": ""
},
"buildOptions": {
"xmlDoc": true
},
"dependencies": {
"JetBrains.Annotations": {
"version": "10.2.1",
"type": "build"
}
},
"frameworks": {
"net45": {
"frameworkAssemblies": {
}
}
}
}

View File

@@ -0,0 +1,225 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using NFluent;
using NUnit.Framework;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
[Timeout(5000)]
public class FluentMockServerTests
{
private FluentMockServer _server;
[Test]
public async Task Should_respond_to_request()
{
// given
_server = FluentMockServer.Start();
_server
.Given(Requests
.WithUrl("/foo")
.UsingGet())
.RespondWith(Responses
.WithStatusCode(200)
.WithBody(@"{ msg: ""Hello world!""}"));
// when
var response
= await new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo");
// then
Check.That(response).IsEqualTo(@"{ msg: ""Hello world!""}");
}
[Test]
public async Task Should_respond_404_for_unexpected_request()
{
// given
_server = FluentMockServer.Start();
// when
var response
= await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/foo");
// then
Check.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound);
Check.That((int)response.StatusCode).IsEqualTo(404);
}
[Test]
public async Task Should_record_requests_in_the_requestlogs()
{
// given
_server = FluentMockServer.Start();
// when
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/foo");
// then
Check.That(_server.RequestLogs).HasSize(1);
var requestLogged = _server.RequestLogs.First();
Check.That(requestLogged.Verb).IsEqualTo("get");
Check.That(requestLogged.Body).IsEmpty();
}
[Test]
public async Task Should_find_a_request_satisfying_a_request_spec()
{
// given
_server = FluentMockServer.Start();
// when
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/foo");
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
// then
var result = _server.SearchLogsFor(Requests.WithUrl("/b*"));
Check.That(result).HasSize(1);
var requestLogged = result.First();
Check.That(requestLogged.Url).IsEqualTo("/bar");
}
[Test]
public async Task Should_reset_requestlogs()
{
// given
_server = FluentMockServer.Start();
// when
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/foo");
_server.Reset();
// then
Check.That(_server.RequestLogs).IsEmpty();
}
[Test]
public void Should_reset_routes()
{
// given
_server = FluentMockServer.Start();
_server
.Given(Requests
.WithUrl("/foo")
.UsingGet())
.RespondWith(Responses
.WithStatusCode(200)
.WithBody(@"{ msg: ""Hello world!""}"));
// when
_server.Reset();
// then
Check.ThatAsyncCode(() => new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo"))
.ThrowsAny();
}
[Test]
public async Task Should_respond_a_redirect_without_body()
{
// given
_server = FluentMockServer.Start();
_server
.Given(Requests
.WithUrl("/foo")
.UsingGet())
.RespondWith(Responses
.WithStatusCode(307)
.WithHeader("Location", "/bar"));
_server
.Given(Requests
.WithUrl("/bar")
.UsingGet())
.RespondWith(Responses
.WithStatusCode(200)
.WithBody("REDIRECT SUCCESSFUL"));
// when
var response
= await new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo");
// then
Check.That(response).IsEqualTo("REDIRECT SUCCESSFUL");
}
[Test]
public async Task Should_delay_responses_for_a_given_route()
{
// given
_server = FluentMockServer.Start();
_server
.Given(Requests
.WithUrl("/*"))
.RespondWith(Responses
.WithStatusCode(200)
.WithBody(@"{ msg: ""Hello world!""}")
.AfterDelay(TimeSpan.FromMilliseconds(2000)));
// when
var watch = new Stopwatch();
watch.Start();
await new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo");
watch.Stop();
// then
Check.That(watch.ElapsedMilliseconds).IsGreaterThan(2000);
}
[Test]
public async Task Should_delay_responses()
{
// given
_server = FluentMockServer.Start();
_server.AddRequestProcessingDelay(TimeSpan.FromMilliseconds(2000));
_server
.Given(Requests
.WithUrl("/*"))
.RespondWith(Responses
.WithStatusCode(200)
.WithBody(@"{ msg: ""Hello world!""}"));
// when
var watch = new Stopwatch();
watch.Start();
await new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo");
watch.Stop();
// then
Check.That(watch.ElapsedMilliseconds).IsGreaterThan(2000);
}
[TearDown]
public void ShutdownServer()
{
_server.Stop();
}
}
}

View File

@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using NFluent;
using NUnit.Framework;
using WireMock.Http;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock.Net.Tests.Http
{
[TestFixture]
public class TinyHttpServerTests
{
[Test]
public void Should_Call_Handler_on_Request()
{
// given
var port = Ports.FindFreeTcpPort();
bool called = false;
var urlPrefix = "http://localhost:" + port + "/";
var server = new TinyHttpServer(urlPrefix, ctx => called = true);
server.Start();
// when
var httpClient = new HttpClient();
httpClient.GetAsync(urlPrefix).Wait(3000);
// then
Check.That(called).IsTrue();
}
}
}

View File

@@ -0,0 +1,166 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using NFluent;
using NUnit.Framework;
using WireMock.Http;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
public class HttpListenerRequestMapperTests
{
private MapperServer _server;
[SetUp]
public void StartListenerServer()
{
_server = MapperServer.Start();
}
[Test]
public async Task Should_map_uri_from_listener_request()
{
// given
var client = new HttpClient();
// when
await client.GetAsync(MapperServer.UrlPrefix + "toto");
// then
Check.That(MapperServer.LastRequest).IsNotNull();
Check.That(MapperServer.LastRequest.Url).IsEqualTo("/toto");
}
[Test]
public async Task Should_map_verb_from_listener_request()
{
// given
var client = new HttpClient();
// when
await client.PutAsync(MapperServer.UrlPrefix, new StringContent("Hello!"));
// then
Check.That(MapperServer.LastRequest).IsNotNull();
Check.That(MapperServer.LastRequest.Verb).IsEqualTo("put");
}
[Test]
public async Task Should_map_body_from_listener_request()
{
// given
var client = new HttpClient();
// when
await client.PutAsync(MapperServer.UrlPrefix, new StringContent("Hello!"));
// then
Check.That(MapperServer.LastRequest).IsNotNull();
Check.That(MapperServer.LastRequest.Body).IsEqualTo("Hello!");
}
[Test]
public async Task Should_map_headers_from_listener_request()
{
// given
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Alex", "1706");
// when
await client.GetAsync(MapperServer.UrlPrefix);
// then
Check.That(MapperServer.LastRequest).IsNotNull();
Check.That(MapperServer.LastRequest.Headers).Not.IsNullOrEmpty();
Check.That(MapperServer.LastRequest.Headers.Contains(new KeyValuePair<string, string>("x-alex", "1706"))).IsTrue();
}
[Test]
public async Task Should_map_params_from_listener_request()
{
// given
var client = new HttpClient();
// when
await client.GetAsync(MapperServer.UrlPrefix + "index.html?id=toto");
// then
Check.That(MapperServer.LastRequest).IsNotNull();
Check.That(MapperServer.LastRequest.Path).EndsWith("/index.html");
Check.That(MapperServer.LastRequest.GetParameter("id")).HasSize(1);
}
[TearDown]
public void StopListenerServer()
{
_server.Stop();
}
private class MapperServer : TinyHttpServer
{
private static volatile Request _lastRequest;
private MapperServer(string urlPrefix, Action<HttpListenerContext> httpHandler) : base(urlPrefix, httpHandler)
{
}
public static Request LastRequest
{
get
{
return _lastRequest;
}
private set
{
_lastRequest = value;
}
}
public static string UrlPrefix { get; private set; }
public static new MapperServer Start()
{
var port = Ports.FindFreeTcpPort();
UrlPrefix = "http://localhost:" + port + "/";
var server = new MapperServer(
UrlPrefix,
context =>
{
LastRequest = new HttpListenerRequestMapper().Map(context.Request);
context.Response.Close();
});
((TinyHttpServer)server).Start();
return server;
}
public new void Stop()
{
base.Stop();
LastRequest = null;
}
}
}
}

View File

@@ -0,0 +1,126 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using NFluent;
using NUnit.Framework;
using WireMock.Http;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
public class HttpListenerResponseMapperTests
{
private TinyHttpServer _server;
private Task<HttpResponseMessage> _responseMsgTask;
[Test]
public void Should_map_status_code_from_original_response()
{
// given
var response = new Response { StatusCode = 404 };
var httpListenerResponse = CreateHttpListenerResponse();
// when
new HttpListenerResponseMapper().Map(response, httpListenerResponse);
// then
Check.That(httpListenerResponse.StatusCode).IsEqualTo(404);
}
[Test]
public void Should_map_headers_from_original_response()
{
// given
var response = new Response();
response.AddHeader("cache-control", "no-cache");
var httpListenerResponse = CreateHttpListenerResponse();
// when
new HttpListenerResponseMapper().Map(response, httpListenerResponse);
// then
Check.That(httpListenerResponse.Headers).HasSize(1);
Check.That(httpListenerResponse.Headers.Keys).Contains("cache-control");
Check.That(httpListenerResponse.Headers.Get("cache-control")).Contains("no-cache");
}
[Test]
public void Should_map_body_from_original_response()
{
// given
var response = new Response();
response.Body = "Hello !!!";
var httpListenerResponse = CreateHttpListenerResponse();
// when
new HttpListenerResponseMapper().Map(response, httpListenerResponse);
// then
var responseMessage = ToResponseMessage(httpListenerResponse);
Check.That(responseMessage).IsNotNull();
var contentTask = responseMessage.Content.ReadAsStringAsync();
Check.That(contentTask.Result).IsEqualTo("Hello !!!");
}
[TearDown]
public void StopServer()
{
if (_server != null)
{
_server.Stop();
}
}
/// <summary>
/// Dirty HACK to get HttpListenerResponse instances
/// </summary>
/// <returns>
/// The <see cref="HttpListenerResponse"/>.
/// </returns>
public HttpListenerResponse CreateHttpListenerResponse()
{
var port = Ports.FindFreeTcpPort();
var urlPrefix = "http://localhost:" + port + "/";
var responseReady = new AutoResetEvent(false);
HttpListenerResponse response = null;
_server = new TinyHttpServer(
urlPrefix,
context =>
{
response = context.Response;
responseReady.Set();
});
_server.Start();
_responseMsgTask = new HttpClient().GetAsync(urlPrefix);
responseReady.WaitOne();
return response;
}
public HttpResponseMessage ToResponseMessage(HttpListenerResponse listenerResponse)
{
listenerResponse.Close();
_responseMsgTask.Wait();
return _responseMsgTask.Result;
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WireMock.Net.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WireMock.Net.Tests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d8b56d28-33ce-4bef-97d4-7dd546e37f25")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using NFluent;
using NUnit.Framework;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
public class RequestTests
{
[Test]
public void Should_handle_empty_query()
{
// given
var request = new Request("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
// then
Check.That(request.GetParameter("foo")).IsEmpty();
}
[Test]
public void Should_parse_query_params()
{
// given
var request = new Request("/foo", "foo=bar&multi=1&multi=2", "blabla", "whatever", new Dictionary<string, string>());
// then
Check.That(request.GetParameter("foo")).Contains("bar");
Check.That(request.GetParameter("multi")).Contains("1");
Check.That(request.GetParameter("multi")).Contains("2");
}
}
}

View File

@@ -0,0 +1,215 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using NFluent;
using NUnit.Framework;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
public class RequestsTests
{
[Test]
public void Should_specify_requests_matching_given_url()
{
// given
var spec = Requests.WithUrl("/foo");
// when
var request = new Request("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_specify_requests_matching_given_url_prefix()
{
// given
var spec = Requests.WithUrl("/foo*");
// when
var request = new Request("/foo/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_exclude_requests_not_matching_given_url()
{
// given
var spec = Requests.WithUrl("/foo");
// when
var request = new Request("/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
}
[Test]
public void Should_specify_requests_matching_given_path()
{
// given
var spec = Requests.WithPath("/foo");
// when
var request = new Request("/foo", "?param=1", "blabla", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_specify_requests_matching_given_url_and_method()
{
// given
var spec = Requests.WithUrl("/foo").UsingPut();
// when
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_exclude_requests_matching_given_url_but_not_http_method()
{
// given
var spec = Requests.WithUrl("/foo").UsingPut();
// when
var request = new Request("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
}
[Test]
public void Should_exclude_requests_matching_given_http_method_but_not_url()
{
// given
var spec = Requests.WithUrl("/bar").UsingPut();
// when
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
}
[Test]
public void Should_specify_requests_matching_given_url_and_headers()
{
// given
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
// when
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_exclude_requests_not_matching_given_headers()
{
// given
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
// when
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
}
[Test]
public void Should_specify_requests_matching_given_header_prefix()
{
// given
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
// when
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_specify_requests_matching_given_body()
{
// given
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
// when
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_specify_requests_matching_given_body_as_wildcard()
{
// given
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody("H*o wor?d!");
// when
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_exclude_requests_not_matching_given_body()
{
// given
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
// when
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
}
[Test]
public void Should_specify_requests_matching_given_params()
{
// given
var spec = Requests.WithPath("/foo").WithParam("bar", "1", "2");
// when
var request = new Request("/foo", "bar=1&bar=2", "Get", "Hello world!", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
}
[Test]
public void Should_exclude_requests_not_matching_given_params()
{
// given
var spec = Requests.WithPath("/foo").WithParam("bar", "1");
// when
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string>());
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
}
}
}

View File

@@ -0,0 +1,48 @@
using System.Diagnostics.CodeAnalysis;
using NFluent;
using NUnit.Framework;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
public class WildcardPatternMatcherTests
{
[Test]
public void Should_evaluate_patterns()
{
// Positive Tests
Check.That(WildcardPatternMatcher.MatchWildcardString("*", string.Empty)).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("?", " ")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("*", "a")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("*", "ab")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("?", "a")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("*?", "abc")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("?*", "abc")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc", "abc")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc*", "abc")).IsTrue();
Check.That(WildcardPatternMatcher.MatchWildcardString("*a*bc*", "aXXXbc")).IsTrue();
// Negative Tests
Check.That(WildcardPatternMatcher.MatchWildcardString("*a", string.Empty)).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("a*", string.Empty)).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("?", string.Empty)).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("*b*", "a")).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("b*a", "ab")).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("??", "a")).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("*?", string.Empty)).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("??*", "a")).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc", "abX")).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc*", "Xbc")).IsFalse();
Check.That(WildcardPatternMatcher.MatchWildcardString("*a*bc*", "ac")).IsFalse();
}
}
}

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D8B56D28-33CE-4BEF-97D4-7DD546E37F25}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WireMock.Net.Tests</RootNamespace>
<AssemblyName>WireMock.Net.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.5.30.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\packages\Moq.4.5.30\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NFluent, Version=1.3.1.0, Culture=neutral, PublicKeyToken=18828b37b84b1437, processorArchitecture=MSIL">
<HintPath>..\..\packages\NFluent.1.3.1.0\lib\net40\NFluent.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WireMock">
<HintPath>..\..\src\WireMock\bin\$(Configuration)\net45\WireMock.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FluentMockServerTests.cs" />
<Compile Include="HttpListenerRequestMapperTests.cs" />
<Compile Include="HttpListenerResponseMapperTests.cs" />
<Compile Include="Http\TinyHttpServerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequestsTests.cs" />
<Compile Include="RequestTests.cs" />
<Compile Include="WildcardPatternMatcherTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Moq" version="4.5.30" targetFramework="net452" />
<package id="NFluent" version="1.3.1.0" targetFramework="net452" />
<package id="NUnit" version="3.6.0" targetFramework="net452" />
</packages>