Example #1
0
        /// <summary>
        /// Tests all Appointment fields match the expected values.
        /// </summary>
        /// <see href="https://www.martinfowler.com/bliki/AliasingBug.html">About deep copy and aliasing bugs.</see>
        /// <remarks>Calculated fields, such as EndTime, are tested elsewhere because they are not required
        /// to validate all the data fields passed into the constructor match expected values.</remarks>
        internal static void AssertAreEqual(AppointmentBuilder expected, Appointment actual, string message)
        {
            var messagePrefix = String.Format("{0} Label:<{1}>.", message, expected.GetLabel());

            Assert.AreEqual(expected.GetDetails(), actual.GetDetails(), String.Concat(messagePrefix, " details"));
            Assert.AreEqual(expected.GetDurationMinutes(), actual.GetDurationMinutes(), String.Concat(messagePrefix, " durationMinutes"));
            Assert.AreEqual(false, actual.IsRepeating(), String.Concat(messagePrefix, " IsRepeating"));
            Assert.AreEqual(expected.GetLabel(), actual.GetLabel(), String.Concat(messagePrefix, " label"));

            Assert.AreEqual(ToString(expected.GetOccurs()), ToString(actual.GetStartTime()), String.Concat(messagePrefix, " startTime"));
            Assert.AreNotSame(actual.GetStartTime(), actual.GetStartTime(), String.Concat(messagePrefix, " startTime deep copy"));

            var expectedClassId = new ClassId("Appointment");

            Assert.AreEqual(0, actual.GetClassId().CompareTo(expectedClassId), String.Concat(messagePrefix, " classId"));

            //Test Contact relations
            var relation        = actual.GetContacts();
            var contactBuilders = expected.GetContactBuilders();

            Assert.AreEqual(contactBuilders.Length, relation.GetChildCount(), String.Concat(messagePrefix, " contacts.Count"));

            for (int i = 0; i < contactBuilders.Length; i++)
            {
                Helper.AssertAreEqual(contactBuilders[i], relation.GetChild(i), String.Concat(messagePrefix, " contacts[", i.ToString(), "].Data"));
            }
        }