/// <summary>
        /// Should throw the InvalidPlacesCount error code.
        /// </summary>
        private void ShouldThrowInvalidPlacesCountErrorCode(int placesCount)
        {
            // Build the test harness.
            SchedulingBusinessLogicComponentTestHarness testHarness = new SchedulingBusinessLogicComponentTestHarness();

            // Build the NewCourseSchedule business request.
            NewCourseScheduleBusinessRequest newCourseScheduleBusinessRequest = new NewCourseScheduleBusinessRequest();

            // Build the Session business request element.
            NewCourseScheduleBusinessRequest.SessionBusinessRequestElement sessionBusinessRequestElement = new NewCourseScheduleBusinessRequest.SessionBusinessRequestElement();
            sessionBusinessRequestElement.SessionCode = "6dk61ufcuzp3f7vs";
            newCourseScheduleBusinessRequest.Session  = sessionBusinessRequestElement;

            // Build the CourseSchedule business request element.
            NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement courseScheduleBusinessRequestElement = new NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement();
            courseScheduleBusinessRequestElement.DayOfWeek  = DayOfWeek.Monday;
            courseScheduleBusinessRequestElement.Time       = new TimeSpan(9, 15, 0);
            newCourseScheduleBusinessRequest.CourseSchedule = courseScheduleBusinessRequestElement;

            // Build the CourseGroup business request elements.
            List <NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement> courseGroupBusinessRequestElements = new List <NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement>();

            // Build the CourseGroup business request element.
            NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement courseGroupBusinessRequestElement = new NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement();
            courseGroupBusinessRequestElement.PlacesCount = placesCount;
            courseGroupBusinessRequestElements.Add(courseGroupBusinessRequestElement);

            // Set the CourseGroup business request elements.
            courseScheduleBusinessRequestElement.CourseGroups = courseGroupBusinessRequestElements.ToArray();

            try
            {
                // Invoke the NewCourseSchedule business operation.
                testHarness.SchedulingBusinessLogicComponent.NewCourseSchedule(testHarness.MockedDatabaseConnection, newCourseScheduleBusinessRequest).Wait();

                // Validate an exception was thrown.
                Assert.Fail();
            }
            catch (AggregateException ex)
            {
                // Verify the mocked components.
                testHarness.VerifyMockedComponents();

                // Validate a NewCourseSchedule business exception was thrown.
                NewCourseScheduleBusinessException NewCourseScheduleBusinessException = ex.InnerExceptions[0] as NewCourseScheduleBusinessException;
                Assert.IsNotNull(NewCourseScheduleBusinessException);
                Assert.AreEqual("SchedulingBusinessLogicComponent.NewCourseSchedule() has thrown a NewCourseSchedule business exception. See the Errors property for details.", NewCourseScheduleBusinessException.Message);

                // Validate the NewCourseSchedule business exception contains the InvalidPlacesCount error code.
                Assert.IsNotNull(NewCourseScheduleBusinessException.Errors);
                Assert.AreEqual(1, NewCourseScheduleBusinessException.Errors.Length);
                Assert.AreEqual(NewCourseScheduleBusinessException.ErrorCodes.InvalidPlacesCount, NewCourseScheduleBusinessException.Errors[0].ErrorCode);
                Assert.AreEqual(placesCount, NewCourseScheduleBusinessException.Errors[0].ErroneousValue);
            }
        }
        /// <summary>
        /// Builds a NewCourseSchedule business exception.
        /// </summary>
        private NewCourseScheduleBusinessException BuildNewCourseScheduleBusinessException(NewCourseScheduleBusinessException.ErrorBusinessExceptionElement[] errorBusinessExceptionElements)
        {
            // Build the business exception.
            NewCourseScheduleBusinessException businessException = new NewCourseScheduleBusinessException();

            businessException.ErrorMessage = String.Format("SchedulingBusinessLogicComponent.NewCourseSchedule() has thrown a NewCourseSchedule business exception. See the Errors property for details.");
            businessException.Errors       = errorBusinessExceptionElements;

            // Return the business exception.
            return(businessException);
        }
        /// <summary>
        /// Validates the NewCourseSchedule business operation.
        /// </summary>
        private async Task ValidateNewCourseScheduleOperation(IDatabaseConnection databaseConnection, NewCourseScheduleBusinessRequest businessRequest, NewCourseScheduleOperationData operationData)
        {
            // Validate the InvalidSessionCode error code.
            operationData.SessionDataRow = await this.sessionDataAccessComponent.ReadBySessionCode(databaseConnection, businessRequest.Session.SessionCode);

            if (operationData.SessionDataRow == null)
            {
                // Throw a NewCourseSchedule business exception.
                NewCourseScheduleBusinessException businessException = this.BuildNewCourseScheduleBusinessException(NewCourseScheduleBusinessException.ErrorCodes.InvalidSessionCode, businessRequest.Session.SessionCode);
                throw businessException;
            }
        }
        public void ShouldThrowInvalidSessionCodeErrorCode_GivenNonExistingSessionCode()
        {
            // Build the test harness.
            SchedulingBusinessLogicComponentTestHarness testHarness = new SchedulingBusinessLogicComponentTestHarness();

            // Mock the reading of the Session data row.
            testHarness.MockedSessionDataAccessComponent
            .Setup(mock => mock.ReadBySessionCode(It.IsAny <IDatabaseConnection>(), "6dk61ufcuzp3f7vs"))
            .Returns(Task.FromResult <SessionDataRow>(null))
            .Verifiable();

            // Build the NewCourseSchedule business request.
            NewCourseScheduleBusinessRequest newCourseScheduleBusinessRequest = new NewCourseScheduleBusinessRequest();

            // Build the Session business request element.
            NewCourseScheduleBusinessRequest.SessionBusinessRequestElement sessionBusinessRequestElement = new NewCourseScheduleBusinessRequest.SessionBusinessRequestElement();
            sessionBusinessRequestElement.SessionCode = "6dk61ufcuzp3f7vs";
            newCourseScheduleBusinessRequest.Session  = sessionBusinessRequestElement;

            // Build the CourseSchedule business request element.
            NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement courseScheduleBusinessRequestElement = new NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement();
            courseScheduleBusinessRequestElement.DayOfWeek  = DayOfWeek.Monday;
            courseScheduleBusinessRequestElement.Time       = new TimeSpan(9, 15, 0);
            newCourseScheduleBusinessRequest.CourseSchedule = courseScheduleBusinessRequestElement;

            // Build the CourseGroup business request elements.
            courseScheduleBusinessRequestElement.CourseGroups = new NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement[0];

            try
            {
                // Invoke the NewCourseSchedule business operation.
                testHarness.SchedulingBusinessLogicComponent.NewCourseSchedule(testHarness.MockedDatabaseConnection, newCourseScheduleBusinessRequest).Wait();

                // Validate an exception was thrown.
                Assert.Fail();
            }
            catch (AggregateException ex)
            {
                // Verify the mocked components.
                testHarness.VerifyMockedComponents();

                // Validate a NewCourseSchedule business exception was thrown.
                NewCourseScheduleBusinessException NewCourseScheduleBusinessException = ex.InnerExceptions[0] as NewCourseScheduleBusinessException;
                Assert.IsNotNull(NewCourseScheduleBusinessException);
                Assert.AreEqual("SchedulingBusinessLogicComponent.NewCourseSchedule() has thrown a NewCourseSchedule business exception. See the Errors property for details.", NewCourseScheduleBusinessException.Message);

                // Validate the NewCourseSchedule business exception contains the InvalidSessionCode error code.
                Assert.IsNotNull(NewCourseScheduleBusinessException.Errors);
                Assert.AreEqual(1, NewCourseScheduleBusinessException.Errors.Length);
                Assert.AreEqual(NewCourseScheduleBusinessException.ErrorCodes.InvalidSessionCode, NewCourseScheduleBusinessException.Errors[0].ErrorCode);
                Assert.AreEqual("6dk61ufcuzp3f7vs", NewCourseScheduleBusinessException.Errors[0].ErroneousValue);
            }
        }
        /// <summary>
        /// Builds a NewCourseSchedule business exception.
        /// </summary>
        private NewCourseScheduleBusinessException BuildNewCourseScheduleBusinessException(NewCourseScheduleBusinessException.ErrorCodes errorCode, object erroneousValue)
        {
            // Build an Error business exception element.
            NewCourseScheduleBusinessException.ErrorBusinessExceptionElement errorBusinessExceptionElement = new NewCourseScheduleBusinessException.ErrorBusinessExceptionElement();
            errorBusinessExceptionElement.ErrorCode      = errorCode;
            errorBusinessExceptionElement.ErroneousValue = erroneousValue;

            // Build the business exception.
            NewCourseScheduleBusinessException businessException = this.BuildNewCourseScheduleBusinessException(new NewCourseScheduleBusinessException.ErrorBusinessExceptionElement[] { errorBusinessExceptionElement });

            // Return the business exception.
            return(businessException);
        }
        public void ShouldThrowInvalidSessionErrorCode()
        {
            // Build the test harness.
            SchedulingBusinessLogicComponentTestHarness testHarness = new SchedulingBusinessLogicComponentTestHarness();

            // Build the NewCourseSchedule business request.
            NewCourseScheduleBusinessRequest newCourseScheduleBusinessRequest = new NewCourseScheduleBusinessRequest();

            // Build the Session business request element.
            newCourseScheduleBusinessRequest.Session = null;

            // Build the CourseSchedule business request element.
            NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement courseScheduleBusinessRequestElement = new NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement();
            courseScheduleBusinessRequestElement.DayOfWeek  = DayOfWeek.Monday;
            courseScheduleBusinessRequestElement.Time       = new TimeSpan(9, 15, 0);
            newCourseScheduleBusinessRequest.CourseSchedule = courseScheduleBusinessRequestElement;

            // Build the CourseGroup business request elements.
            courseScheduleBusinessRequestElement.CourseGroups = new NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement[0];

            try
            {
                // Invoke the NewCourseSchedule business operation.
                testHarness.SchedulingBusinessLogicComponent.NewCourseSchedule(testHarness.MockedDatabaseConnection, newCourseScheduleBusinessRequest).Wait();

                // Validate an exception was thrown.
                Assert.Fail();
            }
            catch (AggregateException ex)
            {
                // Verify the mocked components.
                testHarness.VerifyMockedComponents();

                // Validate a NewCourseSchedule business exception was thrown.
                NewCourseScheduleBusinessException NewCourseScheduleBusinessException = ex.InnerExceptions[0] as NewCourseScheduleBusinessException;
                Assert.IsNotNull(NewCourseScheduleBusinessException);
                Assert.AreEqual("SchedulingBusinessLogicComponent.NewCourseSchedule() has thrown a NewCourseSchedule business exception. See the Errors property for details.", NewCourseScheduleBusinessException.Message);

                // Validate the NewCourseSchedule business exception contains the InvalidSession error code.
                Assert.IsNotNull(NewCourseScheduleBusinessException.Errors);
                Assert.AreEqual(1, NewCourseScheduleBusinessException.Errors.Length);
                Assert.AreEqual(NewCourseScheduleBusinessException.ErrorCodes.InvalidSession, NewCourseScheduleBusinessException.Errors[0].ErrorCode);
                Assert.AreEqual(null, NewCourseScheduleBusinessException.Errors[0].ErroneousValue);
            }
        }
        /// <summary>
        /// Validates the NewCourseSchedule business request.
        /// </summary>
        private void ValidateNewCourseScheduleRequest(NewCourseScheduleBusinessRequest businessRequest)
        {
            // Build the list of errors.
            List <NewCourseScheduleBusinessException.ErrorBusinessExceptionElement> errorBusinessExceptionElements = new List <NewCourseScheduleBusinessException.ErrorBusinessExceptionElement>();

            // Validate the Session business request element.
            this.ValidateNewCourseScheduleRequestProperty(businessRequest, "Session", businessRequest.Session, NewCourseScheduleBusinessException.ErrorCodes.InvalidSession, errorBusinessExceptionElements);
            if (businessRequest.Session != null)
            {
                // Validate the Session business request element properties.
                NewCourseScheduleBusinessRequest.SessionBusinessRequestElement sessionBusinessRequestElement = businessRequest.Session;
                this.ValidateNewCourseScheduleRequestProperty(sessionBusinessRequestElement, "SessionCode", sessionBusinessRequestElement.SessionCode, NewCourseScheduleBusinessException.ErrorCodes.InvalidSessionCode, errorBusinessExceptionElements);
            }

            // Validate the CourseSchedule business request element.
            this.ValidateNewCourseScheduleRequestProperty(businessRequest, "CourseSchedule", businessRequest.CourseSchedule, NewCourseScheduleBusinessException.ErrorCodes.InvalidCourseSchedule, errorBusinessExceptionElements);
            if (businessRequest.CourseSchedule != null)
            {
                // Validate the CourseSchedule business request element properties.
                NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement courseScheduleBusinessRequestElement = businessRequest.CourseSchedule;
                this.ValidateNewCourseScheduleRequestProperty(courseScheduleBusinessRequestElement, "Time", courseScheduleBusinessRequestElement.Time, NewCourseScheduleBusinessException.ErrorCodes.InvalidTime, errorBusinessExceptionElements);

                // Validate the CourseGroup business request elements.
                this.ValidateNewCourseScheduleRequestProperty(courseScheduleBusinessRequestElement, "CourseGroups", courseScheduleBusinessRequestElement.CourseGroups, NewCourseScheduleBusinessException.ErrorCodes.InvalidCourseGroups, errorBusinessExceptionElements);
                if (courseScheduleBusinessRequestElement.CourseGroups != null)
                {
                    // Skip the null business request elements.
                    NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement[] nonNullCourseGroupBusinessRequestElements = courseScheduleBusinessRequestElement.CourseGroups.Where(courseGroupBusinessRequestElement => courseGroupBusinessRequestElement != null).ToArray();
                    foreach (NewCourseScheduleBusinessRequest.CourseScheduleBusinessRequestElement.CourseGroupBusinessRequestElement courseGroupBusinessRequestElement in nonNullCourseGroupBusinessRequestElements)
                    {
                        // Validate the CourseGroup business request element properties.
                        this.ValidateNewCourseScheduleRequestProperty(courseGroupBusinessRequestElement, "PlacesCount", courseGroupBusinessRequestElement.PlacesCount, NewCourseScheduleBusinessException.ErrorCodes.InvalidPlacesCount, errorBusinessExceptionElements);
                    }
                }
            }

            // Check if any errors were added to the list.
            if (errorBusinessExceptionElements.Any())
            {
                // Throw a NewCourseSchedule business exception.
                NewCourseScheduleBusinessException businessException = this.BuildNewCourseScheduleBusinessException(errorBusinessExceptionElements.ToArray());
                throw businessException;
            }
        }