public void ItemUpdatingPositiveTest()
        {
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));

            //Setup our mock so that it pass all validations
            SPItemEventProperties spItemEventProperties = this.CreateMockSpItemEventProperties("My Title",
                                                                                               "12345678",
                                                                                               DateTime.Today,
                                                                                               DateTime.Today.AddDays(1),
                                                                                               DateTime.Today.AddDays(2),
                                                                                               100);

            //Call our event receiver with our mocked SPItemEventProperties
            TrainingCourseItemEventReceiver receiver = new TrainingCourseItemEventReceiver();

            receiver.ItemUpdating(spItemEventProperties);

            Assert.IsFalse(spItemEventProperties.Cancel);
        }
        public void AddingCourseWithInvalidCourseCodeCancelsWithError()
        {
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));

            //Setup our mock so that our course code is invalid
            SPItemEventProperties spItemEventProperties = this.CreateMockSpItemEventProperties("My Title",
                                                                                               "1234",
                                                                                               DateTime.Today,
                                                                                               DateTime.Today.AddDays(1),
                                                                                               DateTime.Today.AddDays(2),
                                                                                               100);

            //Call our event receiver with our mocked SPItemEventProperties
            TrainingCourseItemEventReceiver receiver = new TrainingCourseItemEventReceiver();

            receiver.ItemAdding(spItemEventProperties);

            StringAssert.Contains(spItemEventProperties.ErrorMessage, "The Course Code must be 8 characters long.");
            Assert.IsTrue(spItemEventProperties.Cancel);
        }
        public void UpdatingCourseWithNegativeCostCancelsWithError()
        {
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));

            //Setup our mock so that course count returns 1
            SPItemEventProperties spItemEventProperties = this.CreateMockSpItemEventProperties("My Title",
                                                                                               "12345679",
                                                                                               DateTime.Today,
                                                                                               DateTime.Today.AddDays(1),
                                                                                               DateTime.Today.AddDays(2),
                                                                                               -100);

            //Call our event receiver with our mocked SPItemEventProperties
            TrainingCourseItemEventReceiver receiver = new TrainingCourseItemEventReceiver();

            receiver.ItemUpdating(spItemEventProperties);

            StringAssert.Contains(spItemEventProperties.ErrorMessage, "Negative values are not allowed for Cost.");
            Assert.IsTrue(spItemEventProperties.Cancel);
        }
        public void UpdatingCourseWithInvalidEndDateCancelsWithError()
        {
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));

            //Setup our mock so that the end date is invalid
            SPItemEventProperties spItemEventProperties = this.CreateMockSpItemEventProperties("My Title",
                                                                                               "12345678",
                                                                                               DateTime.Today,
                                                                                               DateTime.Today.AddDays(1),
                                                                                               DateTime.Today.AddDays(-2),
                                                                                               100);

            //Call our event receiver with our mocked SPItemEventProperties
            TrainingCourseItemEventReceiver receiver = new TrainingCourseItemEventReceiver();

            receiver.ItemUpdating(spItemEventProperties);

            StringAssert.Contains(spItemEventProperties.ErrorMessage, "The End Date can not be before the Start Date.");
            Assert.IsTrue(spItemEventProperties.Cancel);
        }
        public void UpdatingCourseWithExisitingCodeCancelsWithError()
        {
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));
            MockTrainingCourseRepository.TrainingCourseReturnedByGet = new TrainingCourse();

            //Setup our mock so that course count returns 1
            SPItemEventProperties spItemEventProperties = this.CreateMockSpItemEventProperties("My Title",
                                                                                               "12345679",
                                                                                               DateTime.Today,
                                                                                               DateTime.Today.AddDays(1),
                                                                                               DateTime.Today.AddDays(2),
                                                                                               100);

            //Call our event receiver with our mocked SPItemEventProperties
            TrainingCourseItemEventReceiver receiver = new TrainingCourseItemEventReceiver();

            receiver.ItemUpdating(spItemEventProperties);

            StringAssert.Contains(spItemEventProperties.ErrorMessage, "The Course Code is already in use.");
            Assert.IsTrue(spItemEventProperties.Cancel);
        }