added tests for partitioned collections
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using MongoDbGenericRepository.Models;
|
||||
using NUnit.Framework;
|
||||
using System.Configuration;
|
||||
|
||||
namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
public class BaseMongoDbRepositoryTests<T> where T : Document, new()
|
||||
{
|
||||
public T GetDocumentInstance()
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
|
||||
public BaseMongoDbRepositoryTests()
|
||||
{
|
||||
var type = GetDocumentInstance();
|
||||
if (type is IPartitionedDocument)
|
||||
{
|
||||
PartitionKey = ((IPartitionedDocument)type).PartitionKey;
|
||||
}
|
||||
}
|
||||
|
||||
public string PartitionKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SUT: System Under Test
|
||||
/// </summary>
|
||||
protected static ITestRepository SUT { get; set; }
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Init()
|
||||
{
|
||||
var connectionString = ConfigurationManager.ConnectionStrings["MongoDbTests"].ConnectionString;
|
||||
SUT = new TestRepository(connectionString, "MongoDbTests");
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void Cleanup()
|
||||
{
|
||||
// We drop the collection at the end of each test session.
|
||||
if (!string.IsNullOrEmpty(PartitionKey))
|
||||
{
|
||||
SUT.DropTestCollection<T>(PartitionKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
SUT.DropTestCollection<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,6 @@ namespace IntegrationTests
|
||||
public interface ITestRepository : IBaseMongoRepository
|
||||
{
|
||||
void DropTestCollection<TDocument>();
|
||||
void DropTestCollection<TDocument>(string partitionKey);
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,10 @@ namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
_mongoDbContext.DropCollection<TDocument>();
|
||||
}
|
||||
|
||||
public void DropTestCollection<TDocument>(string partitionKey)
|
||||
{
|
||||
_mongoDbContext.DropCollection<TDocument>(partitionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user