-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCustomBinding_Should.cs
More file actions
70 lines (59 loc) · 2.18 KB
/
CustomBinding_Should.cs
File metadata and controls
70 lines (59 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace LEGO.AsyncAPI.Tests.Bindings
{
using System;
using FluentAssertions;
using LEGO.AsyncAPI.Bindings;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;
using NUnit.Framework;
public class MyBinding : ChannelBinding<MyBinding>
{
public string Custom { get; set; }
public override string Type => "my";
public override string BindingVersion { get; set; }
protected override FixedFieldMap<MyBinding> FixedFieldMap => new FixedFieldMap<MyBinding>()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "custom", (a, n) => { a.Custom = n.GetScalarValue(); } },
};
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteRequiredProperty("custom", this.Custom);
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteEndObject();
}
}
public class CustomBinding_Should
{
[Test]
public void CustomBinding_SerializesDeserializes()
{
// Arrange
var expected =
@"bindings:
my:
custom: someValue
bindingVersion: 0.1.0";
var channel = new AsyncApiChannel();
channel.Bindings.Add(new MyBinding
{
Custom = "someValue",
BindingVersion = "0.1.0",
});
// Act
var actual = channel.SerializeAsYaml(AsyncApiVersion.AsyncApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
var settings = new AsyncApiReaderSettings();
settings.BindingParsers.Add(new MyBinding());
var binding = new AsyncApiStringReader(settings).ReadFragment<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0, out _);
// Assert
Assert.AreEqual(actual, expected);
binding.Should().BeEquivalentTo(channel);
}
}
}