LCOV - code coverage report
Current view: top level - Azure/Tests/Cqrs.Azure.BlobStorage.Test.Integration - TableStorageDataStoreTests.cs Hit Total Coverage
Test: doc-coverage.info Lines: 1 9 11.1 %
Date: 2017-07-26

          Line data    Source code
       1             : using System;
       2             : using System.Collections.Generic;
       3             : using System.Diagnostics;
       4             : using System.Linq;
       5             : using cdmdotnet.Logging;
       6             : using cdmdotnet.Logging.Configuration;
       7             : using cdmdotnet.StateManagement.Threaded;
       8             : using Cqrs.Azure.BlobStorage.DataStores;
       9             : using Cqrs.Azure.BlobStorage.Repositories;
      10             : using Cqrs.Azure.ServiceBus.Tests.Unit;
      11             : using Cqrs.Configuration;
      12             : using Cqrs.DataStores;
      13             : using Cqrs.Entities;
      14             : using Cqrs.Repositories.Queries;
      15             : using NUnit.Framework;
      16             : using TestClass = NUnit.Framework.TestFixtureAttribute;
      17             : using TestMethod = NUnit.Framework.TestAttribute;
      18             : using TestInitialize = NUnit.Framework.SetUpAttribute;
      19             : using TestCleanup = NUnit.Framework.TearDownAttribute;
      20             : using TestContext = System.Object;
      21             : 
      22             : namespace Cqrs.Azure.BlobStorage.Test.Integration
      23             : {
      24             :         /// <summary>
      25             :         /// A series of tests on the <see cref="TableStorageDataStore{TData}"/> class
      26             :         /// </summary>
      27             :         [TestClass]
      28             :         public class TableStorageDataStoreTests
      29           1 :         {
      30             :                 [TestMethod]
      31           0 :                 public virtual void Add_ValidProjectionView_ProjectionViewCanBeRetreived()
      32             :                 {
      33             :                         // Arrange
      34             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      35             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      36             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
      37             :                         TableStorageDataStore<TestEvent> dataStore = CreateDataStore<TestEvent>(logger, new ConfigurationManager());
      38             : 
      39             :                         var event1 = new TestEvent
      40             :                         {
      41             :                                 Rsn = Guid.NewGuid(),
      42             :                                 Id = Guid.NewGuid(),
      43             :                                 CorrelationId = correlationIdHelper.GetCorrelationId(),
      44             :                                 Frameworks = new List<string> { "Test 1" },
      45             :                                 TimeStamp = DateTimeOffset.UtcNow
      46             :                         };
      47             : 
      48             :                         // Act
      49             :                         dataStore.Add(event1);
      50             : 
      51             :                         // Assert
      52             :                         var timer = new Stopwatch();
      53             :                         var repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEvent>, TestEvent>(() => dataStore, null);
      54             :                         timer.Start();
      55             :                         TestEvent view = repository.Load(event1.Rsn);
      56             :                         timer.Stop();
      57             :                         Console.WriteLine("Load operation took {0}", timer.Elapsed);
      58             :                         Assert.IsNotNull(view);
      59             :                         Assert.AreEqual(event1.Id, view.Id);
      60             :                 }
      61             : 
      62             :                 [TestMethod]
      63           0 :                 public virtual void Add_ValidProjectionEntityView_ProjectionEntityViewCanBeRetreived()
      64             :                 {
      65             :                         // Arrange
      66             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      67             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      68             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
      69             :                         TableStorageDataStore<TestEntity> dataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
      70             : 
      71             :                         var event1 = new TestEntity
      72             :                         {
      73             :                                 Rsn = Guid.NewGuid(),
      74             :                                 Name = "Name"
      75             :                         };
      76             : 
      77             :                         // Act
      78             :                         dataStore.Add(event1);
      79             : 
      80             :                         // Assert
      81             :                         var timer = new Stopwatch();
      82             :                         var repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEntity>, TestEntity>(() => dataStore, null);
      83             :                         timer.Start();
      84             :                         TestEntity view = repository.Load(event1.Rsn);
      85             :                         timer.Stop();
      86             :                         Console.WriteLine("Load operation took {0}", timer.Elapsed);
      87             :                         Assert.IsNotNull(view);
      88             :                         Assert.AreEqual(event1.Rsn, view.Rsn);
      89             :                         Assert.AreEqual(event1.Name, view.Name);
      90             :                 }
      91             : 
      92             :                 [TestMethod]
      93           0 :                 public virtual void Update_ValidProjectionEntityView_ProjectionEntityViewCanBeRetreived()
      94             :                 {
      95             :                         // Arrange
      96             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      97             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      98             :                         var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
      99             :                         TableStorageDataStore<TestEntity> dataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
     100             : 
     101             :                         var event1 = new TestEntity
     102             :                         {
     103             :                                 Rsn = Guid.NewGuid(),
     104             :                                 Name = "Name1"
     105             :                         };
     106             :                         dataStore.Add(event1);
     107             : 
     108             :                         // The repo disposes the datastore, so a copy is needed.
     109             :                         TableStorageDataStore<TestEntity> repoDataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
     110             :                         var repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEntity>, TestEntity>(() => repoDataStore, null);
     111             :                         TestEntity view = repository.Load(event1.Rsn);
     112             :                         view.Name = "Name2";
     113             : 
     114             :                         // Act
     115             :                         dataStore.Update(event1);
     116             : 
     117             :                         // Assert
     118             :                         var timer = new Stopwatch();
     119             :                         timer.Start();
     120             :                         // Refresh the data store due to disposal.
     121             :                         repoDataStore = CreateDataStore<TestEntity>(logger, new ConfigurationManager());
     122             :                         repository = new TableStorageRepository<TestQueryStrategy, TestQueryBuilder<TestEntity>, TestEntity>(() => repoDataStore, null);
     123             :                         view = repository.Load(event1.Rsn);
     124             :                         timer.Stop();
     125             :                         Console.WriteLine("Load operation took {0}", timer.Elapsed);
     126             :                         Assert.IsNotNull(view);
     127             :                         Assert.AreEqual(event1.Rsn, view.Rsn);
     128             :                         Assert.AreEqual(event1.Name, view.Name);
     129             :                 }
     130             : 
     131           0 :                 protected virtual TableStorageDataStore<TData> CreateDataStore<TData>(ILogger logger, IConfigurationManager configurationManager)
     132             :                         where TData : Entity
     133             :                 {
     134             :                         return new TableStorageDataStore<TData>(logger, new TableStorageDataStoreConnectionStringFactory(configurationManager, logger));
     135             :                 }
     136             : 
     137             :                 public class TestQueryStrategy : IQueryStrategy
     138           0 :                 {
     139             :                         #region Implementation of IQueryStrategy
     140             : 
     141             :                         public IQueryPredicate QueryPredicate { get; set; }
     142             : 
     143             :                         #endregion
     144             :                 }
     145             : 
     146             :                 public class TestQueryBuilder<TData> : QueryBuilder<TestQueryStrategy, TData>
     147             :                         where TData : Entity
     148           0 :                 {
     149           0 :                         public TestQueryBuilder(IDataStore<TData> dataStore, IDependencyResolver dependencyResolver)
     150             :                                 : base(dataStore, dependencyResolver)
     151             :                         {
     152             :                         }
     153             : 
     154             :                         #region Overrides of QueryBuilder<TestQueryStrategy,TData>
     155             : 
     156           0 :                         protected override IQueryable<TData> GeneratePredicate(QueryPredicate queryPredicate, IQueryable<TData> leftHandQueryable = null)
     157             :                         {
     158             :                                 throw new NotImplementedException();
     159             :                         }
     160             : 
     161             :                         #endregion
     162             :                 }
     163             :         }
     164             : }

Generated by: LCOV version 1.10