public void given_a_request_when_ProcessImageUseCase_ExecuteGet_method_is_called_then_it_returns_the_response_object_of_correct_type_and_data()
        {
            //assert
            var request  = MatProcessDataHelper.CreateGetProcessImageRequestObject();
            var imageKey = ImagePersistingHelper.generateImageKey(request.processType, request.imageId, request.processRef, request.fileExtension);

            var expectedBase64ImageString = MatProcessDataHelper.CreatePostProcessImageRequestObject().base64Image;

            _mockGateway.Setup(g => g.RetrieveImage(It.Is <string>(obj => obj == imageKey))).Returns(expectedBase64ImageString);

            var expectedUsecaseResponse = new GetProcessImageResponse(expectedBase64ImageString, DateTime.Now, request); //The date time is impossible to test equality for, as it will differ in few microseconds from the actual response one. So I set it to DateTime.Min to signify its unimportance.

            //act
            var usecaseResponse = _processImageUseCase.ExecuteGet(request);

            //assert
            Assert.IsNotNull(usecaseResponse);
            Assert.IsInstanceOf <GetProcessImageResponse>(usecaseResponse);

            Assert.AreEqual(expectedUsecaseResponse.Base64Image, usecaseResponse.Base64Image);
            Assert.AreEqual(expectedUsecaseResponse.Request.processRef, usecaseResponse.Request.processRef);
            Assert.AreEqual(expectedUsecaseResponse.Request.imageId, usecaseResponse.Request.imageId);

            //This assertion has an accuracy of 1 second. If time difference between [when expected object was created] and [when actual usecase response was created] is within 1 second, then the times are considered equal. 1 Second is plenty of time for the code in between to run, considering it's using a Mock gateway.
            Assert.Less((usecaseResponse.GeneratedAt - expectedUsecaseResponse.GeneratedAt).TotalMilliseconds, 1000);
        }
        public GetProcessImageResponse ExecuteGet(GetProcessImageRequest request)
        {
            var imageKey        = ImagePersistingHelper.generateImageKey(request.processType, request.imageId, request.processRef, request.fileExtension);
            var gatewayResponse = _processImageGateway.RetrieveImage(imageKey);

            return(new GetProcessImageResponse(gatewayResponse, DateTime.Now, request));
        }
 public static ProcessImageData CreateImageDataObject(PostProcessImageRequest request, Base64DecodedData decodedStringData)
 {
     return(new ProcessImageData()
     {
         processRef = request.processRef,
         imageId = request.imageId,
         imageData = decodedStringData,
         key = ImagePersistingHelper.generateImageKey(request.processType, request.imageId, request.processRef, decodedStringData.imageExtension)
     });
 }
        public void given_a_request_when_ProcessImageUseCase_ExecuteGet_method_is_called_then_it_calls_the_gateway_with_imageKey_generated_based_on_the_request()
        {
            //assert
            var request  = MatProcessDataHelper.CreateGetProcessImageRequestObject();
            var imageKey = ImagePersistingHelper.generateImageKey(request.processType, request.imageId, request.processRef, request.fileExtension);

            //act
            _processImageUseCase.ExecuteGet(request);

            //assert
            _mockGateway.Verify(g => g.RetrieveImage(It.Is <string>(obj => obj == imageKey)), Times.Once);
        }
        public void test_that_generated_key_is_correct(string imageId)
        {
            //arrange
            var processRef    = faker.Random.Guid().ToString();
            var fileExtension = faker.Random.Word();
            var processType   = faker.Random.Word();
            var expectedKey   = $"{processType}/{processRef}/{imageId}.{fileExtension}";
            //act
            var result = ImagePersistingHelper.generateImageKey(processType, imageId, processRef, fileExtension);

            Assert.AreEqual(expectedKey, result);
        }