remove nfluent

This commit is contained in:
Stef Heyenrath
2026-02-26 22:02:54 +01:00
parent c4c8ad3fa9
commit 62d0b0db5b
142 changed files with 899 additions and 1020 deletions

View File

@@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Settings;
@@ -27,6 +27,6 @@ public class ResponseCreateTests
var response = await responseBuilder.ProvideResponseAsync(mapping, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message).Equals(responseMessage);
response.Message.Should().Be(responseMessage);
}
}
}

View File

@@ -2,7 +2,6 @@
using System.Net;
using System.Net.Http;
using AwesomeAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;

View File

@@ -1,12 +1,11 @@
// Copyright © WireMock.Net
using System.Text;
using AwesomeAssertions;
using JsonConverter.Newtonsoft.Json;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -45,15 +44,15 @@ public class ResponseWithBodyTests
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var responseBuilder = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.String, Encoding.ASCII);
var responseBuilder = Response.Create().WithBody([48, 49], BodyDestinationFormat.String, Encoding.ASCII);
// act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// then
Check.That(response.Message.BodyData.BodyAsString).Equals("01");
Check.That(response.Message.BodyData.BodyAsBytes).IsNull();
Check.That(response.Message.BodyData.Encoding).Equals(Encoding.ASCII);
response.Message.BodyData.BodyAsString.Should().Be("01");
response.Message.BodyData.BodyAsBytes.Should().BeNull();
response.Message.BodyData.Encoding.Should().Be(Encoding.ASCII);
}
[Fact]
@@ -67,15 +66,15 @@ public class ResponseWithBodyTests
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var responseBuilder = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.SameAsSource, Encoding.ASCII);
var responseBuilder = Response.Create().WithBody([48, 49], BodyDestinationFormat.SameAsSource, Encoding.ASCII);
// act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// then
Check.That(response.Message.BodyData.BodyAsBytes).ContainsExactly(new byte[] { 48, 49 });
Check.That(response.Message.BodyData.BodyAsString).IsNull();
Check.That(response.Message.BodyData.Encoding).IsNull();
response.Message.BodyData.BodyAsBytes.Should().ContainInOrder([48, 49]);
response.Message.BodyData.BodyAsString.Should().BeNull();
response.Message.BodyData.Encoding.Should().BeNull();
}
[Fact]
@@ -95,8 +94,8 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// then
Check.That(response.Message.BodyData.BodyAsString).Equals("test");
Check.That(response.Message.BodyData.Encoding).Equals(Encoding.ASCII);
response.Message.BodyData.BodyAsString.Should().Be("test");
response.Message.BodyData.Encoding.Should().Be(Encoding.ASCII);
}
[Fact]
@@ -117,8 +116,8 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// then
Check.That(response.Message.BodyData.BodyAsJson).Equals(x);
Check.That(response.Message.BodyData.Encoding).Equals(Encoding.ASCII);
response.Message.BodyData.BodyAsJson.Should().Be(x);
response.Message.BodyData.Encoding.Should().Be(Encoding.ASCII);
}
[Fact]
@@ -133,10 +132,10 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsBytes).IsNull();
Check.That(response.Message.BodyData.BodyAsJson).IsNull();
Check.That(response.Message.BodyData.BodyAsString).Equals("r");
Check.That(response.Message.BodyData.Encoding).Equals(Encoding.ASCII);
response.Message.BodyData.BodyAsBytes.Should().BeNull();
response.Message.BodyData.BodyAsJson.Should().BeNull();
response.Message.BodyData.BodyAsString.Should().Be("r");
response.Message.BodyData.Encoding.Should().Be(Encoding.ASCII);
}
[Fact]
@@ -151,10 +150,10 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsNull();
Check.That(response.Message.BodyData.BodyAsJson).IsNull();
Check.That(response.Message.BodyData.BodyAsBytes).IsNotNull();
Check.That(response.Message.BodyData.Encoding).Equals(Encoding.ASCII);
response.Message.BodyData.BodyAsString.Should().BeNull();
response.Message.BodyData.BodyAsJson.Should().BeNull();
response.Message.BodyData.BodyAsBytes.Should().NotBeNull();
response.Message.BodyData.Encoding.Should().Be(Encoding.ASCII);
}
[Fact]
@@ -169,10 +168,10 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsNull();
Check.That(response.Message.BodyData.BodyAsBytes).IsNull();
Check.That(((dynamic)response.Message.BodyData.BodyAsJson).value).Equals(42);
Check.That(response.Message.BodyData.Encoding).Equals(Encoding.ASCII);
response.Message.BodyData!.BodyAsString.Should().BeNull();
response.Message.BodyData.BodyAsBytes.Should().BeNull();
((int)((JObject)response.Message.BodyData.BodyAsJson)["value"]!).Should().Be(42);
response.Message.BodyData.Encoding.Should().Be(Encoding.ASCII);
}
[Fact]
@@ -193,8 +192,8 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// then
Check.That(response.Message.BodyData.BodyAsJson).Equals(x);
Check.That(response.Message.BodyData.BodyAsJsonIndented).IsEqualTo(true);
response.Message.BodyData.BodyAsJson.Should().Be(x);
response.Message.BodyData.BodyAsJsonIndented.Should().Be(true);
}
[Fact]
@@ -259,15 +258,15 @@ public class ResponseWithBodyTests
var response2 = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request2, _settings);
// Assert
Check.That(((JToken)response1.Message.BodyData.BodyAsJson).SelectToken("id")?.Value<int>()).IsEqualTo(request1Id);
Check.That(response1.Message.BodyData.BodyAsBytes).IsNull();
Check.That(response1.Message.BodyData.BodyAsString).IsNull();
Check.That(response1.Message.StatusCode).IsEqualTo(200);
((JToken)response1.Message.BodyData.BodyAsJson).SelectToken("id")?.Value<int>().Should().Be(request1Id);
response1.Message.BodyData.BodyAsBytes.Should().BeNull();
response1.Message.BodyData.BodyAsString.Should().BeNull();
response1.Message.StatusCode.Should().Be(200);
Check.That(((JToken)response2.Message.BodyData.BodyAsJson).SelectToken("id")?.Value<int>()).IsEqualTo(request2Id);
Check.That(response2.Message.BodyData.BodyAsBytes).IsNull();
Check.That(response2.Message.BodyData.BodyAsString).IsNull();
Check.That(response2.Message.StatusCode).IsEqualTo(200);
((JToken)response2.Message.BodyData.BodyAsJson).SelectToken("id")?.Value<int>().Should().Be(request2Id);
response2.Message.BodyData.BodyAsBytes.Should().BeNull();
response2.Message.BodyData.BodyAsString.Should().BeNull();
response2.Message.StatusCode.Should().Be(200);
}
[Fact]
@@ -282,8 +281,8 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request1, _settings);
Check.That(response.Message.StatusCode).IsEqualTo(200);
Check.That(response.Message.BodyData.BodyAsString).Contains(fileContents);
response.Message.StatusCode.Should().Be(200);
response.Message.BodyData.BodyAsString.Should().Contain(fileContents);
}
[Fact]
@@ -298,8 +297,8 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request1, _settings);
Check.That(response.Message.StatusCode).IsEqualTo(200);
Check.That(response.Message.BodyData.BodyAsString).Contains(fileContents);
response.Message.StatusCode.Should().Be(200);
response.Message.BodyData.BodyAsString.Should().Contain(fileContents);
}
[Fact]
@@ -314,8 +313,8 @@ public class ResponseWithBodyTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request1, _settings);
Check.That(response.Message.StatusCode).IsEqualTo(200);
Check.That(response.Message.BodyData?.BodyAsString).Contains("File deleted.");
response.Message.StatusCode.Should().Be(200);
response.Message.BodyData?.BodyAsString.Should().Contain("File deleted.");
}
[Fact]
@@ -338,7 +337,6 @@ public class ResponseWithBodyTests
response.Message.BodyData!.BodyAsString.Should().Be("""{"foo":"< > & ' 😀 👍 ","n":42}""");
}
#if !(NET451 || NET452 || NET461)
[Fact]
public async Task Response_ProvideResponse_WithBody_SystemTextJsonConverter()
{
@@ -358,5 +356,4 @@ public class ResponseWithBodyTests
// Assert
response.Message.BodyData!.BodyAsString.Should().Be("""{"foo":"\u003C \u003E \u0026 \u0027 \uD83D\uDE00 \uD83D\uDC4D \u2764\uFE0F","n":42}""");
}
#endif
}

