public void TestLocalVariableDictionary(string sinkId) { MemoryLogger logger = new MemoryLogger(null); MockEventSource <IDictionary <string, string> > mockEventSource = CreateEventsource <IDictionary <string, string> >("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(sinkId, logger); //"TextDecoration": "{$myvar2}" mockEventSource.Subscribe(sink); var data1 = new Dictionary <string, string>() { { "myvar1", "myval1" } }; var data2 = new Dictionary <string, string>() { { "myvar2", "myval2" } }; DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data1, timestamp); Assert.Empty(sink.Records); mockEventSource.MockEvent(data2, timestamp); Assert.Equal("myval2", sink.Records[0]); }
public void TestLocalVariableAnonymousObject() { MemoryLogger logger = new MemoryLogger(null); MockEventSource <object> mockEventSource = CreateEventsource <object>("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink("TextDecorationLocalVariable", logger); //"TextDecoration": "{$myvar2}" mockEventSource.Subscribe(sink); var data1 = new { myvar1 = "myval1" }; var data2 = new { myvar2 = "myval2" }; DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data1, timestamp); Assert.Empty(sink.Records); mockEventSource.MockEvent(data2, timestamp); Assert.Equal("myval2", sink.Records[0]); }
public void TestObjectDecorationWithFileName(string sinkId) { string id = sinkId + (Utility.IsWindows ? string.Empty : TestUtility.LINUX); MemoryLogger logger = new MemoryLogger(null); MockEventSource <IDictionary <string, string> > mockEventSource = CreateEventsource <IDictionary <string, string> >("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(id, logger); mockEventSource.Subscribe(sink); string text = "some text"; Dictionary <string, string> data = new Dictionary <string, string>() { { "data", text } }; DateTime timestamp = DateTime.UtcNow; string filePath = Path.Combine(TestUtility.GetTestHome(), "test.log"); long position = 11; long lineNumber = 1; mockEventSource.MockLogEvent(data, timestamp, text, filePath, position, lineNumber); string result = sink.Records[0]; Assert.Equal($"{{\"data\":\"{text}\",\"ComputerName\":\"{ComputerOrHostName}\",\"FileName\":\"{Path.GetFileName(filePath)}\",\"Position\":\"{position}\"}}", result); }