using MongoDbGenericRepository.Models; using NUnit.Framework; using System.Collections.Generic; using System.Configuration; namespace IntegrationTests.Infrastructure { public class BaseMongoDbRepositoryTests where T : class, new() { public T CreateTestDocument() { return new T(); } public List CreateTestDocuments(int numberOfDocumentsToCreate) { var docs = new List(); 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; } /// /// SUT: System Under Test /// 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(PartitionKey); } else { SUT.DropTestCollection(); } } } }