LCOV - code coverage report
Current view: top level - Cqrs.WebApi - CqrsEventApiController.cs Hit Total Coverage
Test: doc-coverage.info Lines: 2 5 40.0 %
Date: 2017-07-26

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="cdmdotnet Limited">
       4             : // //   Copyright cdmdotnet Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using System.Collections.Generic;
      11             : using cdmdotnet.Logging;
      12             : using Cqrs.Authentication;
      13             : using Cqrs.Events;
      14             : using Cqrs.Services;
      15             : 
      16             : namespace Cqrs.WebApi
      17             : {
      18             :         /// <summary>
      19             :         /// A <see cref="CqrsApiController"/> that includes an implementation of the <see cref="IEventService{TAuthenticationToken}.GetEventData"/> method
      20             :         /// </summary>
      21             :         public abstract class CqrsEventApiController<TSingleSignOnToken>
      22             :                 : CqrsApiController
      23             :                 , IEventService<TSingleSignOnToken>
      24             :                 where TSingleSignOnToken : ISingleSignOnToken, new()
      25           1 :         {
      26           0 :                 protected CqrsEventApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IAuthenticationTokenHelper<TSingleSignOnToken> authenticationTokenHelper, IEventStore<TSingleSignOnToken> eventStore)
      27             :                         : base(logger, correlationIdHelper)
      28             :                 {
      29             :                         AuthenticationTokenHelper = authenticationTokenHelper;
      30             :                         EventStore = eventStore;
      31             :                 }
      32             : 
      33             :                 protected IAuthenticationTokenHelper<TSingleSignOnToken> AuthenticationTokenHelper { get; private set; }
      34             : 
      35             :                 protected virtual IEventStore<TSingleSignOnToken> EventStore { get; private set; }
      36             : 
      37             : 
      38             :                 #region Implementation of IEventService<SingleSignOnToken>
      39             : 
      40             :                 IServiceResponseWithResultData<IEnumerable<EventData>> IEventService<TSingleSignOnToken>.GetEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest)
      41             :                 {
      42             :                         return GetEventData(serviceRequest);
      43             :                 }
      44             : 
      45             :                 /// <summary>
      46             :                 /// Query for all the events that match the provided CorrelationId.
      47             :                 /// </summary>
      48             :                 /// <param name="serviceRequest">A <see cref="IServiceRequestWithData{TAuthenticationToken,TData}">service-request</see> that contains the CorrelationId.</param>
      49             :                 /// <returns>A collection of <see cref="EventData">event data</see></returns>
      50           1 :                 protected virtual IServiceResponseWithResultData<IEnumerable<EventData>> GetEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest)
      51             :                 {
      52             :                         AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
      53             :                         CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);
      54             : 
      55             :                         OnGetEventData(serviceRequest);
      56             :                         IEnumerable<EventData> results = EventStore.Get(serviceRequest.Data);
      57             :                         results = OnGotEventData(serviceRequest, results);
      58             : 
      59             :                         return new ServiceResponseWithResultData<IEnumerable<EventData>>
      60             :                         {
      61             :                                 State = ServiceResponseStateType.Succeeded,
      62             :                                 ResultData = results,
      63             :                                 CorrelationId = CorrelationIdHelper.GetCorrelationId()
      64             :                         };
      65             :                 }
      66             : 
      67             :                 #endregion
      68             : 
      69           0 :                 protected virtual void OnGetEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest) { }
      70             : 
      71           0 :                 protected virtual IEnumerable<EventData> OnGotEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest, IEnumerable<EventData> results)
      72             :                 {
      73             :                         return results;
      74             :                 }
      75             :         }
      76             : }

Generated by: LCOV version 1.10