Exemplo n.º 1
0
    private static ISqsQueue TestQueue(
        IMessageSerializationRegister messageSerializationRegister,
        string queueName,
        Action spy = null)
    {
        var message = new TestJustSayingMessage
        {
            QueueName = queueName,
        };

        var messages = new List <Message>
        {
            new TestMessage {
                Body = messageSerializationRegister.Serialize(message, false)
            },
        };

        var queue = new FakeSqsQueue(async ct =>
        {
            spy?.Invoke();
            await Task.Delay(30, ct);
            return(messages);
        }, queueName);

        return(queue);
    }
Exemplo n.º 2
0
 protected override void Given()
 {
     _serializationRegister.Serialize(Arg.Any <Message>(), Arg.Is(true)).Returns(Message);
     Sns.FindTopicAsync("TopicName")
     .Returns(new Topic {
         TopicArn = TopicArn
     });
 }
Exemplo n.º 3
0
 protected override Task Given()
 {
     _sqs.GetQueueUrlAsync(Arg.Any <string>()).Returns(new GetQueueUrlResponse {
         QueueUrl = Url
     });
     _sqs.GetQueueAttributesAsync(Arg.Any <GetQueueAttributesRequest>()).Returns(new GetQueueAttributesResponse());
     _serializationRegister.Serialize(_message, false).Returns("serialized_contents");
     return(Task.CompletedTask);
 }
Exemplo n.º 4
0
 protected override Task Given()
 {
     _serializationRegister.Serialize(Arg.Any <Message>(), Arg.Is(true)).Returns(Message);
     _sns.FindTopicAsync("TopicName")
     .Returns(new Topic {
         TopicArn = TopicArn
     });
     return(Task.CompletedTask);
 }
Exemplo n.º 5
0
        private PublishRequest BuildPublishRequest(Message message, PublishMetadata metadata)
        {
            var messageToSend = _serializationRegister.Serialize(message, serializeForSnsPublishing: true);
            var messageType   = _messageSubjectProvider.GetSubjectForType(message.GetType());

            return(new PublishRequest
            {
                TopicArn = Arn,
                Subject = messageType,
                Message = messageToSend,
                MessageAttributes = BuildMessageAttributes(metadata)
            });
        }
        protected override void Given()
        {
            Sqs.GetQueueUrlAsync(Arg.Any <string>())
            .Returns(new GetQueueUrlResponse {
                QueueUrl = Url
            });

            Sqs.GetQueueAttributesAsync(Arg.Any <GetQueueAttributesRequest>())
            .Returns(new GetQueueAttributesResponse());

            _serializationRegister.Serialize(_testMessage, false)
            .Returns("serialized_contents");

            Sqs.SendMessageAsync(Arg.Any <SendMessageRequest>())
            .Returns(PublishResult);
        }
        private static ISqsQueue TestQueue(
            IMessageSerializationRegister messageSerializationRegister,
            string queueName,
            Action spy = null)
        {
            async Task <ReceiveMessageResponse> GetMessages()
            {
                spy?.Invoke();
                await Task.Delay(30);

                var message = new TestJustSayingMessage
                {
                    QueueName = queueName,
                };

                var messages = new List <Message>
                {
                    new TestMessage {
                        Body = messageSerializationRegister.Serialize(message, false)
                    },
                };

                return(new ReceiveMessageResponse {
                    Messages = messages
                });
            }

            IAmazonSQS sqsClientMock = Substitute.For <IAmazonSQS>();

            sqsClientMock
            .ReceiveMessageAsync(Arg.Any <ReceiveMessageRequest>(), Arg.Any <CancellationToken>())
            .Returns(_ => GetMessages());

            ISqsQueue sqsQueueMock = Substitute.For <ISqsQueue>();

            sqsQueueMock.Uri.Returns(new Uri("http://test.com"));
            sqsQueueMock.Client.Returns(sqsClientMock);
            sqsQueueMock.QueueName.Returns(queueName);
            sqsQueueMock.Uri.Returns(new Uri("http://foo.com"));

            return(sqsQueueMock);
        }
Exemplo n.º 8
0
 public string GetMessageInContext(Message message) => _serializationRegister.Serialize(message, serializeForSnsPublishing: false);