View File

@@ -2,10 +2,9 @@
using System.Net;
using System.Text;
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -48,13 +47,13 @@ public class ResponseWithCallbackTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("path: /test");
Check.That(response.Message.BodyData.BodyAsBytes).IsNull();
Check.That(response.Message.BodyData.BodyAsJson).IsNull();
Check.That(response.Message.BodyData.Encoding.CodePage).Equals(Encoding.UTF8.CodePage);
Check.That(response.Message.StatusCode).IsEqualTo(500);
Check.That(response.Message.Headers["H1"].ToString()).IsEqualTo("X1");
Check.That(response.Message.Headers["H2"].ToString()).IsEqualTo("X2");
response.Message.BodyData.BodyAsString.Should().Be("path: /test");
response.Message.BodyData.BodyAsBytes.Should().BeNull();
response.Message.BodyData.BodyAsJson.Should().BeNull();
response.Message.BodyData.Encoding.CodePage.Should().Be(Encoding.UTF8.CodePage);
response.Message.StatusCode.Should().Be(500);
response.Message.Headers["H1"].ToString().Should().Be("X1");
response.Message.Headers["H2"].ToString().Should().Be("X2");
}
[Fact]
@@ -131,13 +130,13 @@ public class ResponseWithCallbackTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("path: /test");
Check.That(response.Message.BodyData.BodyAsBytes).IsNull();
Check.That(response.Message.BodyData.BodyAsJson).IsNull();
Check.That(response.Message.BodyData.Encoding.CodePage).Equals(Encoding.UTF8.CodePage);
Check.That(response.Message.StatusCode).IsEqualTo(500);
Check.That(response.Message.Headers["H1"].ToString()).IsEqualTo("X1");
Check.That(response.Message.Headers["H2"].ToString()).IsEqualTo("X2");
response.Message.BodyData.BodyAsString.Should().Be("path: /test");
response.Message.BodyData.BodyAsBytes.Should().BeNull();
response.Message.BodyData.BodyAsJson.Should().BeNull();
response.Message.BodyData.Encoding.CodePage.Should().Be(Encoding.UTF8.CodePage);
response.Message.StatusCode.Should().Be(500);
response.Message.Headers["H1"].ToString().Should().Be("X1");
response.Message.Headers["H2"].ToString().Should().Be("X2");
}
[Fact]
@@ -313,4 +312,5 @@ public class ResponseWithCallbackTests
// Assert
response.Message.Headers![headerKey].Should().Contain("extra");
}
}
}

