Beispiel #1
0
        public void Validation_Failure()
        {
            ScheduleItem item = new ScheduleItem
            {
                ScheduleItemDate = Constants.NULL_DATE,
                Person           = new Person {
                    PersonID = Constants.NULL_INT
                },
                ApprovedBy  = TestFactories.GetDefaultPerson(),
                IsConfirmed = true,
                ScheduleID  = 0
            };

            try
            {
                bool result = item.IsValid;
                Assert.Fail(string.Format("Validation should have failed, not returned '{0}'", result));
            }
            catch (ValidationException ex)
            {
                Assert.IsTrue(ex.Errors[0].Contains("Person"));
                Assert.IsTrue(ex.Errors[1].Contains("Schedule Date"));
                Assert.IsTrue(ex.Errors[2].Contains("Schedule"));
                Assert.IsTrue(ex.Errors[3].Contains("not found"));
            }
        }
Beispiel #2
0
        public void Adding_ScheduleItem_On_Blacked_Out_Date_Should_Fail()
        {
            DateTime           blackedOutDate = DateTime.Now.AddDays(3);
            string             key            = KeyHelper.GetKey <IScheduleRepository>();
            var                repository     = RepositoryFactory.GetRepository <IScheduleRepository>(key);
            ScheduleController controller     = new ScheduleController();

            controller.CreateSchedule(TestFactories.GetDefaultLookup(), "Test Schedule", "This is a test", "test user");

            Schedule schedule = repository.GetAllSchedules().Last();

            controller.CreateBlackoutDate(schedule, "Test blackout date", blackedOutDate, "test user");

            try
            {
                controller.CreateScheduleItem(schedule, blackedOutDate, TestFactories.GetDefaultPerson(), new List <Baptizer>(),
                                              TestFactories.GetDefaultPerson(), true, "test user");
                Assert.Fail("controller.CreateScheduleItem() should throw an exception.");
            }
            catch (ValidationException ex)
            {
                Assert.IsTrue(ex.Errors[0].Contains("Unable to schedule a baptism on a Black Out Date."));
                Assert.AreEqual(ex.Errors.Count, 1);
            }
        }
Beispiel #3
0
        public void Validation_Success()
        {
            BlackoutDate blackoutDate = TestFactories.GetBlackoutDate();
            bool         result       = blackoutDate.IsValid;

            Assert.IsTrue(result);
            Assert.AreEqual(blackoutDate.Errors.Count, 0);
        }
Beispiel #4
0
        public void Validation_Success()
        {
            ScheduleItem item   = TestFactories.GetScheduleItem();
            bool         result = item.IsValid;

            Assert.IsTrue(result);
            Assert.AreEqual(item.Errors.Count, 0);
        }
Beispiel #5
0
        public void Validation_Success()
        {
            Schedule schedule = TestFactories.GetSchedule();
            bool     result   = schedule.IsValid;

            Assert.IsTrue(result);
            Assert.AreEqual(schedule.Errors.Count, 0);
        }
        public void Validation_Success()
        {
            Baptizer baptizer = TestFactories.GetBaptizer();
            bool     result   = baptizer.IsValid;

            Assert.IsTrue(result);
            Assert.AreEqual(baptizer.Errors.Count, 0);
        }
Beispiel #7
0
        public Schedule CreateSchedule()
        {
            string             key        = KeyHelper.GetKey <IScheduleRepository>();
            var                repository = RepositoryFactory.GetRepository <IScheduleRepository>(key);
            ScheduleController controller = new ScheduleController();

            controller.CreateSchedule(TestFactories.GetDefaultLookup(), "Test Schedule", "This is a test", "test user");
            return(repository.GetAllSchedules().Last());
        }
Beispiel #8
0
        public void Schedule_Update()
        {
            ScheduleController controller = new ScheduleController();
            Schedule           schedule   = CreateSchedule();

            schedule.Name = "new name";
            controller.UpdateSchedule(schedule.ScheduleID, TestFactories.GetDefaultLookup(), schedule.Name, schedule.Description, "new user");
            Assert.AreNotEqual(schedule.Name, "Test Schedule");
            Assert.AreNotEqual(schedule.CreatedBy, schedule.ModifiedBy);
            Assert.AreEqual(schedule.ModifiedBy, "new user");
        }
Beispiel #9
0
        public void Schedule_Item_Create()
        {
            ScheduleController controller = new ScheduleController();
            Schedule           schedule   = CreateSchedule();

            controller.CreateScheduleItem(schedule, DateTime.Now, TestFactories.GetDefaultPerson(), new List <Baptizer>(),
                                          TestFactories.GetDefaultPerson(), true, "test user");

            Assert.Greater(schedule.ScheduleItems.Count, 0);
            Assert.AreEqual(schedule.ScheduleItems.First().CreatedBy, "test user");
            Assert.Greater(schedule.ScheduleItems.First().ScheduleItemID, 0);
        }
 public FakeBlackoutDateRepository()
 {
     if (blackoutDates.Count == 0)
     {
         for (int i = 0; i < 3; i++)
         {
             BlackoutDate blackoutDate = TestFactories.GetBlackoutDate();
             blackoutDate.BlackoutDateID = i + 1;
             blackoutDates.Add(blackoutDate);
             count++;
         }
     }
 }
 public FakeScheduleItemRepository()
 {
     if (items.Count == 0)
     {
         for (int i = 0; i < 3; i++)
         {
             ScheduleItem item = TestFactories.GetScheduleItem();
             item.ScheduleItemID = i + 1;
             items.Add(item);
             count++;
         }
     }
 }
