Skip to content

Commit

Permalink
unit with bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
yurvon-screamo committed Aug 8, 2024
1 parent dacc7d8 commit c03cf70
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using LEGO.AsyncAPI.Bindings.Kafka;
using Saunter.AttributeProvider.Attributes;
using Shouldly;
using Xunit;
Expand Down Expand Up @@ -42,6 +43,61 @@ public void PublishTenantEvent<TEvent>(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<TEvent>(Guid tenantId, TEvent @event)
where TEvent : IEvent
{
}
}
}

public class AnyTenantCreated : IEvent { }
Expand Down

0 comments on commit c03cf70

Please sign in to comment.