public void TestForwardingNullEvent()
        {
            EventSourceSink       testSink        = new EventSourceSink();
            EventRedirectorToSink eventRedirector = new EventRedirectorToSink(5, testSink);

            ((IEventRedirector)eventRedirector).ForwardEvent(null);
        }
        public void TestForwardingNotNullEvent()
        {
            EventSourceSink       testSink        = new EventSourceSink();
            EventRedirectorToSink eventRedirector = new EventRedirectorToSink(5, testSink);
            BuildMessageEventArgs messageEvent    = new BuildMessageEventArgs("My message", "Help me keyword", "Sender", MessageImportance.High);
            bool wentInHandler = false;

            testSink.AnyEventRaised += new AnyEventHandler
                                       (
                delegate
                (
                    object sender,
                    BuildEventArgs buildEvent
                )
            {
                wentInHandler = true;
                BuildMessageEventArgs messageEventFromPacket = buildEvent as BuildMessageEventArgs;
                Assert.Equal(messageEvent, messageEventFromPacket);       // "Expected messageEvent to be forwarded to match actually forwarded event"
            }

                                       );

            ((IEventRedirector)eventRedirector).ForwardEvent(messageEvent);
            Assert.True(wentInHandler); // "Expected to go into event handler"
        }
Beispiel #3
0
        public void RaiseGenericBuildEventArgs()
        {
            EventSourceSink  sink        = new EventSourceSink();
            RaiseEventHelper eventHelper = new RaiseEventHelper(sink);

            eventHelper.RaiseBuildEvent(RaiseEventHelper.GenericBuildEvent);
        }
        public void ForwardingLoggingPerformanceSummary()
        {
            EventSourceSink source = new EventSourceSink();

            TestForwardingLogger logger = new TestForwardingLogger
            {
                BuildEventRedirector = null,
                Parameters           = "PERFORMANCESUMMARY",
                Verbosity            = LoggerVerbosity.Quiet
            };

            logger.Initialize(source, 4);

            RaiseEvents(source);

            logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
            {
                _buildStarted,
                _projectStarted,
                _targetStarted,
                _taskStarted,
                _warning,
                _error,
                _taskFinished,
                _targetFinished,
                _projectFinished,
                _buildFinished,
            });
        }
Beispiel #5
0
        /// <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");
                    }
                }
            }
        }
