Пример #1
0
        public void Test_Bad_WriteRelatedID_ParameterName()
        {
#if true
            Debug.WriteLine("Test disabled because the fix it tests is not in CoreCLR yet.");
#else
            Guid oldGuid;
            Guid newGuid  = Guid.NewGuid();
            Guid newGuid2 = Guid.NewGuid();
            EventSource.SetCurrentThreadActivityId(newGuid, out oldGuid);

            using (var 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.Contains("EventSource expects the first parameter of the Event method to be of type Guid and to be named \"relatedActivityId\" when calling WriteEventWithRelatedActivityId.", message);
                }
#endif
        }
Пример #2
0
        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();
                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(events.Count, 1);
                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
        }