예제 #1
0
        public async Task <ActionResult> Thumbnail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(HttpNotFound());
            }

            var file = await this.store.FindByIdAsync(id);

            if (file == null)
            {
                return(HttpNotFound());
            }
            var outStream = new MemoryStream();

            using (var stream = new MemoryStream())
            {
                await file.WriteAsync(stream);

                stream.Position = 0;

                ThumbnailProcessor.RenderThumbnail(stream, this.thumbnailPreset, outStream);
                outStream.Position = 0;
                return(File(outStream, "image/jpeg"));
            }
        }
        public void TestInitialize()
        {
            this.imageService = new Mock <IImageService>(MockBehavior.Strict);
            this.logger       = new Mock <ILogger>();

            this.storageAccount = new Mock <ICloudStorageAccount>();
            this.blobClient     = new Mock <ICloudBlobClient>();
            this.container      = new Mock <ICloudBlobContainer>();
            this.output         = new Mock <ICloudBlockBlob>();
            this.output2        = new Mock <ICloudBlockBlob>();

            this.input = new Mock <ICloudBlockBlob>();
            var inputProperties = new Mock <IBlobProperties>();

            inputProperties.Setup(v => v.CacheControl).Returns("cache-control");
            this.input.Setup(v => v.Properties).Returns(inputProperties.Object);
            input.Setup(v => v.SetMetadataAsync()).Returns(Task.FromResult(0));

            this.inputMetadata = new Dictionary <string, string>();
            this.input.Setup(v => v.Metadata).Returns(this.inputMetadata);

            this.storageAccount.Setup(v => v.CreateCloudBlobClient()).Returns(this.blobClient.Object);
            this.blobClient.Setup(v => v.GetContainerReference(ContainerName)).Returns(this.container.Object);
            this.container.Setup(v => v.GetBlockBlobReference(OutputBlobName)).Returns(this.output.Object);
            this.container.Setup(v => v.GetBlockBlobReference(OutputBlobName2)).Returns(this.output2.Object);

            this.outputProperties = new Mock <IBlobProperties>();
            this.output.Setup(v => v.Properties).Returns(this.outputProperties.Object);
            this.output.Setup(v => v.SetPropertiesAsync(CancellationToken.None)).Returns(Task.FromResult(0));
            this.outputProperties.SetupProperty(v => v.ContentType, null);
            this.outputProperties.SetupProperty(v => v.CacheControl, null);

            this.outputProperties2 = new Mock <IBlobProperties>();
            this.output2.Setup(v => v.Properties).Returns(this.outputProperties2.Object);
            this.output2.Setup(v => v.SetPropertiesAsync(CancellationToken.None)).Returns(Task.FromResult(0));
            this.outputProperties2.SetupProperty(v => v.ContentType, null);
            this.outputProperties2.SetupProperty(v => v.CacheControl, null);

            this.outputMetadata  = new Dictionary <string, string>();
            this.outputMetadata2 = new Dictionary <string, string>();
            this.output.Setup(v => v.Metadata).Returns(this.outputMetadata);
            this.output2.Setup(v => v.Metadata).Returns(this.outputMetadata2);

            this.outputStream = new MockCloudBlobStream();
            this.output.Setup(v => v.OpenWriteAsync(CancellationToken.None)).ReturnsAsync(this.outputStream);

            this.outputStream2 = new MockCloudBlobStream();
            this.output2.Setup(v => v.OpenWriteAsync(CancellationToken.None)).ReturnsAsync(this.outputStream2);

            this.target = new ThumbnailProcessor(this.imageService.Object);
        }