Esempio n. 1
0
        public void ShouldForwardTagfile()
        {
            // When a SNS message comes in with data, it should be mapped to a Tag File Request and processed
            var e = CreateExecutor <TagFileSnsProcessExecutor>();
            CompactionTagFileRequest receivedTagFile = null;

            var payLoad = new SnsPayload()
            {
                Type     = SnsPayload.NotificationType,
                TopicArn = "TestArn",
                Message  = JsonConvert.SerializeObject(new SnsTagFile()
                {
                    Data     = MockRequest.Data,
                    FileName = "test-filename-no-download",
                    FileSize = MockRequest.Data.Length
                })
            };

            // Ensure the tag file will be upload and save the response
            TRexTagFileProxy
            .Setup(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                      It.IsAny <IHeaderDictionary>()))
            .Callback <CompactionTagFileRequest, IHeaderDictionary>((tagFileRequest, _) => receivedTagFile = tagFileRequest)
            .Returns(Task.FromResult(new ContractExecutionResult()));

            // Handle the upload
            TransferProxy.Setup(m => m.Upload(It.IsAny <Stream>(), It.IsAny <string>()));

            var result = e.ProcessAsync(payLoad).Result;

            // Validate
            TRexTagFileProxy
            .Verify(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                       It.IsAny <IHeaderDictionary>()),
                    Times.Once);


            // Validate result and data
            result.Should().NotBeNull();
            result.Code.Should().Be(0);

            receivedTagFile.Should().NotBeNull();
            receivedTagFile.Data.Should().BeEquivalentTo(MockRequest.Data);
            receivedTagFile.FileName.Should().Be("test-filename-no-download");
        }
Esempio n. 2
0
        public void ShouldDownloadDataWhenNeeded()
        {
            // When a SNS message comes in, it may contain a URL to download the file content
            // This test checks that, and ensures the data is downloaded and sent as a tag file correctly
            var e       = CreateExecutor <TagFileSnsProcessExecutor>();
            var testUrl = "http://not-a-real-host/tag";
            CompactionTagFileRequest receivedTagFile = null;

            var payLoad = new SnsPayload()
            {
                Type     = SnsPayload.NotificationType,
                TopicArn = "TestArn",
                Message  = JsonConvert.SerializeObject(new SnsTagFile()
                {
                    DownloadUrl = testUrl,
                    FileName    = "test-filename",
                    FileSize    = MockRequest.Data.Length
                })
            };

            WebRequest.Setup(m => m.ExecuteRequestAsStreamContent(It.IsAny <string>(),
                                                                  It.IsAny <HttpMethod>(),
                                                                  It.IsAny <IHeaderDictionary>(),
                                                                  It.IsAny <Stream>(),
                                                                  It.IsAny <int?>(),
                                                                  It.IsAny <int>(),
                                                                  It.IsAny <bool>()))
            .Returns(Task.FromResult <HttpContent>(new ByteArrayContent(MockRequest.Data.ToArray())));

            // Ensure the tag file will be upload and save the response
            TRexTagFileProxy
            .Setup(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                      It.IsAny <IHeaderDictionary>()))
            .Callback <CompactionTagFileRequest, IHeaderDictionary>((tagFileRequest, _) => receivedTagFile = tagFileRequest)
            .Returns(Task.FromResult(new ContractExecutionResult()));

            // Handle the upload
            TransferProxy.Setup(m => m.Upload(It.IsAny <Stream>(), It.IsAny <string>()));

            var result = e.ProcessAsync(payLoad).Result;

            // Validate
            WebRequest.Verify(m => m.ExecuteRequestAsStreamContent(It.Is <string>(m => m == testUrl),
                                                                   It.Is <HttpMethod>(m => m == HttpMethod.Get),
                                                                   It.IsAny <IHeaderDictionary>(),
                                                                   It.IsAny <Stream>(),
                                                                   It.IsAny <int?>(),
                                                                   It.IsAny <int>(),
                                                                   It.IsAny <bool>()),
                              Times.Once);

            TRexTagFileProxy
            .Verify(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                       It.IsAny <IHeaderDictionary>()),
                    Times.Once);


            // Validate result and data
            result.Should().NotBeNull();
            result.Code.Should().Be(0);

            receivedTagFile.Should().NotBeNull();
            receivedTagFile.Data.Should().BeEquivalentTo(MockRequest.Data);
            receivedTagFile.FileName.Should().Be("test-filename");
        }