Skip to content

Commit

Permalink
chore(settings)!: make reader bindings IEnumerable to allow for simpl…
Browse files Browse the repository at this point in the history
…er usage

```csharp
new Settings
{
  Bindings = BindingCollection.All,
};
```

BREAKING CHANGE: changes how bindings are applied.
  • Loading branch information
VisualBean committed Oct 31, 2023
1 parent 1df49c8 commit e1f8c87
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Dictionary<string, Func<AsyncApiAny, IAsyncApiExtension>>
{ get; set; } =
new Dictionary<string, Func<AsyncApiAny, IAsyncApiExtension>>();

public List<IBindingParser<IBinding>>
public IEnumerable<IBindingParser<IBinding>>
Bindings
{ get; set; } =
new List<IBindingParser<IBinding>>();
Expand Down
4 changes: 2 additions & 2 deletions test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/LEGO.AsyncAPI.Tests/Bindings/CustomBinding_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0, out _);

// Assert
Expand Down
5 changes: 2 additions & 3 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0, out _);


// Assert
Assert.AreEqual(actual, expected);
binding.Should().BeEquivalentTo(channel);
Expand Down Expand Up @@ -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<AsyncApiOperation>(actual, AsyncApiVersion.AsyncApi2_0, out _);


Expand Down
4 changes: 2 additions & 2 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0,
out _);
Expand Down Expand Up @@ -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<AsyncApiOperation>(actual, AsyncApiVersion.AsyncApi2_0, out _);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0, out _);

// Assert
Expand Down Expand Up @@ -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<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0, out _);

// Assert
Expand Down

0 comments on commit e1f8c87

Please sign in to comment.