Megha Agarwal
05/05/2023, 6:03 AMpublic void EnsureEventApiHonoursPactWithConsumer()
{
string pactPath = Path.Combine("..",
"..",
"..",
"..",
// "Consumer.Tests",
"pacts",
"Poc.Pactflow.Kafka.Consumer1-Poc.Pactflow.Kafka.Producer1.json");
var defaultSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented
};
this.verifier
.MessagingProvider("Poc.Pactflow.Kafka.Producer1", defaultSettings)
.WithProviderMessages(scenarios =>
{
scenarios.Add("a single event", () => new NotificationSmsEvent()
{
NotificationId = 237,
PhoneNumber = "123456789",
Message = "event consumed"
})
.Add("some stock events", builder =>
{
builder.WithMetadata(new
{
ContentType = "application/json",
kafka_topic = "products"
})
.WithContent(() => new[] {
new NotificationSmsEvent() { NotificationId = 237, PhoneNumber = "123456789", Message = "event consumed"}
}
);
});
})
.WithFileSource(new FileInfo(pactPath))
.Verify();
}
here this.verifier is the PactVerifier object....
Below is the pactfile generated by Consumer test
{
"consumer": {
"name": "Poc.Pactflow.Kafka.Consumer1"
},
"messages": [
{
"contents": [
{
"message": "event consumed",
"notificationId": 123,
"phoneNumber": "123456789",
"something": "123"
}
],
"description": "some stock events",
"matchingRules": {
"body": {
"$": {
"combine": "AND",
"matchers": [
{
"match": "type",
"min": 1
}
]
},
"$[*].message": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$[*].notificationId": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$[*].phoneNumber": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$[*].something": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"metadata": {
"contentType": "application/json",
"kafka_topic": "products"
},
"providerStates": [
{
"name": "A list of events is pushed to the queue"
}
]
}
],
"metadata": {
"pactRust": {
"ffi": "0.4.0",
"models": "1.0.4"
},
"pactSpecification": {
"version": "3.0.0"
}
},
"provider": {
"name": "Poc.Pactflow.Kafka.Producer1"
}
}
this test is passing.... but when I am changing the contract in pact json, the test is not failing .... but when I change the description it fails......
On debugging I found that thr r no events to verify..... Am I missing anything?