View File

@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using WireMock.Models;

View File

@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;

View File

@@ -1,11 +1,9 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using HandlebarsDotNet;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -57,7 +55,7 @@ public class ResponseWithHandlebarsFileTests
// Assert
var j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["Data"].Value<string>()).Equals("abc");
j["Data"].Value<string>().Should().Be("abc");
// Verify
_filesystemHandlerMock.Verify(fs => fs.ReadResponseBodyAsString("x.json"), Times.Once);
@@ -82,7 +80,7 @@ public class ResponseWithHandlebarsFileTests
// Assert
var j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["Data"].Value<string>()).Equals("abc");
j["Data"].Value<string>().Should().Be("abc");
// Verify
_filesystemHandlerMock.Verify(fs => fs.ReadResponseBodyAsString("x.json"), Times.Once);
@@ -103,7 +101,8 @@ public class ResponseWithHandlebarsFileTests
.WithTransformer();
// Act
Check.ThatCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings)).Throws<HandlebarsException>();
Func<Task> act = () => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
act.Should().ThrowAsync<HandlebarsException>();
// Verify
_filesystemHandlerMock.Verify(fs => fs.ReadResponseBodyAsString(It.IsAny<string>()), Times.Never);

View File

@@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -42,6 +42,6 @@ public class ResponseWithHandlebarsHelpersTests
var response = await responseBuilder.ProvideResponseAsync(Mock.Of<IMapping>(), Mock.Of<HttpContext>(), request, _settings);
// assert
Check.That(response.Message.BodyData.BodyAsString).Equals("ABC");
response.Message.BodyData.BodyAsString.Should().Be("ABC");
}
}
}

