Example #1
0
        public void MatchJavaLineExtendedEventTest()
        {
            const string regexPattern = @"(?<ts>[^;]+); (?<pid>[^\s]+) (?<thread>[^\s]+) (?<class>[^\s]+) (?<sev>[^\s]+) (?<message>[^\s]+) " +
                                        @"(?<req>[^\s]+) (?<sess>[^\s]+) (?<site>[^\s]+) (?<user>[^\s]+)";

            const string input = "2020-09-28 17:44:18.273; 123 thread1 class1 info testMessage testRequest testSession testSite testUser";
            var          expectedCommonOutput = new Dictionary <string, object>
            {
                { "Class", "class1" },
                { "Message", "testMessage" },
                { "ProcessId", 123 },
                { "Severity", "info" },
                { "SuccessfulMatch", true },
                { "Thread", "thread1" },
                { "Timestamp", new DateTime(2020, 9, 28, 17, 44, 18, 273) },
            };
            var expectedExtendedOutput = new Dictionary <string, object>(expectedCommonOutput)
            {
                { "RequestId", "testRequest" },
                { "SessionId", "testSession" },
                { "Site", "testSite" },
                { "User", "testUser" }
            };

            var regex = new Regex(regexPattern);

            var resultForCommonLine = input.MatchJavaLine(regex);

            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(resultForCommonLine, expectedCommonOutput, "Base method with extra fields");

            var resultForExtendedLine = input.MatchJavaLineWithSessionInfo(regex);

            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(resultForExtendedLine, expectedExtendedOutput, "Extended method with extra fields");
        }
Example #2
0
        public void MatchJavaLineSharedTests(string testName, string regexPattern, object input, IDictionary <string, object> expectedOutputProps)
        {
            var regex = new Regex(regexPattern);

            var resultForCommonLine = input.MatchJavaLine(regex);

            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(resultForCommonLine, expectedOutputProps, testName);

            var resultForExtendedLine = input.MatchJavaLineWithSessionInfo(regex);

            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(resultForExtendedLine, expectedOutputProps, testName);
        }
        public void TestDifferentEvents(string testName, string @class, string message, string severity, IDictionary <string, object> nonNullProps)
        {
            var testLine = GetTestLine(@class, message, severity);

            var result = _eventParser.ParseEvent(_testLogLine, testLine);

            if (nonNullProps == null)
            {
                result.Should().BeNull();
                return;
            }

            result.Should().NotBeNull();
            var expectedPropValues = AddFixedPropValues(nonNullProps, @class, message, severity);

            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(result, expectedPropValues, testName);
            result.VerifyBaseEventProperties(Timestamp, _testLogLine);
            _buildTrackerMock.Verify(m => m.GetBuild(Timestamp), Times.Once);
        }
Example #4
0
        public void RunTestCases(string testName, string logLineText, DateTime timestamp, LogType logType, IDictionary <string, object> nonNullProps)
        {
            var testWriterFactory = new TestWriterFactory();
            var logLine           = new LogLine(new ReadLogLineResult(123, logLineText), TestLogFileInfo);
            SinglePluginExecutionResults processingResults;

            using (var plugin = new LogShark.Plugins.TabadminController.TabadminControllerPlugin())
            {
                plugin.Configure(testWriterFactory, null, _processingNotificationsCollectorMock.Object, new NullLoggerFactory());
                plugin.ProcessLogLine(logLine, logType);
                processingResults = plugin.CompleteProcessing();
            }

            _processingNotificationsCollectorMock.VerifyNoOtherCalls();

            processingResults.AdditionalTags.Should().BeEmpty();
            processingResults.HasAdditionalTags.Should().BeFalse();
            processingResults.WritersStatistics.Count.Should().Be(1);

            if (nonNullProps == null)
            {
                testWriterFactory.AssertAllWritersAreDisposedAndEmpty(1);
                processingResults.WritersStatistics[0].LinesPersisted.Should().Be(0);
                return;
            }

            processingResults.WritersStatistics[0].LinesPersisted.Should().Be(1);
            var testWriter = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <TabadminControllerEvent>("TabadminControllerEvents", 1);

            testWriter.ReceivedObjects.Count.Should().Be(1);
            var result = testWriter.ReceivedObjects.FirstOrDefault() as TabadminControllerEvent;

            result.Should().NotBeNull();
            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(result, nonNullProps, testName);
            result.VerifyBaseEventProperties(timestamp, logLine);
        }