Beispiel #1
0
        /// <summary>
        /// Executes the HTTP GET method.
        /// </summary>
        public async Task <HttpResponseMessage> Get()
        {
            // Open a database connection and begin a database transaction.
            using (IDatabaseConnection databaseConnection = await this.databaseConnectionProvider.OpenDatabaseConnection())
                using (IDatabaseTransaction databaseTransaction = databaseConnection.BeginDatabaseTransaction())
                {
                    // Invoke the GetSessions business operation.
                    GetSessionsBusinessResponse getSessionsBusinessResponse = await this.InvokeGetSessions(databaseConnection);

                    // Build the Session resources.
                    List <SessionResource> sessionResources = new List <SessionResource>();
                    foreach (GetSessionsBusinessResponse.SessionBusinessResponseElement sessionBusinessResponseElement in getSessionsBusinessResponse.Sessions)
                    {
                        // Build the Session resource.
                        SessionResource sessionResource = new SessionResource();
                        sessionResources.Add(sessionResource);

                        // Build the Session resource element.
                        SessionResource.SessionResourceElement sessionResourceElement = new SessionResource.SessionResourceElement();
                        sessionResourceElement.SessionCode = sessionBusinessResponseElement.SessionCode;
                        sessionResourceElement.Name        = sessionBusinessResponseElement.Name;
                        sessionResourceElement.StartDate   = sessionBusinessResponseElement.StartDate;
                        sessionResource.Session            = sessionResourceElement;
                    }

                    // Commit the database transaction.
                    databaseTransaction.Commit();

                    // Return an HTTP response message.
                    HttpResponseMessage httpResponseMessage = this.Request.CreateResponse(HttpStatusCode.OK, sessionResources.ToArray());
                    return(httpResponseMessage);
                }
        }
Beispiel #2
0
        /// <summary>
        /// Invokes the GetSessions business operation.
        /// </summary>
        private async Task <GetSessionsBusinessResponse> InvokeGetSessions(IDatabaseConnection databaseConnection)
        {
            try
            {
                // Build the GetSessions business request.
                GetSessionsBusinessRequest getSessionsBusinessRequest = new GetSessionsBusinessRequest();

                // Invoke the GetSessions business operation.
                GetSessionsBusinessResponse getSessionsBusinessResponse = await this.schedulingBusinessLogicComponent.GetSessions(databaseConnection, getSessionsBusinessRequest);

                // The business operation succeeded.
                return(getSessionsBusinessResponse);
            }
            catch (GetSessionsBusinessException getSessionsBusinessException)
            {
                // Wrap the GetSessions business exception into a service exception.
                ServiceException serviceException = ServiceExceptionBuilder.BuildServiceException(
                    "SchedulingServiceComponent.SessionsController.Get()",
                    getSessionsBusinessException,
                    getSessionsBusinessException.Errors.Select(error => error.ErrorCode.ToString()).ToArray(),
                    getSessionsBusinessException.Errors.Select(error => error.ErroneousValue).ToArray());

                // Throw the ErrorCode service exception.
                throw serviceException;
            }
        }
Beispiel #3
0
        public void ShouldReturnZeroSessionsResponseElements()
        {
            // Build the test harness.
            SchedulingBusinessLogicComponentTestHarness testHarness = new SchedulingBusinessLogicComponentTestHarness();

            // Mock the reading of the Session data rows.
            testHarness.MockedSessionDataAccessComponent
            .Setup(mock => mock.ReadAll(It.IsAny <IDatabaseConnection>()))
            .Returns(Task.FromResult(new SessionDataRow[0]))
            .Verifiable();

            // Build the GetSessions business request.
            GetSessionsBusinessRequest getSessionsBusinessRequest = new GetSessionsBusinessRequest();

            // Invoke the GetSessions business operation.
            GetSessionsBusinessResponse getSessionsBusinessResponse = testHarness.SchedulingBusinessLogicComponent.GetSessions(testHarness.MockedDatabaseConnection, getSessionsBusinessRequest).Result;

            // Verify the mocked components.
            testHarness.VerifyMockedComponents();

            // Validate the Session business response elements count.
            Assert.IsNotNull(getSessionsBusinessResponse);
            Assert.IsNotNull(getSessionsBusinessResponse.Sessions);
            Assert.AreEqual(0, getSessionsBusinessResponse.Sessions.Length);
        }
