public void TestGetImage( ) { PhotoFileType image1Entity = null; try { // Create the image image1Entity = CreateImage1( ); using (var request = new PlatformHttpRequest(string.Format(@"data/v1/image/{0}", image1Entity.Id))) { HttpWebResponse response = request.GetResponse( ); // check that it worked (200) Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); using (var ms = new MemoryStream( )) using (var originalImage = new MemoryStream( )) { using (Stream dataStream = response.GetResponseStream( )) { Assert.IsNotNull(dataStream); dataStream.CopyTo(ms); } // Get the actual image as a memory stream using (FileStream fs = File.Open(Image1Jpg, FileMode.Open, FileAccess.Read, FileShare.Read)) { fs.CopyTo(originalImage); } Sha256FileTokenProvider tokenProvider = new Sha256FileTokenProvider(); // Compare the values string streamHash = tokenProvider.ComputeToken(ms); string fileHash = tokenProvider.ComputeToken(originalImage); string eTagValue = response.Headers.Get("ETag"); Assert.AreEqual(fileHash, streamHash, "The file hash is invalid"); Assert.AreEqual("\"" + fileHash + "\"", eTagValue, "The ETag value is invalid"); } } } finally { if (image1Entity != null) { image1Entity.Delete( ); } } }
public void TestGetImageThumbnail( ) { PhotoFileType image1Entity = null; try { // Create the image image1Entity = CreateImage1( ); var thumbnailSize = Entity.Get <ThumbnailSizeEnum>(new EntityRef("console", "smallThumbnail")); // Get the thumbnail using ( var request = new PlatformHttpRequest(string.Format(@"data/v1/image/thumbnail/{0}/console-smallThumbnail/core-cropImage", image1Entity.Id))) { HttpWebResponse response = request.GetResponse( ); // check that it worked (200) Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); using (var ms = new MemoryStream( )) { using (Stream dataStream = response.GetResponseStream( )) { Assert.IsNotNull(dataStream); dataStream.CopyTo(ms); } using (Image image = Image.FromStream(ms)) { Assert.AreEqual(image.Width, thumbnailSize.ThumbnailWidth, "The image width is invalid"); Assert.AreEqual(image.Height, thumbnailSize.ThumbnailHeight, "The image height is invalid"); } Sha256FileTokenProvider tokenProvider = new Sha256FileTokenProvider(); string streamHash = tokenProvider.ComputeToken(ms); string fileHash; using (FileStream fs = File.Open(Image1Jpg, FileMode.Open, FileAccess.Read, FileShare.Read)) { fileHash = tokenProvider.ComputeToken(fs); } Assert.AreNotEqual(fileHash, streamHash, "The file hash should not match"); string eTagValue = response.Headers.Get("ETag"); string expectedETag = GetImageThumbnailETag(fileHash, new EntityRef("console", "smallThumbnail"), new EntityRef("core", "cropImage")); Assert.AreNotEqual("\"" + expectedETag + "\"", eTagValue, "The ETag is invalid"); } } } finally { if (image1Entity != null) { image1Entity.Delete( ); } } }