-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IFileSystemHandler to support Azure for StaticMapping location (#180
- Loading branch information
Showing
21 changed files
with
505 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
examples/WireMock.Net.Console.NETCoreApp2/WireMock.Net.Console.NETCoreApp2.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon> | ||
<StartupObject>WireMock.Net.Console.NETCoreApp.Program</StartupObject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\WireMock.Net.ConsoleApplication\CustomFileSystemFileHandler.cs" Link="CustomFileSystemFileHandler.cs" /> | ||
<Compile Include="..\WireMock.Net.ConsoleApplication\MainApp.cs" Link="MainApp.cs" /> | ||
<Compile Include="..\WireMock.Net.Console.NETCoreApp\Program.cs" Link="Program.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="__admin\mappings\*.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\WireMock.Net.Console.NETCoreApp\log4net.config" Link="log4net.config" /> | ||
<None Include="..\WireMock.Net.Console.NETCoreApp\nlog.config" Link="nlog.config" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" /> | ||
<PackageReference Include="log4net" Version="2.0.8" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="log4net.config"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="nlog.config"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="__admin\mappings\791a3f31-6946-4ce7-8e6f-0237c7443275.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="__admin\mappings\791a3f31-6946-4ce7-8e6f-0237c7443275.json"> | ||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
22 changes: 22 additions & 0 deletions
22
...reMock.Net.Console.NETCoreApp2/__admin/mappings/11111110-a633-40e8-a244-5cb80bc0ab66.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"Request": { | ||
"Path": { | ||
"Matchers": [ | ||
{ | ||
"Name": "WildcardMatcher", | ||
"Pattern": "/static/mapping" | ||
} | ||
] | ||
}, | ||
"Methods": [ | ||
"get" | ||
] | ||
}, | ||
"Response": { | ||
"BodyAsJson": { "body": "static mapping" }, | ||
"Headers": { | ||
"Content-Type": "application/json", | ||
"Test-X": [ "test 1", "test 2" ] | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...reMock.Net.Console.NETCoreApp2/__admin/mappings/791a3f31-6946-4ce7-8e6f-0237c7443275.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"Guid": "791a3f31-6946-4ce7-8e6f-0237c7443275", | ||
"Title": "", | ||
"Priority": 0, | ||
"Request": { | ||
"Path": "/proxy-google-test-post", | ||
"Methods": [ | ||
"post" | ||
], | ||
"Body": {} | ||
}, | ||
"Response": { | ||
"StatusCode": 404, | ||
"Body": "<!DOCTYPE html>\n<html lang=en>\n <meta charset=utf-8>\n <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n <title>Error 404 (Not Found)!!1</title>\n <style>\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n </style>\n <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n <p><b>404.</b> <ins>That’s an error.</ins>\n <p>The requested URL <code>/proxy-google-test-post</code> was not found on this server. <ins>That’s all we know.</ins>\n", | ||
"BodyAsBytes": "PCFET0NUW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"CodePage": 65001, | ||
"EncodingName": "Unicode (UTF-8)", | ||
"WebName": "utf-8" | ||
}, | ||
"UseTransformer": false, | ||
"Headers": { | ||
"Date": "Wed, 27 Oct 2017 18:57:40 GMT", | ||
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"39,38,37,35\"", | ||
"Referrer-Policy": "no-referrer", | ||
"Connection": "close" | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...reMock.Net.Console.NETCoreApp2/__admin/mappings/873d495f-940e-4b86-a1f4-4f0fc7be8b8b.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Guid": "873d495f-940e-4b86-a1f4-4f0fc7be8b8b", | ||
"Priority": 4, | ||
"Request": { | ||
"Path": {}, | ||
"Methods": [ | ||
"get" | ||
] | ||
}, | ||
"Response": { | ||
"StatusCode": 200, | ||
"BodyDestination": "SameAsSource", | ||
"Body": "NO PATH OR URL", | ||
"UseTransformer": false, | ||
"Headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
examples/WireMock.Net.ConsoleApplication/CustomFileSystemFileHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using WireMock.Handlers; | ||
|
||
namespace WireMock.Net.ConsoleApplication | ||
{ | ||
internal class CustomFileSystemFileHandler : IFileSystemHandler | ||
{ | ||
private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings"); | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.FolderExists"/> | ||
public bool FolderExists(string path) | ||
{ | ||
return Directory.Exists(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.CreateFolder"/> | ||
public void CreateFolder(string path) | ||
{ | ||
Directory.CreateDirectory(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.EnumerateFiles"/> | ||
public IEnumerable<string> EnumerateFiles(string path) | ||
{ | ||
return Directory.EnumerateFiles(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.GetMappingFolder"/> | ||
public string GetMappingFolder() | ||
{ | ||
return Path.Combine(@"c:\temp-wiremock", AdminMappingsFolder); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.ReadMappingFile"/> | ||
public string ReadMappingFile(string path) | ||
{ | ||
return File.ReadAllText(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.WriteMappingFile"/> | ||
public void WriteMappingFile(string path, string text) | ||
{ | ||
File.WriteAllText(path, text); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace WireMock.Handlers | ||
{ | ||
/// <summary> | ||
/// Handler to interact with the file system to handle folders and read and write static mapping files. | ||
/// </summary> | ||
public interface IFileSystemHandler | ||
{ | ||
/// <summary> | ||
/// Gets the folder where the static mappings are located. For local file system, this would be `{CurrentFolder}/__admin/mappings`. | ||
/// </summary> | ||
/// <returns>The foldername.</returns> | ||
string GetMappingFolder(); | ||
|
||
/// <summary> | ||
/// Determines whether the given path refers to an existing directory on disk. | ||
/// </summary> | ||
/// <param name="path">The path.</param> | ||
/// <returns>true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.</returns> | ||
bool FolderExists(string path); | ||
|
||
/// <summary> | ||
/// Creates all directories and subdirectories in the specified path unless they already exist. | ||
/// </summary> | ||
/// <param name="path">The path.</param> | ||
void CreateFolder(string path); | ||
|
||
/// <summary> | ||
/// Returns an enumerable collection of file names in a specified path. | ||
/// </summary> | ||
/// <param name="path">The path.</param> | ||
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> | ||
IEnumerable<string> EnumerateFiles(string path); | ||
|
||
/// <summary> | ||
/// Read a static mapping file as text. | ||
/// </summary> | ||
/// <param name="path">The path (folder + filename with .json extension).</param> | ||
string ReadMappingFile(string path); | ||
|
||
/// <summary> | ||
/// Write the static mapping. | ||
/// </summary> | ||
/// <param name="path">The path (folder + filename with .json extension).</param> | ||
/// <param name="text">The text.</param> | ||
void WriteMappingFile(string path, string text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace WireMock.Handlers | ||
{ | ||
/// <summary> | ||
/// Default implementation for a handler to interact with the local file system to read and write static mapping files. | ||
/// </summary> | ||
public class LocalFileSystemHandler : IFileSystemHandler | ||
{ | ||
private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings"); | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.FolderExists"/> | ||
public bool FolderExists(string path) | ||
{ | ||
return Directory.Exists(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.CreateFolder"/> | ||
public void CreateFolder(string path) | ||
{ | ||
Directory.CreateDirectory(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.EnumerateFiles"/> | ||
public IEnumerable<string> EnumerateFiles(string path) | ||
{ | ||
return Directory.EnumerateFiles(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.GetMappingFolder"/> | ||
public string GetMappingFolder() | ||
{ | ||
return Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.ReadMappingFile"/> | ||
public string ReadMappingFile(string path) | ||
{ | ||
return File.ReadAllText(path); | ||
} | ||
|
||
/// <inheritdoc cref="IFileSystemHandler.WriteMappingFile"/> | ||
public void WriteMappingFile(string path, string text) | ||
{ | ||
File.WriteAllText(path, text); | ||
} | ||
} | ||
} |
Oops, something went wrong.