|
| 1 | +// Copyright (c) The LEGO Group. All rights reserved. |
| 2 | + |
| 3 | +namespace LEGO.AsyncAPI.Tests.Bindings.WebSockets |
| 4 | +{ |
| 5 | + using System.Linq; |
| 6 | + using FluentAssertions; |
| 7 | + using LEGO.AsyncAPI.Bindings.MQTT; |
| 8 | + using LEGO.AsyncAPI.Bindings.Pulsar; |
| 9 | + using LEGO.AsyncAPI.Bindings.WebSockets; |
| 10 | + using LEGO.AsyncAPI.Models; |
| 11 | + using NUnit.Framework; |
| 12 | + |
| 13 | + public class BindingExtensions_Should |
| 14 | + { |
| 15 | + [Test] |
| 16 | + public void TryGetValue_WithChannelBinding_ReturnsBinding() |
| 17 | + { |
| 18 | + var channel = new AsyncApiChannel(); |
| 19 | + channel.Bindings.Add(new WebSocketsChannelBinding |
| 20 | + { |
| 21 | + Method = "POST", |
| 22 | + Query = new AsyncApiSchema |
| 23 | + { |
| 24 | + Description = "this mah query", |
| 25 | + }, |
| 26 | + Headers = new AsyncApiSchema |
| 27 | + { |
| 28 | + Description = "this mah binding", |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + var result = channel.Bindings.TryGetValue<WebSocketsChannelBinding>(out var channelBinding); |
| 33 | + result.Should().BeTrue(); |
| 34 | + channelBinding.Should().NotBeNull(); |
| 35 | + channelBinding.Should().BeEquivalentTo(channel.Bindings.First().Value); |
| 36 | + } |
| 37 | + |
| 38 | + [Test] |
| 39 | + public void TryGetValue_WithServerBinding_ReturnsBinding() |
| 40 | + { |
| 41 | + var server = new AsyncApiServer(); |
| 42 | + server.Bindings.Add(new PulsarServerBinding |
| 43 | + { |
| 44 | + Tenant = "test tenant", |
| 45 | + }); |
| 46 | + |
| 47 | + var result = server.Bindings.TryGetValue<PulsarServerBinding>(out var serverBinding); |
| 48 | + result.Should().BeTrue(); |
| 49 | + serverBinding.Should().NotBeNull(); |
| 50 | + serverBinding.Should().BeEquivalentTo(server.Bindings.First().Value); |
| 51 | + } |
| 52 | + |
| 53 | + [Test] |
| 54 | + public void TryGetValue_WithOperationBinding_ReturnsBinding() |
| 55 | + { |
| 56 | + var operation = new AsyncApiOperation(); |
| 57 | + operation.Bindings.Add(new MQTTOperationBinding |
| 58 | + { |
| 59 | + QoS = 23, |
| 60 | + MessageExpiryInterval = 1, |
| 61 | + Retain = true, |
| 62 | + }); |
| 63 | + |
| 64 | + var result = operation.Bindings.TryGetValue<MQTTOperationBinding>(out var operationBinding); |
| 65 | + result.Should().BeTrue(); |
| 66 | + operationBinding.Should().NotBeNull(); |
| 67 | + operationBinding.Should().BeEquivalentTo(operation.Bindings.First().Value); |
| 68 | + } |
| 69 | + |
| 70 | + [Test] |
| 71 | + public void TryGetValue_WithMessageBinding_ReturnsBinding() |
| 72 | + { |
| 73 | + var message = new AsyncApiMessage(); |
| 74 | + message.Bindings.Add(new MQTTMessageBinding |
| 75 | + { |
| 76 | + PayloadFormatIndicator = 2, |
| 77 | + CorrelationData = new AsyncApiSchema |
| 78 | + { |
| 79 | + Description = "Test", |
| 80 | + }, |
| 81 | + }); |
| 82 | + |
| 83 | + var result = message.Bindings.TryGetValue<MQTTMessageBinding>(out var messageBinding); |
| 84 | + result.Should().BeTrue(); |
| 85 | + messageBinding.Should().NotBeNull(); |
| 86 | + messageBinding.Should().BeEquivalentTo(message.Bindings.First().Value); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments