Files
mongodb-generic-repository/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs
T
alexandre-spieser 1d985e0274 Added tests
2017-09-24 21:34:29 +00:00

63 lines
1.7 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()
{
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>();
}
}
}
}