public void SaveAndLoadTest()
        {
            var builders = new ContactBuilder[3]
            {
                new ContactBuilder(),
                new ContactBuilder(),
                new ContactBuilder()
            };

            using (var creator = new ContactCreator())
            {
                builders[0].SetFirstName("Brian").SetLastName("Rothwell").SetContactInfo("*****@*****.**");
                builders[1].SetFirstName("Billy").SetLastName("Bob").SetContactInfo("*****@*****.**");
                builders[2].SetFirstName("Jenny").SetLastName("Twotone").SetContactInfo("(210) 867-5308");

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

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

                creator.Save();
            }

            using (var creator = new ContactCreator())  // Re-open the files.
            {
                foreach (var builder in builders)
                {
                    var objectId     = builder.GetObjectId();
                    var savedContact = (Contact)creator.Create(objectId);

                    Helper.AssertAreEqual(builder, savedContact, "Saved");
                }
            }
        }
Exemple #2
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");
                }
            }
        }
        public void SaveAndLoadTest()
        {
            var builders = new PeriodicAppointmentBuilder[3]
            {
                new PeriodicAppointmentBuilder(),
                new PeriodicAppointmentBuilder(),
                new PeriodicAppointmentBuilder()
            };

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

                builders[1].SetOccurs(new Diary.DateTime(new Date(2, Date.Month.MARCH, 2017), 8, 20));
                builders[1].SetDurationMinutes(30);
                builders[1].SetLabel("Ear Doctor");
                builders[1].SetDetails("Annual Cleaning");
                builders[1].SetPeriodHours(24 * 365);
                builders[1].SetNotToExceedDateTime(new Diary.DateTime(new Date(1, Date.Month.MARCH, 2022), 8, 20));

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

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

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

                creator.Save();
            }

            using (var appointmentCreator = new PeriodicAppointmentCreator())  // Re-open the files.
            {
                foreach (var builder in builders)
                {
                    var objectId = builder.GetObjectId();
                    var savedPeriodicAppointment = (PeriodicAppointment)appointmentCreator.Create(objectId);

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


                // Now add some contacts to the existing appointments
                using (var contactCreator = new ContactCreator())
                {
                    builders[1].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 = (PeriodicAppointment)appointmentCreator.Create(builders[1].GetObjectId());
                    for (int i = 0; i < contacts.Length; i++)
                    {
                        drAppointment.AddRelation(contacts[i]);
                    }

                    appointmentCreator.Save();
                }

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

                        Helper.AssertAreEqual(builder, savedAppointment, "Post Contact Save");
                    }
                }
            }
        }