View File

@@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -46,6 +46,7 @@ public class ResponseWithHandlebarsHumanizerTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["Text"].Value<string>()).IsEqualTo("Pascal case input string is turned into sentence");
j["Text"].Value<string>().Should().Be("Pascal case input string is turned into sentence");
}
}
}

View File

@@ -1,12 +1,12 @@
// Copyright © WireMock.Net
using System.Text;
using AwesomeAssertions;
using HandlebarsDotNet;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -84,8 +84,8 @@ public class ResponseWithHandlebarsJsonPathTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["x"]).IsNotNull();
Check.That(j["x"]["Name"].ToString()).Equals("Acme Co");
j["x"].Should().NotBeNull();
j["x"]["Name"].ToString().Should().Be("Acme Co");
}
[Fact]
@@ -110,7 +110,7 @@ public class ResponseWithHandlebarsJsonPathTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson!);
Check.That(j["x"].Value<long>()).Equals(99);
j["x"].Value<long>().Should().Be(99);
}
[Fact]
@@ -163,7 +163,7 @@ public class ResponseWithHandlebarsJsonPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).Equals($"{{{Environment.NewLine} \"Name\": \"Acme Co\",{Environment.NewLine} \"Products\": [{Environment.NewLine} {{{Environment.NewLine} \"Name\": \"Anvil\",{Environment.NewLine} \"Price\": 50{Environment.NewLine} }}{Environment.NewLine} ]{Environment.NewLine}}}");
response.Message.BodyData.BodyAsString.Should().Be($"{{{Environment.NewLine} \"Name\": \"Acme Co\",{Environment.NewLine} \"Products\": [{Environment.NewLine} {{{Environment.NewLine} \"Name\": \"Anvil\",{Environment.NewLine} \"Price\": 50{Environment.NewLine} }}{Environment.NewLine} ]{Environment.NewLine}}}");
}
[Fact]
@@ -216,7 +216,7 @@ public class ResponseWithHandlebarsJsonPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).Equals($"{{{Environment.NewLine} \"Name\": \"Acme Co\",{Environment.NewLine} \"Products\": [{Environment.NewLine} {{{Environment.NewLine} \"Name\": \"Anvil\",{Environment.NewLine} \"Price\": 50{Environment.NewLine} }}{Environment.NewLine} ]{Environment.NewLine}}}");
response.Message.BodyData.BodyAsString.Should().Be($"{{{Environment.NewLine} \"Name\": \"Acme Co\",{Environment.NewLine} \"Products\": [{Environment.NewLine} {{{Environment.NewLine} \"Name\": \"Anvil\",{Environment.NewLine} \"Price\": 50{Environment.NewLine} }}{Environment.NewLine} ]{Environment.NewLine}}}");
}
[Fact]
@@ -269,7 +269,7 @@ public class ResponseWithHandlebarsJsonPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).Equals("%0:Anvil%%1:Elbow Grease%");
response.Message.BodyData.BodyAsString.Should().Be("%0:Anvil%%1:Elbow Grease%");
}
[Fact]
@@ -322,7 +322,7 @@ public class ResponseWithHandlebarsJsonPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).Equals("%0:Anvil%%1:Elbow Grease%");
response.Message.BodyData.BodyAsString.Should().Be("%0:Anvil%%1:Elbow Grease%");
}
[Fact]
@@ -348,7 +348,8 @@ public class ResponseWithHandlebarsJsonPathTests
.WithTransformer();
// Act
Check.ThatCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings)).Throws<ArgumentNullException>();
Func<Task> act = () => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
act.Should().ThrowAsync<HandlebarsException>();
}
[Fact]

