user1081326
user1081326

Reputation: 425

Assert.AreEqual failed Error C#

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.");
}

Upvotes: 1

Views: 1719

Answers (4)

Azhar Khorasany
Azhar Khorasany

Reputation: 2709

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);

Upvotes: 2

Haris Hasan
Haris Hasan

Reputation: 30097

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#

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500525

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).

Upvotes: 1

Oded
Oded

Reputation: 499002

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.

Upvotes: 0

Related Questions