mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 23:20:11 +02:00
* Fix for issue #118 * Adding test cases for fix #118 * Moved the namespace in using block for fix #118
This commit is contained in:
committed by
Stef Heyenrath
parent
7bd63a0baf
commit
0abe12f5c8
@@ -745,6 +745,11 @@ namespace WireMock.Server
|
|||||||
responseBuilder = responseBuilder.WithBodyFromBase64(responseModel.BodyFromBase64, ToEncoding(responseModel.BodyEncoding));
|
responseBuilder = responseBuilder.WithBodyFromBase64(responseModel.BodyFromBase64, ToEncoding(responseModel.BodyEncoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (responseModel.BodyAsFile != null)
|
||||||
|
{
|
||||||
|
responseBuilder = responseBuilder.WithBodyFromFile(responseModel.BodyAsFile);
|
||||||
|
}
|
||||||
|
|
||||||
if (responseModel.UseTransformer)
|
if (responseModel.UseTransformer)
|
||||||
{
|
{
|
||||||
responseBuilder = responseBuilder.WithTransformer();
|
responseBuilder = responseBuilder.WithTransformer();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using WireMock.RequestBuilders;
|
|||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests
|
namespace WireMock.Net.Tests
|
||||||
{
|
{
|
||||||
@@ -76,6 +77,34 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(mappings.First().Title).IsNullOrEmpty();
|
Check.That(mappings.First().Title).IsNullOrEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FluentMockServer_ReadStaticMapping_WithResponseBodyFromFile()
|
||||||
|
{
|
||||||
|
string guid = "00000002-ee28-4f29-ae63-1ac9b0802d87";
|
||||||
|
|
||||||
|
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", guid + ".json");
|
||||||
|
string json = File.ReadAllText(folder);
|
||||||
|
|
||||||
|
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "ResponseBodyFiles", "responsebody.json");
|
||||||
|
|
||||||
|
dynamic jsonObj = JsonConvert.DeserializeObject(json);
|
||||||
|
jsonObj["Response"]["BodyAsFile"] = responseBodyFilePath;
|
||||||
|
|
||||||
|
string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
|
||||||
|
File.WriteAllText(folder, output);
|
||||||
|
|
||||||
|
_server = FluentMockServer.Start();
|
||||||
|
_server.ReadStaticMappingAndAddOrUpdate(folder);
|
||||||
|
|
||||||
|
var mappings = _server.Mappings.ToArray();
|
||||||
|
Check.That(mappings).HasSize(1);
|
||||||
|
|
||||||
|
Check.That(mappings.First().RequestMatcher).IsNotNull();
|
||||||
|
Check.That(mappings.First().Provider).IsNotNull();
|
||||||
|
Check.That(mappings.First().Guid).Equals(Guid.Parse(guid));
|
||||||
|
Check.That(mappings.First().Title).IsNullOrEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void FluentMockServer_ReadStaticMappings()
|
public void FluentMockServer_ReadStaticMappings()
|
||||||
{
|
{
|
||||||
@@ -85,7 +114,7 @@ namespace WireMock.Net.Tests
|
|||||||
_server.ReadStaticMappings(folder);
|
_server.ReadStaticMappings(folder);
|
||||||
|
|
||||||
var mappings = _server.Mappings.ToArray();
|
var mappings = _server.Mappings.ToArray();
|
||||||
Check.That(mappings).HasSize(2);
|
Check.That(mappings).HasSize(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"test": "test"
|
||||||
|
}
|
||||||
@@ -31,9 +31,15 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Update="ResponseBodyFiles\responsebody.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d86.json">
|
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d86.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d87.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="__admin\mappings\documentdb_root.json">
|
<None Update="__admin\mappings\documentdb_root.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"Guid": "00000002-ee28-4f29-ae63-1ac9b0802d87",
|
||||||
|
"Priority": 0,
|
||||||
|
"Request": {
|
||||||
|
"Path": {
|
||||||
|
"Matchers": [
|
||||||
|
{
|
||||||
|
"Name": "ExactMatcher",
|
||||||
|
"Pattern": "/response/staticfile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Methods": [
|
||||||
|
"get"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"StatusCode": 200,
|
||||||
|
"BodyAsFile": "responsebody.json",
|
||||||
|
"Headers": {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user