-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from Analogy-LogViewer/refacor
Refacor
- Loading branch information
Showing
40 changed files
with
1,143 additions
and
1,343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 0 additions & 125 deletions
125
Analogy.LogViewer.Serilog.UnitTests/Analogy.Logserver.20200913.log
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
Analogy.LogViewer.Serilog.UnitTests/CompactJsonFormatTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using Analogy.LogViewer.Serilog.DataTypes; | ||
using Analogy.LogViewer.Serilog.IAnalogy; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Analogy.LogViewer.Serilog.UnitTests | ||
{ | ||
[TestClass] | ||
public class CompactJsonFormatTests | ||
{ | ||
private string Folder { get; } = Environment.CurrentDirectory; | ||
[TestMethod] | ||
[DataRow("CompactJsonFormat.clef",4, "2016-10-12T04:46:58.0554314Z")] | ||
[DataRow("CompactJsonFormatSourceContextTest.clef",2, "2020-06-18T18:03:19.2248275Z")] | ||
[DataRow("CompactJsonFormatTestColumns.clef",4, "2020-06-26T14:21:34.7233612Z")] | ||
[DataRow("CompactJsonFormat.gz",4, "2016-10-12T04:46:58.0554314Z")] | ||
public async Task OfflineProviderParserTimestampTest(string fileName,int numberOfMessages,string datetimeToParse) | ||
{ | ||
OfflineDataProvider parser = new OfflineDataProvider(); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string file = Path.Combine(Folder, "log files", fileName); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await parser.Process(file, cts.Token, forTesting)).ToList(); | ||
DateTimeOffset dto = DateTimeOffset.Parse(datetimeToParse); | ||
Assert.IsTrue(messages.Count == numberOfMessages); | ||
Assert.IsTrue(messages[0].Date == dto.DateTime); | ||
} | ||
|
||
|
||
[TestMethod] | ||
[DataRow("CompactJsonFormat.clef")] | ||
[DataRow("CompactJsonFormatSourceContextTest.clef")] | ||
[DataRow("CompactJsonFormatTestColumns.clef")] | ||
[DataRow("CompactJsonFormat.gz")] | ||
public void CompactJsonFormatTestAutomaticDetection(string fileName) | ||
{ | ||
string file = Path.Combine(Folder, "log files", fileName); | ||
var type = OfflineDataProvider.TryDetectFormat(file); | ||
Assert.IsTrue(type == FileFormat.CompactJsonFormatPerLine); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public async Task CompactJsonFormatParserTest() | ||
{ | ||
CompactJsonFormatParser parser = new CompactJsonFormatParser(); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "CompactJsonFormat.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.IsTrue(messages.Count == 4); | ||
Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Id: 101 }"); | ||
} | ||
|
||
// Test reading the (optional) source context | ||
[TestMethod] | ||
public async Task CompactJsonFormatSourceContextTest() | ||
{ | ||
CompactJsonFormatParser parser = new CompactJsonFormatParser(); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "CompactJsonFormatSourceContextTest.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
|
||
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList(); | ||
|
||
Assert.AreEqual(2, messages.Count()); | ||
|
||
// The first event doesn't have a source context | ||
var firstEvent = messages.ElementAt(0); | ||
Assert.AreEqual("Hello, Serilog!", firstEvent.Text); | ||
Assert.AreEqual(string.Empty, firstEvent.Source); | ||
Assert.AreEqual(1, firstEvent.ThreadId); | ||
Assert.IsNotNull(firstEvent.Module); | ||
Assert.IsNotNull(firstEvent.FileName); | ||
Assert.IsNotNull(firstEvent.Category); | ||
Assert.IsNotNull(firstEvent.User); | ||
Assert.IsNotNull(firstEvent.MethodName); | ||
// The second event should have a source context | ||
var secondEvent = messages.ElementAt(1); | ||
Assert.AreEqual("Contextual Log", secondEvent.Text); | ||
Assert.AreEqual("SerilogLogging.Program", secondEvent.Source); | ||
Assert.AreEqual(1, secondEvent.ThreadId); | ||
Assert.IsNotNull(secondEvent.Module); | ||
Assert.IsNotNull(secondEvent.FileName); | ||
Assert.IsNotNull(secondEvent.Category); | ||
Assert.IsNotNull(secondEvent.User); | ||
Assert.IsNotNull(secondEvent.MethodName); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public async Task CompactJsonFormatTestColumns() | ||
{ | ||
CompactJsonFormatParser parser = new CompactJsonFormatParser(); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "CompactJsonFormatTestColumns.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.AreEqual(4, messages.Count()); | ||
// The first event doesn't have a source context | ||
Assert.IsTrue(messages[0].MachineName == "Test"); | ||
Assert.IsTrue(messages[1].AdditionalInformation["CustomProperty"] == "\"Custom Value\""); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public async Task CompactJsonFormatTestGZFile() | ||
{ | ||
CompactJsonFormatParser parser = new CompactJsonFormatParser(); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "CompactJsonFormat.gz"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.AreEqual(4, messages.Count()); | ||
// The first event doesn't have a source context | ||
Assert.IsTrue(messages[2].AdditionalInformation["Tags"] == "[\"test\", \"orange\"]"); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Analogy.LogViewer.Serilog.DataTypes; | ||
using Analogy.LogViewer.Serilog.IAnalogy; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Analogy.LogViewer.Serilog.UnitTests | ||
{ | ||
[TestClass] | ||
public class JsonFormatTests | ||
{ | ||
private string Folder { get; } = Environment.CurrentDirectory; | ||
|
||
[TestMethod] | ||
public async Task CompactJsonFormatFullFileTest() | ||
{ | ||
JsonFileParser parser = new JsonFileParser(new CompactJsonFormatMessageFields()); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "JsonFileCompactFormat.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.IsTrue(messages.Count == 2); | ||
Assert.IsTrue(messages[0].MachineName == "MY-MACHINE"); | ||
Assert.IsTrue(messages[1].Text.StartsWith("An unknown error occurred")); | ||
Assert.IsTrue((messages[1].Module == "My process")); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public async Task JsonFilePerLineTest() | ||
{ | ||
var p = new JsonFormatterParser(new JsonFormatMessageFields()); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "JsonFormatPerLine.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await p.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.IsTrue(messages.Count == 2); | ||
//Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Tags: [1, 2, 3] }, 0000007b at 06/07/2016 06:44:57","got"+ messages[0].Text); | ||
Assert.IsTrue(messages[0].User == "{ Name: \"nblumhardt\", Tags: [1, 2, 3] }"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task JsonFilePerFileTest() | ||
{ | ||
JsonFileParser parser = new JsonFileParser(new JsonFormatMessageFields()); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "JsonFormatPerFile.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.IsTrue(messages.Count == 2); | ||
//Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Tags: [1, 2, 3] }, 0000007b at 06/07/2016 06:44:57","got"+ messages[0].Text); | ||
Assert.IsTrue(messages[0].User == "{ Name: \"nblumhardt\", Tags: [1, 2, 3] }"); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("JsonFileCompactFormat.clef", FileFormat.CompactJsonFormatPerFile)] | ||
[DataRow("JsonFormatPerLine.clef", FileFormat.JsonFormatPerLine)] | ||
public void CompactJsonFormatTestAutomaticDetection(string fileName, FileFormat format) | ||
{ | ||
string file = Path.Combine(Folder, "log files", fileName); | ||
var type = OfflineDataProvider.TryDetectFormat(file); | ||
Assert.IsTrue(type == format); | ||
} | ||
|
||
[TestMethod] | ||
public async Task JsonFilePerLineDateTimeWithOffsetTest() | ||
{ | ||
var p = new JsonFormatterParser(new JsonFormatMessageFields()); | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
string fileName = Path.Combine(Folder, "log files", "JsonFormatPerLine.clef"); | ||
MessageHandlerForTesting forTesting = new MessageHandlerForTesting(); | ||
var messages = (await p.Process(fileName, cts.Token, forTesting)).ToList(); | ||
Assert.IsTrue(messages.Count == 2); | ||
|
||
Assert.IsTrue(messages[0].User == "{ Name: \"nblumhardt\", Tags: [1, 2, 3] }"); | ||
|
||
DateTimeOffset dto = DateTimeOffset.Parse("2020-06-07T13:44:57.8532799+10:00"); | ||
//Assert.IsTrue(messages[0].Date == dto.DateTime); | ||
//Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Tags: [1, 2, 3] }, 0000007b at 06/07/2016 06:44:57", "got" + messages[0].Text); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
Analogy.LogViewer.Serilog.UnitTests/log files/JsonFormatPerFile.clef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[ | ||
{ | ||
"Timestamp": "2020-06-07T13:44:57.8532799+10:00", | ||
"Level": "Information", | ||
"MessageTemplate": "Hello, {@User}, {N:x8} at {Now}", | ||
"Properties": { | ||
"User": { | ||
"Name": "nblumhardt", | ||
"Tags": [ 1, 2, 3 ] | ||
}, | ||
"N": 123, | ||
"Now": "2016-06-07T13:44:57.8532799+10:00" | ||
}, | ||
"Renderings": { | ||
"N": [ | ||
{ | ||
"Format": "x8", | ||
"Rendering": "0000007b" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Timestamp": "2016-06-07T13:44:57.8532799+10:00", | ||
"Level": "Information", | ||
"MessageTemplate": "Hello, {@User}, {N:x8} at {Now}", | ||
"Properties": { | ||
"User": { | ||
"Name": "Lior", | ||
"Tags": [ 1, 2, 3 ] | ||
}, | ||
"N": 123, | ||
"Now": "2016-06-07T13:44:57.8532799+10:00" | ||
}, | ||
"Renderings": { | ||
"N": [ | ||
{ | ||
"Format": "x8", | ||
"Rendering": "0000007b" | ||
} | ||
] | ||
} | ||
} | ||
] |
2 changes: 2 additions & 0 deletions
2
Analogy.LogViewer.Serilog.UnitTests/log files/JsonFormatPerLine.clef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"Timestamp":"2020-06-07T13:44:57.8532799+10:00","Level":"Information","MessageTemplate":"Hello, {@User}, {N:x8} at {Now}","Properties":{"User":{"Name":"nblumhardt","Tags":[1,2,3]},"N":123,"Now":"2016-06-07T13:44:57.8532799+10:00"},"Renderings":{"N":[{"Format":"x8","Rendering":"0000007b"}]}} | ||
{"Timestamp":"2016-06-07T13:44:57.8532799+10:00","Level":"Information","MessageTemplate":"Hello, {@User}, {N:x8} at {Now}","Properties":{"User":{"Name":"Lior","Tags":[1,2,3]},"N":123,"Now":"2016-06-07T13:44:57.8532799+10:00"},"Renderings":{"N":[{"Format":"x8","Rendering":"0000007b"}]}} |
1 change: 0 additions & 1 deletion
1
Analogy.LogViewer.Serilog.UnitTests/log files/JsonFormatter.clef
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.