/// <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")); } }
public void GetObjectIdTest() { var objectId = new ObjectId(); var appointment = new AppointmentBuilder().SetObjectId(objectId).Build(); new DiaryProductTest().GetObjectIdTest(appointment, objectId); }
/// <summary> /// Testing of end time method. /// </summary> internal void GetEndTimeTest(AppointmentBuilder builder, Diary.DateTime occurs, Diary.DateTime endTime, int durationMinutes) { var appointment = (Appointment)builder.SetOccurs(occurs).SetDurationMinutes(durationMinutes).Build(); var actualEndTime = appointment.GetEndTime(); // Validate results. var expected = Helper.ToString(endTime); var actual = Helper.ToString(actualEndTime); Assert.AreEqual(expected, actual, "Input occurs:<{0}>. Input durationMinutes:<{1}>.", Helper.ToString(occurs), durationMinutes); }
public void AppointmentConstructorTest() { var builder = new AppointmentBuilder(); builder.SetLabel("Test Label"); builder.SetDetails("Detail text"); builder.SetOccurs(new Diary.DateTime(new Date(6, Date.Month.MAY, 2017), 10, 3)); builder.SetDurationMinutes(42); Helper.AssertAreEqual(builder, (Appointment)builder.Build(), ""); }
public void GetContactsTest() { var builder = new AppointmentBuilder(); var appointment = (Appointment)builder.SetContactBuilders().Build(); var contactBuilders = builder.GetContactBuilders(); foreach (var contactBuilder in contactBuilders) { appointment.AddRelation((Contact)contactBuilder.Build()); } Helper.AssertAreEqual(builder, appointment, ""); }
public void ConstructorAliasingTest() { var builder = new AppointmentBuilder(); var dateTime = new Diary.DateTime(); var appointment = (Appointment)builder.SetOccurs(dateTime).Build(); var expected = 0; var actual = appointment.GetStartTime().GetMinutes(); Assert.AreEqual(expected, actual, "Original"); dateTime.AddTime(0, 1); actual = appointment.GetStartTime().GetMinutes(); Assert.AreEqual(expected, actual, "After"); }