Beispiel #12
0
 public FakeScheduleRepository()
 {
     if (schedules.Count == 0)
     {
         for (int i = 0; i < 3; i++)
         {
             Schedule schedule = TestFactories.GetSchedule();
             schedule.ScheduleID = i + 1;
             schedules.Add(schedule);
             count++;
         }
     }
 }
 public FakeBaptizerRepository()
 {
     if (baptizers.Count == 0)
     {
         for (int i = 0; i < 3; i++)
         {
             Baptizer baptizer = TestFactories.GetBaptizer();
             baptizer.BaptizerID = i + 1;
             baptizers.Add(baptizer);
             count++;
         }
     }
 }
Beispiel #14
0
        public void Schedule_Item_Read()
        {
            ScheduleController controller = new ScheduleController();
            Schedule           schedule   = CreateSchedule();

            controller.CreateScheduleItem(schedule, DateTime.Now, TestFactories.GetDefaultPerson(), new List <Baptizer>(),
                                          TestFactories.GetDefaultPerson(), true, "test user");

            ScheduleItem item    = schedule.ScheduleItems.First();
            string       key     = KeyHelper.GetKey <IScheduleItemRepository>();
            ScheduleItem newItem = RepositoryFactory.GetRepository <IScheduleItemRepository>(key).GetScheduleItem(item.ScheduleItemID);

            Assert.AreSame(item, newItem);
        }
Beispiel #15
0
        public void Schedule_Item_Delete()
        {
            ScheduleController controller = new ScheduleController();
            Schedule           schedule   = CreateSchedule();

            controller.CreateScheduleItem(schedule, DateTime.Now, TestFactories.GetDefaultPerson(), new List <Baptizer>(),
                                          TestFactories.GetDefaultPerson(), true, "test user");

            ScheduleItem item   = schedule.ScheduleItems.First();
            int          itemID = item.ScheduleItemID;

            controller.DeleteScheduleItem(schedule, item.ScheduleItemID);
            string key = KeyHelper.GetKey <IScheduleItemRepository>();

            Assert.IsFalse(RepositoryFactory.GetRepository <IScheduleItemRepository>(key).Exists(itemID));
        }
Beispiel #16
0
        public void Schedule_Create()
        {
            string             key        = KeyHelper.GetKey <IScheduleRepository>();
            var                repository = RepositoryFactory.GetRepository <IScheduleRepository>(key);
            ScheduleController controller = new ScheduleController();

            controller.CreateSchedule(TestFactories.GetDefaultLookup(), "Test Schedule", "This is a test", "test user");
            var schedules = repository.GetAllSchedules();

            Assert.Greater(schedules.Count(), 3);

            Schedule schedule = repository.GetAllSchedules().Last();

            Assert.Greater(schedule.ScheduleID, 0);
            Assert.AreEqual(schedule.CreatedBy, "test user");
            Assert.AreEqual(schedule.ModifiedBy, "test user");
        }
Beispiel #17
0
        public void Schedule_Item_Update()
        {
            ScheduleController controller = new ScheduleController();
            Schedule           schedule   = CreateSchedule();

            controller.CreateScheduleItem(schedule, DateTime.Now, TestFactories.GetDefaultPerson(), new List <Baptizer>(),
                                          TestFactories.GetDefaultPerson(), true, "test user");

            ScheduleItem item = schedule.ScheduleItems.First();

            item.ScheduleItemDate = DateTime.Now.AddDays(1);
            controller.UpdateScheduleItem(schedule, item.ScheduleItemID, item.ScheduleItemDate, item.Person,
                                          item.Baptizers.ToList(), item.ApprovedBy, true, "other user");

            Assert.AreNotEqual(item.ScheduleItemDate, DateTime.Now);
            Assert.AreNotEqual(item.CreatedBy, item.ModifiedBy);
            Assert.AreEqual(item.ModifiedBy, "other user");
        }
Beispiel #18
0
        public void Schedule_Item_Baptizer_Sync()
        {
            ScheduleController controller = new ScheduleController();
            Schedule           schedule   = CreateSchedule();

            Baptizer b1 = new Baptizer
            {
                Person = new Person {
                    PersonID = 3, FirstName = "Jimmy", LastName = "Jams"
                }
            };

            Baptizer b2 = new Baptizer
            {
                Person = new Person {
                    PersonID = 4, FirstName = "James", LastName = "Jams"
                }
            };

            List <Baptizer> baptizers = new List <Baptizer>
            {
                TestFactories.GetBaptizer(),
                            b1
            };

            controller.CreateScheduleItem(schedule, DateTime.Now, TestFactories.GetDefaultPerson(), baptizers,
                                          TestFactories.GetDefaultPerson(), true, "test user");
            ScheduleItem item = schedule.ScheduleItems.First();

            baptizers = new List <Baptizer>
            {
                TestFactories.GetBaptizer(),
                    b2
            };

            controller.UpdateScheduleItem(schedule, item.ScheduleItemID, DateTime.Now, TestFactories.GetDefaultPerson(), baptizers,
                                          TestFactories.GetDefaultPerson(), true, "test user");

            Assert.AreEqual(item.Baptizers.Count, 2);
            Assert.IsTrue(item.Baptizers.Any(b => b.Person.PersonID == 2));
            Assert.IsTrue(item.Baptizers.Any(b => b.Person.PersonID == 4));
            Assert.IsFalse(item.Baptizers.Any(b => b.Person.PersonID == 3));
        }
 public Person GetCurrentPerson()
 {
     return(TestFactories.GetDefaultPerson());
 }