Documentation Coverage Report
Current view: top level - Ninject/Cqrs.Ninject.MongoDB - TestMongoDataStoreConnectionStringFactory.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.Configuration;
      10             : using cdmdotnet.StateManagement;
      11             : using cdmdotnet.StateManagement.Threaded;
      12             : using Cqrs.DataStores;
      13             : using Cqrs.Events;
      14             : using Cqrs.MongoDB.Events;
      15             : using Cqrs.MongoDB.Factories;
      16             : 
      17             : namespace Cqrs.Ninject.MongoDB
      18             : {
      19             :         /// <summary>
      20             :         /// A <see cref="IMongoDbDataStoreConnectionStringFactory"/> and <see cref="IMongoDbEventStoreConnectionStringFactory"/>
      21             :         /// that enables you to set a database name with <see cref="DatabaseName"/>. This means you can randomly generate your own database name per test.
      22             :         /// Both <see cref="IEventStore{TAuthenticationToken}"/> and <see cref="IDataStore{TData}"/> use the same connection string and database name.
      23             :         /// </summary>
      24             :         public class TestMongoDbDataStoreConnectionStringFactory
      25             :                 : IMongoDbDataStoreConnectionStringFactory
      26             :                 , IMongoDbEventStoreConnectionStringFactory
      27           1 :         {
      28             :                 private const string MongoDbConnectionStringKey = "MongoDb-Test";
      29             : 
      30             :                 private const string CallContextDatabaseNameKey = "MongoDataStoreConnectionStringFactory¿DatabaseName";
      31             : 
      32             :                 private static IContextItemCollection Query { get; set; }
      33             : 
      34             :                 static TestMongoDbDataStoreConnectionStringFactory()
      35             :                 {
      36             :                         Query = new ThreadedContextItemCollection();
      37             :                 }
      38             : 
      39             :                 /// <summary>
      40             :                 /// The name of the database currently being used.
      41             :                 /// </summary>
      42             :                 public static string DatabaseName
      43             :                 {
      44             :                         get
      45             :                         {
      46             :                                 return Query.GetData<string>(CallContextDatabaseNameKey);
      47             :                         }
      48             :                         set
      49             :                         {
      50             :                                 Query.SetData(CallContextDatabaseNameKey, value);
      51             :                         }
      52             :                 }
      53             : 
      54             :                 #region Implementation of IMongoDataStoreConnectionStringFactory
      55             : 
      56             :                 /// <summary>
      57             :                 /// Gets the current connection string.
      58             :                 /// </summary>
      59           1 :                 public string GetDataStoreConnectionString()
      60             :                 {
      61             :                         return ConfigurationManager.ConnectionStrings[MongoDbConnectionStringKey].ConnectionString;
      62             :                 }
      63             : 
      64             :                 /// <summary>
      65             :                 /// Gets the value of <see cref="DatabaseName"/>.
      66             :                 /// </summary>
      67           1 :                 public string GetDataStoreDatabaseName()
      68             :                 {
      69             :                         return DatabaseName;
      70             :                 }
      71             : 
      72             :                 #endregion
      73             : 
      74             :                 #region Implementation of IMongoDbEventStoreConnectionStringFactory
      75             : 
      76             :                 /// <summary>
      77             :                 /// Gets the current connection string.
      78             :                 /// </summary>
      79           1 :                 public string GetEventStoreConnectionString()
      80             :                 {
      81             :                         return GetDataStoreConnectionString();
      82             :                 }
      83             : 
      84             :                 /// <summary>
      85             :                 /// Gets the value of <see cref="DatabaseName"/>.
      86             :                 /// </summary>
      87           1 :                 public string GetEventStoreDatabaseName()
      88             :                 {
      89             :                         return DatabaseName;
      90             :                 }
      91             : 
      92             :                 #endregion
      93             :         }
      94             : }

Generated by: LCOV version 1.10