diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs index 6368db66..63e818b4 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs @@ -32,176 +32,178 @@ public void AsyncApiDocument_WithStreetLightsExample_SerializesAndDeserializes() { // Arrange var expected = -@"asyncapi: 2.6.0 -info: - title: Streetlights Kafka API - version: 1.0.0 - description: The Smartylighting Streetlights API allows you to remotely manage the city lights. - license: - name: Apache 2.0 - url: https://www.apache.org/licenses/LICENSE-2.0 -servers: - scram-connections: - url: test.mykafkacluster.org:18092 - protocol: kafka-secure - description: Test broker secured with scramSha256 - security: - - saslScram: [] - tags: - - name: env:test-scram - description: This environment is meant for running internal tests through scramSha256 - - name: kind:remote - description: This server is a remote server. Not exposed by the application - - name: visibility:private - description: This resource is private and only available to certain users - mtls-connections: - url: test.mykafkacluster.org:28092 - protocol: kafka-secure - description: Test broker secured with X509 - security: - - certs: [] - tags: - - name: env:test-mtls - description: This environment is meant for running internal tests through mtls - - name: kind:remote - description: This server is a remote server. Not exposed by the application - - name: visibility:private - description: This resource is private and only available to certain users -defaultContentType: application/json -channels: - 'smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured': - description: The topic on which measured values may be produced and consumed. - publish: - operationId: receiveLightMeasurement - summary: Inform about environmental lighting conditions of a particular streetlight. - traits: - - $ref: '#/components/operationTraits/kafka' - message: - $ref: '#/components/messages/lightMeasured' - parameters: - streetlightId: - $ref: '#/components/parameters/streetlightId' - 'smartylighting.streetlights.1.0.action.{streetlightId}.turn.on': - subscribe: - operationId: turnOn - traits: - - $ref: '#/components/operationTraits/kafka' - message: - $ref: '#/components/messages/turnOnOff' - parameters: - streetlightId: - $ref: '#/components/parameters/streetlightId' - 'smartylighting.streetlights.1.0.action.{streetlightId}.turn.off': - subscribe: - operationId: turnOff - traits: - - $ref: '#/components/operationTraits/kafka' - message: - $ref: '#/components/messages/turnOnOff' - parameters: - streetlightId: - $ref: '#/components/parameters/streetlightId' - 'smartylighting.streetlights.1.0.action.{streetlightId}.dim': - subscribe: - operationId: dimLight - traits: - - $ref: '#/components/operationTraits/kafka' - message: - $ref: '#/components/messages/dimLight' - parameters: - streetlightId: - $ref: '#/components/parameters/streetlightId' -components: - schemas: - lightMeasuredPayload: - type: object - properties: - lumens: - type: integer - description: Light intensity measured in lumens. - minimum: 0 - sentAt: - $ref: '#/components/schemas/sentAt' - turnOnOffPayload: - type: object - properties: - command: - type: string - description: Whether to turn on or off the light. - enum: - - on - - off - sentAt: - $ref: '#/components/schemas/sentAt' - dimLightPayload: - type: object - properties: - percentage: - type: integer - description: Percentage to which the light should be dimmed to. - maximum: 100 - minimum: 0 - sentAt: - $ref: '#/components/schemas/sentAt' - sentAt: - type: string - format: date-time - description: Date and time when the message was sent. - messages: - lightMeasured: - payload: - $ref: '#/components/schemas/lightMeasuredPayload' - contentType: application/json - name: lightMeasured - title: Light measured - summary: Inform about environmental lighting conditions of a particular streetlight. - traits: - - $ref: '#/components/messageTraits/commonHeaders' - turnOnOff: - payload: - $ref: '#/components/schemas/turnOnOffPayload' - name: turnOnOff - title: Turn on/off - summary: Command a particular streetlight to turn the lights on or off. - traits: - - $ref: '#/components/messageTraits/commonHeaders' - dimLight: - payload: - $ref: '#/components/schemas/dimLightPayload' - name: dimLight - title: Dim light - summary: Command a particular streetlight to dim the lights. - traits: - - $ref: '#/components/messageTraits/commonHeaders' - securitySchemes: - saslScram: - type: scramSha256 - description: Provide your username and password for SASL/SCRAM authentication - certs: - type: X509 - description: Download the certificate files from service provider - parameters: - streetlightId: - description: The ID of the streetlight. - schema: - type: string - operationTraits: - kafka: - bindings: - kafka: - clientId: - type: string - enum: - - my-app-id - messageTraits: - commonHeaders: - headers: - type: object - properties: - my-app-header: - type: integer - maximum: 100 - minimum: 0"; + """ + asyncapi: 2.6.0 + info: + title: Streetlights Kafka API + version: 1.0.0 + description: The Smartylighting Streetlights API allows you to remotely manage the city lights. + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0 + servers: + scram-connections: + url: test.mykafkacluster.org:18092 + protocol: kafka-secure + description: Test broker secured with scramSha256 + security: + - saslScram: [] + tags: + - name: env:test-scram + description: This environment is meant for running internal tests through scramSha256 + - name: kind:remote + description: This server is a remote server. Not exposed by the application + - name: visibility:private + description: This resource is private and only available to certain users + mtls-connections: + url: test.mykafkacluster.org:28092 + protocol: kafka-secure + description: Test broker secured with X509 + security: + - certs: [] + tags: + - name: env:test-mtls + description: This environment is meant for running internal tests through mtls + - name: kind:remote + description: This server is a remote server. Not exposed by the application + - name: visibility:private + description: This resource is private and only available to certain users + defaultContentType: application/json + channels: + 'smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured': + description: The topic on which measured values may be produced and consumed. + publish: + operationId: receiveLightMeasurement + summary: Inform about environmental lighting conditions of a particular streetlight. + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/lightMeasured' + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + 'smartylighting.streetlights.1.0.action.{streetlightId}.turn.on': + subscribe: + operationId: turnOn + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/turnOnOff' + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + 'smartylighting.streetlights.1.0.action.{streetlightId}.turn.off': + subscribe: + operationId: turnOff + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/turnOnOff' + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + 'smartylighting.streetlights.1.0.action.{streetlightId}.dim': + subscribe: + operationId: dimLight + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/dimLight' + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + components: + schemas: + lightMeasuredPayload: + type: object + properties: + lumens: + type: integer + description: Light intensity measured in lumens. + minimum: 0 + sentAt: + $ref: '#/components/schemas/sentAt' + turnOnOffPayload: + type: object + properties: + command: + type: string + description: Whether to turn on or off the light. + enum: + - on + - off + sentAt: + $ref: '#/components/schemas/sentAt' + dimLightPayload: + type: object + properties: + percentage: + type: integer + description: Percentage to which the light should be dimmed to. + maximum: 100 + minimum: 0 + sentAt: + $ref: '#/components/schemas/sentAt' + sentAt: + type: string + format: date-time + description: Date and time when the message was sent. + messages: + lightMeasured: + payload: + $ref: '#/components/schemas/lightMeasuredPayload' + contentType: application/json + name: lightMeasured + title: Light measured + summary: Inform about environmental lighting conditions of a particular streetlight. + traits: + - $ref: '#/components/messageTraits/commonHeaders' + turnOnOff: + payload: + $ref: '#/components/schemas/turnOnOffPayload' + name: turnOnOff + title: Turn on/off + summary: Command a particular streetlight to turn the lights on or off. + traits: + - $ref: '#/components/messageTraits/commonHeaders' + dimLight: + payload: + $ref: '#/components/schemas/dimLightPayload' + name: dimLight + title: Dim light + summary: Command a particular streetlight to dim the lights. + traits: + - $ref: '#/components/messageTraits/commonHeaders' + securitySchemes: + saslScram: + type: scramSha256 + description: Provide your username and password for SASL/SCRAM authentication + certs: + type: X509 + description: Download the certificate files from service provider + parameters: + streetlightId: + description: The ID of the streetlight. + schema: + type: string + operationTraits: + kafka: + bindings: + kafka: + clientId: + type: string + enum: + - my-app-id + messageTraits: + commonHeaders: + headers: + type: object + properties: + my-app-header: + type: integer + maximum: 100 + minimum: 0 + """; var asyncApiDocument = new AsyncApiDocumentBuilder() .WithInfo(new AsyncApiInfo @@ -704,113 +706,115 @@ public void AsyncApiDocument_WithStreetLightsExample_SerializesAndDeserializes() public void SerializeV2_WithFullSpec_Serializes() { var expected = - @"asyncapi: 2.6.0 -info: - title: apiTitle - version: apiVersion - description: description - termsOfService: https://example.com/termsOfService - contact: - name: contactName - url: https://example.com/contact - email: contactEmail - license: - name: licenseName - url: https://example.com/license - x-extension: value - x-extension: value -id: documentId -servers: - myServer: - url: https://example.com/server - protocol: KafkaProtocol - protocolVersion: protocolVersion - description: serverDescription - security: - - securitySchemeName: - - requirementItem -channels: - channel1: - description: channelDescription - subscribe: - operationId: myOperation - summary: operationSummary - description: operationDescription - tags: - - name: tagName - description: tagDescription - externalDocs: - description: externalDocsDescription - url: https://example.com/externalDocs - traits: - - operationId: myOperation - summary: traitSummary - description: traitDescription - tags: - - name: tagName - description: tagDescription - externalDocs: - description: externalDocsDescription - url: https://example.com/externalDocs - x-extension: value - message: - oneOf: - - contentType: contentType - name: messageName - title: messageTitle - summary: messageSummary - description: messageDescription - - correlationId: - description: correlationDescription - location: correlationLocation - x-extension: value - schemaFormat: schemaFormat - contentType: contentType - name: messageName - title: messageTitle - summary: messageSummary - description: messageDescription - traits: - - headers: - title: schemaTitle - description: schemaDescription - writeOnly: true - examples: - - key: value - otherKey: 9223372036854775807 - name: traitName - title: traitTitle - summary: traitSummary - description: traitDescription - tags: - - name: tagName - description: tagDescription - externalDocs: - description: externalDocsDescription - url: https://example.com/externalDocs - examples: - - name: exampleName - summary: exampleSummary - payload: - key: value - otherKey: 9223372036854775807 + """ + asyncapi: 2.6.0 + info: + title: apiTitle + version: apiVersion + description: description + termsOfService: https://example.com/termsOfService + contact: + name: contactName + url: https://example.com/contact + email: contactEmail + license: + name: licenseName + url: https://example.com/license x-extension: value - x-extension: value - x-extension: value - x-extension: value -components: - securitySchemes: - securitySchemeName: - type: oauth2 - description: securitySchemeDescription - flows: - implicit: - authorizationUrl: https://example.com/authorization - tokenUrl: https://example.com/tokenUrl - refreshUrl: https://example.com/refresh - scopes: - securitySchemeScopeKey: securitySchemeScopeValue - x-extension: value"; + x-extension: value + id: documentId + servers: + myServer: + url: https://example.com/server + protocol: KafkaProtocol + protocolVersion: protocolVersion + description: serverDescription + security: + - securitySchemeName: + - requirementItem + channels: + channel1: + description: channelDescription + subscribe: + operationId: myOperation + summary: operationSummary + description: operationDescription + tags: + - name: tagName + description: tagDescription + externalDocs: + description: externalDocsDescription + url: https://example.com/externalDocs + traits: + - operationId: myOperation + summary: traitSummary + description: traitDescription + tags: + - name: tagName + description: tagDescription + externalDocs: + description: externalDocsDescription + url: https://example.com/externalDocs + x-extension: value + message: + oneOf: + - contentType: contentType + name: messageName + title: messageTitle + summary: messageSummary + description: messageDescription + - correlationId: + description: correlationDescription + location: correlationLocation + x-extension: value + schemaFormat: schemaFormat + contentType: contentType + name: messageName + title: messageTitle + summary: messageSummary + description: messageDescription + traits: + - headers: + title: schemaTitle + description: schemaDescription + writeOnly: true + examples: + - key: value + otherKey: 9223372036854775807 + name: traitName + title: traitTitle + summary: traitSummary + description: traitDescription + tags: + - name: tagName + description: tagDescription + externalDocs: + description: externalDocsDescription + url: https://example.com/externalDocs + examples: + - name: exampleName + summary: exampleSummary + payload: + key: value + otherKey: 9223372036854775807 + x-extension: value + x-extension: value + x-extension: value + x-extension: value + components: + securitySchemes: + securitySchemeName: + type: oauth2 + description: securitySchemeDescription + flows: + implicit: + authorizationUrl: https://example.com/authorization + tokenUrl: https://example.com/tokenUrl + refreshUrl: https://example.com/refresh + scopes: + securitySchemeScopeKey: securitySchemeScopeValue + x-extension: value + """; // Arrange var title = "apiTitle"; @@ -1219,29 +1223,31 @@ public void Serialize_WithBindingReferences_SerializesDeserializes() [Test] public void Serializev2_WithBindings_Serializes() { - var expected = @"asyncapi: 2.6.0 -info: - description: test description -servers: - production: - url: example.com - protocol: pulsar+ssl - description: test description -channels: - testChannel: - publish: - message: - bindings: - http: - headers: - description: this mah binding - kafka: - key: - description: this mah other binding - bindings: - kafka: - partitions: 2 - replicas: 1"; + var expected = """ + asyncapi: 2.6.0 + info: + description: test description + servers: + production: + url: example.com + protocol: pulsar+ssl + description: test description + channels: + testChannel: + publish: + message: + bindings: + http: + headers: + description: this mah binding + kafka: + key: + description: this mah other binding + bindings: + kafka: + partitions: 2 + replicas: 1 + """; var doc = new AsyncApiDocument(); doc.Info = new AsyncApiInfo() diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiLicenseTests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiLicenseTests.cs index d436dc1e..1edcbe37 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiLicenseTests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiLicenseTests.cs @@ -18,11 +18,13 @@ public class AsyncApiLicenseTests : TestBase [Test] public void Serialize_WithAllProperties_Serializes() { - var expected = @"{ - ""name"": ""test"", - ""url"": ""https://example.com/license"", - ""x-extension"": ""value"" -}"; + var expected = """ + { + "name": "test", + "url": "https://example.com/license", + "x-extension": "value" + } + """; var license = new AsyncApiLicense() { Name = "test", @@ -54,11 +56,13 @@ public static Stream GenerateStreamFromString(string s) public void LoadLicense_WithJson_Deserializes() { // Arrange - var input = @"{ - ""name"": ""test"", - ""url"": ""https://example.com/license"", - ""x-extension"": ""value"" -}"; + var input = """ + { + "name": "test", + "url": "https://example.com/license", + "x-extension": "value" + } + """; using (var stream = GenerateStreamFromString(input)) { diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiReaderTests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiReaderTests.cs index 40a2ddbb..bf19a944 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiReaderTests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiReaderTests.cs @@ -26,18 +26,19 @@ public void Read_WithMissingEverything_DeserializesWithErrors() public void Read_WithExtensionParser_Parses() { var extensionName = "x-someValue"; - var yaml = @$"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 - contact: - name: API Support - url: https://www.example.com/support - email: support@example.com -channels: - workspace: - {extensionName}: onetwothreefour -"; + var yaml = $""" + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + contact: + name: API Support + url: https://www.example.com/support + email: support@example.com + channels: + workspace: + {extensionName}: onetwothreefour + """; Func valueExtensionParser = (any) => { if (any.TryGetValue(out var value)) @@ -68,18 +69,19 @@ public void Read_WithExtensionParser_Parses() public void Read_WithThrowingExtensionParser_AddsToDiagnostics() { var extensionName = "x-fail"; - var yaml = @$"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 - contact: - name: API Support - url: https://www.example.com/support - email: support@example.com -channels: - workspace: - {extensionName}: onetwothreefour -"; + var yaml = $""" + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + contact: + name: API Support + url: https://www.example.com/support + email: support@example.com + channels: + workspace: + {extensionName}: onetwothreefour + """; Func failingExtensionParser = (any) => { throw new AsyncApiException("Failed to parse"); @@ -106,18 +108,19 @@ public void Read_WithThrowingExtensionParser_AddsToDiagnostics() [Test] public void Read_WithBasicPlusContact_Deserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 - contact: - name: API Support - url: https://www.example.com/support - email: support@example.com -channels: - workspace: - x-eventarchetype: objectchanged -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + contact: + name: API Support + url: https://www.example.com/support + email: support@example.com + channels: + workspace: + x-eventarchetype: objectchanged + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); Assert.AreEqual("support@example.com", doc.Info.Contact.Email); @@ -128,26 +131,27 @@ public void Read_WithBasicPlusContact_Deserializes() [Test] public void Read_WithBasicPlusExternalDocs_Deserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - publish: - bindings: - http: - type: response - message: - $ref: '#/components/messages/WorkspaceEventPayload' -components: - messages: - WorkspaceEventPayload: - schemaFormat: application/schema+yaml;version=draft-07 - externalDocs: - description: Find more info here - url: https://example.com -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + publish: + bindings: + http: + type: response + message: + $ref: '#/components/messages/WorkspaceEventPayload' + components: + messages: + WorkspaceEventPayload: + schemaFormat: application/schema+yaml;version=draft-07 + externalDocs: + description: Find more info here + url: https://example.com + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var message = doc.Channels["workspace"].Publish.Message; @@ -158,17 +162,18 @@ public void Read_WithBasicPlusExternalDocs_Deserializes() [Test] public void Read_WithBasicPlusTag_Deserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - x-eventarchetype: objectchanged -tags: - - name: user - description: User-related messages -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + x-eventarchetype: objectchanged + tags: + - name: user + description: User-related messages + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var tag = doc.Tags.First(); @@ -179,19 +184,20 @@ public void Read_WithBasicPlusTag_Deserializes() [Test] public void Read_WithBasicPlusServerDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - x-eventarchetype: objectchanged -servers: - production: - url: 'pulsar+ssl://prod.events.managed.io:1234' - protocol: pulsar+ssl - description: Pulsar broker -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + x-eventarchetype: objectchanged + servers: + production: + url: 'pulsar+ssl://prod.events.managed.io:1234' + protocol: pulsar+ssl + description: Pulsar broker + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var server = doc.Servers.First(); @@ -204,26 +210,27 @@ public void Read_WithBasicPlusServerDeserializes() [Test] public void Read_WithBasicPlusServerVariablesDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - x-eventarchetype: objectchanged -servers: - production: - url: 'pulsar+ssl://prod.events.managed.io:{port}' - protocol: pulsar+ssl - description: Pulsar broker - variables: - port: - description: Secure connection (TLS) is available through port 8883. - default: '1883' - enum: - - '1883' - - '8883' -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + x-eventarchetype: objectchanged + servers: + production: + url: 'pulsar+ssl://prod.events.managed.io:{port}' + protocol: pulsar+ssl + description: Pulsar broker + variables: + port: + description: Secure connection (TLS) is available through port 8883. + default: '1883' + enum: + - '1883' + - '8883' + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var server = doc.Servers.First(); @@ -236,26 +243,27 @@ public void Read_WithBasicPlusServerVariablesDeserializes() [Test] public void Read_WithBasicPlusCorrelationIDDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - publish: - bindings: - http: - type: response - message: - $ref: '#/components/messages/WorkspaceEventPayload' -components: - messages: - WorkspaceEventPayload: - schemaFormat: application/schema+yaml;version=draft-07 - correlationId: - description: Default Correlation ID - location: $message.header#/correlationId -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + publish: + bindings: + http: + type: response + message: + $ref: '#/components/messages/WorkspaceEventPayload' + components: + messages: + WorkspaceEventPayload: + schemaFormat: application/schema+yaml;version=draft-07 + correlationId: + description: Default Correlation ID + location: $message.header#/correlationId + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var message = doc.Channels["workspace"].Publish.Message; @@ -266,27 +274,28 @@ public void Read_WithBasicPlusCorrelationIDDeserializes() [Test] public void Read_WithOneOfMessage_Reads() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - publish: - bindings: - http: - type: response - message: - oneOf: - - $ref: '#/components/messages/WorkspaceEventPayload' -components: - messages: - WorkspaceEventPayload: - schemaFormat: application/schema+yaml;version=draft-07 - correlationId: - description: Default Correlation ID - location: $message.header#/correlationId -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + publish: + bindings: + http: + type: response + message: + oneOf: + - $ref: '#/components/messages/WorkspaceEventPayload' + components: + messages: + WorkspaceEventPayload: + schemaFormat: application/schema+yaml;version=draft-07 + correlationId: + description: Default Correlation ID + location: $message.header#/correlationId + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var message = doc.Channels["workspace"].Publish.Message.First(); @@ -297,27 +306,28 @@ public void Read_WithOneOfMessage_Reads() [Test] public void Read_WithBasicPlusSecuritySchemeDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - publish: - bindings: - http: - type: response - message: - $ref: '#/components/messages/WorkspaceEventPayload' -components: - messages: - WorkspaceEventPayload: - schemaFormat: application/schema+yaml;version=draft-07 - securitySchemes: - saslScram: - type: scramSha256 - description: Provide your username and password for SASL/SCRAM authentication -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + publish: + bindings: + http: + type: response + message: + $ref: '#/components/messages/WorkspaceEventPayload' + components: + messages: + WorkspaceEventPayload: + schemaFormat: application/schema+yaml;version=draft-07 + securitySchemes: + saslScram: + type: scramSha256 + description: Provide your username and password for SASL/SCRAM authentication + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var scheme = doc.Components.SecuritySchemes.First(); @@ -329,24 +339,25 @@ public void Read_WithBasicPlusSecuritySchemeDeserializes() [Test] public void Read_WithBasicPlusOAuthFlowDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - x-something: yes -components: - securitySchemes: - oauth2: - type: oauth2 - flows: - implicit: - authorizationUrl: https://example.com/api/oauth/dialog - scopes: - write:pets: modify pets in your account - read:pets: read your pets -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + x-something: yes + components: + securitySchemes: + oauth2: + type: oauth2 + flows: + implicit: + authorizationUrl: https://example.com/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var scheme = doc.Components.SecuritySchemes.First(); @@ -361,36 +372,37 @@ public void Read_WithBasicPlusOAuthFlowDeserializes() [Test] public void Read_WithServerReference_ResolvesReference() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -servers: - production: - $ref: '#/components/servers/production' -channels: - workspace: - x-something: yes -components: - servers: - production: - url: 'pulsar+ssl://prod.events.managed.io:1234' - protocol: pulsar+ssl - description: Pulsar broker - security: - - petstore_auth: - - write:pets - - read:pets - securitySchemes: - petstore_auth: - type: oauth2 - flows: - implicit: - authorizationUrl: https://example.com/api/oauth/dialog - scopes: - write:pets: modify pets in your account - read:pets: read your pets -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + servers: + production: + $ref: '#/components/servers/production' + channels: + workspace: + x-something: yes + components: + servers: + production: + url: 'pulsar+ssl://prod.events.managed.io:1234' + protocol: pulsar+ssl + description: Pulsar broker + security: + - petstore_auth: + - write:pets + - read:pets + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: https://example.com/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); Assert.AreEqual("pulsar+ssl://prod.events.managed.io:1234", doc.Servers.First().Value.Url); @@ -399,44 +411,45 @@ public void Read_WithServerReference_ResolvesReference() [Test] public void Read_WithChannelReference_ResolvesReference() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -servers: - production: - $ref: '#/components/servers/production' -channels: - workspace: - $ref: '#/components/channels/workspace' -components: - channels: - workspace: - publish: - message: - $ref: '#/components/messages/WorkspaceEventPayload' - servers: - production: - url: 'pulsar+ssl://prod.events.managed.io:1234' - protocol: pulsar+ssl - description: Pulsar broker - security: - - petstore_auth: - - write:pets - - read:pets - messages: - WorkspaceEventPayload: - schemaFormat: 'application/schema+yaml;version=draft-07' - securitySchemes: - petstore_auth: - type: oauth2 - flows: - implicit: - authorizationUrl: https://example.com/api/oauth/dialog - scopes: - write:pets: modify pets in your account - read:pets: read your pets -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + servers: + production: + $ref: '#/components/servers/production' + channels: + workspace: + $ref: '#/components/channels/workspace' + components: + channels: + workspace: + publish: + message: + $ref: '#/components/messages/WorkspaceEventPayload' + servers: + production: + url: 'pulsar+ssl://prod.events.managed.io:1234' + protocol: pulsar+ssl + description: Pulsar broker + security: + - petstore_auth: + - write:pets + - read:pets + messages: + WorkspaceEventPayload: + schemaFormat: 'application/schema+yaml;version=draft-07' + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: https://example.com/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); Assert.AreEqual("application/schema+yaml;version=draft-07", doc.Channels.First().Value.Publish.Message.First().SchemaFormat); @@ -445,38 +458,39 @@ public void Read_WithChannelReference_ResolvesReference() [Test] public void Read_WithBasicPlusMessageTraitsDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -channels: - workspace: - publish: - bindings: - http: - type: response - message: - $ref: '#/components/messages/WorkspaceEventPayload' -components: - messages: - WorkspaceEventPayload: - schemaFormat: application/schema+yaml;version=draft-07 - externalDocs: - description: Find more info here - url: https://example.com - traits: - - $ref: '#/components/messageTraits/commonHeaders' - messageTraits: - commonHeaders: - description: a common headers for common things - headers: - type: object - properties: - my-app-header: - type: integer - minimum: 0 - maximum: 100 -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + channels: + workspace: + publish: + bindings: + http: + type: response + message: + $ref: '#/components/messages/WorkspaceEventPayload' + components: + messages: + WorkspaceEventPayload: + schemaFormat: application/schema+yaml;version=draft-07 + externalDocs: + description: Find more info here + url: https://example.com + traits: + - $ref: '#/components/messageTraits/commonHeaders' + messageTraits: + commonHeaders: + description: a common headers for common things + headers: + type: object + properties: + my-app-header: + type: integer + minimum: 0 + maximum: 100 + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); @@ -491,44 +505,46 @@ public void Read_WithBasicPlusMessageTraitsDeserializes() [Test] public void Serialize_withOneOfSchema_DoesNotWriteThen() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -defaultContentType: application/json -channels: - channel1: - publish: - operationId: channel1 - summary: tthe first channel - description: a channel of great importance - message: - $ref: '#/components/messages/item1' -components: - schemas: - item2: - type: object - properties: - icon: - description: Theme icon - oneOf: - - type: 'null' - - $ref: '#/components/schemas/item3' - item3: - type: object - properties: - title: - type: string - description: The title. - format: string - messages: - item1: - payload: - $ref: '#/components/schemas/item2' - name: item1 - title: item 1 - summary: the first item - description: a first item for firsting the items"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + defaultContentType: application/json + channels: + channel1: + publish: + operationId: channel1 + summary: tthe first channel + description: a channel of great importance + message: + $ref: '#/components/messages/item1' + components: + schemas: + item2: + type: object + properties: + icon: + description: Theme icon + oneOf: + - type: 'null' + - $ref: '#/components/schemas/item3' + item3: + type: object + properties: + title: + type: string + description: The title. + format: string + messages: + item1: + payload: + $ref: '#/components/schemas/item2' + name: item1 + title: item 1 + summary: the first item + description: a first item for firsting the items + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); @@ -540,33 +556,34 @@ public void Serialize_withOneOfSchema_DoesNotWriteThen() [Test] public void Read_WithBasicPlusSecurityRequirementsDeserializes() { - var yaml = @"asyncapi: 2.3.0 -info: - title: test - version: 1.0.0 -servers: - production: - url: 'pulsar+ssl://prod.events.managed.io:1234' - protocol: pulsar+ssl - description: Pulsar broker - security: - - petstore_auth: - - write:pets - - read:pets -channels: - workspace: - x-something: yes -components: - securitySchemes: - petstore_auth: - type: oauth2 - flows: - implicit: - authorizationUrl: https://example.com/api/oauth/dialog - scopes: - write:pets: modify pets in your account - read:pets: read your pets -"; + var yaml = """ + asyncapi: 2.3.0 + info: + title: test + version: 1.0.0 + servers: + production: + url: 'pulsar+ssl://prod.events.managed.io:1234' + protocol: pulsar+ssl + description: Pulsar broker + security: + - petstore_auth: + - write:pets + - read:pets + channels: + workspace: + x-something: yes + components: + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: https://example.com/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + """; var reader = new AsyncApiStringReader(); var doc = reader.Read(yaml, out var diagnostic); var requirement = doc.Servers.First().Value.Security.First().First(); diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/AMQP/AMQPBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/AMQP/AMQPBindings_Should.cs index 7dce6ed3..5ef0d8d1 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/AMQP/AMQPBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/AMQP/AMQPBindings_Should.cs @@ -17,15 +17,17 @@ public void AMQPChannelBinding_WithRoutingKey_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - amqp: - is: routingKey - exchange: - name: myExchange - type: topic - durable: true - autoDelete: false - vhost: /"; + """ + bindings: + amqp: + is: routingKey + exchange: + name: myExchange + type: topic + durable: true + autoDelete: false + vhost: / + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new AMQPChannelBinding @@ -60,15 +62,17 @@ public void AMQPChannelBinding_WithQueue_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - amqp: - is: queue - queue: - name: my-queue-name - durable: true - exclusive: true - autoDelete: false - vhost: /"; + """ + bindings: + amqp: + is: queue + queue: + name: my-queue-name + durable: true + exclusive: true + autoDelete: false + vhost: / + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new AMQPChannelBinding @@ -103,10 +107,12 @@ public void AMQPMessageBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - amqp: - contentEncoding: gzip - messageType: user.signup"; + """ + bindings: + amqp: + contentEncoding: gzip + messageType: user.signup + """; var message = new AsyncApiMessage(); @@ -133,19 +139,21 @@ public void AMQPOperationBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - amqp: - expiration: 100000 - userId: guest - cc: - - user.logs - priority: 10 - deliveryMode: 2 - mandatory: false - bcc: - - external.audit - timestamp: true - ack: false"; + """ + bindings: + amqp: + expiration: 100000 + userId: guest + cc: + - user.logs + priority: 10 + deliveryMode: 2 + mandatory: false + bcc: + - external.audit + timestamp: true + ack: false + """; var operation = new AsyncApiOperation(); operation.Bindings.Add(new AMQPOperationBinding diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs index 8bd56063..448e588b 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs @@ -69,16 +69,18 @@ public void CustomBinding_SerializesDeserializes() { // Arrange var expected = -@"bindings: - my: - custom: someValue - bindingVersion: 0.1.0 - any: - anyKeyName: anyValue - nestedConfiguration: - name: nested - x-myNestedExtension: nestedValue - x-myextension: someValue"; + """ + bindings: + my: + custom: someValue + bindingVersion: 0.1.0 + any: + anyKeyName: anyValue + nestedConfiguration: + name: nested + x-myNestedExtension: nestedValue + x-myextension: someValue + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new MyBinding diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Http/HttpBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Http/HttpBindings_Should.cs index d31c9174..f2c17c6c 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Http/HttpBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Http/HttpBindings_Should.cs @@ -16,10 +16,12 @@ public void HttpMessageBinding_FilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - http: - headers: - description: this mah binding"; + """ + bindings: + http: + headers: + description: this mah binding + """; var message = new AsyncApiMessage(); @@ -48,12 +50,14 @@ public void HttpOperationBinding_FilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - http: - type: request - method: POST - query: - description: this mah query"; + """ + bindings: + http: + type: request + method: POST + query: + description: this mah query + """; var operation = new AsyncApiOperation(); diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Kafka/KafkaBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Kafka/KafkaBindings_Should.cs index ec41a06a..2c5c6f3f 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Kafka/KafkaBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Kafka/KafkaBindings_Should.cs @@ -17,23 +17,25 @@ public void KafkaChannelBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - kafka: - topic: myTopic - partitions: 5 - replicas: 4 - topicConfiguration: - cleanup.policy: - - delete - - compact - retention.ms: 15552000000 - retention.bytes: 2 - delete.retention.ms: 3 - max.message.bytes: 4 - confluent.key.schema.validation: true - confluent.key.subject.name.strategy: TopicNameStrategy - confluent.value.schema.validation: true - confluent.value.subject.name.strategy: TopicNameStrategy"; + """ + bindings: + kafka: + topic: myTopic + partitions: 5 + replicas: 4 + topicConfiguration: + cleanup.policy: + - delete + - compact + retention.ms: 15552000000 + retention.bytes: 2 + delete.retention.ms: 3 + max.message.bytes: 4 + confluent.key.schema.validation: true + confluent.key.subject.name.strategy: TopicNameStrategy + confluent.value.schema.validation: true + confluent.value.subject.name.strategy: TopicNameStrategy + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new KafkaChannelBinding @@ -74,12 +76,14 @@ public void KafkaServerBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"url: https://example.com -protocol: kafka -bindings: - kafka: - schemaRegistryUrl: https://example.com/schemaregistry - schemaRegistryVendor: confluent"; + """ + url: https://example.com + protocol: kafka + bindings: + kafka: + schemaRegistryUrl: https://example.com/schemaregistry + schemaRegistryVendor: confluent + """; var server = new AsyncApiServer() { @@ -110,13 +114,15 @@ public void KafkaMessageBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - kafka: - key: - description: this mah other binding - SchemaIdLocation: test - schemaIdPayloadEncoding: test - schemaLookupStrategy: header"; + """ + bindings: + kafka: + key: + description: this mah other binding + SchemaIdLocation: test + schemaIdPayloadEncoding: test + schemaLookupStrategy: header + """; var message = new AsyncApiMessage(); @@ -148,12 +154,14 @@ public void KafkaOperationBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - kafka: - groupId: - description: this mah groupId - clientId: - description: this mah clientId"; + """ + bindings: + kafka: + groupId: + description: this mah groupId + clientId: + description: this mah clientId + """; var operation = new AsyncApiOperation(); diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Pulsar/PulsarBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Pulsar/PulsarBindings_Should.cs index 26e6ba68..e8a80ac1 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Pulsar/PulsarBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Pulsar/PulsarBindings_Should.cs @@ -17,20 +17,22 @@ public void PulsarChannelBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - pulsar: - namespace: staging - persistence: persistent - compaction: 1000 - geo-replication: - - us-east1 - - us-west1 - retention: - time: 7 - size: 1000 - ttl: 360 - deduplication: true - bindingVersion: 0.1.0"; + """ + bindings: + pulsar: + namespace: staging + persistence: persistent + compaction: 1000 + geo-replication: + - us-east1 + - us-west1 + retention: + time: 7 + size: 1000 + ttl: 360 + deduplication: true + bindingVersion: 0.1.0 + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new PulsarChannelBinding @@ -71,9 +73,11 @@ public void PulsarChannelBindingNamespaceDefaultToNull() { // Arrange var actual = - @"bindings: - pulsar: - persistence: persistent"; + """ + bindings: + pulsar: + persistence: persistent + """; // Act var settings = new AsyncApiReaderSettings(); @@ -89,9 +93,11 @@ public void PulsarChannelBindingPropertiesExceptNamespaceDefaultToNull() { // Arrange var actual = - @"bindings: - pulsar: - namespace: staging"; + """ + bindings: + pulsar: + namespace: staging + """; // Act // Assert @@ -114,11 +120,13 @@ public void PulsarServerBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"url: https://example.com -protocol: pulsar -bindings: - pulsar: - tenant: contoso"; + """ + url: https://example.com + protocol: pulsar + bindings: + pulsar: + tenant: contoso + """; var server = new AsyncApiServer() { @@ -148,11 +156,13 @@ public void ServerBindingVersionDefaultsToNull() { // Arrange var expected = - @"url: https://example.com -protocol: pulsar -bindings: - pulsar: - tenant: contoso"; + """ + url: https://example.com + protocol: pulsar + bindings: + pulsar: + tenant: contoso + """; var server = new AsyncApiServer() { @@ -184,11 +194,13 @@ public void ServerTenantDefaultsToNull() { // Arrange var expected = - @"url: https://example.com -protocol: pulsar -bindings: - pulsar: - bindingVersion: latest"; + """ + url: https://example.com + protocol: pulsar + bindings: + pulsar: + bindingVersion: latest + """; var server = new AsyncApiServer() { diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs index e7aaae0b..6d4f5779 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs @@ -19,35 +19,37 @@ public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = - @"bindings: - sns: - name: myTopic - ordering: - type: FIFO - contentBasedDeduplication: true - x-orderingExtension: - orderingXPropertyName: orderingXPropertyValue - policy: - statements: - - effect: Deny - principal: arn:aws:iam::123456789012:user/alex.wichmann - action: - - sns:Publish - - sns:Delete - - effect: Allow - principal: - - arn:aws:iam::123456789012:user/alex.wichmann - - arn:aws:iam::123456789012:user/dec.kolakowski - action: sns:Create - x-statementExtension: - statementXPropertyName: statementXPropertyValue - x-policyExtension: - policyXPropertyName: policyXPropertyValue - tags: - owner: AsyncAPI.NET - platform: AsyncAPIOrg - x-bindingExtension: - bindingXPropertyName: bindingXPropertyValue"; + """ + bindings: + sns: + name: myTopic + ordering: + type: FIFO + contentBasedDeduplication: true + x-orderingExtension: + orderingXPropertyName: orderingXPropertyValue + policy: + statements: + - effect: Deny + principal: arn:aws:iam::123456789012:user/alex.wichmann + action: + - sns:Publish + - sns:Delete + - effect: Allow + principal: + - arn:aws:iam::123456789012:user/alex.wichmann + - arn:aws:iam::123456789012:user/dec.kolakowski + action: sns:Create + x-statementExtension: + statementXPropertyName: statementXPropertyValue + x-policyExtension: + policyXPropertyName: policyXPropertyValue + tags: + owner: AsyncAPI.NET + platform: AsyncAPIOrg + x-bindingExtension: + bindingXPropertyName: bindingXPropertyValue + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new SnsChannelBinding() @@ -152,66 +154,68 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = - @"bindings: - sns: - topic: - name: someTopic - x-identifierExtension: - identifierXPropertyName: identifierXPropertyValue - consumers: - - protocol: sqs - endpoint: - name: someQueue - x-identifierExtension: - identifierXPropertyName: identifierXPropertyValue - filterPolicy: - store: - - asyncapi_corp - contact: dec.kolakowski - event: - - anything-but: order_cancelled - order_key: - transient: by_area - customer_interests: - - rugby - - football - - baseball - filterPolicyScope: MessageAttributes - rawMessageDelivery: false - redrivePolicy: - deadLetterQueue: - arn: arn:aws:SQS:eu-west-1:0000000:123456789 - x-identifierExtension: - identifierXPropertyName: identifierXPropertyValue - maxReceiveCount: 25 - x-redrivePolicyExtension: - redrivePolicyXPropertyName: redrivePolicyXPropertyValue - deliveryPolicy: - minDelayTarget: 10 - maxDelayTarget: 100 - numRetries: 5 - numNoDelayRetries: 2 - numMinDelayRetries: 3 - numMaxDelayRetries: 5 - backoffFunction: linear - maxReceivesPerSecond: 2 - x-deliveryPolicyExtension: - deliveryPolicyXPropertyName: deliveryPolicyXPropertyValue - x-consumerExtension: - consumerXPropertyName: consumerXPropertyValue - deliveryPolicy: - minDelayTarget: 10 - maxDelayTarget: 100 - numRetries: 5 - numNoDelayRetries: 2 - numMinDelayRetries: 3 - numMaxDelayRetries: 5 - backoffFunction: geometric - maxReceivesPerSecond: 10 - x-deliveryPolicyExtension: - deliveryPolicyXPropertyName: deliveryPolicyXPropertyValue - x-bindingExtension: - bindingXPropertyName: bindingXPropertyValue"; + """ + bindings: + sns: + topic: + name: someTopic + x-identifierExtension: + identifierXPropertyName: identifierXPropertyValue + consumers: + - protocol: sqs + endpoint: + name: someQueue + x-identifierExtension: + identifierXPropertyName: identifierXPropertyValue + filterPolicy: + store: + - asyncapi_corp + contact: dec.kolakowski + event: + - anything-but: order_cancelled + order_key: + transient: by_area + customer_interests: + - rugby + - football + - baseball + filterPolicyScope: MessageAttributes + rawMessageDelivery: false + redrivePolicy: + deadLetterQueue: + arn: arn:aws:SQS:eu-west-1:0000000:123456789 + x-identifierExtension: + identifierXPropertyName: identifierXPropertyValue + maxReceiveCount: 25 + x-redrivePolicyExtension: + redrivePolicyXPropertyName: redrivePolicyXPropertyValue + deliveryPolicy: + minDelayTarget: 10 + maxDelayTarget: 100 + numRetries: 5 + numNoDelayRetries: 2 + numMinDelayRetries: 3 + numMaxDelayRetries: 5 + backoffFunction: linear + maxReceivesPerSecond: 2 + x-deliveryPolicyExtension: + deliveryPolicyXPropertyName: deliveryPolicyXPropertyValue + x-consumerExtension: + consumerXPropertyName: consumerXPropertyValue + deliveryPolicy: + minDelayTarget: 10 + maxDelayTarget: 100 + numRetries: 5 + numNoDelayRetries: 2 + numMinDelayRetries: 3 + numMaxDelayRetries: 5 + backoffFunction: geometric + maxReceivesPerSecond: 10 + x-deliveryPolicyExtension: + deliveryPolicyXPropertyName: deliveryPolicyXPropertyValue + x-bindingExtension: + bindingXPropertyName: bindingXPropertyValue + """; var operation = new AsyncApiOperation(); operation.Bindings.Add(new SnsOperationBinding() diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs index 6f2d7ba6..c031621c 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs @@ -19,60 +19,62 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = - @"bindings: - sqs: - queue: - name: myQueue - fifoQueue: true - deduplicationScope: messageGroup - fifoThroughputLimit: perMessageGroupId - deliveryDelay: 30 - visibilityTimeout: 60 - receiveMessageWaitTime: 0 - messageRetentionPeriod: 86400 - redrivePolicy: - deadLetterQueue: - arn: arn:aws:SQS:eu-west-1:0000000:123456789 - x-identifierExtension: - identifierXPropertyName: identifierXPropertyValue - maxReceiveCount: 15 - x-redrivePolicyExtension: - redrivePolicyXPropertyName: redrivePolicyXPropertyValue - policy: - statements: - - effect: deny - principal: arn:aws:iam::123456789012:user/alex.wichmann - action: - - sqs:SendMessage - - sqs:ReceiveMessage - x-statementExtension: - statementXPropertyName: statementXPropertyValue - - effect: allow - principal: - - arn:aws:iam::123456789012:user/alex.wichmann - - arn:aws:iam::123456789012:user/dec.kolakowski - action: sqs:CreateQueue - x-policyExtension: - policyXPropertyName: policyXPropertyValue - tags: - owner: AsyncAPI.NET - platform: AsyncAPIOrg - x-queueExtension: - queueXPropertyName: queueXPropertyValue - deadLetterQueue: - name: myQueue_error - deliveryDelay: 0 - visibilityTimeout: 0 - receiveMessageWaitTime: 0 - messageRetentionPeriod: 604800 - policy: - statements: - - effect: allow - principal: arn:aws:iam::123456789012:user/alex.wichmann - action: - - sqs:* - x-internalObject: - myExtensionPropertyName: myExtensionPropertyValue"; + """ + bindings: + sqs: + queue: + name: myQueue + fifoQueue: true + deduplicationScope: messageGroup + fifoThroughputLimit: perMessageGroupId + deliveryDelay: 30 + visibilityTimeout: 60 + receiveMessageWaitTime: 0 + messageRetentionPeriod: 86400 + redrivePolicy: + deadLetterQueue: + arn: arn:aws:SQS:eu-west-1:0000000:123456789 + x-identifierExtension: + identifierXPropertyName: identifierXPropertyValue + maxReceiveCount: 15 + x-redrivePolicyExtension: + redrivePolicyXPropertyName: redrivePolicyXPropertyValue + policy: + statements: + - effect: deny + principal: arn:aws:iam::123456789012:user/alex.wichmann + action: + - sqs:SendMessage + - sqs:ReceiveMessage + x-statementExtension: + statementXPropertyName: statementXPropertyValue + - effect: allow + principal: + - arn:aws:iam::123456789012:user/alex.wichmann + - arn:aws:iam::123456789012:user/dec.kolakowski + action: sqs:CreateQueue + x-policyExtension: + policyXPropertyName: policyXPropertyValue + tags: + owner: AsyncAPI.NET + platform: AsyncAPIOrg + x-queueExtension: + queueXPropertyName: queueXPropertyValue + deadLetterQueue: + name: myQueue_error + deliveryDelay: 0 + visibilityTimeout: 0 + receiveMessageWaitTime: 0 + messageRetentionPeriod: 604800 + policy: + statements: + - effect: allow + principal: arn:aws:iam::123456789012:user/alex.wichmann + action: + - sqs:* + x-internalObject: + myExtensionPropertyName: myExtensionPropertyValue + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new SqsChannelBinding() @@ -232,58 +234,60 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = - @"bindings: - sqs: - queues: - - name: myQueue - deliveryDelay: 30 - visibilityTimeout: 60 - receiveMessageWaitTime: 0 - messageRetentionPeriod: 86400 - redrivePolicy: - deadLetterQueue: - arn: arn:aws:SQS:eu-west-1:0000000:123456789 - x-identifierExtension: - identifierXPropertyName: identifierXPropertyValue - maxReceiveCount: 15 - x-redrivePolicyExtension: - redrivePolicyXPropertyName: redrivePolicyXPropertyValue - policy: - statements: - - effect: deny - principal: arn:aws:iam::123456789012:user/alex.wichmann - action: - - sqs:SendMessage - - sqs:ReceiveMessage - x-statementExtension: - statementXPropertyName: statementXPropertyValue - - effect: allow - principal: - - arn:aws:iam::123456789012:user/alex.wichmann - - arn:aws:iam::123456789012:user/dec.kolakowski - action: sqs:CreateQueue - x-policyExtension: - policyXPropertyName: policyXPropertyValue - tags: - owner: AsyncAPI.NET - platform: AsyncAPIOrg - x-queueExtension: - queueXPropertyName: queueXPropertyValue - - name: myQueue_error - deliveryDelay: 0 - visibilityTimeout: 0 - receiveMessageWaitTime: 0 - messageRetentionPeriod: 604800 - policy: - statements: - - effect: allow - principal: arn:aws:iam::123456789012:user/alex.wichmann - action: - - sqs:* - x-queueExtension: - queueXPropertyName: queueXPropertyValue - x-internalObject: - myExtensionPropertyName: myExtensionPropertyValue"; + """ + bindings: + sqs: + queues: + - name: myQueue + deliveryDelay: 30 + visibilityTimeout: 60 + receiveMessageWaitTime: 0 + messageRetentionPeriod: 86400 + redrivePolicy: + deadLetterQueue: + arn: arn:aws:SQS:eu-west-1:0000000:123456789 + x-identifierExtension: + identifierXPropertyName: identifierXPropertyValue + maxReceiveCount: 15 + x-redrivePolicyExtension: + redrivePolicyXPropertyName: redrivePolicyXPropertyValue + policy: + statements: + - effect: deny + principal: arn:aws:iam::123456789012:user/alex.wichmann + action: + - sqs:SendMessage + - sqs:ReceiveMessage + x-statementExtension: + statementXPropertyName: statementXPropertyValue + - effect: allow + principal: + - arn:aws:iam::123456789012:user/alex.wichmann + - arn:aws:iam::123456789012:user/dec.kolakowski + action: sqs:CreateQueue + x-policyExtension: + policyXPropertyName: policyXPropertyValue + tags: + owner: AsyncAPI.NET + platform: AsyncAPIOrg + x-queueExtension: + queueXPropertyName: queueXPropertyValue + - name: myQueue_error + deliveryDelay: 0 + visibilityTimeout: 0 + receiveMessageWaitTime: 0 + messageRetentionPeriod: 604800 + policy: + statements: + - effect: allow + principal: arn:aws:iam::123456789012:user/alex.wichmann + action: + - sqs:* + x-queueExtension: + queueXPropertyName: queueXPropertyValue + x-internalObject: + myExtensionPropertyName: myExtensionPropertyValue + """; var operation = new AsyncApiOperation(); operation.Bindings.Add(new SqsOperationBinding() diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs index f9c9c6f7..c437f15c 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs @@ -63,9 +63,11 @@ public void StringOrStringList_ThrowsArgumentException_WhenIntialisedWithListOfN public void StringOrStringList_WhenValueIsString_SerializesDeserializes() { // Arrange - var expected = @"bindings: - testBinding: - testProperty: someValue"; + var expected = """ + bindings: + testBinding: + testProperty: someValue + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new StringOrStringListTestBinding @@ -91,12 +93,14 @@ public void StringOrStringList_WhenValueIsString_SerializesDeserializes() public void StringOrStringList_WhenValueIsStringList_SerializesDeserializes() { // Arrange - var expected = @"bindings: - testBinding: - testProperty: - - someValue01 - - someValue02 - - someValue03"; + var expected = """ + bindings: + testBinding: + testProperty: + - someValue01 + - someValue02 + - someValue03 + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new StringOrStringListTestBinding diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/WebSockets/WebSocketBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/WebSockets/WebSocketBindings_Should.cs index 67d71ff5..b8aef976 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/WebSockets/WebSocketBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/WebSockets/WebSocketBindings_Should.cs @@ -16,13 +16,15 @@ public void WebSocketChannelBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - websockets: - method: POST - query: - description: this mah query - headers: - description: this mah binding"; + """ + bindings: + websockets: + method: POST + query: + description: this mah query + headers: + description: this mah binding + """; var channel = new AsyncApiChannel(); channel.Bindings.Add(new WebSocketsChannelBinding diff --git a/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj b/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj index 3249426d..dfce344e 100644 --- a/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj +++ b/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj @@ -1,34 +1,35 @@  - net6.0 - disable - enable - false - $(NoWarn);SA1600 + 11 + net6.0 + disable + enable + false + $(NoWarn);SA1600 - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/test/LEGO.AsyncAPI.Tests/MQTT/MQTTBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/MQTT/MQTTBindings_Should.cs index c91187ca..bbccf86e 100644 --- a/test/LEGO.AsyncAPI.Tests/MQTT/MQTTBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/MQTT/MQTTBindings_Should.cs @@ -16,20 +16,22 @@ public void MQTTServerBinding_FilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"url: https://example.com -protocol: mqtt -bindings: - mqtt: - clientId: guest - cleanSession: true - lastWill: - topic: /last-wills - qos: 2 - message: Guest gone offline. - retain: false - keepAlive: 60 - sessionExpiryInterval: 600 - maximumPacketSize: 1200"; + """ + url: https://example.com + protocol: mqtt + bindings: + mqtt: + clientId: guest + cleanSession: true + lastWill: + topic: /last-wills + qos: 2 + message: Guest gone offline. + retain: false + keepAlive: 60 + sessionExpiryInterval: 600 + maximumPacketSize: 1200 + """; var server = new AsyncApiServer(); server.Url = "https://example.com"; @@ -69,11 +71,13 @@ public void MQTTOperationBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - mqtt: - qos: 2 - retain: true - messageExpiryInterval: 60"; + """ + bindings: + mqtt: + qos: 2 + retain: true + messageExpiryInterval: 60 + """; var operation = new AsyncApiOperation(); operation.Bindings.Add(new MQTTOperationBinding @@ -101,12 +105,14 @@ public void MQTTMessageBinding_WithFilledObject_SerializesAndDeserializes() { // Arrange var expected = -@"bindings: - mqtt: - correlationData: - type: string - format: uuid - contentType: application/json"; + """ + bindings: + mqtt: + correlationData: + type: string + format: uuid + contentType: application/json + """; var message = new AsyncApiMessage(); diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiChannel_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiChannel_Should.cs index 641c763e..ef24e07b 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiChannel_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiChannel_Should.cs @@ -15,18 +15,20 @@ internal class AsyncApiChannel_Should : TestBase [Test] public void AsyncApiChannel_WithWebSocketsBinding_Serializes() { - var expected = @"bindings: - websockets: - method: POST - query: - properties: - index: - description: the index - headers: - properties: - x-correlation-id: - description: the correlationid - bindingVersion: 0.1.0"; + var expected = """ + bindings: + websockets: + method: POST + query: + properties: + index: + description: the index + headers: + properties: + x-correlation-id: + description: the correlationid + bindingVersion: 0.1.0 + """; var channel = new AsyncApiChannel { @@ -77,11 +79,13 @@ public void AsyncApiChannel_WithWebSocketsBinding_Serializes() public void AsyncApiChannel_WithKafkaBinding_Serializes() { var expected = -@"bindings: - kafka: - topic: topic - partitions: 5 - replicas: 2"; + """ + bindings: + kafka: + topic: topic + partitions: 5 + replicas: 2 + """; var channel = new AsyncApiChannel { diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs index 974fbfb2..a37f1503 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs @@ -20,19 +20,21 @@ public void AsyncApiMessage_WithNoType_DeserializesToDefault() { // Arrange var expected = - @"{ - ""payload"": { - ""type"": ""object"", - ""properties"": { - ""someProp"": { - ""enum"": [ - ""test"", - ""test2"" - ] - } - } - } - }"; + """ + { + "payload": { + "type": "object", + "properties": { + "someProp": { + "enum": [ + "test", + "test2" + ] + } + } + } + } + """; // Act var message = new AsyncApiStringReader().ReadFragment(expected, AsyncApiVersion.AsyncApi2_0, out var diagnostic); @@ -47,12 +49,14 @@ public void AsyncApiMessage_WithNoSchemaFormat_DeserializesToDefault() { // Arrange var expected = -@"payload: - properties: - propertyA: - type: - - 'null' - - string"; + """ + payload: + properties: + propertyA: + type: + - 'null' + - string + """; // Act var message = new AsyncApiStringReader().ReadFragment(expected, AsyncApiVersion.AsyncApi2_0, out var diagnostic); @@ -67,13 +71,15 @@ public void AsyncApiMessage_WithUnsupportedSchemaFormat_DeserializesWithError() { // Arrange var expected = -@"payload: - properties: - propertyA: - type: - - 'null' - - string -schemaFormat: application/vnd.apache.avro;version=1.9.0"; + """ + payload: + properties: + propertyA: + type: + - 'null' + - string + schemaFormat: application/vnd.apache.avro;version=1.9.0 + """; // Act new AsyncApiStringReader().ReadFragment(expected, AsyncApiVersion.AsyncApi2_0, out var diagnostic); @@ -88,12 +94,14 @@ public void AsyncApiMessage_WithNoSchemaFormat_DoesNotSerializeSchemaFormat() { // Arrange var expected = -@"payload: - properties: - propertyA: - type: - - 'null' - - string"; + """ + payload: + properties: + propertyA: + type: + - 'null' + - string + """; var message = new AsyncApiMessage(); message.Payload = new AsyncApiSchema() @@ -126,13 +134,15 @@ public void AsyncApiMessage_WithSchemaFormat_Serializes() { // Arrange var expected = -@"payload: - properties: - propertyA: - type: - - 'null' - - string -schemaFormat: application/vnd.aai.asyncapi+json;version=2.6.0"; + """ + payload: + properties: + propertyA: + type: + - 'null' + - string + schemaFormat: application/vnd.aai.asyncapi+json;version=2.6.0 + """; var message = new AsyncApiMessage(); message.SchemaFormat = "application/vnd.aai.asyncapi+json;version=2.6.0"; @@ -163,72 +173,74 @@ public void AsyncApiMessage_WithSchemaFormat_Serializes() public void AsyncApiMessage_WithFilledObject_Serializes() { var expected = -@"headers: - title: HeaderTitle - description: HeaderDescription - writeOnly: true - examples: - - x-correlation-id: nil -payload: - properties: - propA: - type: string - propB: - type: string -correlationId: - description: CorrelationDescription - location: Header - x-extension-a: a -contentType: MessageContentType -name: MessageName -title: MessageTitle -summary: MessageSummary -description: MessageDescription -tags: - - name: tagA - description: a -externalDocs: - description: example docs description - url: https://example.com/docs -bindings: - http: - headers: - title: SchemaTitle - description: SchemaDescription - writeOnly: true - examples: - - cKey: c - dKey: 1 -examples: - - payload: - PropA: a - PropB: b -traits: - - headers: - title: SchemaTitle - description: SchemaDescription - writeOnly: true - examples: - - eKey: e - fKey: 1 - name: MessageTraitName - title: MessageTraitTitle - summary: MessageTraitSummary - description: MessageTraitDescription - tags: - - name: tagB - description: b - externalDocs: - description: example docs description - url: https://example.com/docs - examples: - - name: MessageExampleName - summary: MessageExampleSummary - payload: - gKey: g - hKey: true - x-extension-b: b - x-extension-c: c"; + """ + headers: + title: HeaderTitle + description: HeaderDescription + writeOnly: true + examples: + - x-correlation-id: nil + payload: + properties: + propA: + type: string + propB: + type: string + correlationId: + description: CorrelationDescription + location: Header + x-extension-a: a + contentType: MessageContentType + name: MessageName + title: MessageTitle + summary: MessageSummary + description: MessageDescription + tags: + - name: tagA + description: a + externalDocs: + description: example docs description + url: https://example.com/docs + bindings: + http: + headers: + title: SchemaTitle + description: SchemaDescription + writeOnly: true + examples: + - cKey: c + dKey: 1 + examples: + - payload: + PropA: a + PropB: b + traits: + - headers: + title: SchemaTitle + description: SchemaDescription + writeOnly: true + examples: + - eKey: e + fKey: 1 + name: MessageTraitName + title: MessageTraitTitle + summary: MessageTraitSummary + description: MessageTraitDescription + tags: + - name: tagB + description: b + externalDocs: + description: example docs description + url: https://example.com/docs + examples: + - name: MessageExampleName + summary: MessageExampleSummary + payload: + gKey: g + hKey: true + x-extension-b: b + x-extension-c: c + """; var message = new AsyncApiMessage { diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiOperation_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiOperation_Should.cs index 29d59488..5597b211 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiOperation_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiOperation_Should.cs @@ -30,10 +30,12 @@ public void SerializeV2_WithNullWriter_Throws() public void SerializeV2_WithMultipleMessages_SerializesWithOneOf() { // Arrange - var expected = @"message: - oneOf: - - name: First Message - - name: Second Message"; + var expected = """ + message: + oneOf: + - name: First Message + - name: Second Message + """; var asyncApiOperation = new AsyncApiOperation(); asyncApiOperation.Message.Add(new AsyncApiMessage { Name = "First Message" }); @@ -56,8 +58,10 @@ public void SerializeV2_WithMultipleMessages_SerializesWithOneOf() public void SerializeV2_WithSingleMessage_Serializes() { // Arrange - var expected = @"message: - name: First Message"; + var expected = """ + message: + name: First Message + """; var asyncApiOperation = new AsyncApiOperation(); asyncApiOperation.Message.Add(new AsyncApiMessage { Name = "First Message" }); @@ -79,17 +83,19 @@ public void SerializeV2_WithSingleMessage_Serializes() public void AsyncApiOperation_WithBindings_Serializes() { var expected = -@"bindings: - http: - type: request - method: PUT - query: - description: some query - kafka: - groupId: - description: some Id - clientId: - description: some Id"; + """ + bindings: + http: + type: request + method: PUT + query: + description: some query + kafka: + groupId: + description: some Id + clientId: + description: some Id + """; var operation = new AsyncApiOperation { diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiReference_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiReference_Should.cs index 895d063f..c4491e40 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiReference_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiReference_Should.cs @@ -15,8 +15,10 @@ public class AsyncApiReference_Should : TestBase public void AsyncApiReference_WithExternalFragmentUriReference_AllowReference() { // Arrange - var actual = @"payload: - $ref: http://example.com/some-resource#/path/to/external/fragment"; + var actual = """ + payload: + $ref: http://example.com/some-resource#/path/to/external/fragment + """; var reader = new AsyncApiStringReader(); // Act @@ -41,8 +43,10 @@ public void AsyncApiReference_WithExternalFragmentUriReference_AllowReference() public void AsyncApiReference_WithFragmentReference_AllowReference() { // Arrange - var actual = @"payload: - $ref: /fragments/myFragment"; + var actual = """ + payload: + $ref: /fragments/myFragment + """; var reader = new AsyncApiStringReader(); // Act @@ -67,8 +71,10 @@ public void AsyncApiReference_WithFragmentReference_AllowReference() public void AsyncApiReference_WithInternalComponentReference_AllowReference() { // Arrange - var actual = @"payload: - $ref: '#/components/schemas/test'"; + var actual = """ + payload: + $ref: '#/components/schemas/test' + """; var reader = new AsyncApiStringReader(); // Act @@ -92,8 +98,10 @@ public void AsyncApiReference_WithInternalComponentReference_AllowReference() public void AsyncApiReference_WithExternalFragmentReference_AllowReference() { // Arrange - var actual = @"payload: - $ref: ./myjsonfile.json#/fragment"; + var actual = """ + payload: + $ref: ./myjsonfile.json#/fragment + """; var reader = new AsyncApiStringReader(); // Act @@ -116,8 +124,10 @@ public void AsyncApiReference_WithExternalFragmentReference_AllowReference() public void AsyncApiReference_WithExternalComponentReference_AllowReference() { // Arrange - var actual = @"payload: - $ref: ./someotherdocument.json#/components/schemas/test"; + var actual = """ + payload: + $ref: ./someotherdocument.json#/components/schemas/test + """; var reader = new AsyncApiStringReader(); // Act @@ -141,17 +151,19 @@ public void AsyncApiReference_WithExternalComponentReference_AllowReference() public void AsyncApiDocument_WithInternalComponentReference_ResolvesReference() { // Arrange - var actual = @"asyncapi: 2.6.0 -info: - title: My AsyncAPI Document - version: 1.0.0 -channels: - myChannel: - $ref: '#/components/channels/myChannel' -components: - channels: - myChannel: - description: customDescription"; + var actual = """ + asyncapi: 2.6.0 + info: + title: My AsyncAPI Document + version: 1.0.0 + channels: + myChannel: + $ref: '#/components/channels/myChannel' + components: + channels: + myChannel: + description: customDescription + """; var settings = new AsyncApiReaderSettings() { @@ -178,13 +190,15 @@ public void AsyncApiDocument_WithInternalComponentReference_ResolvesReference() public void AsyncApiDocument_WithExternalReference_DoesNotResolve() { // Arrange - var actual = @"asyncapi: 2.6.0 -info: - title: My AsyncAPI Document - version: 1.0.0 -channels: - myChannel: - $ref: http://example.com/channel.json"; + var actual = """ + asyncapi: 2.6.0 + info: + title: My AsyncAPI Document + version: 1.0.0 + channels: + myChannel: + $ref: http://example.com/channel.json + """; var settings = new AsyncApiReaderSettings() { @@ -212,8 +226,10 @@ public void AsyncApiDocument_WithExternalReference_DoesNotResolve() public void AsyncApiReference_WithExternalReference_AllowsReferenceDoesNotResolve() { // Arrange - var actual = @"payload: - $ref: http://example.com/json.json"; + var actual = """ + payload: + $ref: http://example.com/json.json + """; var reader = new AsyncApiStringReader(); // Act diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs index f6c56063..830a44bc 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs @@ -301,19 +301,21 @@ public void SerializeAsJson_WithBasicSchema_V2Works() public void SerializeAsJson_WithAdvancedSchemaNumber_V2Works() { // Arrange - var expected = @"{ - ""title"": ""title1"", - ""type"": ""integer"", - ""maximum"": 42, - ""minimum"": 10, - ""exclusiveMinimum"": true, - ""multipleOf"": 3, - ""default"": 15, - ""nullable"": true, - ""externalDocs"": { - ""url"": ""http://example.com/externalDocs"" - } -}"; + var expected = """ + { + "title": "title1", + "type": "integer", + "maximum": 42, + "minimum": 10, + "exclusiveMinimum": true, + "multipleOf": 3, + "default": 15, + "nullable": true, + "externalDocs": { + "url": "http://example.com/externalDocs" + } + } + """; // Act var actual = AdvancedSchemaNumber.SerializeAsJson(AsyncApiVersion.AsyncApi2_0); @@ -327,19 +329,21 @@ public void SerializeAsJson_WithAdvancedSchemaNumber_V2Works() public void SerializeAsJson_WithAdvancedSchemaBigNumbers_V2Works() { // Arrange - var expected = @"{ - ""title"": ""title1"", - ""type"": ""integer"", - ""maximum"": 1.7976931348623157E+308, - ""minimum"": -1.7976931348623157E+308, - ""exclusiveMinimum"": true, - ""multipleOf"": 3, - ""default"": 15, - ""nullable"": true, - ""externalDocs"": { - ""url"": ""http://example.com/externalDocs"" - } -}"; + var expected = """ + { + "title": "title1", + "type": "integer", + "maximum": 1.7976931348623157E+308, + "minimum": -1.7976931348623157E+308, + "exclusiveMinimum": true, + "multipleOf": 3, + "default": 15, + "nullable": true, + "externalDocs": { + "url": "http://example.com/externalDocs" + } + } + """; // Act var actual = AdvancedSchemaBigNumbers.SerializeAsJson(AsyncApiVersion.AsyncApi2_0); diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiServer_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiServer_Should.cs index 5c0a464e..8b14560b 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiServer_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiServer_Should.cs @@ -16,23 +16,25 @@ public void AsyncApiServer_Serializes() { // Arrange var expected = -@"url: 'https://example.com/{channelkey}' -protocol: test -protocolVersion: 0.1.0 -description: some description -variables: - channelkey: - description: some description -security: - - schem1: - - requirement -tags: - - name: mytag1 - description: description of tag1 -bindings: - kafka: - schemaRegistryUrl: http://example.com - schemaRegistryVendor: kafka"; + """ + url: 'https://example.com/{channelkey}' + protocol: test + protocolVersion: 0.1.0 + description: some description + variables: + channelkey: + description: some description + security: + - schem1: + - requirement + tags: + - name: mytag1 + description: description of tag1 + bindings: + kafka: + schemaRegistryUrl: http://example.com + schemaRegistryVendor: kafka + """; var server = new AsyncApiServer { @@ -79,12 +81,14 @@ public void AsyncApiServer_Serializes() public void AsyncApiServer_WithKafkaBinding_Serializes() { var expected = -@"url: -protocol: -bindings: - kafka: - schemaRegistryUrl: http://example.com - schemaRegistryVendor: kafka"; + """ + url: + protocol: + bindings: + kafka: + schemaRegistryUrl: http://example.com + schemaRegistryVendor: kafka + """; var server = new AsyncApiServer { Bindings = new AsyncApiBindings