static partial void Test_WriteEvent_ArgsBasicTypes_Etw_Validate_DateTime(EventSourceTest log) { DateTime now = DateTime.Now; log.EventDateTime(now); Assert.Equal(24, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal((DateTime)LoudListener.LastEvent.Payload[0], now); }
public void Test_WriteEvent_ArgsBasicTypes() { TestUtilities.CheckNoEventSourcesRunning("Start"); using (var log = new EventSourceTest()) { using (var el = new LoudListener()) { var sources = EventSource.GetSources(); Assert.True(sources.Contains(log)); 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.LastEvent.EventId); Assert.Equal(0, LoudListener.LastEvent.Payload.Count); #region Validate "int" arguments log.EventI(10); Assert.Equal(2, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(10, (int)LoudListener.LastEvent.Payload[0]); log.EventII(10, 11); Assert.Equal(3, LoudListener.LastEvent.EventId); Assert.Equal(2, LoudListener.LastEvent.Payload.Count); Assert.Equal(10, (int)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]); log.EventIII(10, 11, 12); Assert.Equal(4, LoudListener.LastEvent.EventId); Assert.Equal(3, LoudListener.LastEvent.Payload.Count); Assert.Equal(10, (int)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]); Assert.Equal(12, (int)LoudListener.LastEvent.Payload[2]); #endregion #region Validate "long" arguments log.EventL(10); Assert.Equal(5, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(10, (long)LoudListener.LastEvent.Payload[0]); log.EventLL(10, 11); Assert.Equal(6, LoudListener.LastEvent.EventId); Assert.Equal(2, LoudListener.LastEvent.Payload.Count); Assert.Equal(10, (long)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (long)LoudListener.LastEvent.Payload[1]); log.EventLLL(10, 11, 12); Assert.Equal(7, LoudListener.LastEvent.EventId); Assert.Equal(3, LoudListener.LastEvent.Payload.Count); Assert.Equal(10, (long)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (long)LoudListener.LastEvent.Payload[1]); Assert.Equal(12, (long)LoudListener.LastEvent.Payload[2]); #endregion #region Validate "string" arguments log.EventS("10"); Assert.Equal(8, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]); log.EventSS("10", "11"); Assert.Equal(9, LoudListener.LastEvent.EventId); Assert.Equal(2, LoudListener.LastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]); Assert.Equal("11", (string)LoudListener.LastEvent.Payload[1]); log.EventSSS("10", "11", "12"); Assert.Equal(10, LoudListener.LastEvent.EventId); Assert.Equal(3, LoudListener.LastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]); Assert.Equal("11", (string)LoudListener.LastEvent.Payload[1]); Assert.Equal("12", (string)LoudListener.LastEvent.Payload[2]); #endregion #region Validate byte array arguments byte[] arr = new byte[20]; log.EventWithByteArray(arr); Assert.Equal(52, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(arr.Length, ((byte[])LoudListener.LastEvent.Payload[0]).Length); #endregion #region Validate mixed type arguments log.EventSI("10", 11); Assert.Equal(11, LoudListener.LastEvent.EventId); Assert.Equal(2, LoudListener.LastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]); log.EventSL("10", 11); Assert.Equal(12, LoudListener.LastEvent.EventId); Assert.Equal(2, LoudListener.LastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (long)LoudListener.LastEvent.Payload[1]); log.EventSII("10", 11, 12); Assert.Equal(13, LoudListener.LastEvent.EventId); Assert.Equal(3, LoudListener.LastEvent.Payload.Count); Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]); Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]); Assert.Equal(12, (int)LoudListener.LastEvent.Payload[2]); #endregion #region Validate enums/flags log.EventEnum(MyColor.Blue); Assert.Equal(19, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(MyColor.Blue, (MyColor)LoudListener.LastEvent.Payload[0]); log.EventEnum1(MyColor.Green); Assert.Equal(20, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(MyColor.Green, (MyColor)LoudListener.LastEvent.Payload[0]); log.EventFlags(MyFlags.Flag1); Assert.Equal(21, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.LastEvent.Payload[0]); log.EventFlags1(MyFlags.Flag1); Assert.Equal(22, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.LastEvent.Payload[0]); #endregion #if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864. #region Validate DateTime DateTime now = DateTime.Now; log.EventDateTime(now); Assert.Equal(24, LoudListener.LastEvent.EventId); Assert.Equal(1, LoudListener.LastEvent.Payload.Count); Assert.Equal((DateTime)LoudListener.LastEvent.Payload[0], now); #endregion #endif // USE_ETW } } TestUtilities.CheckNoEventSourcesRunning("Stop"); }