Beispiel #1
0
        public void ShouldNotUploadWhenTrexProxyReturnsInternalProcessingErrorType()
        {
            var e           = CreateExecutor <TagFileSnsProcessExecutor>();
            var theFileName = "test-filename-no-download";

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

            var key = TagFileProcessExecutor.GetS3Key(theFileName);
            var expectedS3PathOnFailure = $"{TagFileProcessExecutor.CONNECTION_ERROR_FOLDER}/{key}";
            var expectedS3Path          = $"{key}";

            var expectedErrorCode = 3124; // Executor should forward on the error code and in this case, not archive this internal error

            // Setup a failed connection
            TRexTagFileProxy
            .Setup(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                      It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult(new ContractExecutionResult(expectedErrorCode)));

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

            // Run the test
            var result = e.ProcessAsync(payLoad).Result;

            // Validate we tried to upload
            TRexTagFileProxy
            .Verify(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                       It.IsAny <IHeaderDictionary>()),
                    Times.Exactly(1));

            // Validate that the file was not saved anywhere
            TransferProxy.Verify(m => m.Upload(It.IsAny <MemoryStream>(), It.Is <string>(s => s == expectedS3Path)), Times.Never);
            TransferProxy.Verify(m => m.Upload(It.IsAny <MemoryStream>(), It.Is <string>(s => s == expectedS3PathOnFailure)), Times.Never);

            // Validate we got a non-zero result
            result.Code.Should().Be(ContractExecutionStatesEnum.InternalProcessingError);
        }
Beispiel #2
0
        public void ShouldUploadWhenTrexProxyPasses()
        {
            var e           = CreateExecutor <TagFileSnsProcessExecutor>();
            var theFileName = "test-filename-no-download";

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

            var key            = TagFileProcessExecutor.GetS3Key(theFileName);
            var expectedS3Path = $"{key}";

            // 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, _) => { })
            .Returns(Task.FromResult(new ContractExecutionResult()));

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

            // Run the test
            var result = e.ProcessAsync(payLoad).Result;

            // Validate we tried to upload
            TRexTagFileProxy
            .Verify(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                       It.IsAny <IHeaderDictionary>()),
                    Times.Exactly(1));

            // Validate that the path was correct (we check the data separately)
            TransferProxy.Verify(m => m.Upload(It.IsAny <MemoryStream>(), It.Is <string>(s => s == expectedS3Path)), Times.Once);

            // Validate we got a non-zero result
            result.Code.Should().Be(0);
        }
Beispiel #3
0
        public void ShouldUploadWhenTrexProxyThrowsException()
        {
            // This simulates a situation when tRexProxy cant connect to TRex
            // We want to upload the tag file to S3, but return an error to the caller
            var executor = CreateExecutor <TagFileProcessExecutor>();

            executor.ArchiveOnInternalError = true;

            var key            = TagFileProcessExecutor.GetS3Key(MockRequest.FileName);
            var expectedS3Path = $"{TagFileProcessExecutor.CONNECTION_ERROR_FOLDER}/{key}";
            var uploadedData   = new List <byte>();

            // Setup a failed connection
            TRexTagFileProxy
            .Setup(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                      It.IsAny <IHeaderDictionary>()))
            .Throws <HttpRequestException>();

            // Handle the upload, and save the data for validation
            TransferProxy.Setup(m => m.Upload(It.IsAny <Stream>(), It.IsAny <string>()))
            .Callback <Stream, string>((stream, path) => { uploadedData.AddRange(((MemoryStream)stream).ToArray()); });

            // Run the test
            var result = executor.ProcessAsync(MockRequest).Result;

            // Validate we tried to upload
            TRexTagFileProxy
            .Verify(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                       It.IsAny <IHeaderDictionary>()),
                    Times.Exactly(1));

            // Validate that the path was correct (we check the data separately)
            TransferProxy.Verify(m => m.Upload(It.IsAny <MemoryStream>(), It.Is <string>(s => s == expectedS3Path)), Times.Once);

            // Validate the data
            uploadedData.Should().BeEquivalentTo(MockRequest.Data);

            // Validate we got a non-zero result
            result.Code.Should().NotBe(0);
        }
Beispiel #4
0
        public void ShouldUploadWhenTrexProxyFails()
        {
            var executor = CreateExecutor <TagFileProcessExecutor>();

            executor.ArchiveOnInternalError = true;

            var key               = TagFileProcessExecutor.GetS3Key(MockRequest.FileName);
            var expectedS3Path    = $"{key}";
            var uploadedData      = new List <byte>();
            var expectedErrorCode = 55; // Executor should forward on the error code when tRexProxy returns an error

            // Setup a failed connection
            TRexTagFileProxy
            .Setup(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                      It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult(new ContractExecutionResult(expectedErrorCode)));

            // Handle the upload, and save the data for validation
            TransferProxy.Setup(m => m.Upload(It.IsAny <Stream>(), It.IsAny <string>()))
            .Callback <Stream, string>((stream, path) => { uploadedData.AddRange(((MemoryStream)stream).ToArray()); });

            // Run the test
            var result = executor.ProcessAsync(MockRequest).Result;

            // Validate we tried to upload
            TRexTagFileProxy
            .Verify(m => m.SendTagFile(It.IsAny <CompactionTagFileRequest>(),
                                       It.IsAny <IHeaderDictionary>()),
                    Times.Exactly(1));

            // Validate that the path was correct (we check the data separately)
            TransferProxy.Verify(m => m.Upload(It.IsAny <MemoryStream>(), It.Is <string>(s => s == expectedS3Path)), Times.Once);

            // Validate the data
            uploadedData.Should().BeEquivalentTo(MockRequest.Data);

            // Validate we got a non-zero result
            result.Code.Should().Be(expectedErrorCode);
        }