public void RegistrationTest() { using (var reader = FixtureRootRepoFolder.GetReader(DateTime.MinValue, false)) { Assert.IsTrue(reader.IsAccessing(FixtureRootRepoFolder, false)); Assert.IsTrue(Repository.IsDataBeingAccessed(FixtureRootRepoFolder, false)); Assert.IsTrue(Repository.IsDataBeingReadFrom(FixtureRootRepoFolder, false)); var readers = Repository.GetReaders(FixtureRootRepoFolder, false); Assert.AreEqual(1, readers.Count); Assert.AreSame(reader, readers[0]); reader.Close(); Assert.IsFalse(Repository.IsDataBeingAccessed(FixtureRootRepoFolder, false)); Assert.IsFalse(Repository.IsDataBeingReadFrom(FixtureRootRepoFolder, false)); Assert.IsFalse(reader.IsAccessing(FixtureRootRepoFolder, false)); readers = Repository.GetReaders(FixtureRootRepoFolder, false); Assert.AreEqual(0, readers.Count); reader.Dispose(); Assert.IsFalse(Repository.UnRegisterReader(reader), "Dispose did not unregister reader"); Assert.Throws <ObjectDisposedException>(() => reader.AddFolder(FixtureRootRepoFolder)); Assert.Throws <ObjectDisposedException>(() => reader.Seek(DateTime.Now)); Assert.Throws <ObjectDisposedException>(() => reader.Direction = bfs.Repository.Util.EnumerationDirection.Backwards); Assert.Throws <ObjectDisposedException>(() => reader.CanChangeDirection.ToString()); Assert.Throws <ObjectDisposedException>(() => reader.Read()); Assert.Throws <ObjectDisposedException>(() => reader.RemoveFolder(null)); Assert.IsFalse(reader.IsAccessing(FixtureRootRepoFolder, true)); } }
public void TestRegisterUnregisterAccessors() { Assert.Throws <ArgumentNullException>(() => Repository.RegisterReader(null)); Assert.Throws <ArgumentNullException>(() => Repository.RegisterWriter(null)); using (var writer = FixtureRootRepoFolder.GetWriter()) { Assert.IsFalse(Repository.UnRegisterReader(writer), "Writer reported to have been successfully unregistered as reader"); // must have been registered Assert.IsTrue(Repository.UnRegisterWriter(writer)); Assert.IsFalse(Repository.UnRegisterWriter(writer), "Unregistered writer reported to have been successfully unregistered again"); } using (var reader = FixtureRootRepoFolder.GetReader(DateTime.Now, false)) { Assert.IsFalse(Repository.UnRegisterWriter(reader), "Reader reported to have been successfully unregistered as writer"); // must have been registered Assert.IsTrue(Repository.UnRegisterReader(reader: reader)); Assert.IsFalse(Repository.UnRegisterReader(reader: reader), "Unregistered reader reported to have been successfully unregistered again"); } }