public void ConstructorNotToExceedDateTimeAliasingTest()
        {
            var occurs = new DateTime(new Date(1, Date.Month.JANUARY, 2000), 0, 0);
            var notToExceedDateTime = new Diary.DateTime(occurs);

            var occurenceDate = new Date(2, Date.Month.JANUARY, 2000);

            var builder = new PeriodicAppointmentBuilder();

            builder.SetOccurs(occurs);
            builder.SetPeriodHours(24);
            builder.SetNotToExceedDateTime(notToExceedDateTime);
            var appointment = (PeriodicAppointment)builder.Build();

            var expected = false;
            var actual   = appointment.IsOccuringOn(occurenceDate);

            Assert.AreEqual(expected, actual, "Original");

            notToExceedDateTime.AddTime(100, 0);

            actual = appointment.IsOccuringOn(occurenceDate);

            Assert.AreEqual(expected, actual, "After");
        }
Exemple #2
0
        public void IsBetweenTest()
        {
            var startDay     = int.Parse(TestContext.DataRow["startDay"].ToString());
            var startMonth   = int.Parse(TestContext.DataRow["startMonth"].ToString());
            var startYear    = int.Parse(TestContext.DataRow["startYear"].ToString());
            var startHours   = int.Parse(TestContext.DataRow["startHours"].ToString());
            var startMinutes = int.Parse(TestContext.DataRow["startMinutes"].ToString());

            var endDay     = int.Parse(TestContext.DataRow["endDay"].ToString());
            var endMonth   = int.Parse(TestContext.DataRow["endMonth"].ToString());
            var endYear    = int.Parse(TestContext.DataRow["endYear"].ToString());
            var endHours   = int.Parse(TestContext.DataRow["endHours"].ToString());
            var endMinutes = int.Parse(TestContext.DataRow["endMinutes"].ToString());

            var day     = int.Parse(TestContext.DataRow["Day"].ToString());
            var month   = int.Parse(TestContext.DataRow["Month"].ToString());
            var year    = int.Parse(TestContext.DataRow["Year"].ToString());
            var hours   = int.Parse(TestContext.DataRow["hours"].ToString());
            var minutes = int.Parse(TestContext.DataRow["minutes"].ToString());

            var  expectedIsBetweenString = TestContext.DataRow["isBetween"].ToString();
            bool expected = (expectedIsBetweenString == "1");

            var startDateTime = new Diary.DateTime(new Date(startDay, (Date.Month)startMonth, startYear), startHours, startMinutes);
            var endDateTime   = new Diary.DateTime(new Date(endDay, (Date.Month)endMonth, endYear), endHours, endMinutes);
            var dateTime      = new Diary.DateTime(new Date(day, (Date.Month)month, year), hours, minutes);

            var actual = dateTime.IsBetween(startDateTime, endDateTime);

            var message = String.Format("Input DateTime:<{0}>. Input Start DateTime:<{1}>. Input End DateTime:<{2}>.", Helper.ToString(dateTime), Helper.ToString(startDateTime), Helper.ToString(endDateTime));

            Assert.AreEqual(expected, actual, message);
        }
Exemple #3
0
        public void IsOccuringOnTest()
        {
            // Get input data for test.
            var startYear    = int.Parse(TestContext.DataRow["startYear"].ToString());
            var startMonth   = int.Parse(TestContext.DataRow["startMonth"].ToString());
            var startDay     = int.Parse(TestContext.DataRow["startDay"].ToString());
            var startHours   = int.Parse(TestContext.DataRow["startHours"].ToString());
            var startMinutes = int.Parse(TestContext.DataRow["startMinutes"].ToString());

            var endYear    = int.Parse(TestContext.DataRow["endYear"].ToString());
            var endMonth   = int.Parse(TestContext.DataRow["endMonth"].ToString());
            var endDay     = int.Parse(TestContext.DataRow["endDay"].ToString());
            var endHours   = int.Parse(TestContext.DataRow["endHours"].ToString());
            var endMinutes = int.Parse(TestContext.DataRow["endMinutes"].ToString());

            var durationMinutes = int.Parse(TestContext.DataRow["durationMinutes"].ToString());

            // Create appointment and exercise the method under test.
            var expectedStartDate = new Date(startDay, (Date.Month)startMonth, startYear);
            var appointmentTime   = new Diary.DateTime(expectedStartDate, startHours, startMinutes);
            var appointment       = (Appointment) new AppointmentBuilder().SetOccurs(appointmentTime).SetDurationMinutes(durationMinutes).Build();
            var expectedEndDate   = new Date(endDay, (Date.Month)endMonth, endYear);

            CalendarEventTest.IsOccuringOnTest(appointment, expectedStartDate, expectedEndDate);
        }
