-
-
Couldn't load subscription status.
- Fork 1
V3 rules tests #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3b856f
Merge pull request #12 from yohanfraga/alex/v3
yohanfraga 904adc0
Merge pull request #13 from yohanfraga/alex/v3
yohanfraga 39ff82c
YFS - Start tests to v3 validation rules
yohanfraga 27fc6e1
Merge pull request #14 from yohanfraga/alex/v3
yohanfraga a9d8c3f
YFS - Add operations messages test
yohanfraga 2b93cf1
YFS - Fix context RootDocument null check
yohanfraga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
242 changes: 161 additions & 81 deletions
242
test/LEGO.AsyncAPI.Tests/Validation/ValidationRuleTests.cs
This file contains hidden or 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,89 +1,169 @@ | ||
| // Copyright (c) The LEGO Group. All rights reserved. | ||
|
|
||
| namespace LEGO.AsyncAPI.Tests.Validation | ||
| namespace LEGO.AsyncAPI.Tests.Validation; | ||
|
|
||
| using System.Linq; | ||
| using FluentAssertions; | ||
| using LEGO.AsyncAPI.Readers; | ||
| using NUnit.Framework; | ||
|
|
||
| public class ValidationRuleTests | ||
| { | ||
| using FluentAssertions; | ||
| using LEGO.AsyncAPI.Readers; | ||
| using NUnit.Framework; | ||
| using System.Linq; | ||
| [Test] | ||
| public void V2_OperationId_WithNonUniqueKey_DiagnosticsError() | ||
| { | ||
| var input = | ||
| """ | ||
| asyncapi: 2.6.0 | ||
| info: | ||
| title: Chat Application | ||
| version: 1.0.0 | ||
| servers: | ||
| testing: | ||
| url: test.mosquitto.org:1883 | ||
| protocol: mqtt | ||
| description: Test broker | ||
| channels: | ||
| chat/{personId}: | ||
| publish: | ||
| operationId: onMessageReceieved | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| chat/{personIdentity}: | ||
| publish: | ||
| operationId: onMessageReceieved | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| """; | ||
|
|
||
| new AsyncApiStringReader().Read(input, out var diagnostic); | ||
| diagnostic.Errors.First().Message.Should().Be("OperationId: 'onMessageReceieved' is not unique."); | ||
| diagnostic.Errors.First().Pointer.Should().Be("#/channels/chat~1{personIdentity}"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void V3_OperationChannel_NotReferencingARootChannel_DiagnosticsError() | ||
| { | ||
| var input = | ||
| """ | ||
| asyncapi: 3.0.0 | ||
| info: | ||
| title: Chat Application | ||
| version: 1.0.0 | ||
| servers: | ||
| testing: | ||
| host: test.mosquitto.org:1883 | ||
| protocol: mqtt | ||
| description: Test broker | ||
| channels: | ||
| chatPersonId: | ||
| address: chat.{personId} | ||
| messages: | ||
| messageReceived: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| operations: | ||
| onMessageReceived: | ||
| title: Message received | ||
| channel: | ||
| $ref: '#/components/channels/secondChannel' | ||
| messages: | ||
| - $ref: '#/channels/chatPersonId/messages/messageReceived' | ||
| components: | ||
| channels: | ||
| secondChannel: | ||
| address: chat.{secondChannel} | ||
| """; | ||
|
|
||
| public class ValidationRuleTests | ||
| { | ||
| [Test] | ||
| public void V2_OperationId_WithNonUniqueKey_DiagnosticsError() | ||
| { | ||
| var input = | ||
| """ | ||
| asyncapi: 2.6.0 | ||
| info: | ||
| title: Chat Application | ||
| version: 1.0.0 | ||
| servers: | ||
| testing: | ||
| url: test.mosquitto.org:1883 | ||
| protocol: mqtt | ||
| description: Test broker | ||
| channels: | ||
| chat/{personId}: | ||
| publish: | ||
| operationId: onMessageReceieved | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| chat/{personIdentity}: | ||
| publish: | ||
| operationId: onMessageReceieved | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| """; | ||
| new AsyncApiStringReader().Read(input, out var diagnostic); | ||
| diagnostic.Errors.First().Message.Should().Be("The operation 'Message received' MUST point to a channel definition located in the root Channels Object."); | ||
| diagnostic.Errors.First().Pointer.Should().Be("#/operations/onMessageReceived"); | ||
| } | ||
|
|
||
| var document = new AsyncApiStringReader().Read(input, out var diagnostic); | ||
| diagnostic.Errors.First().Message.Should().Be("OperationId: 'onMessageReceieved' is not unique."); | ||
| diagnostic.Errors.First().Pointer.Should().Be("#/channels/chat~1{personIdentity}"); | ||
| } | ||
| [Test] | ||
| public void V3_OperationMessage_NotReferencingARootChannel_DiagnosticsError() | ||
| { | ||
| var input = | ||
| """ | ||
| asyncapi: 3.0.0 | ||
| info: | ||
| title: Chat Application | ||
| version: 1.0.0 | ||
| servers: | ||
| testing: | ||
| host: test.mosquitto.org:1883 | ||
| protocol: mqtt | ||
| description: Test broker | ||
| channels: | ||
| chatPersonId: | ||
| address: chat.{personId} | ||
| messages: | ||
| messageReceived: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| operations: | ||
| onMessageReceived: | ||
| title: Message received | ||
| channel: | ||
| $ref: '#/channels/chatPersonId' | ||
| messages: | ||
| - $ref: '#/components/messages/messageSent' | ||
| components: | ||
| messages: | ||
| messageSent: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| """; | ||
|
|
||
| [Test] | ||
| [TestCase("chat")] | ||
| [TestCase("/some/chat/{personId}")] | ||
| [TestCase("chat-{personId}")] | ||
| [TestCase("chat-{person_id}")] | ||
| [TestCase("chat-{person%2Did}")] | ||
| [TestCase("chat-{personId2}")] | ||
| public void ChannelKey_WithValidKey_Success(string channelKey) | ||
| { | ||
| var input = | ||
| $""" | ||
| asyncapi: 2.6.0 | ||
| info: | ||
| title: Chat Application | ||
| version: 1.0.0 | ||
| servers: | ||
| testing: | ||
| url: test.mosquitto.org:1883 | ||
| protocol: mqtt | ||
| description: Test broker | ||
| channels: | ||
| {channelKey}: | ||
| publish: | ||
| operationId: onMessageReceieved | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| subscribe: | ||
| operationId: sendMessage | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| """; | ||
| new AsyncApiStringReader().Read(input, out var diagnostic); | ||
| diagnostic.Errors.First().Message.Should().Be("The messages of operation 'Message received' MUST be a subset of the referenced channels messages."); | ||
| diagnostic.Errors.First().Pointer.Should().Be("#/operations/onMessageReceived"); | ||
| } | ||
|
|
||
| var document = new AsyncApiStringReader().Read(input, out var diagnostic); | ||
| diagnostic.Errors.Should().BeEmpty(); | ||
| } | ||
| } | ||
| [Test] | ||
| [TestCase("chat")] | ||
| [TestCase("/some/chat/{personId}")] | ||
| [TestCase("chat-{personId}")] | ||
| [TestCase("chat-{person_id}")] | ||
| [TestCase("chat-{person%2Did}")] | ||
| [TestCase("chat-{personId2}")] | ||
| public void ChannelKey_WithValidKey_Success(string channelKey) | ||
| { | ||
| var input = | ||
| $""" | ||
| asyncapi: 2.6.0 | ||
| info: | ||
| title: Chat Application | ||
| version: 1.0.0 | ||
| servers: | ||
| testing: | ||
| url: test.mosquitto.org:1883 | ||
| protocol: mqtt | ||
| description: Test broker | ||
| channels: | ||
| {channelKey}: | ||
| publish: | ||
| operationId: onMessageReceieved | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| subscribe: | ||
| operationId: sendMessage | ||
| message: | ||
| name: text | ||
| payload: | ||
| type: string | ||
| """; | ||
|
|
||
| } | ||
| new AsyncApiStringReader().Read(input, out var diagnostic); | ||
| diagnostic.Errors.Should().BeEmpty(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.