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 ItemAddingPositiveTest()
        {
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));

            //Setup our mock so that our vaildations pass
            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.ItemAdding(spItemEventProperties);

            //Assert that the cancel did not get set
            Assert.IsFalse(spItemEventProperties.Cancel);
        }
        public void AddingCourseWithNegativeCostCancelsWithError()
        {
            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.ItemAdding(spItemEventProperties);

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

            //Setup our mock so that our 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.ItemAdding(spItemEventProperties);

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

            //Setup our mock so that the courses count will be 1
            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.ItemAdding(spItemEventProperties);

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