Exemple #4
0
        public void AddTimeTest()
        {
            var dateTime = new Diary.DateTime(new Date(1, Date.Month.JANUARY, 1900), 0, 0);

            dateTime.AddTime(1, 1);


            Assert.AreEqual("1900-01-01 01:01", Helper.ToString(dateTime));
        }
Exemple #5
0
        /// <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);
        }
        internal AppointmentBuilder SetOccurs(Diary.DateTime occurs)
        {
            this.occurs = new Diary.DateTime(occurs);

            // Add descriptive info to the label if we don't have an explicit one provided. This provide identifying information for debugging.
            if (label == String.Empty)
            {
                label = String.Format("Event Label <{0}>.", Helper.ToString(occurs));
            }

            return(this);
        }
        public void IsOccuringOnTest()
        {
            // Get input occurence data for test.
            var firstOccursYear    = int.Parse(TestContext.DataRow["firstOccursYear"].ToString());
            var firstOccursMonth   = int.Parse(TestContext.DataRow["firstOccursMonth"].ToString());
            var firstOccursDay     = int.Parse(TestContext.DataRow["firstOccursDay"].ToString());
            var firstOccursHours   = int.Parse(TestContext.DataRow["firstOccursHours"].ToString());
            var firstOccursMinutes = int.Parse(TestContext.DataRow["firstOccursMinutes"].ToString());

            var notToExceedYear    = int.Parse(TestContext.DataRow["notToExceedYear"].ToString());
            var notToExceedMonth   = int.Parse(TestContext.DataRow["notToExceedMonth"].ToString());
            var notToExceedDay     = int.Parse(TestContext.DataRow["notToExceedDay"].ToString());
            var notToExceedHours   = int.Parse(TestContext.DataRow["notToExceedHours"].ToString());
            var notToExceedMinutes = int.Parse(TestContext.DataRow["notToExceedMinutes"].ToString());

            var durationMinutes = int.Parse(TestContext.DataRow["durationMinutes"].ToString());
            var periodHours     = int.Parse(TestContext.DataRow["periodHours"].ToString());

            // Create the periodic appointment, deriving the overall start and end date
            var firstOccurs         = new Diary.DateTime(new Date(firstOccursDay, (Date.Month)firstOccursMonth, firstOccursYear), firstOccursHours, firstOccursMinutes);
            var notToExceedDateTime = new Diary.DateTime(new Date(notToExceedDay, (Date.Month)notToExceedMonth, notToExceedYear), notToExceedHours, notToExceedMinutes);

            PeriodicAppointmentBuilder builder = new PeriodicAppointmentBuilder();

            builder.SetOccurs(firstOccurs);
            builder.SetDurationMinutes(durationMinutes);
            builder.SetNotToExceedDateTime(notToExceedDateTime);
            builder.SetPeriodHours(periodHours);
            var appointment = (PeriodicAppointment)builder.Build();

            // Look up and evaluate each occurence
            DataRow[] occurencesRows = TestContext.DataRow.GetChildRows("add_occurences");

            foreach (DataRow occurenceRow in occurencesRows)
            {
                DataRow[] occurenceDatePartRows = occurenceRow.GetChildRows("occurences_occurence");
                foreach (DataRow occurenceDatePart in occurenceDatePartRows)
                {
                    var startYear  = int.Parse(occurenceDatePart["startYear"].ToString());
                    var startMonth = int.Parse(occurenceDatePart["startMonth"].ToString());
                    var startDay   = int.Parse(occurenceDatePart["startDay"].ToString());

                    var endYear  = int.Parse(occurenceDatePart["endYear"].ToString());
                    var endMonth = int.Parse(occurenceDatePart["endMonth"].ToString());
                    var endDay   = int.Parse(occurenceDatePart["endDay"].ToString());

                    var expectedStartDate = new Date(startDay, (Date.Month)startMonth, startYear);
                    var expectedEndDate   = new Date(endDay, (Date.Month)endMonth, endYear);

                    CalendarEventTest.IsOccuringOnTest(appointment, expectedStartDate, expectedEndDate);
                }
            }
        }
