Esempio n. 1
0
 public void TestFailedEntry()
 {
     ReentryGuard test = new ReentryGuard();
     using (test.EnterAndExit())
     {
         Assert.Throws<InvalidOperationException>(delegate { test.EnterAndExit(); });
     }
 }
Esempio n. 2
0
 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++;
 }
Esempio n. 3
0
 public void TestEnterAndExit()
 {
     ReentryGuard test = new ReentryGuard();
     Assert.True(test.CanEnter);
     using (test.EnterAndExit())
     {
         Assert.True(!test.CanEnter);
     }
     Assert.True(test.CanEnter);
 }
Esempio n. 4
0
 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++;
 }
Esempio n. 5
0
 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)
                 {
                 }
             }
         });
     }
 }
Esempio n. 6
0
 public void TestConstructor()
 {
     ReentryGuard test = new ReentryGuard();
     Assert.True(test.CanEnter);
     Assert.False(test.HasEntered);
 }