| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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<Person> peopleExpected = new List<Person>();
- List<Person> 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<Person>.Create((x, y) => x.FirstName == y.FirstName && x.LastName == y.LastName ? 0 : 1));
- }
- [TestMethod]
- public void AreCollectionsEquivalentTest()
- {
- PersonManager mgr = new PersonManager();
- List<Person> peopleExpected = new List<Person>();
- List<Person> 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<Person> peopleActual = new List<Person>();
- peopleActual = mgr.GetSupervisors();
- CollectionAssert.AllItemsAreInstancesOfType(peopleActual, typeof(Supervisor));
- }
- [TestMethod]
- public void AreCollectionsEqualTest()
- {
- PersonManager mgr = new PersonManager();
- List<Person> peopleExpected = new List<Person>();
- List<Person> peopleActual = new List<Person>();
- 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<Person> peopleExpected = new List<Person>();
- List<Person> peopleActual = new List<Person>();
- 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);
- }
- }
- }
|