LCOV - code coverage report
Current view: top level - Cqrs.MongoDB.Tests.Integration - MongoDbDataStoreTests.cs Hit Total Coverage
Test: doc-coverage.info Lines: 1 2 50.0 %
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.ServiceBus.Tests.Unit;
       9             : using Cqrs.MongoDB.DataStores;
      10             : using MongoDB.Driver;
      11             : using NUnit.Framework;
      12             : using TestClass = NUnit.Framework.TestFixtureAttribute;
      13             : using TestMethod = NUnit.Framework.TestAttribute;
      14             : using TestInitialize = NUnit.Framework.SetUpAttribute;
      15             : using TestCleanup = NUnit.Framework.TearDownAttribute;
      16             : using TestContext = System.Object;
      17             : 
      18             : namespace Cqrs.MongoDB.Tests.Integration
      19             : {
      20             :         /// <summary>
      21             :         /// A series of tests on the <see cref="MongoDbDataStore{TData}"/> class
      22             :         /// </summary>
      23             :         [TestClass]
      24             :         public class MongoDbDataStoreTests
      25           1 :         {
      26             :                 [TestMethod]
      27           0 :                 public void Save_ValidProjectionView_ProjectionViewCanBeRetreived()
      28             :                 {
      29             :                         // Arrange
      30             :                         var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
      31             :                         correlationIdHelper.SetCorrelationId(Guid.NewGuid());
      32             :                         var logger = new ConsoleLogger(new LoggerSettings(), correlationIdHelper);
      33             : 
      34             :                         var connectionStringFactory = new TestMongoDataStoreConnectionStringFactory();
      35             :                         TestMongoDataStoreConnectionStringFactory.DatabaseName = string.Format("Test-{0}", new Random().Next(0, 9999));
      36             : 
      37             :                         var factory = new TestMongoDbDataStoreFactory(logger, connectionStringFactory);
      38             :                         IMongoCollection<TestEvent> collection = factory.GetTestEventCollection();
      39             :                         try
      40             :                         {
      41             :                                 // Arrange
      42             :                                 var dataStore = new MongoDbDataStore<TestEvent>(logger, collection);
      43             : 
      44             :                                 var event1 = new TestEvent
      45             :                                 {
      46             :                                         Rsn = Guid.NewGuid(),
      47             :                                         Id = Guid.NewGuid(),
      48             :                                         CorrelationId = correlationIdHelper.GetCorrelationId(),
      49             :                                         Frameworks = new List<string> { "Test 1" },
      50             :                                         TimeStamp = DateTimeOffset.UtcNow
      51             :                                 };
      52             : 
      53             :                                 // Act
      54             :                                 dataStore.Add(event1);
      55             : 
      56             :                                 // Assert
      57             :                                 var timer = new Stopwatch();
      58             :                                 timer.Start();
      59             :                                 TestEvent view = dataStore.SingleOrDefault(e => e.Rsn == event1.Rsn);
      60             :                                 timer.Stop();
      61             :                                 Console.WriteLine("Load operation took {0}", timer.Elapsed);
      62             :                                 Assert.IsNotNull(view);
      63             :                                 Assert.AreEqual(event1.Id, view.Id);
      64             :                         }
      65             :                         finally
      66             :                         {
      67             :                                 // Clean-up
      68             :                                 collection.Database.Client.DropDatabase(TestMongoDataStoreConnectionStringFactory.DatabaseName);
      69             :                         }
      70             :                 }
      71             :         }
      72             : }

Generated by: LCOV version 1.10