1

I am pretty new to all this, so any help would be appreciated.

I have created a download image from url method and i need to test it. i have tried filling in the test parameters but i am unsure of what i am meant to be putting in.

Could you please tell me whats meant to go where,

Thank You. Aaron

[TestMethod()]
public void DownloadImageFromURLTest()
{
    string url = "http://www.omnimedicalsearch.com/conditions-diseases/images/skin-mole.jpg";
    Image expected = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\skin-mole.jpg");
    Image actual = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\skin-mole.jpg"); ;
    actual = CloudConnection.DownloadImageFromURL(url);
    Assert.AreEqual(expected, actual);
    Assert.Inconclusive("Verify the correctness of this test method.");
}

4 Answers 4

2

Try this:

  string url = "http://www.omnimedicalsearch.com/conditions-diseases/images/skin-mole.jpg";
  Image expected = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\skin-mole.jpg");
  Image actual = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\skin-mole.jpg"); ;
  actual = CloudConnection.DownloadImageFromURL(url);

  MemoryStream ms = new MemoryStream();
  expected.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  String expectedBitmap = Convert.ToBase64String(ms.ToArray());
  ms.Position = 0;
  actual.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  String actualBitmap = Convert.ToBase64String(ms.ToArray());

  Assert.AreEqual(expectedBitmap, actualBitmap);
Sign up to request clarification or add additional context in comments.

Comments

1

I wouldn't particularly expect Image to override Equals - there are loads of different ways in which you might want equality. It would make more sense to compare the data in the two streams (the file and the web version).

Comments

1

I don't think that Assert.Equal(Image, Image) will compare the contents of the two images instead it will be comparing the references. You should write a method that manually compare the two images

You can convert the images to Bitmap and then compare the bitmaps

Take a look at Comparing Two Images in C#

Comments

0

expected and actual are references to different objects.

Assert.AreEqual will only be able to compare the two images as references, as Image doesn't override Equals - there is no facility to check that the images have identical content. You will need to write this yourself.

3 Comments

Thanks for the quick reply, As i said im still very new to this, How would i go about making this work?
@user1081326 - There are no test methods that will do that for you. You need to compare the images byte by byte, or pixel by pixel (though first comparing the dimensions could be a good optimization).
@AzharKhorasany - You mean your answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.