mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-20 16:44:31 +01:00
Update BodyParser logic (#212)
* Update BodyParser logic * update logic for byte[] * small update * MyGetKey * myget * dotnet nuget push * dotnet build * Release * . * StringContent * 1.0.4.18-preview-02 * Debug * 1.0.4.18-preview-02 * disable some proxy tests * myget * packagesToPack * fix * <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> * Release * <VersionPrefix>1.0.4.18</VersionPrefix> * fix * BodyParserTests * ResponseBodyData (#216) * ResponseBodyData * refactor tests * LogEntryMapperTests
This commit is contained in:
92
test/WireMock.Net.Tests/Serialization/LogEntryMapperTests.cs
Normal file
92
test/WireMock.Net.Tests/Serialization/LogEntryMapperTests.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using NFluent;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Models;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Serialization
|
||||
{
|
||||
public class LogEntryMapperTests
|
||||
{
|
||||
[Fact]
|
||||
public void LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
||||
{
|
||||
// Assign
|
||||
var logEntry = new LogEntry
|
||||
{
|
||||
RequestMessage = new RequestMessage(
|
||||
new UrlDetails("http://localhost"),
|
||||
"post",
|
||||
"::1",
|
||||
new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.Bytes,
|
||||
BodyAsBytes = new byte[] { 0 }
|
||||
}
|
||||
),
|
||||
ResponseMessage = new ResponseMessage
|
||||
{
|
||||
BodyData = new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.Bytes,
|
||||
BodyAsBytes = new byte[] { 0 }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = LogEntryMapper.Map(logEntry);
|
||||
|
||||
// Assert
|
||||
Check.That(result.Request.DetectedBodyType).IsEqualTo("Bytes");
|
||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsEqualTo("None");
|
||||
Check.That(result.Request.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
||||
Check.That(result.Request.Body).IsNull();
|
||||
Check.That(result.Request.BodyAsJson).IsNull();
|
||||
|
||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.None);
|
||||
Check.That(result.Response.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
||||
Check.That(result.Response.Body).IsNull();
|
||||
Check.That(result.Response.BodyAsJson).IsNull();
|
||||
Check.That(result.Response.BodyAsFile).IsNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
||||
{
|
||||
// Assign
|
||||
var logEntry = new LogEntry
|
||||
{
|
||||
RequestMessage = new RequestMessage(new UrlDetails("http://localhost"), "get", "::1"
|
||||
),
|
||||
ResponseMessage = new ResponseMessage
|
||||
{
|
||||
BodyData = new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.File,
|
||||
BodyAsFile = "test"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = LogEntryMapper.Map(logEntry);
|
||||
|
||||
// Assert
|
||||
Check.That(result.Request.DetectedBodyType).IsNull();
|
||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
||||
Check.That(result.Request.Body).IsNull();
|
||||
Check.That(result.Request.BodyAsJson).IsNull();
|
||||
|
||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.File);
|
||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.None);
|
||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
||||
Check.That(result.Response.Body).IsNull();
|
||||
Check.That(result.Response.BodyAsJson).IsNull();
|
||||
Check.That(result.Response.BodyAsFile).IsEqualTo("test");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using Moq;
|
||||
using System;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Serialization;
|
||||
using Xunit;
|
||||
@@ -36,7 +38,7 @@ namespace WireMock.Net.Tests.Serialization
|
||||
var matcherMock2 = new Mock<IStringMatcher>();
|
||||
|
||||
// Act
|
||||
var models = MatcherMapper.Map(new [] { matcherMock1.Object, matcherMock2.Object });
|
||||
var models = MatcherMapper.Map(new[] { matcherMock1.Object, matcherMock2.Object });
|
||||
|
||||
// Assert
|
||||
Check.That(models).HasSize(2);
|
||||
@@ -73,5 +75,61 @@ namespace WireMock.Net.Tests.Serialization
|
||||
// Assert
|
||||
Check.That(model.IgnoreCase).Equals(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_Null()
|
||||
{
|
||||
// Act
|
||||
var result = MatcherMapper.Map((MatcherModel)null);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_Exception()
|
||||
{
|
||||
// Assign
|
||||
var model = new MatcherModel { Name = "test" };
|
||||
|
||||
// Act and Assert
|
||||
Check.ThatCode(() => MatcherMapper.Map(model)).Throws<NotSupportedException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_LinqMatcher_Pattern()
|
||||
{
|
||||
// Assign
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = "LinqMatcher",
|
||||
Pattern = "p"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = (LinqMatcher)MatcherMapper.Map(model);
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
|
||||
Check.That(matcher.GetPatterns()).ContainsExactly("p");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_LinqMatcher_Patterns()
|
||||
{
|
||||
// Assign
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = "LinqMatcher",
|
||||
Patterns = new[] { "p1", "p2" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = (LinqMatcher)MatcherMapper.Map(model);
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
|
||||
Check.That(matcher.GetPatterns()).ContainsExactly("p1", "p2");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user