public void Test_ConvertToObjectList_EmptyReturnsEmpty() { XElement xe = null; List <LingoWordModel> actualResult = FileManagementHelper.ConvertToObjectList(xe); List <LingoWordModel> expectedResult = new List <LingoWordModel>(); Assert.AreEqual(expectedResult.Count, actualResult.Count); Assert.AreEqual(0, actualResult.Count); }
public void Test_ConvertToObjectList() { List <LingoWordModel> expectedResult = new List <LingoWordModel>(2); LingoWordModel lwm = null; for (int index = 1; index < 3; index++) { lwm = new LingoWordModel(); lwm.Category = $"Convert { index }"; lwm.Word = $"Alpha { index }"; expectedResult.Add(lwm); } XElement xEl = new XElement( new XElement("Root", new XElement("Item", new XElement("Category", "Convert 1"), new XElement("Word", "Alpha 1") ), new XElement("Item", new XElement("Category", "Convert 2"), new XElement("Word", "Alpha 2") ))); int matchCount = 0; int totalCount = 0; List <LingoWordModel> actualResult = FileManagementHelper.ConvertToObjectList(xEl); if (actualResult.Count > 0) { for (int jindex = 0; jindex < actualResult.Count; jindex++) { if (expectedResult[jindex].Category == actualResult[jindex].Category) { matchCount++; } totalCount++; if (expectedResult[jindex].Word == actualResult[jindex].Word) { matchCount++; } totalCount++; } } Assert.AreEqual(expectedResult.Count, actualResult.Count); // if equal than both lists have same number of objects Assert.AreEqual(totalCount, matchCount); // if equal than all if conditionals returned true }