Exemple #8
0
        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");
        }
        public void TestDateTimeElement()
        {
            var record = new VariableLengthRecord();

            var value1 = new Diary.DateTime(new Date(30, Date.Month.JUNE, 2018), 6, 15);

            Assert.AreEqual(0, record.GetCount());
            record.AppendValue(value1);
            Assert.AreEqual(1, record.GetCount());
            var value = new Diary.DateTime();

            Assert.IsTrue(record.GetValue(0, ref value));
            Assert.AreEqual(Helper.ToString(value1), Helper.ToString(value));

            var value2 = new Diary.DateTime(new Date(15, Date.Month.JANUARY, 1980), 21, 30);

            record.AppendValue(value2);
            Assert.AreEqual(2, record.GetCount());
            Assert.IsTrue(record.GetValue(1, ref value));
            Assert.AreEqual(Helper.ToString(value2), Helper.ToString(value));
        }
Exemple #10
0
        public void CompareToTest()
        {
            var day     = int.Parse(TestContext.DataRow["day"].ToString());
            var month   = int.Parse(TestContext.DataRow["month"].ToString());
            var year    = int.Parse(TestContext.DataRow["year"].ToString());
            var hours   = int.Parse(TestContext.DataRow["hours"].ToString());
            var minutes = int.Parse(TestContext.DataRow["minutes"].ToString());

            var compareDay     = int.Parse(TestContext.DataRow["compareDay"].ToString());
            var compareMonth   = int.Parse(TestContext.DataRow["compareMonth"].ToString());
            var compareYear    = int.Parse(TestContext.DataRow["compareYear"].ToString());
            var compareHours   = int.Parse(TestContext.DataRow["compareHours"].ToString());
            var compareMinutes = int.Parse(TestContext.DataRow["compareMinutes"].ToString());

            var expected = int.Parse(TestContext.DataRow["expectedResult"].ToString());

            var dateTime        = new Diary.DateTime(new Date(day, (Date.Month)month, year), hours, minutes);
            var compareDateTime = new Diary.DateTime(new Date(compareDay, (Date.Month)compareMonth, compareYear), compareHours, compareMinutes);

            var actual = dateTime.CompareTo(compareDateTime);

            Assert.AreEqual(expected, actual, "Input DateTime:<{0}>. Input Compare DateTime:<{1}>.", Helper.ToString(dateTime), Helper.ToString(compareDateTime));
        }
        public void GetEndTimeTest()
        {
            // Get input data for test.
            var startYear    = int.Parse(TestContext.DataRow["startYear"].ToString());
            var startMonth   = int.Parse(TestContext.DataRow["startMonth"].ToString());
            var startDay     = int.Parse(TestContext.DataRow["startDay"].ToString());
            var startHours   = int.Parse(TestContext.DataRow["startHours"].ToString());
            var startMinutes = int.Parse(TestContext.DataRow["startMinutes"].ToString());

            var endYear    = int.Parse(TestContext.DataRow["endYear"].ToString());
            var endMonth   = int.Parse(TestContext.DataRow["endMonth"].ToString());
            var endDay     = int.Parse(TestContext.DataRow["endDay"].ToString());
            var endHours   = int.Parse(TestContext.DataRow["endHours"].ToString());
            var endMinutes = int.Parse(TestContext.DataRow["endMinutes"].ToString());

            var durationMinutes = int.Parse(TestContext.DataRow["durationMinutes"].ToString());

            // Exercise the method under test.
            var occurs  = new Diary.DateTime(new Date(startDay, (Date.Month)startMonth, startYear), startHours, startMinutes);
            var endTime = new Diary.DateTime(new Date(endDay, (Date.Month)endMonth, endYear), endHours, endMinutes);

            new AppointmentTest().GetEndTimeTest(new PeriodicAppointmentBuilder().SetNotToExceedDateTime(endTime), occurs, endTime, durationMinutes);
        }
