public void Test_Bad_WriteRelatedID_ParameterName()
        {
#if true
            Debug.WriteLine("Test disabled because the fix it tests is not in CoreCLR yet.");
#else
            BadEventSource_IncorrectWriteRelatedActivityIDFirstParameter bes = null;
            EventListenerListener listener = null;
            try
            {
                Guid oldGuid;
                Guid newGuid  = Guid.NewGuid();
                Guid newGuid2 = Guid.NewGuid();
                EventSource.SetCurrentThreadActivityId(newGuid, out oldGuid);

                bes = new BadEventSource_IncorrectWriteRelatedActivityIDFirstParameter();

                using (var listener = new EventListenerListener())
                {
                    var events = new List <Event>();
                    listener.OnEvent = delegate(Event data) { events.Add(data); };

                    listener.EventSourceCommand(bes.Name, EventCommand.Enable);

                    bes.RelatedActivity(newGuid2, "Hello", 42, "AA", "BB");

                    // Confirm that we get exactly one event from this whole process, that has the error message we expect.
                    Assert.Equal(1, events.Count);
                    Event _event = events[0];
                    Assert.Equal("EventSourceMessage", _event.EventName);
                    string message = _event.PayloadString(0, "message");
                    // expected message: "EventSource expects the first parameter of the Event method to be of type Guid and to be named "relatedActivityId" when calling WriteEventWithRelatedActivityId."
                    Assert.True(Regex.IsMatch(message, "EventSource expects the first parameter of the Event method to be of type Guid and to be named \"relatedActivityId\" when calling WriteEventWithRelatedActivityId."));
                }
            }
            finally
            {
                if (bes != null)
                {
                    bes.Dispose();
                }

                if (listener != null)
                {
                    listener.Dispose();
                }
            }
#endif
        }
示例#2
0
        /// <summary>
        /// A helper that can run the test under a variety of conditions
        /// * Whether the eventSource is enabled at startup
        /// * Whether the listener is ETW or an EventListern
        /// * Whether the ETW output is self describing or not.
        /// </summary>
        private void Test_Bad_EventSource_Startup(bool onStartup, Listener listener, EventSourceSettings settings)
        {
            var eventSourceName = typeof(BadEventSource_MismatchedIds).Name;

            Debug.WriteLine("***** Test_BadEventSource_Startup(OnStartUp: " + onStartup + " Listener: " + listener + " Settings: " + settings + ")");

            // Activate the source before the source exists (if told to).
            if (onStartup)
            {
                listener.EventSourceCommand(eventSourceName, EventCommand.Enable);
            }

            var events = new List <Event>();

            listener.OnEvent = delegate(Event data) { events.Add(data); };

            using (var source = new BadEventSource_MismatchedIds(settings))
            {
                Assert.Equal(eventSourceName, source.Name);
                // activate the source after the source exists (if told to).
                if (!onStartup)
                {
                    listener.EventSourceCommand(eventSourceName, EventCommand.Enable);
                }
                source.Event1(1);       // Try to send something.
            }
            listener.Dispose();

            // Confirm that we get exactly one event from this whole process, that has the error message we expect.
            Assert.Equal(events.Count, 1);
            Event _event = events[0];

            Assert.Equal("EventSourceMessage", _event.EventName);
            string message = _event.PayloadString(0, "message");

            Debug.WriteLine(string.Format("Message=\"{0}\"", message));
            // expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_MismatchedIds: Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent. "
            if (!PlatformDetection.IsFullFramework) // Full framework has typo
            {
                Assert.Matches("Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent", message);
            }
        }
示例#3
0
        /// <summary>
        /// A helper that can run the test under a variety of conditions
        /// * Whether the eventSource is enabled at startup
        /// * Whether the listener is ETW or an EventListern
        /// * Whether the ETW output is self describing or not.
        /// </summary>
        private void Test_Bad_EventSource_Startup(bool onStartup, Listener listener, EventSourceSettings settings)
        {
            var eventSourceName = typeof(BadEventSource_MismatchedIds).Name;

            Debug.WriteLine("***** Test_BadEventSource_Startup(OnStartUp: " + onStartup + " Listener: " + listener + " Settings: " + settings + ")");

            // Activate the source before the source exists (if told to).
            if (onStartup)
            {
                listener.EventSourceCommand(eventSourceName, EventCommand.Enable);
            }

            var events = new List <Event>();

            listener.OnEvent = delegate(Event data) { events.Add(data); };

            using (var source = new BadEventSource_MismatchedIds(settings))
            {
                Assert.Equal(eventSourceName, source.Name);
                // activate the source after the source exists (if told to).
                if (!onStartup)
                {
                    listener.EventSourceCommand(eventSourceName, EventCommand.Enable);
                }
                source.Event1(1);       // Try to send something.
            }
            listener.Dispose();

            // Confirm that we get exactly one event from this whole process, that has the error message we expect.
            Assert.Equal(1, events.Count);
            Event _event = events[0];

            Assert.Equal("EventSourceMessage", _event.EventName);
            string message = _event.PayloadString(0, "message");

            Debug.WriteLine(string.Format("Message=\"{0}\"", message));
            // expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_MismatchedIds: Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent. "
            if (!PlatformDetection.IsNetFramework) // .NET Framework has typo
            {
                Assert.Contains("Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent", message);
            }

            // Validate the details of the EventWrittenEventArgs object
            if (_event is EventListenerListener.EventListenerEvent elEvent)
            {
                EventWrittenEventArgs ea = elEvent.Data;
                Assert.NotNull(ea);
                Assert.Equal(EventSource.CurrentThreadActivityId, ea.ActivityId);
                Assert.Equal(EventChannel.None, ea.Channel);
                Assert.Equal(0, ea.EventId);
                Assert.Equal("EventSourceMessage", ea.EventName);
                Assert.NotNull(ea.EventSource);
                Assert.Equal(EventKeywords.None, ea.Keywords);
                Assert.Equal(EventLevel.LogAlways, ea.Level);
                Assert.Equal((EventOpcode)0, ea.Opcode);
                Assert.NotNull(ea.Payload);
                Assert.NotNull(ea.PayloadNames);
                Assert.Equal(ea.PayloadNames.Count, ea.Payload.Count);
                Assert.Equal(Guid.Empty, ea.RelatedActivityId);
                Assert.Equal(EventTags.None, ea.Tags);
                Assert.Equal(EventTask.None, ea.Task);
                Assert.InRange(ea.TimeStamp, DateTime.MinValue, DateTime.MaxValue);
                Assert.Equal(0, ea.Version);
            }
        }