Beispiel #6
0
        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 ForwardingLoggingShowCommandLine()
        {
            EventSourceSink source = new EventSourceSink();

            TestForwardingLogger logger = new TestForwardingLogger
            {
                BuildEventRedirector = null,
                Verbosity            = LoggerVerbosity.Normal,
                Parameters           = "SHOWCOMMANDLINE"
            };

            logger.Initialize(source, 4);

            RaiseEvents(source);

            logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
            {
                _buildStarted,
                _projectStarted,
                _targetStarted,
                _normalMessage,
                _highMessage,
                _commandLine,
                _warning,
                _error,
                _targetFinished,
                _projectFinished,
                _buildFinished,
            });
        }
        public void TestConstructorValidInputs()
        {
            EventSourceSink       testSink        = new EventSourceSink();
            EventRedirectorToSink eventRedirector = new EventRedirectorToSink(5, testSink);

            Assert.NotNull(eventRedirector); // "eventRedirector was not supposed to be null"
        }
        public void RegisterGoodDiscriptions()
        {
            string                   configurableClassName = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
            string                   distributedClassName  = "Microsoft.Build.BackEnd.Logging.CentralForwardingLogger";
            EventSourceSink          sink  = new EventSourceSink();
            EventSourceSink          sink2 = new EventSourceSink();
            List <LoggerDescription> loggerDescriptions = new List <LoggerDescription>();

            loggerDescriptions.Add(CreateLoggerDescription(configurableClassName, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true));
            loggerDescriptions.Add(CreateLoggerDescription(distributedClassName, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true));

            // Register some descriptions with a sink
            _initializedService.InitializeNodeLoggers(loggerDescriptions, sink, 1);

            // Register the same descriptions with another sink (so we can see that another sink was added)
            _initializedService.InitializeNodeLoggers(loggerDescriptions, sink2, 1);

            // Register the descriptions again with the same sink so we can verify that another sink was not created
            _initializedService.InitializeNodeLoggers(loggerDescriptions, sink, 1);

            Assert.NotNull(_initializedService.RegisteredLoggerTypeNames);

            // Should have 6 forwarding logger. three of each type
            Assert.Equal(6, _initializedService.RegisteredLoggerTypeNames.Count);
            Assert.True(_initializedService.RegisteredLoggerTypeNames.Contains("Microsoft.Build.Logging.ConfigurableForwardingLogger"));
            Assert.True(_initializedService.RegisteredLoggerTypeNames.Contains("Microsoft.Build.BackEnd.Logging.CentralForwardingLogger"));

            int countForwardingLogger = 0;

            foreach (string loggerName in _initializedService.RegisteredLoggerTypeNames)
            {
                if (String.Compare("Microsoft.Build.Logging.ConfigurableForwardingLogger", loggerName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    countForwardingLogger++;
                }
            }

            // Should be 3, one for each call to RegisterLoggerDescriptions
            Assert.Equal(3, countForwardingLogger);

            countForwardingLogger = 0;
            foreach (string loggerName in _initializedService.RegisteredLoggerTypeNames)
            {
                if (String.Compare("Microsoft.Build.BackEnd.Logging.CentralForwardingLogger", loggerName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    countForwardingLogger++;
                }
            }

            // Should be 3, one for each call to RegisterLoggerDescriptions
            Assert.Equal(3, countForwardingLogger);

            // Should have 2 event sink
            Assert.NotNull(_initializedService.RegisteredSinkNames);
            Assert.Equal(2, _initializedService.RegisteredSinkNames.Count);

            // There should not be any (this method is to be called on a child node)
            Assert.Equal(0, _initializedService.LoggerDescriptions.Count);
        }
 public void TestConstructorNegativeLoggerId()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         EventSourceSink testSink = new EventSourceSink();
         EventRedirectorToSink eventRedirector = new EventRedirectorToSink(-10, testSink);
     }
                                            );
 }
        public void RaiseEventWithNoBuildEventRedirector()
        {
            BuildMessageEventArgs   normalMessage    = new BuildMessageEventArgs("Message2", "help", "sender", MessageImportance.Normal);
            EventSourceSink         loggerSource     = new EventSourceSink();
            CentralForwardingLogger forwardingLogger = new CentralForwardingLogger();

            forwardingLogger.Initialize(loggerSource);
            loggerSource.Consume(normalMessage);
        }
Beispiel #12
0
 public void RaiseGenericBuildEventArgs()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         EventSourceSink sink         = new EventSourceSink();
         RaiseEventHelper eventHelper = new RaiseEventHelper(sink);
         eventHelper.RaiseBuildEvent(RaiseEventHelper.GenericBuildEvent);
     }
                                            );
 }
Beispiel #13
0
        public void PropertyTests()
        {
            EventSourceSink sink = new EventSourceSink();

            Assert.IsNull(sink.Name);
            string name = "Test Name";

            sink.Name = name;
            Assert.IsTrue(string.Compare(sink.Name, name, StringComparison.OrdinalIgnoreCase) == 0);
        }
        /// <summary>
        /// Create a new forwarding logger, event redirector, and event source.
        /// The returned event source can then have and event raised on it and it can
        /// check to see if the event raised matches the one we were expecting.
        /// </summary>
        /// <param name="buildEventToCheck">A build event we are expecting to be forwarded by the forwarding logger</param>
        /// <returns>An event source on which one can raise an event.</returns>
        private static EventSourceSink AttachForwardingLoggerAndRedirector(BuildEventArgs buildEventToCheck)
        {
            EventSourceSink         loggerEventSource = new EventSourceSink();
            CentralForwardingLogger forwardingLogger  = new CentralForwardingLogger();
            TestEventRedirector     eventRedirector   = new TestEventRedirector(buildEventToCheck);

            forwardingLogger.BuildEventRedirector = eventRedirector;
            forwardingLogger.Initialize(loggerEventSource);
            return(loggerEventSource);
        }
 public void TestForwardingNullEvent()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         EventSourceSink testSink = new EventSourceSink();
         EventRedirectorToSink eventRedirector = new EventRedirectorToSink(5, testSink);
         ((IEventRedirector)eventRedirector).ForwardEvent(null);
     }
                                            );
 }