View File

@@ -1,11 +1,9 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using HandlebarsDotNet;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -49,8 +47,8 @@ public class ResponseWithHandlebarsLinqTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["x"]).IsNotNull();
Check.That(j["x"].ToString()).Equals("/pathtest");
j["x"].Should().NotBeNull();
j["x"].ToString().Should().Be("/pathtest");
}
[Fact(Skip = "DynamicLinq")]
@@ -79,8 +77,8 @@ public class ResponseWithHandlebarsLinqTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["x"]).IsNotNull();
Check.That(j["x"].ToString()).Equals("Test_123");
j["x"].Should().NotBeNull();
j["x"].ToString().Should().Be("Test_123");
}
[Fact(Skip = "DynamicLinq")]
@@ -158,7 +156,10 @@ public class ResponseWithHandlebarsLinqTests
.WithTransformer();
// Act
Check.ThatCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings)).Throws<ArgumentException>();
Func<Task> act = () => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
act.Should().ThrowAsync<HandlebarsException>();
}
[Fact]
@@ -174,7 +175,10 @@ public class ResponseWithHandlebarsLinqTests
.WithTransformer();
// Act
Check.ThatCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings)).Throws<HandlebarsException>();
Func<Task> act = () => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
act.Should().ThrowAsync<HandlebarsException>();
}
[Fact]
@@ -225,9 +229,9 @@ public class ResponseWithHandlebarsLinqTests
.WithTransformer();
// Act
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
Func<Task> act = async () => await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
a.Should().ThrowAsync<HandlebarsException>();
act.Should().ThrowAsync<HandlebarsException>();
}
}

View File

@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;

View File

@@ -1,8 +1,9 @@
// Copyright © WireMock.Net
using HandlebarsDotNet;
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -45,7 +46,7 @@ public class ResponseWithHandlebarsRegexTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// assert
Check.That(response.Message.BodyData.BodyAsString).Equals("abc");
response.Message.BodyData.BodyAsString.Should().Be("abc");
}
[Fact]
@@ -64,7 +65,7 @@ public class ResponseWithHandlebarsRegexTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// assert
Check.That(response.Message.BodyData.BodyAsString).Equals("");
response.Message.BodyData.BodyAsString.Should().Be("");
}
[Fact]
@@ -83,7 +84,7 @@ public class ResponseWithHandlebarsRegexTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// assert
Check.That(response.Message.BodyData.BodyAsString).Equals("5000-https");
response.Message.BodyData.BodyAsString.Should().Be("5000-https");
}
[Fact]
@@ -102,7 +103,7 @@ public class ResponseWithHandlebarsRegexTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// assert
Check.That(response.Message.BodyData.BodyAsString).Equals("");
response.Message.BodyData.BodyAsString.Should().Be("");
}
[Fact]
@@ -117,7 +118,10 @@ public class ResponseWithHandlebarsRegexTests
.WithBody("{{#Regex.Match request.bodyAsJson \"^(?<proto>\\w+)://[^/]+?(?<port>\\d+)/?\"}}{{/Regex.Match}}")
.WithTransformer();
// Act and Assert
Check.ThatCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings)).Throws<ArgumentNullException>();
// Act
Func<Task> act = () => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
act.Should().ThrowAsync<HandlebarsException>();
}
}
}

View File

