Documentation Coverage Report
Current view: top level - Cqrs/Events - DefaultEventBuilder.cs Hit Total Coverage
Version: 2.2 Artefacts: 3 3 100.0 %
Date: 2018-08-07 15:04:50

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using Newtonsoft.Json;
      11             : 
      12             : namespace Cqrs.Events
      13             : {
      14             :         /// <summary>
      15             :         /// Builds <see cref="EventData"/> from various input formats serialising as JSON.
      16             :         /// </summary>
      17             :         /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of the authentication token.</typeparam>
      18             :         public class DefaultEventBuilder<TAuthenticationToken> : EventBuilder<TAuthenticationToken>
      19           1 :         {
      20             :                 /// <summary>
      21             :                 /// The default <see cref="JsonSerializerSettings"/> to use.
      22             :                 /// </summary>
      23             :                 public static JsonSerializerSettings DefaultSettings { get; private set; }
      24             : 
      25             :                 static DefaultEventBuilder()
      26             :                 {
      27             :                         DefaultSettings = DefaultJsonSerializerSettings.DefaultSettings;
      28             :                 }
      29             : 
      30             :                 #region Implementation of EventBuilder
      31             : 
      32             :                 /// <summary>
      33             :                 /// Serialise the provided <paramref name="eventData"/> into JSON a <see cref="string"/>.
      34             :                 /// </summary>
      35             :                 /// <param name="eventData">The <see cref="IEvent{TAuthenticationToken}"/> to serialise.</param>
      36           1 :                 protected override string SerialiseEventDataToString(IEvent<TAuthenticationToken> eventData)
      37             :                 {
      38             :                         JsonSerializerSettings jsonSerialiserSettings = GetSerialisationSettings();
      39             : 
      40             :                         return JsonConvert.SerializeObject(eventData, jsonSerialiserSettings);
      41             :                 }
      42             : 
      43             :                 #endregion
      44             : 
      45             :                 /// <summary>
      46             :                 /// Returns <see cref="DefaultSettings"/>
      47             :                 /// </summary>
      48             :                 /// <returns><see cref="DefaultSettings"/></returns>
      49           1 :                 protected virtual JsonSerializerSettings GetSerialisationSettings()
      50             :                 {
      51             :                         return DefaultSettings;
      52             :                 }
      53             :         }
      54             : }

Generated by: LCOV version 1.12