Beispiel #4
0
        public void ShouldReturnOneSessionResponseElement()
        {
            // Build the test harness.
            SchedulingBusinessLogicComponentTestHarness testHarness = new SchedulingBusinessLogicComponentTestHarness();

            // Mock the reading of the Session data rows.
            testHarness.MockedSessionDataAccessComponent
            .Setup(mock => mock.ReadAll(It.IsAny <IDatabaseConnection>()))
            .Returns(Task.FromResult(new SessionDataRow[]
            {
                new SessionDataRow()
                {
                    SessionID   = 10001,
                    SessionCode = "6dk61ufcuzp3f7vs",
                    Name        = "Session Alpha",
                    StartDate   = new DateTime(2001, 1, 1)
                }
            }))
            .Verifiable();

            // Build the GetSessions business request.
            GetSessionsBusinessRequest getSessionsBusinessRequest = new GetSessionsBusinessRequest();

            // Invoke the GetSessions business operation.
            GetSessionsBusinessResponse getSessionsBusinessResponse = testHarness.SchedulingBusinessLogicComponent.GetSessions(testHarness.MockedDatabaseConnection, getSessionsBusinessRequest).Result;

            // Verify the mocked components.
            testHarness.VerifyMockedComponents();

            // Validate the Session business response elements count.
            Assert.IsNotNull(getSessionsBusinessResponse);
            Assert.IsNotNull(getSessionsBusinessResponse.Sessions);
            Assert.AreEqual(1, getSessionsBusinessResponse.Sessions.Length);

            // Validate the Session business response element.
            Assert.IsNotNull(getSessionsBusinessResponse.Sessions[0]);
            Assert.AreEqual("6dk61ufcuzp3f7vs", getSessionsBusinessResponse.Sessions[0].SessionCode);
            Assert.AreEqual("Session Alpha", getSessionsBusinessResponse.Sessions[0].Name);
            Assert.AreEqual(new DateTime(2001, 1, 1), getSessionsBusinessResponse.Sessions[0].StartDate);
        }
        /// <summary>
        /// Executes the GetSessions business operation.
        /// </summary>
        public async virtual Task <GetSessionsBusinessResponse> GetSessions(IDatabaseConnection databaseConnection, GetSessionsBusinessRequest businessRequest)
        {
            // Validate the business request.
            this.ValidateGetSessionsRequest(businessRequest);

            // Initialize the operation data.
            GetSessionsOperationData operationData = new GetSessionsOperationData();

            // Validate the business operation.
            await this.ValidateGetSessionsOperation(databaseConnection, businessRequest, operationData);

            // Read the Session data rows.
            operationData.SessionDataRows = await this.sessionDataAccessComponent.ReadAll(databaseConnection);

            // Build the business response.
            GetSessionsBusinessResponse businessResponse = new GetSessionsBusinessResponse();

            // Build the Session business response elements.
            List <GetSessionsBusinessResponse.SessionBusinessResponseElement> sessionBusinessResponseElements = new List <GetSessionsBusinessResponse.SessionBusinessResponseElement>();

            foreach (SessionDataRow sessionDataRow in operationData.SessionDataRows)
            {
                // Build the Session business response element.
                GetSessionsBusinessResponse.SessionBusinessResponseElement sessionBusinessResponseElement = new GetSessionsBusinessResponse.SessionBusinessResponseElement();
                sessionBusinessResponseElement.SessionCode = sessionDataRow.SessionCode;
                sessionBusinessResponseElement.Name        = sessionDataRow.Name;
                sessionBusinessResponseElement.StartDate   = sessionDataRow.StartDate;
                sessionBusinessResponseElements.Add(sessionBusinessResponseElement);
            }

            // Set the Session business response elements.
            businessResponse.Sessions = sessionBusinessResponseElements.ToArray();

            // Return the business response.
            return(businessResponse);
        }