@@ -1,9 +1,8 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -83,7 +82,7 @@ public class ResponseWithHandlebarsXPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("abc");
response.Message.BodyData.BodyAsString.Should().Be("abc");
}
[Fact]
@@ -195,7 +194,7 @@ public class ResponseWithHandlebarsXPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualIgnoringCase("True");
response.Message.BodyData.BodyAsString.Should().BeEquivalentTo("True");
}
[Fact]
@@ -223,6 +222,7 @@ public class ResponseWithHandlebarsXPathTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("a1");
response.Message.BodyData.BodyAsString.Should().Be("a1");
}
}
}

View File

@@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -47,8 +47,8 @@ public class ResponseWithHandlebarsXegerTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["Number"].Value<int>()).IsStrictlyGreaterThan(1000).And.IsStrictlyLessThan(9999);
Check.That(j["Postcode"].Value<string>()).IsNotEmpty();
j["Number"].Value<int>().Should().BeGreaterThan(1000).And.BeLessThan(9999);
j["Postcode"].Value<string>().Should().NotBeEmpty();
}
[Fact]
@@ -70,7 +70,8 @@ public class ResponseWithHandlebarsXegerTests
// Assert
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
Check.That(j["Number"].Value<int>()).IsStrictlyGreaterThan(1000).And.IsStrictlyLessThan(9999);
Check.That(j["Postcode"].Value<string>()).IsNotEmpty();
j["Number"].Value<int>().Should().BeGreaterThan(1000).And.BeLessThan(9999);
j["Postcode"].Value<string>().Should().NotBeEmpty();
}
}
}

View File

@@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Settings;
@@ -36,7 +35,7 @@ public class ResponseWithHeadersTests
var response = await builder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), requestMock, _settings);
// Assert
Check.That(response.Message.Headers[headerName].ToString()).Equals(headerValue);
response.Message.Headers[headerName].ToString().Should().Be(headerValue);
}
[Theory]
@@ -52,7 +51,7 @@ public class ResponseWithHeadersTests
var response = await builder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), requestMock, _settings);
// Assert
Check.That(response.Message.Headers[headerName].ToArray()).Equals(headerValues);
response.Message.Headers[headerName].ToArray().Should().Equal(headerValues);
}
[Fact]
@@ -67,7 +66,7 @@ public class ResponseWithHeadersTests
var responseMessage = await response.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(responseMessage.Message.Headers["h"]).ContainsExactly("x");
responseMessage.Message.Headers["h"].Should().ContainSingle("x");
}
[Fact]
@@ -82,7 +81,7 @@ public class ResponseWithHeadersTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.Headers["h"]).ContainsExactly("x");
response.Message.Headers["h"].Should().ContainSingle("x");
}
[Fact]
@@ -97,6 +96,6 @@ public class ResponseWithHeadersTests
var response = await builder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.Headers["h"]).ContainsExactly("x");
response.Message.Headers["h"].Should().ContainSingle("x");
}
}

View File

@@ -3,7 +3,6 @@
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Models;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
@@ -56,10 +55,10 @@ public class ResponseWithProxyTests : IDisposable
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(request.ProxyUrl).IsNotNull();
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo(expectedBody);
Check.That(response.Message.StatusCode).IsEqualTo(201);
Check.That(response.Message.Headers["Content-Type"].ToString()).IsEqualTo("application/json");
request.ProxyUrl.Should().NotBeNull();
response.Message.BodyData.BodyAsString.Should().Be(expectedBody);
response.Message.StatusCode.Should().Be(201);
response.Message.Headers["Content-Type"].ToString().Should().Be("application/json");
}
[Fact]
@@ -80,8 +79,10 @@ public class ResponseWithProxyTests : IDisposable
// Act
var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}/{_guid}"), "GET", ClientIp);
Func<Task> act = () => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
Check.ThatCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings)).Throws<HttpRequestException>();
// Assert
act.Should().ThrowAsync<HttpRequestException>();
}
public void Dispose()
@@ -89,4 +90,5 @@ public class ResponseWithProxyTests : IDisposable
_server?.Stop();
_server?.Dispose();
}
}
}

