LCOV - code coverage report
Current view: top level - Cqrs/DataStores - InProcessDataStore.cs Hit Total Coverage
Test: doc-coverage.info Lines: 3 10 30.0 %
Date: 2017-07-26

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="cdmdotnet Limited">
       4             : // //   Copyright cdmdotnet Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using System.Collections;
      11             : using System.Collections.Generic;
      12             : using System.Linq;
      13             : using System.Linq.Expressions;
      14             : using Cqrs.Entities;
      15             : using Cqrs.Repositories;
      16             : 
      17             : namespace Cqrs.DataStores
      18             : {
      19             :         public class InProcessDataStore<TData> : IDataStore<TData>
      20             :                 where TData : Entity
      21           0 :         {
      22             :                 private InMemoryDatabase InMemoryDatabase { get; set; }
      23             : 
      24           0 :                 public InProcessDataStore()
      25             :                 {
      26             :                         InMemoryDatabase = new InMemoryDatabase();
      27             :                 }
      28             : 
      29             :                 #region Implementation of IEnumerable
      30             : 
      31             :                 /// <summary>
      32             :                 /// Returns an enumerator that iterates through the collection.
      33             :                 /// </summary>
      34             :                 /// <returns>
      35             :                 /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
      36             :                 /// </returns>
      37           1 :                 public IEnumerator<TData> GetEnumerator()
      38             :                 {
      39             :                         return InMemoryDatabase.GetAll<TData>().GetEnumerator();
      40             :                 }
      41             : 
      42             :                 /// <summary>
      43             :                 /// Returns an enumerator that iterates through a collection.
      44             :                 /// </summary>
      45             :                 /// <returns>
      46             :                 /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
      47             :                 /// </returns>
      48             :                 IEnumerator IEnumerable.GetEnumerator()
      49             :                 {
      50             :                         return GetEnumerator();
      51             :                 }
      52             : 
      53             :                 #endregion
      54             : 
      55             :                 #region Implementation of IQueryable
      56             : 
      57             :                 /// <summary>
      58             :                 /// Gets the expression tree that is associated with the instance of <see cref="T:System.Linq.IQueryable"/>.
      59             :                 /// </summary>
      60             :                 /// <returns>
      61             :                 /// The <see cref="T:System.Linq.Expressions.Expression"/> that is associated with this instance of <see cref="T:System.Linq.IQueryable"/>.
      62             :                 /// </returns>
      63             :                 public Expression Expression
      64             :                 {
      65             :                         get { return InMemoryDatabase.GetAll<TData>().AsQueryable().Expression; }
      66             :                 }
      67             : 
      68             :                 /// <summary>
      69             :                 /// Gets the type of the element(s) that are returned when the expression tree associated with this instance of <see cref="T:System.Linq.IQueryable"/> is executed.
      70             :                 /// </summary>
      71             :                 /// <returns>
      72             :                 /// A <see cref="T:System.Type"/> that represents the type of the element(s) that are returned when the expression tree associated with this object is executed.
      73             :                 /// </returns>
      74             :                 public Type ElementType
      75             :                 {
      76             :                         get { return InMemoryDatabase.GetAll<TData>().AsQueryable().ElementType; }
      77             :                 }
      78             : 
      79             :                 /// <summary>
      80             :                 /// Gets the singleResultQuery provider that is associated with this data source.
      81             :                 /// </summary>
      82             :                 /// <returns>
      83             :                 /// The <see cref="T:System.Linq.IQueryProvider"/> that is associated with this data source.
      84             :                 /// </returns>
      85             :                 public IQueryProvider Provider
      86             :                 {
      87             :                         get { return InMemoryDatabase.GetAll<TData>().AsQueryable().Provider; }
      88             :                 }
      89             : 
      90             :                 #endregion
      91             : 
      92             :                 #region Implementation of IDisposable
      93             : 
      94             :                 /// <summary>
      95             :                 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
      96             :                 /// </summary>
      97           1 :                 public void Dispose()
      98             :                 {
      99             :                 }
     100             : 
     101             :                 #endregion
     102             : 
     103             :                 #region Implementation of IDataStore<TData>
     104             : 
     105           0 :                 public void Add(TData data)
     106             :                 {
     107             :                         InMemoryDatabase.Get<TData>().Add(data.Rsn, data);
     108             :                 }
     109             : 
     110           0 :                 public void Add(IEnumerable<TData> data)
     111             :                 {
     112             :                         foreach (TData dataItem in data)
     113             :                                 Add(dataItem);
     114             :                 }
     115             : 
     116             :                 /// <summary>
     117             :                 /// Will mark the <paramref name="data"/> as logically (or soft) by setting <see cref="Entity.IsLogicallyDeleted"/> to true
     118             :                 /// </summary>
     119           1 :                 public void Remove(TData data)
     120             :                 {
     121             :                         InMemoryDatabase.Get<TData>()[data.Rsn].IsLogicallyDeleted = true;
     122             :                 }
     123             : 
     124           0 :                 public void Destroy(TData data)
     125             :                 {
     126             :                         InMemoryDatabase.Get<TData>().Remove(data.Rsn);
     127             :                 }
     128             : 
     129           0 :                 public void RemoveAll()
     130             :                 {
     131             :                         InMemoryDatabase.Get<TData>().Clear();
     132             :                 }
     133             : 
     134           0 :                 public void Update(TData data)
     135             :                 {
     136             :                         InMemoryDatabase.Get<TData>()[data.Rsn] = data;
     137             :                 }
     138             : 
     139             :                 #endregion
     140             :         }
     141             : }

Generated by: LCOV version 1.10