From c03cf70aaa4abba25fb41b775a11fe286ab50b7d Mon Sep 17 00:00:00 2001 From: yurvon-screamo Date: Thu, 8 Aug 2024 11:30:32 +0300 Subject: [PATCH] unit with bindings --- .../ArrangeAttributesTests.cs | 1 + .../MethodAttributesTests.cs | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/ArrangeAttributesTests.cs b/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/ArrangeAttributesTests.cs index d9b14a61..43b357d2 100644 --- a/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/ArrangeAttributesTests.cs +++ b/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/ArrangeAttributesTests.cs @@ -26,6 +26,7 @@ public FakeAsyncApiOptions(Type[] types) public static void Arrange(out AsyncApiOptions options, out AttributeDocumentProvider documentProvider, params Type[] targetTypes) { options = new FakeAsyncApiOptions(targetTypes); + documentProvider = new AttributeDocumentProvider( ActivatorServiceProvider.Instance, new AsyncApiSchemaGenerator(), diff --git a/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/MethodAttributesTests.cs b/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/MethodAttributesTests.cs index de1892e8..0a71284d 100644 --- a/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/MethodAttributesTests.cs +++ b/test/Saunter.Tests/AttributeProvider/DocumentGenerationTests/MethodAttributesTests.cs @@ -1,4 +1,5 @@ using System; +using LEGO.AsyncAPI.Bindings.Kafka; using Saunter.AttributeProvider.Attributes; using Shouldly; using Xunit; @@ -42,6 +43,61 @@ public void PublishTenantEvent(Guid tenantId, TEvent @event) { } } + + [Fact] + public void GenerateDocument_GeneratesDocumentWithKafkaOperationBinding() + { + // Arrange + ArrangeAttributesTests.Arrange(out var options, out var documentProvider, typeof(TenantMessagePublisherWithBind)); + + options.AsyncApi.Components = new() + { + OperationBindings = + { + { + "sample_kaffka", + new() + { + new KafkaOperationBinding() + { + ClientId = new() + { + Type = LEGO.AsyncAPI.Models.SchemaType.Integer, + } + } + } + } + } + }; + + // Act + var document = documentProvider.GetDocument(null, options); + + // Assert + document.ShouldNotBeNull(); + + var channel = document.AssertAndGetChannel("asw.tenant_service.tenants_history.with_bind", "Tenant events."); + + var publish = channel.Publish; + publish.ShouldNotBeNull(); + publish.OperationId.ShouldBe("TenantMessagePublisher"); + publish.Summary.ShouldBe("Publish domains events about tenants."); + publish.Bindings.Reference.Reference.ShouldBe("#/components/operationBindings/sample_kaffka"); + + document.AssertByMessage(publish, "anyTenantCreated"); + } + + [AsyncApi] + public class TenantMessagePublisherWithBind : ITenantMessagePublisher + { + [Channel("asw.tenant_service.tenants_history.with_bind", Description = "Tenant events.")] + [PublishOperation(OperationId = "TenantMessagePublisher", Summary = "Publish domains events about tenants.", BindingsRef = "sample_kaffka")] + [Message(typeof(AnyTenantCreated))] + public void PublishTenantEvent(Guid tenantId, TEvent @event) + where TEvent : IEvent + { + } + } } public class AnyTenantCreated : IEvent { }