public void AfmReorganizesWithCorrectNumberOfRows()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var formatter = new BSONFormatter();
            var core = new FileCore<int, long>() { IdSeed = new Seed32(999), SegmentSeed = new Seed64(), MinimumCoreStride = 512, InitialDbSize = 10240 };

            var addEntities = TestResourceFactory.GetMockClassAObjects(10000).ToList();

            foreach (var entity in addEntities)
                entity.Id = core.IdSeed.Increment();

            addEntities.Reverse();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", 4096, 20000, 4096, core, formatter, new RowSynchronizer<long>(new BinConverter64())))
                {
                    afm.Load<int>();

                    afm.Rebuilt += new Rebuild<MockClassA>(delegate(Guid transactionId, int newStride, long newLength, int newSeedStride)
                    {
                        afm.SaveCore<int>();
                    });

                    AtomicFileManagerHelper.SaveSegments(afm, addEntities.ToDictionary(e => e.Id));
                }

                addEntities.Reverse();

                var seg = 1;

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", 4096, 20000, 4096, formatter, new RowSynchronizer<long>(new BinConverter64())))
                {
                    afm.Load<int>();

                    Assert.AreNotEqual(1, afm.LoadSegmentFrom(seg).Id);

                    afm.Reorganized += new Reorganized<MockClassA>(delegate(int recordsWritten)
                    {
                        afm.SaveCore<int>();
                    });

                    afm.Reorganize<int>(new BinConverter32(), j => j.Value<int>("Id"));
                }

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", 4096, 20000, 4096, core, formatter, new RowSynchronizer<long>(new BinConverter64())))
                {
                    afm.Load<int>();

                    foreach (var entity in addEntities)
                    {
                        Assert.AreEqual(entity.Id, afm.LoadSegmentFrom(seg).Id, "Id {0} was not found in the right order, Id {1} was found instead.", entity.Id, afm.LoadSegmentFrom(seg).Id);
                        seg++;
                    }
                }
            }
        }