diff --git a/test/Savvyio.Extensions.NATS.Tests/Commands/NatsCommandQueueOptionsTest.cs b/test/Savvyio.Extensions.NATS.Tests/Commands/NatsCommandQueueOptionsTest.cs index 2d864fc..ad8c746 100644 --- a/test/Savvyio.Extensions.NATS.Tests/Commands/NatsCommandQueueOptionsTest.cs +++ b/test/Savvyio.Extensions.NATS.Tests/Commands/NatsCommandQueueOptionsTest.cs @@ -69,6 +69,18 @@ public void Heartbeat_Can_Be_Set_Manually() Assert.Equal(TimeSpan.FromSeconds(10), options.Heartbeat); } + [Fact] + public void Heartbeat_Can_Be_Overridden_After_Expires() + { + var options = new NatsCommandQueueOptions(); + + options.Expires = TimeSpan.FromSeconds(60); + Assert.Equal(TimeSpan.FromSeconds(5), options.Heartbeat); + + options.Heartbeat = TimeSpan.FromSeconds(15); + Assert.Equal(TimeSpan.FromSeconds(15), options.Heartbeat); + } + [Fact] public void StreamName_And_ConsumerName_Can_Be_Set_And_Gotten() { diff --git a/test/Savvyio.Extensions.RabbitMQ.Tests/RabbitMqMessageTest.cs b/test/Savvyio.Extensions.RabbitMQ.Tests/RabbitMqMessageTest.cs index f002e13..fada94c 100644 --- a/test/Savvyio.Extensions.RabbitMQ.Tests/RabbitMqMessageTest.cs +++ b/test/Savvyio.Extensions.RabbitMQ.Tests/RabbitMqMessageTest.cs @@ -101,6 +101,33 @@ public async Task EnsureConnectivityAsync_InitializesConnectionAndChannel_Once() factoryMock.Verify(f => f.CreateConnectionAsync(It.IsAny()), Times.Once); } + [Fact] + public async Task EnsureConnectivityAsync_IsThreadSafe_WhenCalledConcurrently() + { + var marshaller = new Mock().Object; + var options = new RabbitMqMessageOptions { AmqpUrl = new Uri("amqp://localhost:5672") }; + + var connectionMock = new Mock(); + var channelMock = new Mock(); + connectionMock.Setup(c => c.CreateChannelAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(channelMock.Object); + + var factoryMock = new Mock(); + factoryMock.Setup(f => f.CreateConnectionAsync(It.IsAny())) + .ReturnsAsync(connectionMock.Object); + + var sut = new TestRabbitMqMessage(marshaller, options); + typeof(RabbitMqMessage) + .GetProperty("RabbitMqFactory", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) + .SetValue(sut, factoryMock.Object); + + await Task.WhenAll( + sut.CallEnsureConnectivityAsync(), + sut.CallEnsureConnectivityAsync()); + + factoryMock.Verify(f => f.CreateConnectionAsync(It.IsAny()), Times.Once); + } + [Fact] public async Task OnDisposeManagedResourcesAsync_DisposesChannelAndConnection() { diff --git a/test/Savvyio.Extensions.SimpleQueueService.Tests/AmazonMessageReceiveOptionsTest.cs b/test/Savvyio.Extensions.SimpleQueueService.Tests/AmazonMessageReceiveOptionsTest.cs index a5b140c..1ef3e89 100644 --- a/test/Savvyio.Extensions.SimpleQueueService.Tests/AmazonMessageReceiveOptionsTest.cs +++ b/test/Savvyio.Extensions.SimpleQueueService.Tests/AmazonMessageReceiveOptionsTest.cs @@ -45,5 +45,17 @@ public void PollingTimeout_ShouldClampValue_WhenOutsideRangeOfAllowedLimits() sut.PollingTimeout = TimeSpan.MaxValue; Assert.Equal(TimeSpan.FromSeconds(AmazonMessageOptions.MaxPollingWaitTimeInSeconds), sut.PollingTimeout); } + + [Fact] + public void VisibilityTimeout_ShouldClampValue_WhenOutsideRangeOfAllowedLimits() + { + var sut = new AmazonMessageReceiveOptions(); + + sut.VisibilityTimeout = TimeSpan.MinValue; + Assert.Equal(TimeSpan.Zero, sut.VisibilityTimeout); + + sut.VisibilityTimeout = TimeSpan.FromSeconds(AmazonMessageOptions.MaxVisibilityTimeoutInSeconds + 1); + Assert.Equal(TimeSpan.FromSeconds(AmazonMessageOptions.MaxVisibilityTimeoutInSeconds), sut.VisibilityTimeout); + } } } diff --git a/test/Savvyio.Extensions.SimpleQueueService.Tests/ClientConfigExtensionsTest.cs b/test/Savvyio.Extensions.SimpleQueueService.Tests/ClientConfigExtensionsTest.cs new file mode 100644 index 0000000..7c56d28 --- /dev/null +++ b/test/Savvyio.Extensions.SimpleQueueService.Tests/ClientConfigExtensionsTest.cs @@ -0,0 +1,38 @@ +using Amazon.Runtime; +using Amazon.SimpleNotificationService; +using Amazon.SQS; +using Codebelt.Extensions.Xunit; +using Xunit; +using Xunit.Abstractions; + +namespace Savvyio.Extensions.SimpleQueueService +{ + public class ClientConfigExtensionsTest : Test + { + public ClientConfigExtensionsTest(ITestOutputHelper output) : base(output) { } + + [Fact] + public void IsValid_ShouldEvaluateConfigurations() + { + ClientConfig[] invalid = null; + Assert.False(invalid.IsValid()); + + var valid = new ClientConfig[] { new AmazonSQSConfig(), new AmazonSimpleNotificationServiceConfig() }; + Assert.True(valid.IsValid()); + + var wrongLength = new ClientConfig[] { new AmazonSQSConfig() }; + Assert.False(wrongLength.IsValid()); + } + + [Fact] + public void ShouldResolveSpecificConfigurations() + { + var sqs = new AmazonSQSConfig(); + var sns = new AmazonSimpleNotificationServiceConfig(); + ClientConfig[] configs = { sqs, sns }; + + Assert.Same(sqs, configs.SimpleQueueService()); + Assert.Same(sns, configs.SimpleNotificationService()); + } + } +} diff --git a/test/Savvyio.Extensions.SimpleQueueService.Tests/EventDriven/StringExtensionsTest.cs b/test/Savvyio.Extensions.SimpleQueueService.Tests/EventDriven/StringExtensionsTest.cs new file mode 100644 index 0000000..8f7bf59 --- /dev/null +++ b/test/Savvyio.Extensions.SimpleQueueService.Tests/EventDriven/StringExtensionsTest.cs @@ -0,0 +1,33 @@ +using System; +using Codebelt.Extensions.Xunit; +using Xunit; +using Xunit.Abstractions; + +namespace Savvyio.Extensions.SimpleQueueService.EventDriven +{ + public class StringExtensionsTest : Test + { + public StringExtensionsTest(ITestOutputHelper output) : base(output) { } + + [Fact] + public void ToSnsUri_ShouldBuildArnWithDefaults() + { + var uri = "sample-topic".ToSnsUri(); + + Assert.Equal(new Uri("arn:aws:sns:eu-west-1:000000000000:sample-topic"), uri); + } + + [Fact] + public void ToSnsUri_ShouldRespectCustomOptions() + { + var uri = "topic".ToSnsUri(o => + { + o.Partition = "aws"; + o.Region = "us-east-1"; + o.AccountId = "123456789012"; + }); + + Assert.Equal(new Uri("arn:aws:sns:us-east-1:123456789012:topic"), uri); + } + } +}