/// <summary>
        /// Builds a NewSession business exception.
        /// </summary>
        private NewSessionBusinessException BuildNewSessionBusinessException(NewSessionBusinessException.ErrorBusinessExceptionElement[] errorBusinessExceptionElements)
        {
            // Build the business exception.
            NewSessionBusinessException businessException = new NewSessionBusinessException();

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

            // Return the business exception.
            return(businessException);
        }
        /// <summary>
        /// Builds a NewSession business exception.
        /// </summary>
        private NewSessionBusinessException BuildNewSessionBusinessException(NewSessionBusinessException.ErrorCodes errorCode, object erroneousValue)
        {
            // Build an Error business exception element.
            NewSessionBusinessException.ErrorBusinessExceptionElement errorBusinessExceptionElement = new NewSessionBusinessException.ErrorBusinessExceptionElement();
            errorBusinessExceptionElement.ErrorCode      = errorCode;
            errorBusinessExceptionElement.ErroneousValue = erroneousValue;

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

            // Return the business exception.
            return(businessException);
        }
コード例 #3
0
        /// <summary>
        /// Should throw the InvalidName error code.
        /// </summary>
        private void ShouldThrowInvalidNameErrorCode(string name)
        {
            // Build the test harness.
            SchedulingBusinessLogicComponentTestHarness testHarness = new SchedulingBusinessLogicComponentTestHarness();

            // Build the NewSession business request.
            NewSessionBusinessRequest newSessionBusinessRequest = new NewSessionBusinessRequest();

            // Build the Session business request element.
            NewSessionBusinessRequest.SessionBusinessRequestElement sessionBusinessRequestElement = new NewSessionBusinessRequest.SessionBusinessRequestElement();
            sessionBusinessRequestElement.Name      = name;
            sessionBusinessRequestElement.StartDate = new DateTime(2001, 1, 1);
            newSessionBusinessRequest.Session       = sessionBusinessRequestElement;

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

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

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

                // Validate the NewSession business exception contains the InvalidName error code.
                Assert.IsNotNull(NewSessionBusinessException.Errors);
                Assert.AreEqual(1, NewSessionBusinessException.Errors.Length);
                Assert.AreEqual(NewSessionBusinessException.ErrorCodes.InvalidName, NewSessionBusinessException.Errors[0].ErrorCode);
                Assert.AreEqual(name, NewSessionBusinessException.Errors[0].ErroneousValue);
            }
        }
        /// <summary>
        /// Validates the NewSession business request.
        /// </summary>
        private void ValidateNewSessionRequest(NewSessionBusinessRequest businessRequest)
        {
            // Build the list of errors.
            List <NewSessionBusinessException.ErrorBusinessExceptionElement> errorBusinessExceptionElements = new List <NewSessionBusinessException.ErrorBusinessExceptionElement>();

            // Validate the Session business request element.
            this.ValidateNewSessionRequestProperty(businessRequest, "Session", businessRequest.Session, NewSessionBusinessException.ErrorCodes.InvalidSession, errorBusinessExceptionElements);
            if (businessRequest.Session != null)
            {
                // Validate the Session business request element properties.
                NewSessionBusinessRequest.SessionBusinessRequestElement sessionBusinessRequestElement = businessRequest.Session;
                this.ValidateNewSessionRequestProperty(sessionBusinessRequestElement, "Name", sessionBusinessRequestElement.Name, NewSessionBusinessException.ErrorCodes.InvalidName, errorBusinessExceptionElements);
            }

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