public void TestTryBracketTerminationInOpening()

in rd-net/Test.Lifetimes/Lifetimes/LifetimeTest.cs [784:862]


    public void TestTryBracketTerminationInOpening()
    {
      
      var log = 0;
      
      
      void InnerSuccess<T>(Func<bool, Result<T>> action)
      {
        log = 0;
        def = new LifetimeDefinition {AllowTerminationUnderExecution = true};
        
        Assert.True(action(false).Succeed);
        Assert.AreEqual(11, log);
        
        log = 0;
        def = new LifetimeDefinition{AllowTerminationUnderExecution = true};
        Assert.True(action(true).Succeed);
        Assert.AreEqual(11, log);
        
        Assert.AreEqual(11, log);
      }
      
      void InnerFail<T>(Func<bool, Result<T>> action)
      {
        log = 0;
        def = new LifetimeDefinition{AllowTerminationUnderExecution = true};
        
        Assert.Throws<FailureException>(() => action(false));
        Assert.AreEqual(11, log);
        
        log = 0;
        def = new LifetimeDefinition{AllowTerminationUnderExecution = true};
        Assert.True(action(true).Exception is FailureException);
        Assert.AreEqual(11, log);
      }
      
      //Action + Action 
      InnerSuccess(wrap => lt.TryBracket(() =>
        {
          log += 1;
          def.Terminate();
        },
        () => { log += 10; },
        wrap
      ));
      
      InnerFail(wrap => lt.TryBracket(() =>
        {
          log += 1;
          def.Terminate();
        },
        () => { log += 10; Fail(); },
        wrap
      ));
      
      
      //Func<T> + Action
      InnerSuccess(wrap => lt.TryBracket(() =>
        {
          log += 1;
          def.Terminate();
          return 1;
        },
        () => { log += 10; },
        wrap
      ));
      

      // Func<T> + Action<T>
      InnerFail(wrap => lt.TryBracket(() =>
        {
          log += 1;
          def.Terminate();
          return 10;
        },
        x => { log += x; Fail();},
        wrap
      )); 
    }