{"id":18937411,"url":"https://github.com/verifytests/verify.masstransit","last_synced_at":"2025-04-15T18:31:59.943Z","repository":{"id":41873935,"uuid":"463487257","full_name":"VerifyTests/Verify.MassTransit","owner":"VerifyTests","description":"Adds Verify support for MassTransit test helpers.","archived":false,"fork":false,"pushed_at":"2024-10-21T03:51:10.000Z","size":382,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-21T06:50:56.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VerifyTests.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"VerifyTests"}},"created_at":"2022-02-25T10:16:25.000Z","updated_at":"2024-10-21T03:49:53.000Z","dependencies_parsed_at":"2023-12-27T04:38:22.763Z","dependency_job_id":"d1cabb2b-39ee-47f1-a45d-f0894f4dfd8d","html_url":"https://github.com/VerifyTests/Verify.MassTransit","commit_stats":{"total_commits":138,"total_committers":4,"mean_commits":34.5,"dds":"0.12318840579710144","last_synced_commit":"8619a7fa43b5679a89bfcfb39f86fff7defe5db3"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.MassTransit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.MassTransit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.MassTransit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.MassTransit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VerifyTests","download_url":"https://codeload.github.com/VerifyTests/Verify.MassTransit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249129224,"owners_count":21217307,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:11:03.911Z","updated_at":"2025-04-15T18:31:54.923Z","avatar_url":"https://github.com/VerifyTests.png","language":"C#","funding_links":["https://github.com/sponsors/VerifyTests"],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"/src/icon.png\" height=\"30px\"\u003e Verify.MassTransit\n\n[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true\u0026label=)](https://github.com/orgs/VerifyTests/discussions)\n[![Build status](https://ci.appveyor.com/api/projects/status/6quuecxv8hh0snd3/branch/main?svg=true)](https://ci.appveyor.com/project/SimonCropp/Verify-MassTransit)\n[![NuGet Status](https://img.shields.io/nuget/v/Verify.MassTransit.svg)](https://www.nuget.org/packages/Verify.MassTransit/)\n\nAdds [Verify](https://github.com/VerifyTests/Verify) support for [MassTransit test helpers](https://masstransit-project.com/usage/testing.html).\n\n**See [Milestones](../../milestones?state=closed) for release notes.**\n\n\n## NuGet package\n\nhttps://nuget.org/packages/Verify.MassTransit/\n\n\n## Usage\n\n\u003c!-- snippet: enable --\u003e\n\u003ca id='snippet-enable'\u003e\u003c/a\u003e\n```cs\n[ModuleInitializer]\npublic static void Initialize() =\u003e\n    VerifyMassTransit.Initialize();\n```\n\u003csup\u003e\u003ca href='/src/Tests/ModuleInitializer.cs#L3-L9' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-enable' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Consumer Test\n\nUsing traditional asserts consumer interactions can be tested as follows:\n\n\u003c!-- snippet: ConsumerTestAsserts --\u003e\n\u003ca id='snippet-ConsumerTestAsserts'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task TestWithAsserts()\n{\n    using var harness = new InMemoryTestHarness();\n    var consumerHarness = harness.Consumer\u003cSubmitOrderConsumer\u003e();\n\n    await harness.Start();\n    try\n    {\n        await harness.InputQueueSendEndpoint\n            .Send(\n                new SubmitOrder\n                {\n                    OrderId = InVar.Id\n                });\n\n        // did the endpoint consume the message\n        Assert.True(await harness.Consumed.Any\u003cSubmitOrder\u003e());\n        // did the actual consumer consume the message\n        Assert.True(await consumerHarness.Consumed.Any\u003cSubmitOrder\u003e());\n        // the consumer publish the event\n        Assert.True(await harness.Published.Any\u003cOrderSubmitted\u003e());\n        // ensure that no faults were published by the consumer\n        Assert.False(await harness.Published.Any\u003cFault\u003cSubmitOrder\u003e\u003e());\n    }\n    finally\n    {\n        await harness.Stop();\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ConsumerTests.cs#L5-L38' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ConsumerTestAsserts' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nUsing Verify, the TestHarness and any number of ConsumerHarness, can be passed to `Verify`.\n\n\u003c!-- snippet: ConsumerTestVerify --\u003e\n\u003ca id='snippet-ConsumerTestVerify'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task TestWithVerify()\n{\n    using var harness = new InMemoryTestHarness();\n    var consumer = harness.Consumer\u003cSubmitOrderConsumer\u003e();\n\n    await harness.Start();\n    try\n    {\n        await harness.InputQueueSendEndpoint\n            .Send(\n                new SubmitOrder\n                {\n                    OrderId = InVar.Id\n                });\n\n        await Verify(new\n        {\n            harness,\n            consumer\n        });\n    }\n    finally\n    {\n        await harness.Stop();\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ConsumerTests.cs#L40-L70' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ConsumerTestVerify' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nThe above will result in the following snapshot file that will need to be [accepted](https://github.com/VerifyTests/Verify#snapshot-management).\n\n\u003c!-- snippet: ConsumerTests.TestWithVerify.verified.txt --\u003e\n\u003ca id='snippet-ConsumerTests.TestWithVerify.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  harness: {\n    Messages: [\n      {\n        Sent: ConsumerTests.SubmitOrder,\n        MessageId: Guid_1,\n        ConversationId: Guid_2,\n        DestinationAddress: input_queue,\n        Message: {\n          OrderId: Guid_3\n        }\n      },\n      {\n        Received: ConsumerTests.SubmitOrder,\n        MessageId: Guid_1,\n        ConversationId: Guid_2,\n        DestinationAddress: input_queue,\n        Message: {\n          OrderId: Guid_3\n        }\n      },\n      {\n        Published: ConsumerTests.OrderSubmitted,\n        MessageId: Guid_4,\n        ConversationId: Guid_2,\n        DestinationAddress: Tests:ConsumerTests+OrderSubmitted,\n        Message: {\n          OrderId: Guid_3\n        }\n      }\n    ]\n  },\n  consumer: {\n    Consumed: [\n      {\n        Received: ConsumerTests.SubmitOrder,\n        MessageId: Guid_1,\n        ConversationId: Guid_2,\n        DestinationAddress: input_queue,\n        Message: {\n          OrderId: Guid_3\n        }\n      }\n    ]\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ConsumerTests.TestWithVerify.verified.txt#L1-L46' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ConsumerTests.TestWithVerify.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nMoving forward, any change in the message interactions will result in a new snapshot that can then be [accepted or declines](https://github.com/VerifyTests/Verify#snapshot-management)\n\n\n### Saga Test\n\nThe following Saga test:\n\n\u003c!-- snippet: SagaTests --\u003e\n\u003ca id='snippet-SagaTests'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task Run()\n{\n    using var harness = new InMemoryTestHarness();\n    var sagaHarness = harness.Saga\u003cConsumerSaga\u003e();\n\n    var correlationId = NewId.NextGuid();\n\n    await harness.Start();\n    try\n    {\n        await harness.Bus.Publish(new Start {CorrelationId = correlationId});\n\n        await harness.Consumed.Any\u003cStart\u003e();\n\n        await Verify(new {harness, sagaHarness});\n    }\n    finally\n    {\n        await harness.Stop();\n    }\n}\n\npublic class ConsumerSaga :\n    ISaga,\n    InitiatedBy\u003cStart\u003e\n{\n    public Guid CorrelationId { get; set; }\n    public bool StartMessageReceived { get; set; }\n\n    public Task Consume(ConsumeContext\u003cStart\u003e context)\n    {\n        StartMessageReceived = true;\n        return Task.CompletedTask;\n    }\n}\n\npublic class Start : CorrelatedBy\u003cGuid\u003e\n{\n    public Guid CorrelationId { get; init; }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/SagaTests.cs#L5-L47' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-SagaTests' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nWill result in the following snapshot file.\n\n\u003c!-- snippet: SagaTests.Run.verified.txt --\u003e\n\u003ca id='snippet-SagaTests.Run.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  harness: {\n    Messages: [\n      {\n        Published: SagaTests.Start,\n        MessageId: Guid_1,\n        ConversationId: Guid_2,\n        DestinationAddress: Tests:SagaTests+Start,\n        Message: {\n          CorrelationId: Guid_3\n        }\n      },\n      {\n        Received: SagaTests.Start,\n        MessageId: Guid_1,\n        ConversationId: Guid_2,\n        DestinationAddress: Tests:SagaTests+Start,\n        Message: {\n          CorrelationId: Guid_3\n        }\n      }\n    ]\n  },\n  sagaHarness: {\n    Consumed: [\n      {\n        Received: SagaTests.Start,\n        MessageId: Guid_1,\n        ConversationId: Guid_2,\n        DestinationAddress: Tests:SagaTests+Start,\n        Message: {\n          CorrelationId: Guid_3\n        }\n      }\n    ],\n    Sagas: [\n      {\n        Saga: {\n          CorrelationId: Guid_3,\n          StartMessageReceived: true\n        },\n        ElementId: Guid_3\n      }\n    ]\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/SagaTests.Run.verified.txt#L1-L46' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-SagaTests.Run.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Icon\n\n[Approval](https://thenounproject.com/term/bus/4628287/) designed by [SAM Designs](https://thenounproject.com/ma2947422/) from [The Noun Project](https://thenounproject.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.masstransit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fverifytests%2Fverify.masstransit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.masstransit/lists"}