Exemple #12
0
        public void DefaultConstructorTest()
        {
            var actual = new Diary.DateTime();

            Assert.AreEqual("1900-01-01 00:00", Helper.ToString(actual));
        }
Exemple #13
0
        public void SaveAndLoadTest()
        {
            var builders = new AppointmentBuilder[4]
            {
                new AppointmentBuilder(),
                new AppointmentBuilder(),
                new AppointmentBuilder(),
                new AppointmentBuilder()
            };

            using (var creator = new AppointmentCreator())
            {
                var yogaDateTime = new Diary.DateTime(new Date(1, Date.Month.FEBRUARY, 2017), 6, 30);
                builders[0].SetLabel("Yoga").SetOccurs(yogaDateTime).SetDurationMinutes(45);
                builders[0].SetDetails("Downward Dog");

                var doctorsDateTime = new Diary.DateTime(new Date(2, Date.Month.MARCH, 2017), 8, 20);
                builders[1].SetLabel("Ear Doctor").SetOccurs(doctorsDateTime).SetDurationMinutes(30);
                builders[1].SetDetails("Annual Cleaning");

                var teacherDateTime = new Diary.DateTime(new Date(7, Date.Month.APRIL, 2017), 12, 00);
                builders[2].SetLabel("School").SetOccurs(teacherDateTime).SetDurationMinutes(25);
                builders[2].SetDetails("5th Grade Arithmetic");

                var reviewDateTime = new Diary.DateTime(new Date(30, Date.Month.MAY, 2017), 18, 30);
                builders[3].SetLabel("Performance Review").SetOccurs(reviewDateTime).SetDurationMinutes(60);
                builders[3].SetDetails("6 Month Evaluation");

                foreach (var builder in builders)
                {
                    builder.SetCreator(creator);
                    var appointment = (Appointment)builder.Build();
                    builder.SetObjectId(appointment.GetObjectId());

                    Helper.AssertAreEqual(builder, appointment, "Original");
                }

                creator.Save();
            }

            using (var appointmentCreator = new AppointmentCreator()) // Re-open the files
            {
                foreach (var builder in builders)
                {
                    var objectId         = builder.GetObjectId();
                    var savedAppointment = (Appointment)appointmentCreator.Create(objectId);

                    Helper.AssertAreEqual(builder, savedAppointment, "Saved");
                }

                // Now add some contacts to the existing appointments
                using (var contactCreator = new ContactCreator())
                {
                    builders[1].SetContactBuilders();
                    builders[3].SetContactBuilders();
                    var contactBuilders = builders[1].GetContactBuilders();
                    var contacts        = new Contact[contactBuilders.Length];
                    for (int i = 0; i < contactBuilders.Length; i++)
                    {
                        contactBuilders[i].SetCreator(contactCreator);
                        contacts[i] = (Contact)contactBuilders[i].Build();
                    }

                    contactCreator.Save();

                    var drAppointment     = (Appointment)appointmentCreator.Create(builders[1].GetObjectId());
                    var reviewAppointment = (Appointment)appointmentCreator.Create(builders[3].GetObjectId());
                    for (int i = 0; i < contacts.Length; i++)
                    {
                        drAppointment.AddRelation(contacts[i]);
                        reviewAppointment.AddRelation(contacts[i]);
                    }

                    appointmentCreator.Save();
                }
            }

            using (var creator = new AppointmentCreator())   // Re-open the files
            {
                foreach (var builder in builders)
                {
                    var objectId         = builder.GetObjectId();
                    var savedAppointment = (Appointment)creator.Create(objectId);

                    Helper.AssertAreEqual(builder, savedAppointment, "Post Contact Save");
                }
            }
        }
