Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw XML POST not working in V2, V3 and V4. Added test for simple POST interaction with different content types. #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/PactNet.Tests/TestXmlRequestBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace PactNet.Tests
{
public class TestXmlRequestBody
{
[Theory]
[InlineData("AnyText", "text/plain")]
[InlineData(@"{ ""simple"":""json"" }", "application/json")]
[InlineData("<?xml version='1.0'?><rootNode><rootNode/>", "application/xml")]
public async Task Post_simple_request_content(string body, string contentType)
{
// Arrange: Define simple POST interaction
var pactBuilder = Pact.V3("consumer", "provider").WithHttpInteractions();
pactBuilder
.UponReceiving("any description")
.Given("any given")
.WithRequest(HttpMethod.Post, "/any/endpoint")
.WithBody(body, contentType)
.WillRespond()
.WithStatus(HttpStatusCode.OK);

await pactBuilder.VerifyAsync(async ctx =>
{
// Act: Make POST request with the same body and content type
var client = new HttpClient();
client.BaseAddress = ctx.MockServerUri;
var something = await client.PostAsync("/any/endpoint", new StringContent(body, Encoding.UTF8, contentType));

// Assert
Assert.True(something.IsSuccessStatusCode);
});
}
}
}