mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-22 08:18:26 +02:00
remove nfluent
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user