Beispiel #16
0
        public void TreatWarningsAsErrorWhenAllSpecified()
        {
            EventSourceSink eventSourceSink = new EventSourceSink()
            {
                WarningsAsErrors = new HashSet <string>(),
            };

            RaiseEventHelper   raiseEventHelper   = new RaiseEventHelper(eventSourceSink);
            EventHandlerHelper eventHandlerHelper = new EventHandlerHelper(eventSourceSink, null);

            raiseEventHelper.RaiseBuildEvent(RaiseEventHelper.Warning);

            Assert.IsType <BuildErrorEventArgs>(eventHandlerHelper.RaisedEvent);
        }
        public void ForwardEvents()
        {
            BuildStartedEventArgs  buildStarted  = new BuildStartedEventArgs("Message", "Help");
            BuildFinishedEventArgs buildFinished = new BuildFinishedEventArgs("Message", "Keyword", true);
            BuildMessageEventArgs  normalMessage = new BuildMessageEventArgs("Message2", "help", "sender", MessageImportance.Normal);

            EventSourceSink loggerSource = AttachForwardingLoggerAndRedirector(buildStarted);

            loggerSource.Consume(buildStarted);

            loggerSource = AttachForwardingLoggerAndRedirector(buildFinished);
            loggerSource.Consume(buildFinished);

            loggerSource = AttachForwardingLoggerAndRedirector(normalMessage);
            loggerSource.Consume(normalMessage);
        }
 private void RaiseEvents(EventSourceSink source)
 {
     source.Consume(_buildStarted);
     source.Consume(_projectStarted);
     source.Consume(_targetStarted);
     source.Consume(_taskStarted);
     source.Consume(_lowMessage);
     source.Consume(_normalMessage);
     source.Consume(_highMessage);
     source.Consume(_commandLine);
     source.Consume(_externalStartedEvent);
     source.Consume(_warning);
     source.Consume(_error);
     source.Consume(_taskFinished);
     source.Consume(_targetFinished);
     source.Consume(_projectFinished);
     source.Consume(_buildFinished);
 }
Beispiel #19
0
        public void NotTreatWarningsAsMessagesWhenNotSpecified()
        {
            BuildWarningEventArgs expectedBuildEvent = RaiseEventHelper.Warning;

            EventSourceSink eventSourceSink = new EventSourceSink()
            {
                WarningsAsMessages = new HashSet <string>
                {
                    "123",
                    "ABC",
                },
            };

            RaiseEventHelper   raiseEventHelper   = new RaiseEventHelper(eventSourceSink);
            EventHandlerHelper eventHandlerHelper = new EventHandlerHelper(eventSourceSink, null);

            raiseEventHelper.RaiseBuildEvent(RaiseEventHelper.Warning);

            Assert.Equal(expectedBuildEvent, eventHandlerHelper.RaisedEvent);
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        public void TreatWarningsAsMessagesWhenSpecified()
        {
            BuildWarningEventArgs expectedBuildEvent = RaiseEventHelper.Warning;

            EventSourceSink eventSourceSink = new EventSourceSink()
            {
                WarningsAsMessages = new HashSet <string>
                {
                    "FOO",
                    expectedBuildEvent.Code,
                    "BAR",
                },
            };

            RaiseEventHelper   raiseEventHelper   = new RaiseEventHelper(eventSourceSink);
            EventHandlerHelper eventHandlerHelper = new EventHandlerHelper(eventSourceSink, null);

            raiseEventHelper.RaiseBuildEvent(RaiseEventHelper.Warning);

            Assert.IsType <BuildMessageEventArgs>(eventHandlerHelper.RaisedEvent);

            BuildMessageEventArgs actualBuildEvent = (BuildMessageEventArgs)eventHandlerHelper.RaisedEvent;

            Assert.Equal(expectedBuildEvent.BuildEventContext, actualBuildEvent.BuildEventContext);
            Assert.Equal(expectedBuildEvent.Code, actualBuildEvent.Code);
            Assert.Equal(expectedBuildEvent.ColumnNumber, actualBuildEvent.ColumnNumber);
            Assert.Equal(expectedBuildEvent.EndColumnNumber, actualBuildEvent.EndColumnNumber);
            Assert.Equal(expectedBuildEvent.EndLineNumber, actualBuildEvent.EndLineNumber);
            Assert.Equal(expectedBuildEvent.File, actualBuildEvent.File);
            Assert.Equal(expectedBuildEvent.HelpKeyword, actualBuildEvent.HelpKeyword);
            Assert.Equal(MessageImportance.Low, actualBuildEvent.Importance);
            Assert.Equal(expectedBuildEvent.LineNumber, actualBuildEvent.LineNumber);
            Assert.Equal(expectedBuildEvent.Message, actualBuildEvent.Message);
            Assert.Equal(expectedBuildEvent.ProjectFile, actualBuildEvent.ProjectFile);
            Assert.Equal(expectedBuildEvent.SenderName, actualBuildEvent.SenderName);
            Assert.Equal(expectedBuildEvent.Subcategory, actualBuildEvent.Subcategory);
            Assert.Equal(expectedBuildEvent.ThreadId, actualBuildEvent.ThreadId);
            Assert.Equal(expectedBuildEvent.Timestamp, actualBuildEvent.Timestamp);
        }
Beispiel #23
0
        public void ForwardingLoggingPerformanceSummary()
        {
            EventSourceSink      source = new EventSourceSink();
            TestForwardingLogger logger = new TestForwardingLogger();

            logger.BuildEventRedirector = null;
            logger.Parameters           = "PERFORMANCESUMMARY";
            logger.Verbosity            = LoggerVerbosity.Quiet;
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(10, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));
            Assert.True(logger.forwardedEvents.Contains(_projectStarted));
            Assert.True(logger.forwardedEvents.Contains(_projectFinished));
            Assert.True(logger.forwardedEvents.Contains(_targetStarted));
            Assert.True(logger.forwardedEvents.Contains(_targetFinished));
            Assert.True(logger.forwardedEvents.Contains(_taskStarted));
            Assert.True(logger.forwardedEvents.Contains(_taskFinished));
        }
