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

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

Open
lacajenne opened this issue Jun 3, 2024 · 3 comments
Open

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

lacajenne opened this issue Jun 3, 2024 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer

Comments

@lacajenne
Copy link

Version information:

  • OS: Windows x64
  • PactNet Version: 5.0.0-beta.2
  • .Net Version: 8.0
  • Pact Broker Version (if applicable): n.a.

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)

@lacajenne lacajenne added bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer labels Jun 3, 2024
@adamrodger
Copy link
Contributor

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
Copy link
Author

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:

  • Use declared types and members

  • Compare enums by value

  • Compare tuples by their properties

  • Compare anonymous types by their properties

  • Compare records by their members

  • Include non-browsable members

  • Include all non-private properties

  • Include all non-private fields

  • Match member by name (or throw)

  • Be strict about the order of items in byte arrays

  • Without automatic conversion.

    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
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants