示例#1
0
        public void CanSendMessages()
        {
            var processor = new PersonProcessor(consumer.Object, publisher.Object);
            var elvis     = new PersonMessage {
                Id = Guid.NewGuid(), Name = "Elvis"
            };

            publisher.Setup(x => x.SendMessagesAsync(new[] { elvis }))
            .ReturnsAsync(true);

            processor.SendMessagesAsync(new[] { elvis });
        }
        public async Task CanSendMessagesFifo()
        {
            var publisher = new PersonPublisher(sqsClient.Object, "sqs.com.fifo");
            var elvis     = new PersonMessage {
                Id = Guid.NewGuid(), Name = "Elvis"
            };
            var response = new SendMessageBatchResponse();

            sqsClient.Setup(x => x.SendMessageBatchAsync(It.IsNotNull <SendMessageBatchRequest>(), It.IsNotNull <CancellationToken>()))
            .ReturnsAsync(response);

            await publisher.SendMessagesAsync(new[] { elvis });
        }
        public async Task CanSendMessage()
        {
            var publisher = new PersonPublisher(sqsClient.Object, "sqs.com");
            var elvis     = new PersonMessage {
                Id = Guid.NewGuid(), Name = "Elvis"
            };
            var response = new SendMessageResponse();

            sqsClient.Setup(x => x.SendMessageAsync(It.Is <SendMessageRequest>(m => Matches(m, elvis)),
                                                    It.IsNotNull <CancellationToken>()))
            .ReturnsAsync(response);

            await publisher.SendMessageAsync(elvis);
        }
        public async Task CanProcess_ActionUnsuccesful_DoesNotRemoveSqsMessage()
        {
            var elvis = new PersonMessage {
                Id = Guid.NewGuid(), Name = "Elvis"
            };
            var processor = new PersonConsumer(sqsClient.Object, SqsUrl, x => Task.FromResult(false));

            var message = new SQSEvent.SQSMessage {
                Body = elvis.ToJson()
            };
            await processor.Process(new[] { message });

            sqsClient.Verify(x => x.DeleteMessageAsync(It.IsAny <DeleteMessageRequest>(), new CancellationToken()), Times.Never);
        }
示例#5
0
        public void CanProcessMessage()
        {
            var processor = new PersonProcessor(consumer.Object, publisher.Object);
            var elvis     = new PersonMessage {
                Id = Guid.NewGuid(), Name = "Elvis"
            };
            var message = new SQSEvent.SQSMessage {
                Body = elvis.ToJson()
            };

            consumer.Setup(x => x.Process(new[] { message }))
            .Returns(Task.CompletedTask);

            processor.Process(new[] { message });
        }
        private static bool Matches(SendMessageRequest actual, PersonMessage expected)
        {
            Validate.Begin()
            .IsNotNull(actual, "actual").Check()
            .IsNotNull(expected, "expected").Check()
            .IsNotNull(actual.MessageBody, "messageBody")
            .Check();

            var person = actual.MessageBody.FromJson <PersonMessage>();

            return(Validate.Begin()
                   .IsNotNull(person, "person").Check()
                   .IsEqual(person.Id, expected.Id, "id")
                   .IsEqual(person.Name, expected.Name, "Name")
                   .Check()
                   .IsValid());
        }
        public void CanProcess_RemovedSqsMessage()
        {
            var elvis = new PersonMessage {
                Id = Guid.NewGuid(), Name = "Elvis"
            };
            var processor = new PersonConsumer(sqsClient.Object, SqsUrl, x =>
            {
                x.Done = true;
                return(Task.FromResult(true));
            });

            sqsClient.Setup(x => x.DeleteMessageAsync(It.IsAny <DeleteMessageRequest>(), new CancellationToken()));

            var message = new SQSEvent.SQSMessage {
                Body = elvis.ToJson()
            };

            processor.Process(new[] { message });
        }