public void PresenterInitializesViewTextHappyCase()
        {
            var view           = new MockRegistrationApprovalView();
            var presenter      = new RegistrationApprovalPresenter(view);
            var trainingCourse = new TrainingCourse()
            {
                Cost = 100, Code = "12345678", Title = "MockCourse"
            };

            MockTrainingCourseRepository.TrainingCourseReturnedByGet = trainingCourse;
            serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository));
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));
            serviceLocator.Register <IRegistrationApprovalTaskRepository>(typeof(MockRegistrationApprovalTaskRepository));
            MockRegistrationRepository.RegistrationReturnedByGet        = new Registration();
            MockRegistrationRepository.RegistrationReturnedByGet.UserId = 1;
            MockRegistrationApprovalTaskRepository.RegistrationApprovalTaskReturnedByGet = new RegistrationApprovalTask();

            bool success = presenter.RenderRegApprovalView(web, "12345");

            Assert.IsTrue(success);
            Assert.AreEqual("Registration Approval", view.HeaderTitle);
            Assert.AreEqual("Registration Approval - " + userName, view.PageTitle);
            Assert.AreEqual(userName, view.HeaderSubtitle);
            StringAssert.Contains(view.Message, string.Format("Please approve or reject the registration request by {0} for course: 12345678 - MockCourse.", userName));
            StringAssert.Contains(view.Message, string.Format("The MockCourse has been requested by {0}.", userName));
            StringAssert.Contains(view.Message, string.Format("The cost of this course is $100.00.", userName));
            Assert.AreEqual(2, view.Status.Count);
            Assert.IsTrue(view.Status.Contains("Approved"));
            Assert.IsTrue(view.Status.Contains("Rejected"));
            Assert.IsTrue(view.ShowConfirmationControls);
        }
        public void RenderViewValidatesTask()
        {
            var view      = new MockRegistrationApprovalView();
            var presenter = new RegistrationApprovalPresenter(view);

            serviceLocator.Register <IRegistrationApprovalTaskRepository>(typeof(MockRegistrationApprovalTaskRepository));

            bool success = presenter.RenderRegApprovalView(web, "00000");

            Assert.IsFalse(success);
            Assert.AreEqual("Registration Approval - Failure", view.PageTitle);
            Assert.AreEqual("Failure", view.HeaderSubtitle);
            StringAssert.Contains(view.Message, "The Approval Task selected is not valid.");
            Assert.IsFalse(view.ShowConfirmationControls);
        }
        public void ProcessApprovalFailureReturnsFalse()
        {
            var view      = new MockRegistrationApprovalView();
            var presenter = new RegistrationApprovalPresenter(view);

            var registration = new Registration();

            MockRegistrationRepository.RegistrationReturnedByGet = registration;
            serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository));
            serviceLocator.Register <IRegistrationApprovalTaskRepository>(typeof(MockRegistrationApprovalTaskRepository));

            bool success = presenter.ProcessApproval(web, "12345", "Approved");

            Assert.IsFalse(success);
            Assert.AreNotSame(registration, MockRegistrationRepository.UpdateCalledWithRegistrationParam);
            Assert.IsNull(registration.RegistrationStatus);
        }
        public void ProcessApprovalUpdatesRegistration()
        {
            var view         = new MockRegistrationApprovalView();
            var presenter    = new RegistrationApprovalPresenter(view);
            var mockWeb      = GetMockSPWeb(true);
            var registration = new Registration();

            MockRegistrationRepository.RegistrationReturnedByGet = registration;
            MockRegistrationApprovalTaskRepository.RegistrationApprovalTaskReturnedByGet = new RegistrationApprovalTask();
            serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository));
            serviceLocator.Register <IRegistrationApprovalTaskRepository>(typeof(MockRegistrationApprovalTaskRepository));

            bool success = presenter.ProcessApproval(mockWeb, "12345", "Approved");

            Assert.IsTrue(success);
            Assert.AreSame(registration, MockRegistrationRepository.UpdateCalledWithRegistrationParam);
            Assert.AreEqual("Approved", registration.RegistrationStatus);
        }
        public void RenderViewValidatesRegistration()
        {
            var view      = new MockRegistrationApprovalView();
            var presenter = new RegistrationApprovalPresenter(view);
            var mockWeb   = GetMockSPWeb(false);

            serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository));
            serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository));
            serviceLocator.Register <IRegistrationApprovalTaskRepository>(typeof(MockRegistrationApprovalTaskRepository));
            MockRegistrationApprovalTaskRepository.RegistrationApprovalTaskReturnedByGet = new RegistrationApprovalTask();

            bool success = presenter.RenderRegApprovalView(mockWeb, "00000");

            Assert.IsFalse(success);
            Assert.AreEqual("Registration Approval - Failure", view.PageTitle);
            Assert.AreEqual("Failure", view.HeaderSubtitle);
            StringAssert.Contains(view.Message, "The Registration associated with the selected Approval Task is not valid.");
            Assert.IsFalse(view.ShowConfirmationControls);
        }