LCOV - code coverage report
Current view: top level - Cqrs.EventStore - ProjectionReader.cs Hit Total Coverage
Test: doc-coverage.info Lines: 0 4 0.0 %
Date: 2017-07-26

          Line data    Source code
       1             : using System.Collections.Generic;
       2             : using System.Linq;
       3             : using System.Text;
       4             : using EventStore.ClientAPI;
       5             : using Newtonsoft.Json;
       6             : 
       7             : namespace Cqrs.EventStore
       8             : {
       9             :         public abstract class ProjectionReader<TAuthenticationToken>
      10           0 :         {
      11             :                 protected IEventStoreConnectionHelper EventStoreConnectionHelper { get; set; }
      12             : 
      13             :                 protected IEventDeserialiser<TAuthenticationToken> EventDeserialiser { get; set; }
      14             : 
      15           0 :                 protected ProjectionReader(IEventStoreConnectionHelper eventStoreConnectionHelper, IEventDeserialiser<TAuthenticationToken> eventDeserialiser)
      16             :                 {
      17             :                         EventStoreConnectionHelper = eventStoreConnectionHelper;
      18             :                         EventDeserialiser = eventDeserialiser;
      19             :                 }
      20             : 
      21           0 :                 protected IEnumerable<dynamic> GetDataByStreamName(string streamName)
      22             :                 {
      23             :                         StreamEventsSlice eventCollection;
      24             :                         using (IEventStoreConnection connection = EventStoreConnectionHelper.GetEventStoreConnection())
      25             :                         {
      26             :                                 eventCollection = connection.ReadStreamEventsBackwardAsync(streamName, StreamPosition.End, 1, false).Result;
      27             :                         }
      28             :                         var jsonSerialiserSettings = EventDeserialiser.GetSerialisationSettings();
      29             :                         var encoder = new UTF8Encoding();
      30             :                         return
      31             :                         (
      32             :                                 (
      33             :                                         (IEnumerable<dynamic>)eventCollection.Events
      34             :                                         .Select(e => JsonConvert.DeserializeObject(((dynamic)encoder.GetString(e.Event.Data)), jsonSerialiserSettings))
      35             :                                         .SingleOrDefault()
      36             :                                 )
      37             :                                         ??
      38             :                                 (
      39             :                                         Enumerable.Empty<dynamic>()
      40             :                                 )
      41             :                         )
      42             :                         .Select(x => x.Value);
      43             :                 }
      44             : 
      45           0 :                 protected IEnumerable<TData> GetDataByStreamName<TData>(string streamName)
      46             :                 {
      47             :                         IList<TData> data = GetDataByStreamName(streamName)
      48             :                                 .Select(e => JsonConvert.DeserializeObject<TData>(e.ToString()))
      49             :                                 .Cast<TData>()
      50             :                                 .ToList();
      51             :                         return data;
      52             :                 }
      53             :         }
      54             : }

Generated by: LCOV version 1.10