Exemple #14
0
 internal PeriodicAppointmentBuilder SetNotToExceedDateTime(Diary.DateTime notToExceedDateTime)
 {
     // Directly use the reference passed so we can later test for aliasing bugs.
     this.notToExceedDateTime = notToExceedDateTime;
     return(this);
 }
        public void TestReadWrite()
        {
            var outputRecord = new VariableLengthRecord();

            outputRecord.AppendValue(100);               // unsigned int value
                outputRecord.AppendValue(200.0F);        // float value
                outputRecord.AppendValue(300.0);         // double value
                outputRecord.AppendValue('a');           // unsigned char value
                outputRecord.AppendValue("Testing");     //string value
                outputRecord.AppendValue(true);          // boolean value

            var dateValue = new Date(31, Date.Month.DECEMBER, 2100);

            outputRecord.AppendValue(dateValue);

            var dateTimeValue = new Diary.DateTime(new Date(6, Date.Month.SEPTEMBER, 1950), 12, 15);

            outputRecord.AppendValue(dateTimeValue);

            String persistenceFilePath = String.Concat(ConfigurationManager.AppSettings["PersistenceFolderPath"], "/TestFile.txt");
            var    folder = Path.GetDirectoryName(persistenceFilePath);

            // Create the persistence directory if it doesn't exist.
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            var outputStream = new RandomAccessFile(persistenceFilePath);

            outputRecord.Serialize(outputStream);
            outputStream.close();

            var inputRecord = new VariableLengthRecord();

            using (var inputStream = new RandomAccessFile(persistenceFilePath))
            {
                Assert.IsTrue(inputRecord.Deserialize(inputStream));
                Assert.AreEqual(inputRecord.GetCount(), 8, "Count");

                int value0 = 0;
                Assert.IsTrue(inputRecord.GetValue(0, ref value0));
                Assert.AreEqual(value0, 100);

                float value1 = 0.0F;
                Assert.IsTrue(inputRecord.GetValue(1, ref value1));
                Assert.AreEqual(value1, 200.0F, 0.001F);

                double value2 = 0.0;
                Assert.IsTrue(inputRecord.GetValue(2, ref value2));
                Assert.AreEqual(value2, 300.0, 0.001);

                char value3 = ' ';
                Assert.IsTrue(inputRecord.GetValue(3, ref value3));
                Assert.AreEqual(value3, 'a');

                String value4 = "";
                Assert.IsTrue(inputRecord.GetValue(4, ref value4));
                Assert.IsTrue(value4.CompareTo("Testing") == 0);

                bool value5 = false;
                Assert.IsTrue(inputRecord.GetValue(5, ref value5));
                Assert.AreEqual(value5, true);

                var value6 = new Date();
                Assert.IsTrue(inputRecord.GetValue(6, ref value6), "Date");
                Assert.AreEqual(Helper.ToString(dateValue), Helper.ToString(value6));

                var value7 = new Diary.DateTime();
                Assert.IsTrue(inputRecord.GetValue(7, ref value7), "DateTime");
                Assert.AreEqual(Helper.ToString(dateTimeValue), Helper.ToString(value7));

                inputStream.close();
            }
        }
Exemple #16
0
 /// <summary>
 /// Returns DateTime identifying properties.
 /// </summary>
 /// <returns>yyyy-MM-dd hh:mm</returns>
 /// <seealso cref="Helper.ToString(Date)"/>
 internal static String ToString(Diary.DateTime dateTime)
 {
     return(String.Format("{0} {1}:{2}", Helper.ToString(dateTime.GetDate()), dateTime.GetHours().ToString("00"), dateTime.GetMinutes().ToString("00")));
 }