public void TestBasicOperations_IsSupported_False() { RemoteInvokeOptions options = new RemoteInvokeOptions(); options.RuntimeConfigurationOptions.Add("System.Diagnostics.Tracing.EventSource.IsSupported", false); RemoteExecutor.Invoke(() => { using (var log = new EventSourceTest()) { using (var listener = new LoudListener(log)) { IEnumerable <EventSource> sources = EventSource.GetSources(); Assert.Empty(sources); Assert.Null(EventSource.GenerateManifest(typeof(SimpleEventSource), string.Empty, EventManifestOptions.OnlyIfNeededForRegistration)); Assert.Null(EventSource.GenerateManifest(typeof(EventSourceTest), string.Empty, EventManifestOptions.AllCultures)); log.Event0(); Assert.Null(LoudListener.LastEvent); EventSource.SendCommand(log, EventCommand.Enable, commandArguments: null); Assert.False(log.IsEnabled()); } } }, options).Dispose(); }
public void Test_EventListenerThrows_ExceptionIsNotRethrownToCaller(bool setThrowOnEventWriteErrorsFlag) { TestUtilities.CheckNoEventSourcesRunning("Start"); using (var log = new EventSourceTest(throwOnEventWriteErrors: setThrowOnEventWriteErrorsFlag)) { using (var listener = new EventListenerListener()) { listener.EventSourceSynchronousEnable(log); var thrownException = new Exception("Oops"); string outOfBandMessage = null; listener.EventWritten += (_, e) => { if (e.EventId == 0) { outOfBandMessage = e.Message; } throw thrownException; }; try { log.Event0(); Assert.False(setThrowOnEventWriteErrorsFlag); } catch (EventSourceException ex) { Assert.True(setThrowOnEventWriteErrorsFlag); Assert.Same(thrownException, ex.InnerException); } Assert.Contains(thrownException.Message, outOfBandMessage); } } TestUtilities.CheckNoEventSourcesRunning("Stop"); }
public void Test_WriteEvent_ArgsBasicTypes() { TestUtilities.CheckNoEventSourcesRunning("Start"); using (var log = new EventSourceTest()) { using (var el = new LoudListener(log)) { var sources = EventSource.GetSources(); Assert.Contains(log, sources); Assert.NotNull(EventSource.GenerateManifest(typeof(SimpleEventSource), string.Empty, EventManifestOptions.OnlyIfNeededForRegistration)); Assert.Null(EventSource.GenerateManifest(typeof(EventSourceTest), string.Empty, EventManifestOptions.OnlyIfNeededForRegistration)); log.Event0(); Assert.Equal(1, LoudListener.t_lastEvent.EventId); Assert.Equal(0, LoudListener.t_lastEvent.Payload.Count); #region Validate "int" arguments log.EventI(10); Assert.Equal(2, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[0]); log.EventII(10, 11); Assert.Equal(3, LoudListener.t_lastEvent.EventId); Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]); log.EventIII(10, 11, 12); Assert.Equal(4, LoudListener.t_lastEvent.EventId); Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]); Assert.Equal(12, (int)LoudListener.t_lastEvent.Payload[2]); #endregion #region Validate "long" arguments log.EventL(10); Assert.Equal(5, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(10, (long)LoudListener.t_lastEvent.Payload[0]); log.EventLL(10, 11); Assert.Equal(6, LoudListener.t_lastEvent.EventId); Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(10, (long)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]); log.EventLLL(10, 11, 12); Assert.Equal(7, LoudListener.t_lastEvent.EventId); Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(10, (long)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]); Assert.Equal(12, (long)LoudListener.t_lastEvent.Payload[2]); #endregion #region Validate "string" arguments log.EventS("10"); Assert.Equal(8, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]); log.EventSS("10", "11"); Assert.Equal(9, LoudListener.t_lastEvent.EventId); Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]); Assert.Equal("11", (string)LoudListener.t_lastEvent.Payload[1]); log.EventSSS("10", "11", "12"); Assert.Equal(10, LoudListener.t_lastEvent.EventId); Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]); Assert.Equal("11", (string)LoudListener.t_lastEvent.Payload[1]); Assert.Equal("12", (string)LoudListener.t_lastEvent.Payload[2]); #endregion #region Validate byte array arguments byte[] arr = new byte[20]; log.EventWithByteArray(arr); Assert.Equal(52, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(arr.Length, ((byte[])LoudListener.t_lastEvent.Payload[0]).Length); #endregion #region Validate mixed type arguments log.EventSI("10", 11); Assert.Equal(11, LoudListener.t_lastEvent.EventId); Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]); log.EventSL("10", 11); Assert.Equal(12, LoudListener.t_lastEvent.EventId); Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]); log.EventSII("10", 11, 12); Assert.Equal(13, LoudListener.t_lastEvent.EventId); Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]); Assert.Equal(12, (int)LoudListener.t_lastEvent.Payload[2]); #endregion #region Validate enums/flags log.EventEnum(MyColor.Blue); Assert.Equal(19, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(MyColor.Blue, (MyColor)LoudListener.t_lastEvent.Payload[0]); log.EventEnum1(MyColor.Green); Assert.Equal(20, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(MyColor.Green, (MyColor)LoudListener.t_lastEvent.Payload[0]); log.EventFlags(MyFlags.Flag1); Assert.Equal(21, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.t_lastEvent.Payload[0]); log.EventFlags1(MyFlags.Flag1); Assert.Equal(22, LoudListener.t_lastEvent.EventId); Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.t_lastEvent.Payload[0]); #endregion #region Validate DateTime Test_WriteEvent_ArgsBasicTypes_Etw_Validate_DateTime(log); #endregion } } TestUtilities.CheckNoEventSourcesRunning("Stop"); }