CollectionAssertClassTest.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using MyClasses.PersonClasses;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace MyClassesTest
  9. {
  10. [TestClass]
  11. public class CollectionAssertClassTest : TestBase
  12. {
  13. [TestMethod]
  14. public void AreCollectionsEqualWithComparerTest()
  15. {
  16. PersonManager mgr = new PersonManager();
  17. List<Person> peopleExpected = new List<Person>();
  18. List<Person> peopleActual;
  19. peopleExpected.Add(new Person() { FirstName = "Paul", LastName = "Sheriff" });
  20. peopleExpected.Add(new Person() { FirstName = "John", LastName = "Kuhn" });
  21. peopleExpected.Add(new Person() { FirstName = "Jim", LastName = "Rulh" });
  22. peopleActual = mgr.GetPeople();
  23. // Note : By default it compares the person objects to see if they are Equal (the
  24. CollectionAssert.AreEqual(peopleExpected, peopleActual,
  25. Comparer<Person>.Create((x, y) => x.FirstName == y.FirstName && x.LastName == y.LastName ? 0 : 1));
  26. }
  27. [TestMethod]
  28. public void AreCollectionsEquivalentTest()
  29. {
  30. PersonManager mgr = new PersonManager();
  31. List<Person> peopleExpected = new List<Person>();
  32. List<Person> peopleActual;
  33. // Get Person objects
  34. peopleActual = mgr.GetPeople();
  35. // Add same Person objects to new collection, but in a different order
  36. peopleExpected.Add(peopleActual[1]);
  37. peopleExpected.Add(peopleActual[2]);
  38. peopleExpected.Add(peopleActual[0]);
  39. CollectionAssert.AreEquivalent(peopleExpected, peopleActual);
  40. }
  41. [TestMethod]
  42. public void IsCollectionOfTypeTest()
  43. {
  44. PersonManager mgr = new PersonManager();
  45. List<Person> peopleActual = new List<Person>();
  46. peopleActual = mgr.GetSupervisors();
  47. CollectionAssert.AllItemsAreInstancesOfType(peopleActual, typeof(Supervisor));
  48. }
  49. [TestMethod]
  50. public void AreCollectionsEqualTest()
  51. {
  52. PersonManager mgr = new PersonManager();
  53. List<Person> peopleExpected = new List<Person>();
  54. List<Person> peopleActual = new List<Person>();
  55. peopleActual = mgr.GetPeople();
  56. peopleExpected = peopleActual;
  57. // Note : By default it compares the person objects to see if they are Equal (the
  58. CollectionAssert.AreEqual(peopleExpected, peopleActual);
  59. }
  60. //[TestMethod]
  61. public void AreCollectionsEqual()
  62. {
  63. PersonManager mgr = new PersonManager();
  64. List<Person> peopleExpected = new List<Person>();
  65. List<Person> peopleActual = new List<Person>();
  66. peopleExpected.Add(new Person() { FirstName = "Paul", LastName = "Sheriff" });
  67. peopleExpected.Add(new Person() { FirstName = "John", LastName = "Kuhn" });
  68. peopleExpected.Add(new Person() { FirstName = "Jim", LastName = "Rulh" });
  69. peopleActual = mgr.GetPeople();
  70. // Note : By default it compares the person objects to see if they are Equal (the
  71. CollectionAssert.AreEqual(peopleExpected, peopleActual);
  72. }
  73. }
  74. }