Pact testing of protobuf message from C# failing due to content type of JSON

39 Views Asked by At

I'm really struggling to get .Net Pact testing of a protobuf format messages working. I have access to the Pact files and they are known to be correct and other teams in our organisation have created tests against them from Java code. I need to be able to do the same from C#.

I am using Nuget library pact-net v5.0.0 (I know it's pre-release) and have a unit test with code like this...

        var bufferWriter = new ArrayBufferWriter<byte>();
        ProtoBuf.Serializer.Serialize(bufferWriter, someMessageObject);
        
        var action = () => PactVerifier
            .WithMessages(messages => messages.Add("Pact Description", builder => builder
                .WithMetadata(new Dictionary<string, string> {{ "contentType", "application/protobuf; message=MessageType" }})
                .WithContent(() => bufferWriter.GetMemory())
            ))
            .WithUriSource(new Uri("http://adress-of-the-pact"))
            .Verify();
        
        action.Should().NotThrow();

The test results in the output below. The confusing part is that it appears acknowledge that the metadata is OK with the expected content type, but it complains that the body is of type "application/json" when I need it to be the same as the metadata (but nowhere have I set the content to be json format).

Verifier Output
---------------

Verifying a pact between producer-msg-type-consumer and producer-msg-type-provider

  Bet Stop (123ms loading, 144ms verification)

  Test Name: pact.ConsumerTest.consumeMessage(AsynchronousMessage)
    generates a message which
      includes metadata
        "contentType" with value "application/protobuf;message=BetStop" (OK)
      has a matching body (FAILED)


Failures:

1) Verifying a pact between producer-msg-type-consumer and producer-msg-type-provider - Message
    1.1) has a matching body
           expected a body of 'application/protobuf;message=BetStop' but the actual content type was 'application/json'

There were 1 pact failures

Can anyone help? I can't find any other examples of how to do this and the PactNet website isn't much help either (https://github.com/pact-foundation/pact-net). At this stage I would simply be happy to get to a point where the message is accepted and returns with validation errors because it doesn't match the contract, but I can't seem to get past the point of it being rejected due to the content type.

0

There are 0 best solutions below