Ejemplo n.º 1
0
        public void ReceiveMessage_WithStoreManagerTest()
        {
            var amazonSQS    = Substitute.For <IAmazonSQS>();
            var storeManager = Substitute.For <IStorageManager>();

            _logger = Substitute.For <ILogger>();

            storeManager.StorageReferenceType.Returns(typeof(S3StorageReference));
            storeManager.When(x => x.DeleteData(Arg.Any <S3StorageReference>())).DoNotCallBase();

            SQSManager subscriber = new SQSManager(amazonSQS, storeManager);

            var content = new LoanMessage
            {
                LoanID     = 1,
                LoanNumber = "067",
                Amount     = 1000
            };

            var serializedContent = JsonConvert.SerializeObject(content);
            var expectedRef       = new S3StorageReference("ValidKey");

            //storeManager.PutData(serializedContent).Returns(info => expectedRef);
            storeManager.GetData(Arg.Any <S3StorageReference>()).ReturnsForAnyArgs(info => serializedContent);

            var message = new Message
            {
                Body          = JsonConvert.SerializeObject(expectedRef),
                ReceiptHandle = "Test_ReceiptHandle"
            };

            message.MessageAttributes.Add("SQSLargePayloadSize",
                                          new MessageAttributeValue {
                DataType = "Number", StringValue = "123456"
            });

            amazonSQS.ReceiveMessageAsync(Arg.Any <ReceiveMessageRequest>()).ReturnsForAnyArgs(
                info =>
                new ReceiveMessageResponse
            {
                HttpStatusCode = HttpStatusCode.OK,
                Messages       = new AutoConstructedList <Message>
                {
                    message
                }
            });


            amazonSQS.CreateQueueAsync(Arg.Any <string>())
            .ReturnsForAnyArgs(info => new CreateQueueResponse {
                QueueUrl = TestQueueURL, HttpStatusCode = HttpStatusCode.OK
            });

            amazonSQS.DeleteMessageAsync(Arg.Any <DeleteMessageRequest>()).ReturnsForAnyArgs(
                info =>
                new DeleteMessageResponse
            {
                HttpStatusCode = HttpStatusCode.OK,
            }
                );


            subscriber.ReceiveMessage <LoanMessage>(QueueName, Handler, default(CancellationToken));

            storeManager.Received().GetData(Arg.Is <S3StorageReference>(x => x.GetStorageKey() == expectedRef.GetStorageKey()));
        }
Ejemplo n.º 2
0
 public void MessageReceiveTest()
 {
     _subscriber.ReceiveMessage <LoanMessage>(QueueName, Handler, default(CancellationToken));
     _amazon.ReceivedWithAnyArgs().ReceiveMessageAsync(new ReceiveMessageRequest());
 }