public async Task TestDownloadFileAsync()
        {
            var md5      = Guid.NewGuid().ToString("N");
            var formFile = Substitute.For <IFormFile>();

            var appService = Substitute.For <IAttachmentAppService>();

            IAttachmentAppService factory(string id) => appService;

            var storeService = Substitute.For <IAttachmentStoreService>();

            var target = new AttachmentController(factory, storeService,
                                                  Substitute.For <IMemoryCache>());

            target.ControllerContext = CreateMockContext();

            var result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <NotFoundResult>();

            appService.GetByIdAsync(md5)
            .Returns(new AttachmentItem
            {
                Id       = md5,
                Status   = UploadStatus.Uploading,
                Location = null
            });
            result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <NotFoundResult>();

            appService.GetByIdAsync(md5)
            .Returns(new AttachmentItem
            {
                Id       = md5,
                Status   = UploadStatus.Uploaded,
                Location = null
            });
            result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <NotFoundResult>();

            var dto = new AttachmentItem
            {
                Id       = md5,
                Status   = UploadStatus.Uploaded,
                Location = "abc.ext"
            };

            appService.GetByIdAsync(md5)
            .Returns(dto);
            storeService.FillMemoryStreamAsync(dto, Arg.Any <MemoryStream>())
            .Returns(Task.CompletedTask);
            result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <FileStreamResult>();

            await storeService.Received().FillMemoryStreamAsync(dto, Arg.Any <MemoryStream>());
        }
        //TODO FIX TestDownloadThumbnailsAsync
        //[TestMethod]
        public async Task TestDownloadThumbnailsAsync()
        {
            var md5      = Guid.NewGuid().ToString("N");
            var formFile = Substitute.For <IFormFile>();

            var appService = Substitute.For <IAttachmentAppService>();

            IAttachmentAppService factory(string id) => appService;

            var cacheDict    = new Dictionary <string, byte[]>();
            var storeService = Substitute.For <IAttachmentStoreService>();
            var cache        = Substitute.For <IMemoryCache>();

            cache.Set(Arg.Any <string>(), Arg.Any <byte[]>(), Arg.Any <TimeSpan>())
            .Returns(x =>
            {
                return(x[1] as byte[]);
            });
            cache.TryGetValue(Arg.Any <string>(), out Arg.Any <byte[]>())
            .Returns(x =>
            {
                if (cacheDict.ContainsKey(x[0].ToString()))
                {
                    x[1] = cacheDict[x[0].ToString()];
                    return(true);
                }
                return(false);
            });

            var target = new AttachmentController(factory, storeService, cache);

            target.ControllerContext = CreateMockContext();

            var result = await target.DownloadThumbnailsAsync(md5, null);

            result.Should().BeOfType <NotFoundResult>();

            appService.GetByIdAsync(md5)
            .Returns(new AttachmentItem
            {
                Id       = md5,
                Status   = UploadStatus.Uploading,
                Location = null
            });
            result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <NotFoundResult>();

            appService.GetByIdAsync(md5)
            .Returns(new AttachmentItem
            {
                Id       = md5,
                Status   = UploadStatus.Uploaded,
                Location = null
            });
            result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <NotFoundResult>();

            var dto = new AttachmentItem
            {
                Id       = md5,
                Status   = UploadStatus.Uploaded,
                Location = "abc.jpg"
            };

            appService.GetByIdAsync(md5)
            .Returns(dto);
            storeService.FillMemoryStreamAsync(dto, Arg.Any <MemoryStream>())
            .Returns(Task.CompletedTask);
            result = await target.DownloadFileAsync(md5, null);

            result.Should().BeOfType <FileStreamResult>();

            await storeService.Received().FillMemoryStreamAsync(dto, Arg.Any <MemoryStream>());
        }