Beispiel #24
0
        public void ForwardingLoggingShowCommandLine()
        {
            EventSourceSink      source = new EventSourceSink();
            TestForwardingLogger logger = new TestForwardingLogger();

            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Normal;
            logger.Parameters           = "SHOWCOMMANDLINE";
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(11, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));
            Assert.True(logger.forwardedEvents.Contains(_highMessage));
            Assert.True(logger.forwardedEvents.Contains(_normalMessage));
            Assert.True(logger.forwardedEvents.Contains(_projectStarted));
            Assert.True(logger.forwardedEvents.Contains(_projectFinished));
            Assert.True(logger.forwardedEvents.Contains(_targetStarted));
            Assert.True(logger.forwardedEvents.Contains(_targetFinished));
            Assert.True(logger.forwardedEvents.Contains(_commandLine));
        }
Beispiel #25
0
        public void ForwardingLoggingNoSummary()
        {
            EventSourceSink      source = new EventSourceSink();
            TestForwardingLogger logger = new TestForwardingLogger();

            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Normal;
            logger.Parameters           = "NOSUMMARY";
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.IsTrue(logger.forwardedEvents.Count == 11);
            Assert.IsTrue(logger.forwardedEvents.Contains(s_buildStarted));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_buildFinished));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_error));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_warning));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_highMessage));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_normalMessage));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_projectStarted));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_projectFinished));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_targetStarted));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_targetFinished));
            Assert.IsTrue(logger.forwardedEvents.Contains(s_commandLine));
        }
Beispiel #26
0
        public void ForwardingLoggingEventsBasedOnVerbosity()
        {
            EventSourceSink      source = new EventSourceSink();
            TestForwardingLogger logger = new TestForwardingLogger();

            logger.BuildEventRedirector = null;
            logger.Parameters           = "BUILDSTARTEDEVENT";
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(1, logger.forwardedEvents.Count);

            logger = new TestForwardingLogger();
            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Quiet;
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(4, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));

            logger = new TestForwardingLogger();
            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Minimal;
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(5, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));
            Assert.True(logger.forwardedEvents.Contains(_highMessage));

            logger = new TestForwardingLogger();
            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Normal;
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(11, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));
            Assert.True(logger.forwardedEvents.Contains(_highMessage));
            Assert.True(logger.forwardedEvents.Contains(_normalMessage));
            Assert.True(logger.forwardedEvents.Contains(_projectStarted));
            Assert.True(logger.forwardedEvents.Contains(_projectFinished));
            Assert.True(logger.forwardedEvents.Contains(_targetStarted));
            Assert.True(logger.forwardedEvents.Contains(_targetFinished));
            Assert.True(logger.forwardedEvents.Contains(_commandLine));

            logger = new TestForwardingLogger();
            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Detailed;
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(14, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));
            Assert.True(logger.forwardedEvents.Contains(_highMessage));
            Assert.True(logger.forwardedEvents.Contains(_lowMessage));
            Assert.True(logger.forwardedEvents.Contains(_normalMessage));
            Assert.True(logger.forwardedEvents.Contains(_projectStarted));
            Assert.True(logger.forwardedEvents.Contains(_projectFinished));
            Assert.True(logger.forwardedEvents.Contains(_targetStarted));
            Assert.True(logger.forwardedEvents.Contains(_targetFinished));
            Assert.True(logger.forwardedEvents.Contains(_taskStarted));
            Assert.True(logger.forwardedEvents.Contains(_taskFinished));
            Assert.True(logger.forwardedEvents.Contains(_commandLine));

            logger = new TestForwardingLogger();
            logger.BuildEventRedirector = null;
            logger.Verbosity            = LoggerVerbosity.Diagnostic;
            logger.Initialize(source, 4);
            RaiseEvents(source);
            Assert.Equal(15, logger.forwardedEvents.Count);
            Assert.True(logger.forwardedEvents.Contains(_buildStarted));
            Assert.True(logger.forwardedEvents.Contains(_buildFinished));
            Assert.True(logger.forwardedEvents.Contains(_error));
            Assert.True(logger.forwardedEvents.Contains(_warning));
            Assert.True(logger.forwardedEvents.Contains(_highMessage));
            Assert.True(logger.forwardedEvents.Contains(_lowMessage));
            Assert.True(logger.forwardedEvents.Contains(_normalMessage));
            Assert.True(logger.forwardedEvents.Contains(_projectStarted));
            Assert.True(logger.forwardedEvents.Contains(_projectFinished));
            Assert.True(logger.forwardedEvents.Contains(_targetStarted));
            Assert.True(logger.forwardedEvents.Contains(_targetFinished));
            Assert.True(logger.forwardedEvents.Contains(_taskStarted));
            Assert.True(logger.forwardedEvents.Contains(_taskFinished));
            Assert.True(logger.forwardedEvents.Contains(_externalStartedEvent));
            Assert.True(logger.forwardedEvents.Contains(_commandLine));
        }
        public void ForwardingLoggingEventsBasedOnVerbosity(LoggerVerbosity?loggerVerbosity)
        {
            EventSourceSink      source = new EventSourceSink();
            TestForwardingLogger logger = new TestForwardingLogger
            {
                BuildEventRedirector = null
            };

            if (loggerVerbosity.HasValue)
            {
                logger.Verbosity = loggerVerbosity.Value;
            }
            else
            {
                // Testing a single event when verbosity is not set
                logger.Parameters = "BUILDSTARTEDEVENT";
            }

            logger.Initialize(source, 4);
            RaiseEvents(source);

            switch (loggerVerbosity)
            {
            case null:
                logger.ForwardedEvents.ShouldBe(new BuildEventArgs[] { _buildStarted });
                break;

            case LoggerVerbosity.Quiet:
                logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
                {
                    _buildStarted,
                    _warning,
                    _error,
                    _buildFinished
                });
                break;

            case LoggerVerbosity.Minimal:
                logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
                {
                    _buildStarted,
                    _highMessage,
                    _warning,
                    _error,
                    _buildFinished
                });
                break;

            case LoggerVerbosity.Normal:
                logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
                {
                    _buildStarted,
                    _projectStarted,
                    _targetStarted,
                    _normalMessage,
                    _highMessage,
                    _commandLine,
                    _warning,
                    _error,
                    _targetFinished,
                    _projectFinished,
                    _buildFinished,
                });
                break;

            case LoggerVerbosity.Detailed:
                logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
                {
                    _buildStarted,
                    _projectStarted,
                    _targetStarted,
                    _taskStarted,
                    _lowMessage,
                    _normalMessage,
                    _highMessage,
                    _commandLine,
                    _warning,
                    _error,
                    _taskFinished,
                    _targetFinished,
                    _projectFinished,
                    _buildFinished,
                });
                break;

            case LoggerVerbosity.Diagnostic:
                logger.ForwardedEvents.ShouldBe(new BuildEventArgs[]
                {
                    _buildStarted,
                    _projectStarted,
                    _targetStarted,
                    _taskStarted,
                    _lowMessage,
                    _normalMessage,
                    _highMessage,
                    _commandLine,
                    _externalStartedEvent,
                    _warning,
                    _error,
                    _taskFinished,
                    _targetFinished,
                    _projectFinished,
                    _buildFinished,
                });
                break;
            }
        }
 public void TestConstructorNegativeLoggerId()
 {
     EventSourceSink       testSink        = new EventSourceSink();
     EventRedirectorToSink eventRedirector = new EventRedirectorToSink(-10, testSink);
 }
Beispiel #29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventSource">Event source on which the events will be raised</param>
 internal RaiseEventHelper(EventSourceSink eventSource)
 {
     _sourceForEvents = eventSource;
 }