I have a method which takes in a list collection of objects. The idea is the method will check a specific field CoverArt
in each of the objects passed into it and if the CoverArt
property is null, an empty string, or an empty space, it will set it to a default value. If the CoverArt
property is not null, empty string, or a white space, it just returns whatever string is in there already.
//checks a list of stories for cover art and sets cover art to a default if it is null
public string CheckIfCoverArtIsNullForStoryList(List<Story> stories)
{
foreach (var story in stories)
{
if (story.CoverArt == null || story.CoverArt == "" || story.CoverArt == " ")
{
return story.CoverArt = "default-book.png";
}
return story.CoverArt;
}
return "";
}
What I'm trying to do is create a unit test that will test whether or not this method even works but I'm having difficult trying to compare two lists. What is wrong with my code?
[TestMethod]
[Description("Tests list of stories for null cover art")]
public void TestingStoryListCoverArtMethodWithValidInput()
{
List<Story> StoryListActual = new List<Story>()
{
new Story()
{
CoverArt = "Lord of the Rings.png"
},
new Story()
{
CoverArt = "Johnny Appleseed.jpeg"
},
new Story()
{
CoverArt = "The Great Gatsby.jpg"
},
new Story()
{
CoverArt = "Happy Gilmore.gif"
}
};
List<Story> CoverArtExpected = new List<Story>()
{
new Story()
{
CoverArt = "Lord of the Rings.png"
},
new Story()
{
CoverArt = "Johnny Appleseed.jpeg"
},
new Story()
{
CoverArt = "The Great Gatsby.jpg"
},
new Story()
{
CoverArt = "Happy Gilmore.gif"
}
};
helper.CheckIfCoverArtIsNullForStoryList(StoryListActual);
for (var i = 0; i < StoryListActual.Count; i++)
{
for (var j = 0; j < CoverArtExpected.Count; j++)
{
Assert.AreEqual(StoryListActual[i].CoverArt, CoverArtExpected[j].CoverArt);
}
}
}
My unit testing is failing with this message.