public override void Execute()
 {
     if (Invocation.Method.Name.Equals("Execute"))
     {
         if (NotifySubscribersOfTaskExecution == null) NotifySubscribersOfTaskExecution = new NotifySubscribersOfTaskExecution();
         NotifySubscribersOfTaskExecution.ExecutingTask = (Task)Invocation.InvocationTarget;
         NotifySubscribersOfTaskExecution.Invocation = Invocation;
         NotifySubscribersOfTaskExecution.Execute();
     }
     else
     {
         Invocation.Proceed();
     }
 }
Esempio n. 2
0
 public override void Execute()
 {
     if (Invocation.Method.Name.Equals("Execute"))
     {
         if (NotifySubscribersOfTaskExecution == null)
         {
             NotifySubscribersOfTaskExecution = new NotifySubscribersOfTaskExecution();
         }
         NotifySubscribersOfTaskExecution.ExecutingTask = (Task)Invocation.InvocationTarget;
         NotifySubscribersOfTaskExecution.Invocation    = Invocation;
         NotifySubscribersOfTaskExecution.Execute();
     }
     else
     {
         Invocation.Proceed();
     }
 }
        public void should_send_notifications_if_task_execution_throws_an_unhandled_exception()
        {
            // Arrange
            var task = new NotifySubscribersOfTaskExecution();

            var taskWithAttributesThatThrows = new MockTaskWithAttributesThatThrows();
            task.ExecutingTask = taskWithAttributesThatThrows;

            var mockInvocation = new Mock<IInvocation>();
            mockInvocation.Setup(invocation => invocation.Proceed()).Callback(taskWithAttributesThatThrows.Execute);
            task.Invocation = mockInvocation.Object;

            // Act
            Assert.Throws(typeof(Exception), task.Execute);

            // Assert
            Assert.That(taskWithAttributesThatThrows.CallbackQueue.Count, Is.EqualTo(5));

            // Note: Attributes on a class are not returned in any order and therefore the it can not be assumed that the
            // first attribute will receive the first callback.
            if (taskWithAttributesThatThrows.CallbackQueue.Peek().Contains("First"))
            {
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("First.Before"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("Second.Before"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("Execute"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("Second.OnError"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("First.OnError"));
            }
            else
            {
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("Second.Before"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("First.Before"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("Execute"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("First.OnError"));
                Assert.That(taskWithAttributesThatThrows.CallbackQueue.Dequeue(), Is.EqualTo("Second.OnError"));
            }
        }