mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-13 05:45:54 +01:00
Use new Handlebars.Net.Helpers (#581)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using HandlebarsDotNet;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
@@ -76,7 +77,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Response_ProvideResponseAsync_Handlebars_File_WithMissingArgument_ThrowsArgumentOutOfRangeException()
|
||||
public void Response_ProvideResponseAsync_Handlebars_File_WithMissingArgument_Throws_HandlebarsException()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "GET", ClientIp);
|
||||
@@ -89,7 +90,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<ArgumentOutOfRangeException>();
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<HandlebarsException>();
|
||||
|
||||
// Verify
|
||||
_filesystemHandlerMock.Verify(fs => fs.ReadResponseBodyAsString(It.IsAny<string>()), Times.Never);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using HandlebarsDotNet;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
@@ -139,7 +141,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Response_ProvideResponse_Handlebars_Linq_Throws_NotSupportedException()
|
||||
public void Response_ProvideResponse_Handlebars_Linq_Throws_ArgumentException()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
@@ -155,7 +157,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<NotSupportedException>();
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<ArgumentException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -175,7 +177,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Response_ProvideResponse_Handlebars_Linq1_Throws_ArgumentException()
|
||||
public void Response_ProvideResponse_Handlebars_Linq1_Throws_HandlebarsException()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData();
|
||||
@@ -187,11 +189,11 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<ArgumentException>();
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<HandlebarsException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Response_ProvideResponse_Handlebars_Linq1_ParseError_Returns_Empty()
|
||||
public void Response_ProvideResponse_Handlebars_Linq1_ParseError_Throws_ExceptionMessage()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
@@ -211,15 +213,14 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
var responseMessage = await response.ProvideResponseAsync(request, _settings);
|
||||
Func<Task> a = async () => await response.ProvideResponseAsync(request, _settings);
|
||||
|
||||
// Assert
|
||||
JObject j = JObject.FromObject(responseMessage.BodyData.BodyAsJson);
|
||||
Check.That(j["x"].ToString()).IsEmpty();
|
||||
a.Should().Throw<HandlebarsException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Response_ProvideResponse_Handlebars_Linq2_ParseError_Returns_Empty()
|
||||
public void Response_ProvideResponse_Handlebars_Linq2_ParseError_Throws_ExceptionMessage()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
@@ -239,11 +240,10 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
var responseMessage = await response.ProvideResponseAsync(request, _settings);
|
||||
Func<Task> a = async () => await response.ProvideResponseAsync(request, _settings);
|
||||
|
||||
// Assert
|
||||
JObject j = JObject.FromObject(responseMessage.BodyData.BodyAsJson);
|
||||
Check.That(j["x"].ToString()).IsEmpty();
|
||||
a.Should().Throw<HandlebarsException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("{{Regex.Match request.body \"^(?<x>\\w+)$\"}}")
|
||||
.WithBody("{{Regex.Match request.body \"^(\\w+)$\"}}")
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
@@ -154,7 +154,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
.WithTransformer();
|
||||
|
||||
// Act and Assert
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<NotSupportedException>();
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<ArgumentNullException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
var response = Response.Create()
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
Number = "{{Xeger \"[1-9]{1}\\d{3}\"}}",
|
||||
Postcode = "{{Xeger \"[1-9][0-9]{3}[A-Z]{2}\"}}"
|
||||
Number = "{{Xeger.Generate \"[1-9]{1}\\d{3}\"}}",
|
||||
Postcode = "{{Xeger.Generate \"[1-9][0-9]{3}[A-Z]{2}\"}}"
|
||||
})
|
||||
.WithTransformer();
|
||||
|
||||
@@ -57,8 +57,8 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
var response = Response.Create()
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
Number = "{{#Xeger \"[1-9]{1}\\d{3}\"}}{{this}}{{/Xeger}}",
|
||||
Postcode = "{{#Xeger \"[1-9][0-9]{3}[A-Z]{2}\"}}{{this}}{{/Xeger}}"
|
||||
Number = "{{#Xeger.Generate \"[1-9]{1}\\d{3}\"}}{{this}}{{/Xeger.Generate}}",
|
||||
Postcode = "{{#Xeger.Generate \"[1-9][0-9]{3}[A-Z]{2}\"}}{{this}}{{/Xeger.Generate}}"
|
||||
})
|
||||
.WithTransformer();
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
var responseMessage = await response.ProvideResponseAsync(request, _settings);
|
||||
|
||||
// Assert
|
||||
Check.That(responseMessage.BodyData.BodyAsString).Equals("test keya=1 idx=1 idx=2 keyb=5");
|
||||
Check.That(responseMessage.BodyData.BodyAsString).Equals("test keya=1,2 idx=1 idx=2 keyb=5");
|
||||
}
|
||||
|
||||
[Theory(Skip = "Invalid token `OpenBracket`")]
|
||||
@@ -503,7 +503,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
Check.That(JsonConvert.SerializeObject(responseMessage.BodyData.BodyAsJson)).Equals("\"test\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "todo...")]
|
||||
public async Task Response_ProvideResponse_Handlebars_WithBodyAsJson_ResultAsTemplatedString()
|
||||
{
|
||||
// Assign
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xamarin.UITest;
|
||||
using Xamarin.UITest.Queries;
|
||||
|
||||
namespace WireMock.Net.XamarinUI.Tests
|
||||
{
|
||||
public class AppInitializer
|
||||
{
|
||||
public static IApp StartApp(Platform platform)
|
||||
{
|
||||
if (platform == Platform.Android)
|
||||
{
|
||||
var androidAppConfigurator = ConfigureApp.Android.InstalledApp("test");
|
||||
|
||||
return androidAppConfigurator.StartApp();
|
||||
}
|
||||
|
||||
return ConfigureApp.iOS.InstalledApp("test").StartApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xamarin.UITest;
|
||||
|
||||
namespace WireMock.Net.XamarinUI.Tests
|
||||
{
|
||||
[TestFixture(Platform.Android)]
|
||||
[TestFixture(Platform.iOS)]
|
||||
public class UIFlowTests
|
||||
{
|
||||
IApp app;
|
||||
Platform platform;
|
||||
|
||||
private WireMockServer _server;
|
||||
|
||||
public UIFlowTests(Platform platform)
|
||||
{
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void BeforeEachTest()
|
||||
{
|
||||
var serverSettings = new WireMockServerSettings();
|
||||
// serverSettings.Port = 5005;
|
||||
serverSettings.AllowPartialMapping = true;
|
||||
|
||||
_server = WireMockServer.Start(serverSettings);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestMockServerIsWorking()
|
||||
{
|
||||
_server
|
||||
.Given(Request.Create()
|
||||
.UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("test"));
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
var result = await httpClient.GetAsync(_server.Urls[0]);
|
||||
var content = await result.Content.ReadAsStringAsync();
|
||||
Assert.AreEqual("test", content);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void ShutdownServer()
|
||||
{
|
||||
_server.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NUnit" Version="3.13.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="Xamarin.UITest" Version="3.0.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user