pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
842 stars 231 forks source link

Match.Type throws an exception on an attribute of type Object #503

Closed lacajenne closed 3 weeks ago

lacajenne commented 4 months ago

Version information:

Describe the bug We are writing consumer tests for an event-driven system. The Match.Type method, when working on an attribute of type Object, throws an exception with this error message: ---- Expected property events[0].Data to be a dictionary or collection of key-value pairs that is keyed to type System.String. It implements .

Steps To Reproduce Write a consumer test validating an object belonging to a class like the following

public sealed class TestDataClass { public WorkflowReference WorkflowReference { get; set; } public string Title { get; set; } public object Data { get; set; }
}

Expected behavior It is possible to invoke Match.Type on the Data attribute.

Log Output Stack Trace:  ConfiguredMessageVerifier.Verify[T](Action1 handler) GainEventProcessorTests.ReceiveSomeStockEvents() line 120 RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) ----- Inner Stack Trace ----- XUnit2TestFramework.Throw(String message) TestFrameworkProvider.Throw(String message) CollectingAssertionStrategy.ThrowIfAny(IDictionary2 context) AssertionScope.Dispose() EquivalencyValidator.AssertEquality(Comparands comparands, EquivalencyValidationContext context) GenericCollectionAssertions3.BeEquivalentTo[TExpectation](IEnumerable1 expectation, Func2 config, String because, Object[] becauseArgs) GenericCollectionAssertions3.BeEquivalentTo[TExpectation](IEnumerable1 expectation, String because, Object[] becauseArgs) <>c__DisplayClass2_0.<ReceiveSomeStockEvents>b__5(ICollection1 events) line 127 ConfiguredMessageVerifier.Verify[T](Action`1 handler)

adamrodger commented 4 months ago

Please could you attach the full verifier output log?

Generally speaking using object types is going to cause problems because the serialisation round trip might not have the appropriate type information to know how to deserialise the JSON in the pact file properly when verifying. Seeing the full logs will probably cast some light on that though.

lacajenne commented 4 months ago

Thanks. This is all I seem to find:

MessageContract.Tests.GainEventProcessorTests.ReceiveSomeStockEvents  Source: GainEventProcessorTests.cs line 34  Duration: 2,7 sec

Message:  PactNet.Exceptions.PactMessageConsumerVerificationException : The message could not be verified by the consumer handler ---- Expected property events[0].Data to be a dictionary or collection of key-value pairs that is keyed to type System.String. It implements .

With configuration:

adamrodger commented 3 months ago

@lacajenne You may need to enable the xUnit output in the PactConfig so get the full verifier output. It contains the logs from the Rust library, which is probably what's needed to investigate this. Also please turn the log level up to at least Debug.

adamrodger commented 3 weeks ago

Closed due to inactivity