Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermanussen/570c556e02ab7cbc7ca854ddb23072e6 to your computer and use it in GitHub Desktop.
Save hermanussen/570c556e02ab7cbc7ca854ddb23072e6 to your computer and use it in GitHub Desktop.
[TestMethod]
[Description("Tests the import of an image into the media library")]
public void TestImageImport()
{
string sampleImage = ConfigurationManager.AppSettings["sampleimage"];
SampleSitecoreLogic.ImportImage(sampleImage);
// Get the imported media item
MediaItem imported = new MediaItem(Sitecore.Context.Database.GetItem("/sitecore/media library/Cdm"));
Assert.IsNotNull(imported, "Imported image could not be found");
Assert.AreEqual("Image", imported.InnerItem.TemplateName);
// Get the imported image data and put it in a memory stream
MemoryStream memoryStream = new MemoryStream();
imported.GetMediaStream().CopyTo(memoryStream);
Assert.IsTrue(
Sitecore.IO.FileUtil.ReadBinaryFile(sampleImage).SequenceEqual(memoryStream.ToArray()),
"The imported image's content is different from the file");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment