public void ConsumeEventsGoodEventsNoHandlers()
 {
     EventSourceSink sink = new EventSourceSink();
     RaiseEventHelper eventHelper = new RaiseEventHelper(sink);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.BuildStarted);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.BuildFinished);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.NormalMessage);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.TaskFinished);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.CommandLine);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.Warning);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.Error);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.TargetStarted);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.TargetFinished);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.ProjectStarted);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.ProjectFinished);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.ExternalStartedEvent);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.ExternalStartedEvent);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.GenericStatusEvent);
 }
 public void ConsumeEventsGoodEvents()
 {
     EventSourceSink sink = new EventSourceSink();
     RaiseEventHelper eventHelper = new RaiseEventHelper(sink);
     EventHandlerHelper testHandlers = new EventHandlerHelper(sink, null);
     VerifyRegisteredHandlers(RaiseEventHelper.BuildStarted, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.BuildFinished, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.NormalMessage, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.TaskFinished, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.CommandLine, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.Warning, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.Error, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.TargetStarted, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.TargetFinished, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.ProjectStarted, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.ProjectFinished, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.ExternalStartedEvent, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.BuildStarted, eventHelper, testHandlers);
     VerifyRegisteredHandlers(RaiseEventHelper.GenericStatusEvent, eventHelper, testHandlers);
 }
        /// <summary>
        /// Verify when an is raised the handlers which are  registered to handle the event should handle them
        /// </summary>
        /// <param name="buildEventToRaise">A buildEventArgs to raise on the event source</param>
        /// <param name="eventHelper">Helper class which events are raised on</param>
        /// <param name="testHandlers">Class which contains a set of event handlers registered on the event source</param>
        private static void VerifyRegisteredHandlers(BuildEventArgs buildEventToRaise, RaiseEventHelper eventHelper, EventHandlerHelper testHandlers)
        {
            try
            {
                eventHelper.RaiseBuildEvent(buildEventToRaise);
                if (buildEventToRaise.GetType() != typeof(GenericBuildStatusEventArgs))
                {
                    Assert.IsTrue(testHandlers.RaisedEvent == buildEventToRaise, "Expected buildevent in handler to match buildevent raised on event source");
                    Assert.IsTrue(testHandlers.RaisedEvent == testHandlers.RaisedAnyEvent, "Expected RaisedEvent and RaisedAnyEvent to match");
                    Assert.IsTrue(testHandlers.EnteredEventHandler, "Expected to enter into event handler");
                }

                Assert.IsTrue(testHandlers.RaisedAnyEvent == buildEventToRaise, "Expected buildEvent in any event handler to match buildevent raised on event source");
                Assert.IsTrue(testHandlers.EnteredAnyEventHandler, "Expected  to enter into AnyEvent handler");

                if (buildEventToRaise is BuildStatusEventArgs)
                {
                    Assert.IsTrue(testHandlers.RaisedStatusEvent == buildEventToRaise, "Expected buildevent in handler to match buildevent raised on event source");
                    Assert.IsTrue(testHandlers.EnteredStatusEventHandler, "Expected to enter into Status event handler");
                }
                else
                {
                    Assert.IsNull(testHandlers.RaisedStatusEvent);
                    Assert.IsFalse(testHandlers.EnteredStatusEventHandler);
                }
            }
            finally
            {
                testHandlers.ResetRaisedEvent();
            }
        }
 /// <summary>
 /// Take an event and an exception to raise, create a new sink and raise the event on it. 
 /// In the event handler registered on the sink, the exception will be thrown.
 /// </summary>
 /// <param name="buildEventToRaise">BuildEvent to raise on the </param>
 /// <param name="exceptionToRaise">Exception to throw in the event handler </param>
 private static void RaiseExceptionInEventHandler(BuildEventArgs buildEventToRaise, Exception exceptionToRaise)
 {
     EventSourceSink sink = new EventSourceSink();
     RaiseEventHelper eventHelper = new RaiseEventHelper(sink);
     EventHandlerHelper testHandlers = new EventHandlerHelper(sink, exceptionToRaise);
     try
     {
         eventHelper.RaiseBuildEvent(buildEventToRaise);
     }
     catch (Exception e)
     {
         // Logger exceptions should be rethrown as is with no wrapping
         if (exceptionToRaise is LoggerException)
         {
             Assert.IsTrue(e == exceptionToRaise, "Expected Logger exception to be raised in event handler and re-thrown by event source");
         }
         else
         {
             if (ExceptionHandling.IsCriticalException(e))
             {
                 Assert.IsTrue(e == exceptionToRaise, "Expected Logger exception to be raised in event handler and re-thrown by event source");
             }
             else
             {
                 // All other exceptions should be wrapped in an InternalLoggerException, with the original exception as the inner exception
                 Assert.IsTrue(e is InternalLoggerException, "Expected general exception to be raised in event handler and re-thrown by event source as a InternalLoggerException");
             }
         }
     }
 }
        public void VerifyShutdown()
        {
            EventSourceSink sink = new EventSourceSink();

            // Registers event handlers onto the event source 
            EventHandlerHelper handlerHelper = new EventHandlerHelper(sink, null);
            RaiseEventHelper raiseEventHelper = new RaiseEventHelper(sink);

            raiseEventHelper.RaiseBuildEvent(RaiseEventHelper.ProjectStarted);
            Assert.IsTrue(handlerHelper.EnteredEventHandler);
            Assert.IsTrue(handlerHelper.EnteredAnyEventHandler);
            Assert.IsTrue(handlerHelper.EnteredStatusEventHandler);
            Assert.IsTrue(handlerHelper.RaisedEvent == RaiseEventHelper.ProjectStarted);
            Assert.IsTrue(handlerHelper.RaisedAnyEvent == RaiseEventHelper.ProjectStarted);
            Assert.IsTrue(handlerHelper.RaisedStatusEvent == RaiseEventHelper.ProjectStarted);

            sink.ShutDown();

            handlerHelper.ResetRaisedEvent();
            raiseEventHelper.RaiseBuildEvent(RaiseEventHelper.ProjectStarted);
            Assert.IsFalse(handlerHelper.EnteredEventHandler);
            Assert.IsFalse(handlerHelper.EnteredAnyEventHandler);
            Assert.IsFalse(handlerHelper.EnteredStatusEventHandler);
            Assert.IsNull(handlerHelper.RaisedEvent);
            Assert.IsNull(handlerHelper.RaisedAnyEvent);
            Assert.IsNull(handlerHelper.RaisedStatusEvent);
        }
 public void RaiseGenericBuildEventArgs()
 {
     EventSourceSink sink = new EventSourceSink();
     RaiseEventHelper eventHelper = new RaiseEventHelper(sink);
     eventHelper.RaiseBuildEvent(RaiseEventHelper.GenericBuildEvent);
 }
 public void RaiseGenericBuildEventArgs()
 {
     Assert.Throws<InternalErrorException>(() =>
     {
         EventSourceSink sink = new EventSourceSink();
         RaiseEventHelper eventHelper = new RaiseEventHelper(sink);
         eventHelper.RaiseBuildEvent(RaiseEventHelper.GenericBuildEvent);
     }
    );
 }