using MongoDbGenericRepository.Models; using System.Collections.Generic; using System; namespace CoreIntegrationTests.Infrastructure { public class BaseMongoDbRepositoryTests : IDisposable where T : 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; } /// /// Constructor, init code /// public BaseMongoDbRepositoryTests() { Init(); 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; } public void Init() { MongoDbConfig.EnsureConfigured(); SUT = TestRepository.Instance; } public void Cleanup() { // We drop the collection at the end of each test session. if (!string.IsNullOrEmpty(PartitionKey)) { SUT.DropTestCollection(PartitionKey); } else { SUT.DropTestCollection(); } } #region IDisposable Support private bool _disposedValue; // Pour détecter les appels redondants protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { Cleanup(); } _disposedValue = true; } } // Ce code est ajouté pour implémenter correctement le modèle supprimable. public void Dispose() { // Ne modifiez pas ce code. Placez le code de nettoyage dans Dispose(bool disposing) ci-dessus. Dispose(true); } #endregion } }