Exemplo n.º 1
0
        public void FindAndRemovesUnusedKeys()
        {
            StoreJob(1, "Create leak");
            StoreJob(1, "Code");

            using (var visitor = new FindUnusedKeysVisitor())
            {
                using (var tr = _db.StartReadOnlyTransaction())
                {
                    visitor.ImportAllKeys(tr);
                    visitor.Iterate(tr);
                }
                var report = DumpUnseenKeys(visitor, "\r\n");
                Approvals.Verify(report);

                using (var tr = _db.StartTransaction())
                {
                    visitor.DeleteUnused(tr);
                    tr.Commit();
                }
            }
            ReopenDb();
            AssertNoLeaksInDb();
            using (var tr = _db.StartReadOnlyTransaction())
            {
                var jobs = tr.Singleton<JobMap>();
                //check that db has is not broken after removing unused keys
                Assert.Equal(jobs.Jobs[1].Duty.Name, "Code");
            }
        }
Exemplo n.º 2
0
        public void FindAndRemovesUnusedKeys()
        {
            StoreJobInDictionary("programming", "code");
            StoreJobInDictionary("chess", "mate");
            using (var tr = _db.StartTransaction())
            {
                var sports = tr.Singleton<Directory>();
                sports.Dir["programming"] = new JobMap();
                tr.Commit();
            }

            using (var visitor = new FindUnusedKeysVisitor())
            {
                using (var tr = _db.StartReadOnlyTransaction())
                {
                    visitor.ImportAllKeys(tr);
                    visitor.Iterate(tr);
                }
                var report = DumpUnseenKeys(visitor, "\r\n");
                Approvals.Verify(report);

                using (var tr = _db.StartTransaction())
                {
                    visitor.DeleteUnused(tr);
                    tr.Commit();
                }
            }
            ReopenDb();
            AssertNoLeaksInDb();
            using (var tr = _db.StartReadOnlyTransaction())
            {
                //check that db has is not broken after removing unused keys
                var sports = tr.Singleton<Directory>();
                Assert.Equal(sports.Dir["chess"].Jobs[0].Duty.Name, "mate");
            }
        }