public void test_that_factory_returns_empty_string_if_s3_response_is_empty()
        {
            //arrange
            var testResponse = new GetObjectResponse(); //empty response
            //act
            var result = ImageRetrievalFactory.EncodeStreamToBase64(testResponse);

            //assert
            Assert.IsEmpty(result);
        }
        public void test_that_factory_can_decode_s3_response_to_base64()
        {
            //arrange
            var testResponse = new GetObjectResponse();

            testResponse.ResponseStream = new MemoryStream(faker.Random.Guid().ToByteArray());
            //act
            var result       = ImageRetrievalFactory.EncodeStreamToBase64(testResponse);
            var resultBase64 = result.Split(",")[1];

            //assert
            Assert.IsNotEmpty(result);
            Assert.True(IsBase64String(resultBase64));
        }
Exemple #3
0
        public void test_that_gateway_returns_base64_string_for_successful_request()
        {
            //arrange
            var s3Response = new GetObjectResponse();
            var data       = faker.Random.Guid().ToByteArray();

            s3Response.ResponseStream = new MemoryStream(data);
            s3Response.HttpStatusCode = HttpStatusCode.OK;
            mockS3Client.Setup(x => x.retrieveImage(It.IsAny <AWSCredentials>(), It.IsAny <string>(), It.IsAny <string>())).Returns(s3Response);
            //second response, as if reusing first one, the stream of data will be closed
            var s3Response2 = new GetObjectResponse();

            s3Response2.ResponseStream = new MemoryStream(data);
            var expectedResponse = ImageRetrievalFactory.EncodeStreamToBase64(s3Response2);
            //act
            var response = classUnderTest.RetrieveImage(It.IsAny <string>());

            Assert.NotNull(response);
            Assert.AreEqual(expectedResponse, response);
        }
 public string RetrieveImage(string imageKey)
 {
     try
     {
         var result = s3Client.retrieveImage(assumeRoleHelper.GetTemporaryCredentials(), imageKey,
                                             Environment.GetEnvironmentVariable("bucket-name"));
         return(ImageRetrievalFactory.EncodeStreamToBase64(result));
     }
     catch (AggregateException ex)
     {
         if (ex.InnerException != null && ex.InnerException.Message == "The specified key does not exist.")
         {
             throw new ImageNotFound(); //if image not found
         }
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }