62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using MongoDbGenericRepository.Models;
|
|
using NUnit.Framework;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
|
|
namespace IntegrationTests.Infrastructure
|
|
{
|
|
public class BaseMongoDbRepositoryTests<T> where T : class, new()
|
|
{
|
|
public T CreateTestDocument()
|
|
{
|
|
return new T();
|
|
}
|
|
|
|
public List<T> CreateTestDocuments(int numberOfDocumentsToCreate)
|
|
{
|
|
var docs = new List<T>();
|
|
for(var i = 0; i < numberOfDocumentsToCreate; i++)
|
|
{
|
|
docs.Add(new T());
|
|
}
|
|
return docs;
|
|
}
|
|
|
|
public BaseMongoDbRepositoryTests()
|
|
{
|
|
var type = CreateTestDocument();
|
|
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()
|
|
{
|
|
SUT = new TestRepository("mongodb://test:Test123!@10.0.3.4:27017", "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>();
|
|
}
|
|
}
|
|
}
|
|
}
|