View File

@@ -1,7 +1,5 @@
// Copyright © WireMock.Net
using AwesomeAssertions;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Settings;
@@ -9,11 +7,7 @@ using WireMock.Types;
using WireMock.Util;
using WireMock.Handlers;
using Moq;
#if NET452
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif
namespace WireMock.Net.Tests.ResponseBuilders;
@@ -69,6 +63,7 @@ public class ResponseWithScribanTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData.BodyAsString).Equals("test http://localhost/foo /foo POSt");
response.Message.BodyData.BodyAsString.Should().Be("test http://localhost/foo /foo POSt");
}
}

View File

@@ -1,7 +1,6 @@
// Copyright © WireMock.Net
using System.Net;
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using WireMock.Models;

View File

@@ -2,12 +2,11 @@
using System.Globalization;
using System.Text;
using AwesomeAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
@@ -76,7 +75,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test http://localhost/foo /foo POSt");
response.Message.BodyData!.BodyAsString.Should().Be("test http://localhost/foo /foo POSt");
}
[Theory]
@@ -100,7 +99,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("url=http://localhost/a/b absoluteurl=http://localhost/wiremock/a/b path=/a/b absolutepath=/wiremock/a/b");
response.Message.BodyData!.BodyAsString.Should().Be("url=http://localhost/a/b absoluteurl=http://localhost/wiremock/a/b path=/a/b absolutepath=/wiremock/a/b");
}
[Fact]
@@ -118,7 +117,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("a b wiremock");
response.Message.BodyData!.BodyAsString.Should().Be("a b wiremock");
}
[Theory]
@@ -141,7 +140,7 @@ public class ResponseWithTransformerTests
// Assert
var json = (JObject)response.Message.BodyData!.BodyAsJson!;
Check.That(json["field"]!.Value<string>()).Equals(expected);
json["field"]!.Value<string>().Should().Be(expected);
}
[Theory(Skip = "Invalid token `OpenBracket`")]
@@ -161,7 +160,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("a wiremock");
response.Message.BodyData!.BodyAsString.Should().Be("a wiremock");
}
[Fact]
@@ -183,7 +182,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test keya=1,2 idx=1 idx=2 keyb=5");
response.Message.BodyData!.BodyAsString.Should().Be("test keya=1,2 idx=1 idx=2 keyb=5");
}
[Theory(Skip = "Invalid token `OpenBracket`")]
@@ -207,7 +206,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test keya=1 idx=1 idx=2 keyb=5");
response.Message.BodyData!.BodyAsString.Should().Be("test keya=1 idx=1 idx=2 keyb=5");
}
[Fact]
@@ -230,8 +229,8 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.StatusCode).Equals("400");
response.Message.BodyData!.BodyAsString.Should().Be("test");
response.Message.StatusCode.Should().Be("400");
}
[Theory(Skip = "WireMockList is not supported by Scriban")]
@@ -256,8 +255,8 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.StatusCode).Equals("400");
response.Message.BodyData!.BodyAsString.Should().Be("test");
response.Message.StatusCode.Should().Be("400");
}
[Theory]
@@ -282,8 +281,8 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.StatusCode).Equals(null);
response.Message.BodyData!.BodyAsString.Should().Be("test");
response.Message.StatusCode.Should().Be(null);
}
[Fact]
@@ -303,9 +302,9 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.Headers).ContainsKey("x");
Check.That(response.Message.Headers!["x"]).ContainsExactly("text/plain");
response.Message.BodyData!.BodyAsString.Should().Be("test");
response.Message.Headers.Should().ContainKey("x");
response.Message.Headers!["x"].Should().ContainSingle("text/plain");
}
[Fact]
@@ -329,8 +328,8 @@ public class ResponseWithTransformerTests
// Assert
response.Message.Headers.Should().NotBeNull();
Check.That(response.Message.Headers).ContainsKey("x");
Check.That(response.Message.Headers!["x"]).ContainsExactly(guid.ToString());
response.Message.Headers.Should().ContainKey("x");
response.Message.Headers!["x"].Should().ContainSingle(guid.ToString());
}
[Fact]
@@ -350,10 +349,10 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.Headers).ContainsKey("x");
Check.That(response.Message.Headers!["x"]).Contains("text/plain");
Check.That(response.Message.Headers["x"]).Contains("http://localhost/foo");
response.Message.BodyData!.BodyAsString.Should().Be("test");
response.Message.Headers.Should().ContainKey("x");
response.Message.Headers!["x"].Should().Contain("text/plain");
response.Message.Headers["x"].Should().Contain("http://localhost/foo");
}
[Theory(Skip = "WireMockList is not supported by Scriban")]
@@ -375,10 +374,10 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.Headers).ContainsKey("x");
Check.That(response.Message.Headers!["x"]).Contains("text/plain");
Check.That(response.Message.Headers["x"]).Contains("http://localhost/foo");
response.Message.BodyData!.BodyAsString.Should().Be("test");
response.Message.Headers.Should().ContainKey("x");
response.Message.Headers!["x"].Should().Contain("text/plain");
response.Message.Headers["x"].Should().Contain("http://localhost/foo");
}
[Theory]
@@ -403,7 +402,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsString).Equals("test http://localhost:1234 1234 http localhost");
response.Message.BodyData!.BodyAsString.Should().Be("test http://localhost:1234 1234 http localhost");
}
[Theory]
@@ -430,7 +429,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson)).Equals("{\"x\":\"test /foo_object\"}");
JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson).Should().Be("{\"x\":\"test /foo_object\"}");
}
[CulturedTheory(["en-US"])]
@@ -577,7 +576,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson)).Equals("[\"first\",\"/foo_array\",\"test 1\",\"test 2\",\"last\"]");
JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson).Should().Be("[\"first\",\"/foo_array\",\"test 1\",\"test 2\",\"last\"]");
}
[Fact]
@@ -594,7 +593,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsFile).Equals(@"c:\1\test.xml");
response.Message.BodyData!.BodyAsFile.Should().Be(@"c:\1\test.xml");
}
[Theory(Skip = @"Does not work in Scriban --> c:\\[""1""]\\test.xml")]
@@ -613,7 +612,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsFile).Equals(@"c:\1\test.xml");
response.Message.BodyData!.BodyAsFile.Should().Be(@"c:\1\test.xml");
}
[Fact]
@@ -637,9 +636,9 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(response.Message.BodyData!.BodyAsFile).Equals(@"c:\1\test.xml");
Check.That(response.Message.BodyData.DetectedBodyType).Equals(BodyType.String);
Check.That(response.Message.BodyData!.BodyAsString).Equals("<xml MyUniqueNumber=\"1\"></xml>");
response.Message.BodyData!.BodyAsFile.Should().Be(@"c:\1\test.xml");
response.Message.BodyData.DetectedBodyType.Should().Be(BodyType.String);
response.Message.BodyData!.BodyAsString.Should().Be("<xml MyUniqueNumber=\"1\"></xml>");
}
[Theory]
@@ -666,7 +665,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson)).Equals("\"test\"");
JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson).Should().Be("\"test\"");
}
[Fact]
@@ -712,7 +711,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson)).Equals("{\"name\":\"WireMock\"}");
JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson).Should().Be("{\"name\":\"WireMock\"}");
}
[Theory(Skip = "{{{ }}} Does not work in Scriban")]
@@ -738,7 +737,7 @@ public class ResponseWithTransformerTests
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of<HttpContext>(), request, _settings);
// Assert
Check.That(JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson)).Equals("{\"name\":\"WireMock\"}");
JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson).Should().Be("{\"name\":\"WireMock\"}");
}
[Theory]
@@ -847,4 +846,7 @@ AAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC
// Assert
response.Message.BodyData!.BodyAsString.Should().Be(expected);
}
}
}