Documentation Coverage Report
Current view: top level - Azure/Tests/Cqrs.Azure.BlobStorage.Test.Integration - BlobStorageEventStoreTests.cs Hit Total Coverage
Version: 2.2 Artefacts: 2 2 100.0 %
Date: 2017-09-22

          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 System.Collections.Generic;
      11             : using System.Diagnostics;
      12             : using System.Linq;
      13             : using cdmdotnet.Logging;
      14             : using cdmdotnet.Logging.Configuration;
      15             : using cdmdotnet.StateManagement.Threaded;
      16             : using Cqrs.Azure.BlobStorage.Events;
      17             : using Cqrs.Azure.ServiceBus.Tests.Unit;
      18             : using Cqrs.Configuration;
      19             : using Cqrs.Events;
      20             : using NUnit.Framework;
      21             : using TestClass = NUnit.Framework.TestFixtureAttribute;
      22             : using TestMethod = NUnit.Framework.TestAttribute;
      23             : using TestInitialize = NUnit.Framework.SetUpAttribute;
      24             : using TestCleanup = NUnit.Framework.TearDownAttribute;
      25             : using TestContext = System.Object;
      26             : 
      27             : namespace Cqrs.Azure.BlobStorage.Test.Integration
      28             : {
      29             :         /// <summary>
      30             :         /// A series of tests on the <see cref="BlobStorageEventStore{TAuthenticationToken}"/> class
      31             :         /// </summary>
      32             :         [TestClass]
      33             :         public class BlobStorageEventStoreTests
      34           1 :         {
      35             :                 /// <summary>
      36             :                 /// Tests the <see cref="IEventStore{TAuthenticationToken}.Save"/> method
      37             :                 /// Passing a valid test <see cref="IEvent{TAuthenticationToken}"/>
      38             :                 /// Expecting the test <see cref="IEvent{TAuthenticationToken}"/> is able to be read.
      39             :                 /// </summary>
      40             :                 [TestMethod]
      41           1 :                 public virtual void Save_ValidEvent_EventCanBeRetreived()
      42             :                 {
      43             :                         // Arrange
      44             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      45             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      46             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
      47             :                         var eventStore = new BlobStorageEventStore<Guid>(new DefaultEventBuilder<Guid>(), new EventDeserialiser<Guid>(), logger, new BlobStorageEventStoreConnectionStringFactory(new ConfigurationManager(), logger));
      48             : 
      49             :                         var event1 = new TestEvent
      50             :                         {
      51             :                                 Rsn = Guid.NewGuid(),
      52             :                                 Id = Guid.NewGuid(),
      53             :                                 CorrelationId = correlationIdHelper.GetCorrelationId(),
      54             :                                 Frameworks = new List<string> { "Test 1" },
      55             :                                 TimeStamp = DateTimeOffset.UtcNow
      56             :                         };
      57             :                         var event2 = new TestEvent
      58             :                         {
      59             :                                 Rsn = Guid.NewGuid(),
      60             :                                 Id = Guid.NewGuid(),
      61             :                                 CorrelationId = correlationIdHelper.GetCorrelationId(),
      62             :                                 Frameworks = new List<string> { "Test 2" },
      63             :                                 TimeStamp = DateTimeOffset.UtcNow
      64             :                         };
      65             : 
      66             :                         // Act
      67             :                         eventStore.Save<TestEvent>(event1);
      68             :                         eventStore.Save<TestEvent>(event2);
      69             : 
      70             :                         // Assert
      71             :                         var timer = new Stopwatch();
      72             :                         IList<IEvent<Guid>> events = eventStore.Get<TestEvent>(event1.Id).ToList();
      73             :                         timer.Stop();
      74             :                         Console.WriteLine("Load one operation took {0}", timer.Elapsed);
      75             :                         Assert.AreEqual(1, events.Count);
      76             :                         Assert.AreEqual(event1.Id, events.Single().Id);
      77             :                         Assert.AreEqual(event1.Frameworks.Single(), events.Single().Frameworks.Single());
      78             : 
      79             :                         timer.Restart();
      80             :                         events = eventStore.Get<TestEvent>(event2.Id).ToList();
      81             :                         timer.Stop();
      82             :                         Console.WriteLine("Load one operation took {0}", timer.Elapsed);
      83             :                         Assert.AreEqual(1, events.Count);
      84             :                         Assert.AreEqual(event2.Id, events.Single().Id);
      85             :                         Assert.AreEqual(event2.Frameworks.Single(), events.Single().Frameworks.Single());
      86             : 
      87             :                         timer.Restart();
      88             :                         IList<EventData> correlatedEvents = eventStore.Get(event1.CorrelationId).ToList();
      89             :                         timer.Stop();
      90             :                         Console.WriteLine("Load several correlated operation took {0}", timer.Elapsed);
      91             :                         Assert.AreEqual(2, correlatedEvents.Count);
      92             :                 }
      93             :         }
      94             : }

Generated by: LCOV version 1.10