using Microsoft.VisualStudio.TestTools.UnitTesting; using MyClasses.PersonClasses; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyClassesTest { [TestClass] public class CollectionAssertClassTest : TestBase { [TestMethod] public void AreCollectionsEqualWithComparerTest() { PersonManager mgr = new PersonManager(); List peopleExpected = new List(); List peopleActual; peopleExpected.Add(new Person() { FirstName = "Paul", LastName = "Sheriff" }); peopleExpected.Add(new Person() { FirstName = "John", LastName = "Kuhn" }); peopleExpected.Add(new Person() { FirstName = "Jim", LastName = "Rulh" }); peopleActual = mgr.GetPeople(); // Note : By default it compares the person objects to see if they are Equal (the CollectionAssert.AreEqual(peopleExpected, peopleActual, Comparer.Create((x, y) => x.FirstName == y.FirstName && x.LastName == y.LastName ? 0 : 1)); } [TestMethod] public void AreCollectionsEquivalentTest() { PersonManager mgr = new PersonManager(); List peopleExpected = new List(); List peopleActual; // Get Person objects peopleActual = mgr.GetPeople(); // Add same Person objects to new collection, but in a different order peopleExpected.Add(peopleActual[1]); peopleExpected.Add(peopleActual[2]); peopleExpected.Add(peopleActual[0]); CollectionAssert.AreEquivalent(peopleExpected, peopleActual); } [TestMethod] public void IsCollectionOfTypeTest() { PersonManager mgr = new PersonManager(); List peopleActual = new List(); peopleActual = mgr.GetSupervisors(); CollectionAssert.AllItemsAreInstancesOfType(peopleActual, typeof(Supervisor)); } [TestMethod] public void AreCollectionsEqualTest() { PersonManager mgr = new PersonManager(); List peopleExpected = new List(); List peopleActual = new List(); peopleActual = mgr.GetPeople(); peopleExpected = peopleActual; // Note : By default it compares the person objects to see if they are Equal (the CollectionAssert.AreEqual(peopleExpected, peopleActual); } //[TestMethod] public void AreCollectionsEqual() { PersonManager mgr = new PersonManager(); List peopleExpected = new List(); List peopleActual = new List(); peopleExpected.Add(new Person() { FirstName = "Paul", LastName = "Sheriff" }); peopleExpected.Add(new Person() { FirstName = "John", LastName = "Kuhn" }); peopleExpected.Add(new Person() { FirstName = "Jim", LastName = "Rulh" }); peopleActual = mgr.GetPeople(); // Note : By default it compares the person objects to see if they are Equal (the CollectionAssert.AreEqual(peopleExpected, peopleActual); } } }