public async Task Then_An_Exception_Is_Not_Thrown() { // Arrange string topicName = Guid.NewGuid().ToString(); ILoggerFactory loggerFactory = OutputHelper.ToLoggerFactory(); IAwsClientFactory clientFactory = CreateClientFactory(); var subjectProvider = new NonGenericMessageSubjectProvider(); var serializationRegister = new MessageSerializationRegister(subjectProvider); var client = clientFactory.GetSnsClient(Region); var topic = new SnsTopicByName( topicName, client, serializationRegister, loggerFactory, subjectProvider); // Act and Assert (await topic.CreateAsync()).ShouldBeTrue(); (await topic.CreateAsync()).ShouldBeTrue(); topic.Arn.ShouldNotBeNull(); topic.Arn.ShouldEndWith(topic.TopicName); }
public async Task CanSubscribeUsingQueueArn() { IAwsClientFactory clientFactory = CreateClientFactory(); var sqsClient = clientFactory.GetSqsClient(Region); var snsClient = clientFactory.GetSnsClient(Region); var queueResponse = await sqsClient.CreateQueueAsync(UniqueName); var anotherUniqueName = $"{Guid.NewGuid():N}-integration-tests"; var topicResponse = await snsClient.CreateTopicAsync(anotherUniqueName); var subscriptionArn = await snsClient.SubscribeQueueAsync(topicResponse.TopicArn, sqsClient, queueResponse.QueueUrl); var queueArn = (await sqsClient.GetQueueAttributesAsync(queueResponse.QueueUrl, new List <string> { SQSConstants.ATTRIBUTE_QUEUE_ARN })).Attributes[SQSConstants.ATTRIBUTE_QUEUE_ARN]; var handler = new InspectableHandler <SimpleMessage>(); var services = GivenJustSaying() .ConfigureJustSaying(builder => builder .Subscriptions(c => c.ForQueueArn <SimpleMessage>(queueArn)) .Publications(c => c.WithTopicArn <SimpleMessage>(topicResponse.TopicArn) ) ) .AddJustSayingHandlers(new[] { handler }); string content = Guid.NewGuid().ToString(); var message = new SimpleMessage { Content = content }; await WhenAsync( services, async (publisher, listener, serviceProvider, cancellationToken) => { await listener.StartAsync(cancellationToken); await publisher.StartAsync(cancellationToken); await publisher.PublishAsync(message, cancellationToken); // Assert await Patiently.AssertThatAsync(OutputHelper, () => { handler.ReceivedMessages.ShouldHaveSingleItem().Content.ShouldBe(content); }); }); }
public async Task Can_Create_Topic_With_Encryption() { // Arrange ILoggerFactory loggerFactory = OutputHelper.ToLoggerFactory(); IAwsClientFactory clientFactory = CreateClientFactory(); var client = clientFactory.GetSnsClient(Region); var topic = new SnsTopicByName( UniqueName, client, loggerFactory); // Act await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = JustSayingConstants.DefaultSnsAttributeEncryptionKeyId }, CancellationToken.None); // Assert topic.ServerSideEncryption.KmsMasterKeyId.ShouldBe(JustSayingConstants.DefaultSnsAttributeEncryptionKeyId); }
public async Task CanPublishUsingTopicArnWithoutStartingBusAndWithNoRegion() { IAwsClientFactory clientFactory = CreateClientFactory(); var snsClient = clientFactory.GetSnsClient(Region); var topicResponse = await snsClient.CreateTopicAsync(UniqueName); var services = new ServiceCollection() .AddLogging((p) => p.AddXUnit(OutputHelper, o => o.IncludeScopes = true).SetMinimumLevel(LogLevel.Debug)) .AddJustSaying( (builder, serviceProvider) => { builder.Client((options) => { options.WithSessionCredentials(AccessKeyId, SecretAccessKey, SessionToken) .WithServiceUri(ServiceUri); }); }) .ConfigureJustSaying(builder => builder .Publications(c => c.WithTopicArn <SimpleMessage>(topicResponse.TopicArn) ) ); string content = Guid.NewGuid().ToString(); var message = new SimpleMessage { Content = content }; await WhenAsync( services, async (publisher, listener, serviceProvider, cancellationToken) => { // Assert does not throw await publisher.PublishAsync(message, cancellationToken); }); }
public async Task Then_An_Exception_Is_Not_Thrown() { // Arrange string topicName = Guid.NewGuid().ToString(); ILoggerFactory loggerFactory = OutputHelper.ToLoggerFactory(); IAwsClientFactory clientFactory = CreateClientFactory(); var client = clientFactory.GetSnsClient(Region); var topic = new SnsTopicByName( topicName, client, loggerFactory); // Shouldn't throw await topic.CreateAsync(CancellationToken.None); await topic.CreateAsync(CancellationToken.None); topic.Arn.ShouldNotBeNull(); topic.Arn.ShouldEndWith(topic.TopicName); }
public async Task Can_Update_Encryption_For_Existing_Topic() { // Arrange ILoggerFactory loggerFactory = OutputHelper.ToLoggerFactory(); IAwsClientFactory clientFactory = CreateClientFactory(); var client = clientFactory.GetSnsClient(Region); var topic = new SnsTopicByName( UniqueName, client, null, loggerFactory, null); await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = "previousKeyId" }); // Act await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = JustSayingConstants.DefaultSnsAttributeEncryptionKeyId }); // Assert topic.ServerSideEncryption.KmsMasterKeyId.ShouldBe(JustSayingConstants.DefaultSnsAttributeEncryptionKeyId); }
public async Task Can_Remove_Encryption() { // Arrange ILoggerFactory loggerFactory = OutputHelper.ToLoggerFactory(); IAwsClientFactory clientFactory = CreateClientFactory(); var client = clientFactory.GetSnsClient(Region); var topic = new SnsTopicByName( UniqueName, client, null, loggerFactory, null); await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = JustSayingConstants.DefaultSnsAttributeEncryptionKeyId }); // Act await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = String.Empty }); // Assert topic.ServerSideEncryption.ShouldBeNull(); }