public void TestFailedEntry() { ReentryGuard test = new ReentryGuard(); using (test.EnterAndExit()) { Assert.Throws<InvalidOperationException>(delegate { test.EnterAndExit(); }); } }
public UsingBlock(ReentryGuard guard) { m_owner = guard; if (m_owner.m_allowReentry==false && m_owner.m_entryCount > 0) throw new InvalidOperationException( "This function or statement block is not allowed to be reentered.\n" + "Make sure that CanEnter is checked first and that EnterAndExit() is\n" + "called within a 'using' block."); m_owner.m_entryCount++; }
public void TestEnterAndExit() { ReentryGuard test = new ReentryGuard(); Assert.True(test.CanEnter); using (test.EnterAndExit()) { Assert.True(!test.CanEnter); } Assert.True(test.CanEnter); }
public UsingBlock(ReentryGuard guard) { m_owner = guard; if (m_owner.m_allowReentry == false && m_owner.m_entryCount > 0) { throw new InvalidOperationException( "This function or statement block is not allowed to be reentered.\n" + "Make sure that CanEnter is checked first and that EnterAndExit() is\n" + "called within a 'using' block."); } m_owner.m_entryCount++; }
public void TestEnterAndExitMultiple() { ReentryGuard test = new ReentryGuard(); using (IDisposable guard = test.EnterAndExitMultiple()) { Assert.True(test.HasEntered); Assert.False(test.CanEnter); Assert.DoesNotThrow(delegate { using (guard) { using (guard) { } } }); } }
public void TestConstructor() { ReentryGuard test = new ReentryGuard(); Assert.True(test.CanEnter); Assert.False(test.HasEntered); }