public void When_method_should_run_the_Action_and_all_others_methods_async_on_another_thread()
        {
            string currentThreadName = Thread.CurrentThread.Name;

            Sailor d = new Sailor();

            //When method should be executed on a thread other than the calling one
            d.When(delegate() { Assert.NotEqual(Thread.CurrentThread.Name, currentThreadName); })
            //Then method should be executed on a thread other than the calling one
            .Then(delegate(object obj) { Assert.NotEqual(Thread.CurrentThread.Name, currentThreadName); })
            //Finally method should be executed on a thread other than the calling one
            .Finally(delegate() { Assert.NotEqual(Thread.CurrentThread.Name, currentThreadName); })
            //Let the test fail if there is an exception
            .OnError(delegate(Exception exc) { Assert.False(true); });
        }
        public void When_method_should_call_Finally_action_when_the_Action_passed_to_it_comlpetes_without_errors()
        {
            int callNr  = 0;
            int callNr1 = 0;

            Sailor d = new Sailor();

            d.When(delegate() { Thread.Sleep(500); })
            .Finally(delegate() { callNr++; })
            .OnError(delegate(Exception exc) { callNr1++; });

            Thread.Sleep(1000);

            //When method should call Finally action when the Action passed to it comlpetes without errors
            Assert.Equal(1, callNr);
            Assert.Equal(0, callNr1);
        }
        public void Then_action_should_be_called_on_the_same_current_thread_if_when_method_is_used_with_a_synch_context()
        {
            SynchronizationContext sc = new SynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(sc);

            string currentThreadName = Thread.CurrentThread.Name;

            Sailor d = new Sailor();

            //When method should be executed on the same calling thread if a synchronization context is set
            d.When(delegate() { Assert.Equal(Thread.CurrentThread.Name, currentThreadName); })
            //Then method should be executed on the same calling thread if a synchronization context is set
            .Then(delegate(object obj) { Assert.Equal(Thread.CurrentThread.Name, currentThreadName); })
            //Finally method should be executed on the same calling thread if a synchronization context is set
            .Finally(delegate() { Assert.Equal(Thread.CurrentThread.Name, currentThreadName); })
            //Let the test fail if there is an exception
            .OnError(delegate(Exception exc) { Assert.False(true); });

            SynchronizationContext.SetSynchronizationContext(null);
        }