forked from asyncapi/saunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Senn Geerts
authored and
Senn Geerts
committed
Jul 11, 2024
1 parent
1b7087a
commit 2c6e2d9
Showing
5 changed files
with
141 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 107 additions & 107 deletions
214
test/Saunter.Tests/Generation/DocumentGeneratorTests/InterfaceAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,107 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Reflection; | ||
using Saunter.AsyncApiSchema.v2; | ||
using Saunter.Attributes; | ||
using Saunter.Generation; | ||
using Shouldly; | ||
using Xunit; | ||
using System.Linq; | ||
|
||
namespace Saunter.Tests.Generation.DocumentGeneratorTests | ||
{ | ||
public class InterfaceAttributeTests | ||
{ | ||
[Theory] | ||
[InlineData(typeof(IServiceEvents))] | ||
[InlineData(typeof(ServiceEventsFromInterface))] | ||
[InlineData(typeof(ServiceEventsFromAnnotatedInterface))] // Check that annotations are not inherited from the interface | ||
public void NonAnnotatedTypesTest(Type type) | ||
{ | ||
// Arrange | ||
var options = new AsyncApiOptions(); | ||
var documentGenerator = new DocumentGenerator(); | ||
|
||
// Act | ||
var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); | ||
|
||
// Assert | ||
document.ShouldNotBeNull(); | ||
document.Channels.Count.ShouldBe(0); | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(IAnnotatedServiceEvents), "interface")] | ||
[InlineData(typeof(AnnotatedServiceEventsFromInterface), "class")] | ||
[InlineData(typeof(AnnotatedServiceEventsFromAnnotatedInterface), "class")] // Check that the actual type's annotation takes precedence of the inherited interface | ||
public void AnnotatedTypesTest(Type type, string source) | ||
{ | ||
// Arrange | ||
var options = new AsyncApiOptions(); | ||
var documentGenerator = new DocumentGenerator(); | ||
|
||
// Act | ||
var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); | ||
|
||
// Assert | ||
document.ShouldNotBeNull(); | ||
document.Channels.Count.ShouldBe(1); | ||
|
||
var channel = document.Channels.First(); | ||
channel.Key.ShouldBe($"{source}.event"); | ||
channel.Value.Description.ShouldBeNull(); | ||
|
||
var publish = channel.Value.Publish; | ||
publish.ShouldNotBeNull(); | ||
publish.OperationId.ShouldBe("PublishEvent"); | ||
publish.Description.ShouldBe($"({source}) Subscribe to domains events about a tenant."); | ||
|
||
var messageRef = publish.Message.ShouldBeOfType<MessageReference>(); | ||
messageRef.Id.ShouldBe("tenantEvent"); | ||
} | ||
|
||
[AsyncApi] | ||
private interface IAnnotatedServiceEvents | ||
{ | ||
[Channel("interface.event")] | ||
[PublishOperation(typeof(TenantEvent), Description = "(interface) Subscribe to domains events about a tenant.")] | ||
void PublishEvent(TenantEvent evt); | ||
} | ||
|
||
private interface IServiceEvents | ||
{ | ||
void PublishEvent(TenantEvent evt); | ||
} | ||
|
||
private class ServiceEventsFromInterface : IServiceEvents | ||
{ | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
private class ServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents | ||
{ | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
[AsyncApi] | ||
private class AnnotatedServiceEventsFromInterface : IAnnotatedServiceEvents | ||
{ | ||
[Channel("class.event")] | ||
[PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
[AsyncApi] | ||
private class AnnotatedServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents | ||
{ | ||
[Channel("class.event")] | ||
[PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
private class TenantEvent { } | ||
} | ||
} | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Reflection; | ||
using Saunter.AsyncApiSchema.v2; | ||
using Saunter.Attributes; | ||
using Saunter.Generation; | ||
using Shouldly; | ||
using Xunit; | ||
using System.Linq; | ||
|
||
namespace Saunter.Tests.Generation.DocumentGeneratorTests | ||
{ | ||
public class InterfaceAttributeTests | ||
{ | ||
[Theory] | ||
[InlineData(typeof(IServiceEvents))] | ||
[InlineData(typeof(ServiceEventsFromInterface))] | ||
[InlineData(typeof(ServiceEventsFromAnnotatedInterface))] // Check that annotations are not inherited from the interface | ||
public void NonAnnotatedTypesTest(Type type) | ||
{ | ||
// Arrange | ||
var options = new AsyncApiOptions(); | ||
var documentGenerator = new DocumentGenerator(); | ||
|
||
// Act | ||
var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); | ||
|
||
// Assert | ||
document.ShouldNotBeNull(); | ||
document.Channels.Count.ShouldBe(0); | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(IAnnotatedServiceEvents), "interface")] | ||
[InlineData(typeof(AnnotatedServiceEventsFromInterface), "class")] | ||
[InlineData(typeof(AnnotatedServiceEventsFromAnnotatedInterface), "class")] // Check that the actual type's annotation takes precedence of the inherited interface | ||
public void AnnotatedTypesTest(Type type, string source) | ||
{ | ||
// Arrange | ||
var options = new AsyncApiOptions(); | ||
var documentGenerator = new DocumentGenerator(); | ||
|
||
// Act | ||
var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); | ||
|
||
// Assert | ||
document.ShouldNotBeNull(); | ||
document.Channels.Count.ShouldBe(1); | ||
|
||
var channel = document.Channels.First(); | ||
channel.Key.ShouldBe($"{source}.event"); | ||
channel.Value.Description.ShouldBeNull(); | ||
|
||
var publish = channel.Value.Publish; | ||
publish.ShouldNotBeNull(); | ||
publish.OperationId.ShouldBe("PublishEvent"); | ||
publish.Description.ShouldBe($"({source}) Subscribe to domains events about a tenant."); | ||
|
||
var messageRef = publish.Message.ShouldBeOfType<MessageReference>(); | ||
messageRef.Id.ShouldBe("tenantEvent"); | ||
} | ||
|
||
[AsyncApi] | ||
private interface IAnnotatedServiceEvents | ||
{ | ||
[Channel("interface.event")] | ||
[PublishOperation(typeof(TenantEvent), Description = "(interface) Subscribe to domains events about a tenant.")] | ||
void PublishEvent(TenantEvent evt); | ||
} | ||
|
||
private interface IServiceEvents | ||
{ | ||
void PublishEvent(TenantEvent evt); | ||
} | ||
|
||
private class ServiceEventsFromInterface : IServiceEvents | ||
{ | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
private class ServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents | ||
{ | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
[AsyncApi] | ||
private class AnnotatedServiceEventsFromInterface : IAnnotatedServiceEvents | ||
{ | ||
[Channel("class.event")] | ||
[PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
[AsyncApi] | ||
private class AnnotatedServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents | ||
{ | ||
[Channel("class.event")] | ||
[PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] | ||
public void PublishEvent(TenantEvent evt) { } | ||
} | ||
|
||
private class TenantEvent { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters