From e1f8c8766767ce642546a911810064a5234f04c3 Mon Sep 17 00:00:00 2001 From: "Alex W. Carlsen" Date: Tue, 24 Oct 2023 10:31:15 +0200 Subject: [PATCH] chore(settings)!: make reader bindings IEnumerable to allow for simpler usage ```csharp new Settings { Bindings = BindingCollection.All, }; ``` BREAKING CHANGE: changes how bindings are applied. --- src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs | 2 +- test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs | 4 ++-- test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs | 2 +- test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs | 5 ++--- test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs | 4 ++-- .../Bindings/StringOrStringList_Should.cs | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs b/src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs index 7f759107..2e715958 100644 --- a/src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs +++ b/src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs @@ -42,7 +42,7 @@ public Dictionary> { get; set; } = new Dictionary>(); - public List> + public IEnumerable> Bindings { get; set; } = new List>(); diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs index 526f164b..b48b1b48 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs @@ -1207,7 +1207,7 @@ public void Serialize_WithBindingReferences_SerializesDeserializes() var actual = doc.Serialize(AsyncApiVersion.AsyncApi2_0, AsyncApiFormat.Yaml); var settings = new AsyncApiReaderSettings(); - settings.Bindings.AddRange(BindingsCollection.Pulsar); + settings.Bindings = BindingsCollection.Pulsar; var reader = new AsyncApiStringReader(settings); var deserialized = reader.Read(actual, out var diagnostic); } @@ -1300,7 +1300,7 @@ public void Serializev2_WithBindings_Serializes() var actual = doc.Serialize(AsyncApiVersion.AsyncApi2_0, AsyncApiFormat.Yaml); var settings = new AsyncApiReaderSettings(); - settings.Bindings.AddRange(BindingsCollection.All); + settings.Bindings = BindingsCollection.All; var reader = new AsyncApiStringReader(settings); var deserialized = reader.Read(actual, out var diagnostic); diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs index 623f6d2b..461bbf79 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs @@ -111,7 +111,7 @@ public void CustomBinding_SerializesDeserializes() expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(new MyBinding()); + settings.Bindings = new[] { new MyBinding() }; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); // Assert diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs index 607510d9..33ad822c 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs @@ -136,10 +136,9 @@ public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes() actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(BindingsCollection.Sns); + settings.Bindings = BindingsCollection.Sns; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); - // Assert Assert.AreEqual(actual, expected); binding.Should().BeEquivalentTo(channel); @@ -379,7 +378,7 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(BindingsCollection.Sns); + settings.Bindings = BindingsCollection.Sns; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs index 50a6fe53..cb96671c 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs @@ -213,7 +213,7 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes() actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(BindingsCollection.Sqs); + settings.Bindings = BindingsCollection.Sqs; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); @@ -438,7 +438,7 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes() actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(BindingsCollection.Sqs); + settings.Bindings = BindingsCollection.Sqs; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); // Assert diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs index 615cf11b..5e2780e7 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/StringOrStringList_Should.cs @@ -81,7 +81,7 @@ public void StringOrStringList_WhenValueIsString_SerializesDeserializes() expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(new StringOrStringListTestBinding()); + settings.Bindings = new[] { new StringOrStringListTestBinding() }; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); // Assert @@ -119,7 +119,7 @@ public void StringOrStringList_WhenValueIsStringList_SerializesDeserializes() expected = expected.MakeLineBreaksEnvironmentNeutral(); var settings = new AsyncApiReaderSettings(); - settings.Bindings.Add(new StringOrStringListTestBinding()); + settings.Bindings = new[] { new StringOrStringListTestBinding() }; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); // Assert