public virtual void ExpireAt() { entityRepo.TruncateCollection(); var entity1 = TestHelper.GetEntity1(); entityRepo.InsertOne(entity1); Assert.IsFalse(string.IsNullOrEmpty(entity1.Id), "DocId has not been set during insert"); var itemsInDatabase = entityRepo.GetAll(); // We try to delete the item : entityRepo.ExpireAt(entity1.Id, DateTime.Now.AddSeconds(2)); var itemsInDatabase2 = entityRepo.GetAll(); Assert.IsTrue(itemsInDatabase.Count() == itemsInDatabase2.Count(), "entityRepo has not been physically deleted after compact"); Thread.Sleep(4000); // We compact the database : entityRepo.CompactDatabase(); var itemsInDatabaseAfterCompact = entityRepo.GetAll(); Assert.IsTrue(itemsInDatabaseAfterCompact.Count() == itemsInDatabase.Count() - 1, "entityRepo has not been physically deleted after compact"); }
public string AddLog <T>(T contentLog, string message, string longMessage, LogLevel level) where T : class { var log = new Log() { Message = message, LongMessage = longMessage, ContentLog = contentLog, Level = level }; var resultInsert = repository.InsertOne(log); if (resultInsert == InsertResult.inserted) { if (daysBeforeExpiration.HasValue) { repository.ExpireAt(log.Id, DateTime.Now.AddDays(daysBeforeExpiration.Value)); } return(log.Id); } else { return(string.Empty); // Generate exception with contracts } }