added test suite for BaseMongoRepository<TKey>

This commit is contained in:
Alexandre SPIESER
2019-04-15 00:26:10 +01:00
parent baaf2b5ee9
commit 530309e9fc
19 changed files with 9015 additions and 4480 deletions
@@ -1,4 +1,5 @@
using MongoDbGenericRepository.Models;
using MongoDbGenericRepository;
using MongoDbGenericRepository.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -30,7 +31,7 @@ namespace CoreIntegrationTests.Infrastructure
_fixture.PartitionKey = PartitionKey;
TestClassName = GetClassName();
MongoDbConfig.EnsureConfigured();
SUT = TestRepository.Instance;
SUT = TestTKeyRepository<Guid>.Instance;
}
protected T CreateTestDocument()
@@ -63,7 +64,7 @@ namespace CoreIntegrationTests.Infrastructure
/// <summary>
/// SUT: System Under Test
/// </summary>
protected static ITestRepository SUT { get; set; }
protected static ITestRepository<Guid> SUT { get; set; }
#region Add
@@ -1,7 +1,43 @@
using MongoDbGenericRepository;
using MongoDB.Bson;
using MongoDbGenericRepository;
using System;
namespace CoreIntegrationTests.Infrastructure
{
public interface ITestRepository<TKey> : IBaseMongoRepository<TKey> where TKey : IEquatable<TKey>
{
void DropTestCollection<TDocument>();
void DropTestCollection<TDocument>(string partitionKey);
}
public class TestTKeyRepository<TKey> : BaseMongoRepository<TKey>, ITestRepository<TKey> where TKey : IEquatable<TKey>
{
const string connectionString = "mongodb://localhost:27017/MongoDbTests";
private static readonly ITestRepository<TKey> _instance = new TestTKeyRepository<TKey>(connectionString);
/// <inheritdoc />
private TestTKeyRepository(string connectionString) : base(connectionString)
{
}
public static ITestRepository<TKey> Instance
{
get
{
return _instance;
}
}
public void DropTestCollection<TDocument>()
{
MongoDbContext.DropCollection<TDocument>();
}
public void DropTestCollection<TDocument>(string partitionKey)
{
MongoDbContext.DropCollection<TDocument>(partitionKey);
}
}
/// <summary>
/// A singleton implementation of the TestRepository
/// </summary>