Documentation Coverage Report
Current view: top level - Azure/Tests/Cqrs.Azure.BlobStorage.Test.Integration - TableStorageDataStoreTests.cs Hit Total Coverage
Version: 2.2 Artefacts: 5 5 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 cdmdotnet.Logging;
      13             : using cdmdotnet.Logging.Configuration;
      14             : using cdmdotnet.StateManagement.Threaded;
      15             : using Cqrs.Azure.BlobStorage.DataStores;
      16             : using Cqrs.Azure.BlobStorage.Repositories;
      17             : using Cqrs.Azure.ServiceBus.Tests.Unit;
      18             : using Cqrs.Configuration;
      19             : using Cqrs.DataStores;
      20             : using Cqrs.Entities;
      21             : using NUnit.Framework;
      22             : using TestClass = NUnit.Framework.TestFixtureAttribute;
      23             : using TestMethod = NUnit.Framework.TestAttribute;
      24             : using TestInitialize = NUnit.Framework.SetUpAttribute;
      25             : using TestCleanup = NUnit.Framework.TearDownAttribute;
      26             : using TestContext = System.Object;
      27             : 
      28             : namespace Cqrs.Azure.BlobStorage.Test.Integration
      29             : {
      30             :         /// <summary>
      31             :         /// A series of tests on the <see cref="TableStorageDataStore{TData}"/> class
      32             :         /// </summary>
      33             :         [TestClass]
      34             :         public class TableStorageDataStoreTests
      35           1 :         {
      36             :                 /// <summary>
      37             :                 /// Tests the <see cref="IDataStore{TData}.Add(TData)"/> method
      38             :                 /// Passing a valid test <see cref="IEntity"/>
      39             :                 /// Expecting the test <see cref="IEntity"/> is able to be read.
      40             :                 /// </summary>
      41             :                 [TestMethod]
      42           1 :                 public virtual void Add_ValidProjectionView_ProjectionViewCanBeRetreived()
      43             :                 {
      44             :                         // Arrange
      45             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      46             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      47             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
      48             :                         TableStorageDataStore<TestEvent> dataStore = CreateDataStore<TestEvent>(logger, new ConfigurationManager());
      49             : 
      50             :                         var event1 = new TestEvent
      51             :                         {
      52             :                                 Rsn = Guid.NewGuid(),
      53             :                                 Id = Guid.NewGuid(),
      54             :                                 CorrelationId = correlationIdHelper.GetCorrelationId(),
      55             :                                 Frameworks = new List<string> { "Test 1" },
      56             :                                 TimeStamp = DateTimeOffset.UtcNow
      57             :                         };
      58             : 
      59             :                         // Act
      60             :                         dataStore.Add(event1);
      61             : 
      62             :                         // Assert
      63             :                         var timer = new Stopwatch();
      64             :                         var repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEvent>, TestEvent>(() => dataStore, null);
      65             :                         timer.Start();
      66             :                         TestEvent view = repository.Load(event1.Rsn);
      67             :                         timer.Stop();
      68             :                         Console.WriteLine("Load operation took {0}", timer.Elapsed);
      69             :                         Assert.IsNotNull(view);
      70             :                         Assert.AreEqual(event1.Id, view.Id);
      71             :                 }
      72             : 
      73             :                 /// <summary>
      74             :                 /// Tests the <see cref="IDataStore{TData}.Add(TData)"/> method
      75             :                 /// Passing a valid test <see cref="IEntity"/>
      76             :                 /// Expecting the test <see cref="IEntity"/> is able to be read.
      77             :                 /// </summary>
      78             :                 [TestMethod]
      79           1 :                 public virtual void Add_ValidProjectionEntityView_ProjectionEntityViewCanBeRetreived()
      80             :                 {
      81             :                         // Arrange
      82             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      83             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      84             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
      85             :                         TableStorageDataStore<TestEntity> dataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
      86             : 
      87             :                         var event1 = new TestEntity
      88             :                         {
      89             :                                 Rsn = Guid.NewGuid(),
      90             :                                 Name = "Name"
      91             :                         };
      92             : 
      93             :                         // Act
      94             :                         dataStore.Add(event1);
      95             : 
      96             :                         // Assert
      97             :                         var timer = new Stopwatch();
      98             :                         var repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEntity>, TestEntity>(() => dataStore, null);
      99             :                         timer.Start();
     100             :                         TestEntity view = repository.Load(event1.Rsn);
     101             :                         timer.Stop();
     102             :                         Console.WriteLine("Load operation took {0}", timer.Elapsed);
     103             :                         Assert.IsNotNull(view);
     104             :                         Assert.AreEqual(event1.Rsn, view.Rsn);
     105             :                         Assert.AreEqual(event1.Name, view.Name);
     106             :                 }
     107             : 
     108             :                 /// <summary>
     109             :                 /// Tests the <see cref="IDataStore{TData}.Update(TData)"/> method
     110             :                 /// Passing a valid test <see cref="IEntity"/>
     111             :                 /// Expecting the test <see cref="IEntity"/> is able to be read with updated properties.
     112             :                 /// </summary>
     113             :                 [TestMethod]
     114           1 :                 public virtual void Update_ValidProjectionEntityView_ProjectionEntityViewCanBeRetreived()
     115             :                 {
     116             :                         // Arrange
     117             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
     118             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
     119             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
     120             :                         TableStorageDataStore<TestEntity> dataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
     121             : 
     122             :                         var event1 = new TestEntity
     123             :                         {
     124             :                                 Rsn = Guid.NewGuid(),
     125             :                                 Name = "Name1"
     126             :                         };
     127             :                         dataStore.Add(event1);
     128             : 
     129             :                         // The repo disposes the datastore, so a copy is needed.
     130             :                         TableStorageDataStore<TestEntity> repoDataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
     131             :                         // DO NOT REMOVE/REFACTOR Closure modifier access thingee stuff...
     132             :                         var store = repoDataStore;
     133             :                         var repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEntity>, TestEntity>(() => store, null);
     134             :                         TestEntity view = repository.Load(event1.Rsn);
     135             :                         view.Name = "Name2";
     136             : 
     137             :                         // Act
     138             :                         dataStore.Update(event1);
     139             : 
     140             :                         // Assert
     141             :                         var timer = new Stopwatch();
     142             :                         timer.Start();
     143             :                         // Refresh the data store due to disposal.
     144             :                         repoDataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
     145             :                         repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEntity>, TestEntity>(() => repoDataStore, null);
     146             :                         view = repository.Load(event1.Rsn);
     147             :                         timer.Stop();
     148             :                         Console.WriteLine("Load operation took {0}", timer.Elapsed);
     149             :                         Assert.IsNotNull(view);
     150             :                         Assert.AreEqual(event1.Rsn, view.Rsn);
     151             :                         Assert.AreEqual(event1.Name, view.Name);
     152             :                 }
     153             : 
     154             :                 /// <summary>
     155             :                 /// Create a <see cref="TableStorageDataStore{TData}"/> ready for testing.
     156             :                 /// </summary>
     157           1 :                 protected virtual TableStorageDataStore<TData> CreateDataStore<TData>(ILogger logger, IConfigurationManager configurationManager)
     158             :                         where TData : Entity
     159             :                 {
     160             :                         return new TableStorageDataStore<TData>(logger, new TableStorageDataStoreConnectionStringFactory(configurationManager, logger));
     161             :                 }
     162             :         }
     163             : }

Generated by: LCOV version 1.10