Documentation Coverage Report
Current view: top level - Cqrs.MongoDB.Tests.Integration - MongoDbDataStoreTests.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.ServiceBus.Tests.Unit;
      17             : using Cqrs.DataStores;
      18             : using Cqrs.Entities;
      19             : using Cqrs.MongoDB.DataStores;
      20             : using MongoDB.Driver;
      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.MongoDB.Tests.Integration
      29             : {
      30             :         /// <summary>
      31             :         /// A series of tests on the <see cref="MongoDbDataStore{TData}"/> class
      32             :         /// </summary>
      33             :         [TestClass]
      34             :         public class MongoDbDataStoreTests
      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 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 LoggerSettings(), correlationIdHelper);
      48             : 
      49             :                         var connectionStringFactory = new TestMongoDataStoreConnectionStringFactory();
      50             :                         TestMongoDataStoreConnectionStringFactory.DatabaseName = string.Format("Test-{0}", new Random().Next(0, 9999));
      51             : 
      52             :                         var factory = new TestMongoDbDataStoreFactory(logger, connectionStringFactory);
      53             :                         IMongoCollection<TestEvent> collection = factory.GetTestEventCollection();
      54             :                         try
      55             :                         {
      56             :                                 // Arrange
      57             :                                 var dataStore = new MongoDbDataStore<TestEvent>(logger, collection);
      58             : 
      59             :                                 var event1 = new TestEvent
      60             :                                 {
      61             :                                         Rsn = Guid.NewGuid(),
      62             :                                         Id = Guid.NewGuid(),
      63             :                                         CorrelationId = correlationIdHelper.GetCorrelationId(),
      64             :                                         Frameworks = new List<string> { "Test 1" },
      65             :                                         TimeStamp = DateTimeOffset.UtcNow
      66             :                                 };
      67             : 
      68             :                                 // Act
      69             :                                 dataStore.Add(event1);
      70             : 
      71             :                                 // Assert
      72             :                                 var timer = new Stopwatch();
      73             :                                 timer.Start();
      74             :                                 TestEvent view = dataStore.SingleOrDefault(e => e.Rsn == event1.Rsn);
      75             :                                 timer.Stop();
      76             :                                 Console.WriteLine("Load operation took {0}", timer.Elapsed);
      77             :                                 Assert.IsNotNull(view);
      78             :                                 Assert.AreEqual(event1.Id, view.Id);
      79             :                         }
      80             :                         finally
      81             :                         {
      82             :                                 // Clean-up
      83             :                                 collection.Database.Client.DropDatabase(TestMongoDataStoreConnectionStringFactory.DatabaseName);
      84             :                         }
      85             :                 }
      86             :         }
      87             : }

Generated by: LCOV version 1.10