using MongoDbGenericRepository; using MongoDbGenericRepository.Models; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; namespace CoreIntegrationTests.Infrastructure { public class MongoDbTestFixture : IDisposable where T : IDocument, new() where TKey : IEquatable { public IMongoDbContext Context; public MongoDbTestFixture() { DocsToDelete = new ConcurrentBag(); } public string PartitionKey { get; set; } public ConcurrentBag DocsToDelete { get; set; } public virtual void Dispose() { if (DocsToDelete.Any()) { TestRepository.Instance.DeleteMany(DocsToDelete.ToList()); } } public T CreateTestDocument() { var doc = new T(); DocsToDelete.Add(doc); return doc; } public List CreateTestDocuments(int numberOfDocumentsToCreate) { var docs = new List(); for (var i = 0; i < numberOfDocumentsToCreate; i++) { var doc = new T(); docs.Add(doc); DocsToDelete.Add(doc); } return docs; } } }