Skip to content

Issue 316: Problem in Highlighting and action trigger rel. 1.11.1 #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/LogExpert.Tests/BufferShiftTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using LogExpert.Classes.Log;
using LogExpert.Entities;

using NUnit.Framework;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogExpert.Tests
Expand All @@ -26,21 +29,26 @@ public void Boot()
public void TestShiftBuffers1()
{
int linesPerFile = 10;
MultiFileOptions options = new MultiFileOptions();
options.MaxDayTry = 0;
options.FormatPattern = "*$J(.)";
MultiFileOptions options = new()
{
MaxDayTry = 0,
FormatPattern = "*$J(.)"
};
LinkedList<string> files = CreateTestFilesWithoutDate();
EncodingOptions encodingOptions = new EncodingOptions();
encodingOptions.Encoding = Encoding.Default;
LogfileReader reader = new LogfileReader(files.Last.Value, encodingOptions, true, 40, 50, options);
EncodingOptions encodingOptions = new()
{
Encoding = Encoding.Default
};
LogfileReader reader = new(files.Last.Value, encodingOptions, true, 40, 50, options);
reader.ReadFiles();

IList<ILogFileInfo> lil = reader.GetLogFileInfoList();
Assert.That(lil.Count, Is.EqualTo(files.Count));

LinkedList<string>.Enumerator enumerator = files.GetEnumerator();
enumerator.MoveNext();
foreach (LogFileInfo li in lil)

foreach (LogFileInfo li in lil.Cast<LogFileInfo>())
{
string fileName = enumerator.Current;
Assert.That(li.FullName, Is.EqualTo(fileName));
Expand All @@ -52,7 +60,7 @@ public void TestShiftBuffers1()
//
files = RolloverSimulation(files, "*$J(.)", false);

// Simulate rollover detection
// Simulate rollover detection
//
reader.ShiftBuffers();

Expand All @@ -73,7 +81,7 @@ public void TestShiftBuffers1()
enumerator.MoveNext();
}

// Check if file buffers have correct files. Assuming here that one buffer fits for a
// Check if file buffers have correct files. Assuming here that one buffer fits for a
// complete file
//
enumerator = files.GetEnumerator();
Expand Down Expand Up @@ -117,7 +125,7 @@ public void TestShiftBuffers1()
//
files = RolloverSimulation(files, "*$J(.)", true);

// Simulate rollover detection
// Simulate rollover detection
//
reader.ShiftBuffers();
lil = reader.GetLogFileInfoList();
Expand Down
4 changes: 2 additions & 2 deletions src/LogExpert.Tests/CSVColumnizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class CSVColumnizerTest
[TestCase(@".\TestData\people-10000.csv", new[] {"Index","User Id","First Name","Last Name","Sex","Email","Phone","Date of birth","Job Title"})]
public void Instantiat_CSVFile_BuildCorrectColumnizer(string filename, string[] expectedHeaders)
{
CsvColumnizer.CsvColumnizer csvColumnizer = new CsvColumnizer.CsvColumnizer();
CsvColumnizer.CsvColumnizer csvColumnizer = new();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
LogfileReader reader = new(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
reader.ReadFiles();
ILogLine line = reader.GetLogLine(0);
IColumnizedLogLine logline = new ColumnizedLogLine();
Expand Down
6 changes: 3 additions & 3 deletions src/LogExpert.Tests/ColumnizerPickerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void FindColumnizer_ReturnCorrectColumnizer(string expectedColumnizerName
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test");

Mock<IAutoLogLineColumnizerCallback> autoLogLineColumnizerCallbackMock = new Mock<IAutoLogLineColumnizerCallback>();
Mock<IAutoLogLineColumnizerCallback> autoLogLineColumnizerCallbackMock = new();

autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(0)).Returns(new TestLogLine()
{
Expand Down Expand Up @@ -67,10 +67,10 @@ public void FindReplacementForAutoColumnizer_ValidTextFile_ReturnCorrectColumniz
string fileName, Type columnizerType)
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
LogfileReader reader = new(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
reader.ReadFiles();

Mock<ILogLineColumnizer> autoColumnizer = new Mock<ILogLineColumnizer>();
Mock<ILogLineColumnizer> autoColumnizer = new();
autoColumnizer.Setup(a => a.GetName()).Returns("Auto Columnizer");

// TODO: When DI container is ready, we can mock this set up.
Expand Down
4 changes: 2 additions & 2 deletions src/LogExpert.Tests/DateFormatParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void TestDateFormatParserFromCulture(string cultureInfoName, params strin

static string RemoveCharacters(string input, string charsToRemove)
{
HashSet<char> charsToRemoveSet = new HashSet<char>(charsToRemove);
StringBuilder result = new StringBuilder();
HashSet<char> charsToRemoveSet = new(charsToRemove);
StringBuilder result = new();

foreach (char c in input)
{
Expand Down
6 changes: 4 additions & 2 deletions src/LogExpert.Tests/Extensions/EnumerableTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using LogExpert.Extensions;

using NUnit.Framework;

using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -27,7 +29,7 @@ public void Extensions_IsEmpty_EmptyArray()
[Test]
public void Extensions_IsEmpty_FilledArray()
{
object[] arrayObject = {new object()};
object[] arrayObject = { new() };

Assert.That(!arrayObject.IsEmpty(), Is.True);
}
Expand All @@ -51,7 +53,7 @@ public void Extensions_IsEmpty_EmptyIEnumerable()
[Test]
public void Extensions_IsEmpty_FilledIEnumerable()
{
IEnumerable<object> arrayObject = new List<object>(new []{new object()});
IEnumerable<object> arrayObject = new List<object>(new[] { new object() });

Assert.That(!arrayObject.IsEmpty(), Is.True);
}
Expand Down
4 changes: 3 additions & 1 deletion src/LogExpert.Tests/JsonColumnizerTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using LogExpert.Classes.Log;
using LogExpert.Entities;

using NUnit.Framework;

using System;
using System.IO;

Expand All @@ -14,7 +16,7 @@ public void GetColumnNames_HappyFile_ColumnNameMatches(string fileName, string e
{
var jsonColumnizer = new JsonColumnizer.JsonColumnizer();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
LogfileReader reader = new(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
reader.ReadFiles();

ILogLine line = reader.GetLogLine(0);
Expand Down
4 changes: 2 additions & 2 deletions src/LogExpert.Tests/JsonCompactColumnizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public void GetPriority_HappyFile_PriorityMatches(string fileName, Priority prio
{
var jsonCompactColumnizer = new JsonColumnizer.JsonCompactColumnizer();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
LogfileReader logFileReader = new(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
logFileReader.ReadFiles();
List<ILogLine> loglines = new List<ILogLine>
List<ILogLine> loglines = new()
{
// Sampling a few lines to select the correct columnizer
logFileReader.GetLogLine(0),
Expand Down
6 changes: 3 additions & 3 deletions src/LogExpert.Tests/LocalFileSystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Boot()
[Test]
public void TestUriHandle()
{
LocalFileSystem fs = new LocalFileSystem();
LocalFileSystem fs = new();
Assert.That(fs.CanHandleUri("file:///c:/logfile.txt"), Is.True);
Assert.That(fs.CanHandleUri("file:///c:\\logfile.txt"), Is.True);
Assert.That(fs.CanHandleUri("c:/logfile.txt"), Is.True);
Expand All @@ -37,13 +37,13 @@ public void TestUriToFileStream()
DirectoryInfo dInfo = Directory.CreateDirectory(RolloverHandlerTest.TEST_DIR_NAME);
string fullName = CreateFile(dInfo, "test.log");

LocalFileSystem fs = new LocalFileSystem();
LocalFileSystem fs = new();
ILogFileInfo info = fs.GetLogfileInfo(fullName);
Assert.That(info.Length > 0, Is.True);
Assert.That(info.OriginalLength == info.Length, Is.True);
Stream stream = info.OpenStream();
Assert.That(stream.CanSeek, Is.True);
StreamReader reader = new StreamReader(stream);
StreamReader reader = new(stream);
string line = reader.ReadLine();
Assert.That(line.StartsWith("line number", StringComparison.InvariantCultureIgnoreCase), Is.True);
reader.Close();
Expand Down
46 changes: 20 additions & 26 deletions src/LogExpert.Tests/LogWindowTest.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@

using LogExpert.Classes;
using LogExpert.Controls.LogTabWindow;
using LogExpert.Controls.LogWindow;
using LogExpert.Entities;
using NUnit.Framework;
using System;
using CsvColumnizerType = CsvColumnizer.CsvColumnizer;
using NUnit.Framework;

namespace LogExpert.Tests
{
//TODO Find out why there is a "Drag and Drop Exception" until then, this 2 Tests can not be executed the block the build pipeline
[TestFixture]
public class LogWindowTest
{
// TODO: Add more tests when DI container is ready.
[TestCase(@".\TestData\JsonColumnizerTest_01.txt", typeof(DefaultLogfileColumnizer))]
public void Instantiate_JsonFile_BuildCorrectColumnizer(string fileName, Type columnizerType)
{
LogTabWindow logTabWindow = new LogTabWindow(null, 0, false);
LogWindow logWindow = new LogWindow(logTabWindow, fileName, false, false);
//// TODO: Add more tests when DI container is ready.
//[TestCase(@".\TestData\JsonColumnizerTest_01.txt", typeof(DefaultLogfileColumnizer))]
//public void Instantiate_JsonFile_BuildCorrectColumnizer(string fileName, Type columnizerType)
//{
// LogTabWindow logTabWindow = new(null, 0, false);
// LogWindow logWindow = new(logTabWindow, fileName, false, false);

Assert.That(columnizerType, Is.EqualTo(logWindow.CurrentColumnizer.GetType()));
}
// Assert.That(columnizerType, Is.EqualTo(logWindow.CurrentColumnizer.GetType()));
//}

[TestCase(@".\TestData\XmlTest_01.xml")]
[TestCase(@".\TestData\CsvTest_01.csv")]
public void Instantiate_AnyFile_NotCrash(string fileName)
{
PluginRegistry.GetInstance().RegisteredColumnizers.Add(new Log4jXmlColumnizer());
PluginRegistry.GetInstance().RegisteredColumnizers.Add(new CsvColumnizerType());
//[TestCase(@".\TestData\XmlTest_01.xml")]
//[TestCase(@".\TestData\CsvTest_01.csv")]
//public void Instantiate_AnyFile_NotCrash(string fileName)
//{
// PluginRegistry.GetInstance().RegisteredColumnizers.Add(new Log4jXmlColumnizer());
// PluginRegistry.GetInstance().RegisteredColumnizers.Add(new CsvColumnizerType());

LogTabWindow logTabWindow = new LogTabWindow(null, 0, false);
LogWindow logWindow = new LogWindow(logTabWindow, fileName, false, false);
// LogTabWindow logTabWindow = new(null, 0, false);
// LogWindow logWindow = new(logTabWindow, fileName, false, false);

Assert.That(true, Is.True);
}
// Assert.That(true, Is.True);
//}
}
}
8 changes: 4 additions & 4 deletions src/LogExpert.Tests/RollingNameTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class RollingNameTest
[TestCase("engine_2010-06-12.log", "*$D(yyyy-MM-dd).log$J(.)")]
public void TestFilename1(string expectedResult, string formatString)
{
RolloverFilenameBuilder fnb = new RolloverFilenameBuilder(formatString);
RolloverFilenameBuilder fnb = new(formatString);
fnb.SetFileName(expectedResult);
string name = fnb.BuildFileName();
Assert.That(name, Is.EqualTo(expectedResult));
Expand All @@ -34,7 +34,7 @@ public void TestFilename1(string expectedResult, string formatString)
[TestCase("engine_2010-06-12.log", "engine_2010-06-12.log.1", "*$D(yyyy-MM-dd).log$J(.)")]
public void TestFilenameAnd1(string fileName, string expectedResult, string formatString)
{
RolloverFilenameBuilder fnb = new RolloverFilenameBuilder(formatString);
RolloverFilenameBuilder fnb = new(formatString);
fnb.SetFileName(fileName);
fnb.Index += 1;
string name = fnb.BuildFileName();
Expand All @@ -46,7 +46,7 @@ public void TestFilenameAnd1(string fileName, string expectedResult, string form
[TestCase("engine.log", "engine.log.2","*.log$J(.)")]
public void TestFilenameAnd2(string fileName, string expectedResult, string formatString)
{
RolloverFilenameBuilder fnb = new RolloverFilenameBuilder(formatString);
RolloverFilenameBuilder fnb = new(formatString);
fnb.SetFileName(fileName);
fnb.Index += 2;
string name = fnb.BuildFileName();
Expand All @@ -58,7 +58,7 @@ public void TestFilenameAnd2(string fileName, string expectedResult, string form
[TestCase("engine1.log", "engine.log","engine$J.log")]
public void TestFilenameMinus1(string fileName, string expectedResult, string formatString)
{
RolloverFilenameBuilder fnb = new RolloverFilenameBuilder(formatString);
RolloverFilenameBuilder fnb = new(formatString);
fnb.SetFileName(fileName);
fnb.Index -= 1;
string name = fnb.BuildFileName();
Expand Down
8 changes: 4 additions & 4 deletions src/LogExpert.Tests/RolloverHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class RolloverHandlerTest : RolloverHandlerTestBase
[TestCase("*$J(.)", 66)]
public void TestFilenameListWithAppendedIndex(string format, int retries)
{
MultiFileOptions options = new MultiFileOptions();
MultiFileOptions options = new();
options.FormatPattern = format;
options.MaxDayTry = retries;

Expand All @@ -22,7 +22,7 @@ public void TestFilenameListWithAppendedIndex(string format, int retries)
string firstFile = files.Last.Value;

ILogFileInfo info = new LogFileInfo(new Uri(firstFile));
RolloverFilenameHandler handler = new RolloverFilenameHandler(info, options);
RolloverFilenameHandler handler = new(info, options);
LinkedList<string> fileList = handler.GetNameList();

Assert.That(fileList, Is.EqualTo(files));
Expand All @@ -34,7 +34,7 @@ public void TestFilenameListWithAppendedIndex(string format, int retries)
[TestCase("*$D(YYYY-mm-DD)_$I.log", 3)]
public void TestFilenameListWithDate(string format, int retries)
{
MultiFileOptions options = new MultiFileOptions();
MultiFileOptions options = new();
options.FormatPattern = format;
options.MaxDayTry = retries;

Expand All @@ -43,7 +43,7 @@ public void TestFilenameListWithDate(string format, int retries)
string firstFile = files.Last.Value;

ILogFileInfo info = new LogFileInfo(new Uri(firstFile));
RolloverFilenameHandler handler = new RolloverFilenameHandler(info, options);
RolloverFilenameHandler handler = new(info, options);
LinkedList<string> fileList = handler.GetNameList();

Assert.That(fileList, Is.EqualTo(files));
Expand Down
8 changes: 4 additions & 4 deletions src/LogExpert.Tests/RolloverHandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class RolloverHandlerTestBase

protected LinkedList<string> CreateTestFilesWithDate()
{
LinkedList<string> createdFiles = new LinkedList<string>();
LinkedList<string> createdFiles = new();
DirectoryInfo dInfo = Directory.CreateDirectory(TEST_DIR_NAME);
createdFiles.AddLast(CreateFile(dInfo, "engine_2010-06-08_1.log"));
createdFiles.AddLast(CreateFile(dInfo, "engine_2010-06-08_0.log"));
Expand All @@ -31,7 +31,7 @@ protected LinkedList<string> CreateTestFilesWithDate()

protected LinkedList<string> CreateTestFilesWithoutDate()
{
LinkedList<string> createdFiles = new LinkedList<string>();
LinkedList<string> createdFiles = new();
DirectoryInfo dInfo = Directory.CreateDirectory(TEST_DIR_NAME);
createdFiles.AddLast(CreateFile(dInfo, "engine.log.6"));
createdFiles.AddLast(CreateFile(dInfo, "engine.log.5"));
Expand All @@ -47,7 +47,7 @@ protected LinkedList<string> RolloverSimulation(LinkedList<string> files, string
bool deleteLatestFile)
{
LinkedList<string> fileList = files;
RolloverFilenameBuilder fnb = new RolloverFilenameBuilder(formatPattern);
RolloverFilenameBuilder fnb = new(formatPattern);
fnb.SetFileName(fileList.Last.Value);
fnb.Index += fileList.Count;
string newFileName = fnb.BuildFileName();
Expand Down Expand Up @@ -88,7 +88,7 @@ protected string CreateFile(DirectoryInfo dInfo, string fileName)
int lineCount = 10;
string fullName = dInfo == null ? fileName : dInfo.FullName + Path.DirectorySeparatorChar + fileName;

using (StreamWriter writer = new StreamWriter(File.Create(fullName)))
using (StreamWriter writer = new(File.Create(fullName)))
{
for (int i = 1; i <= lineCount; ++i)
{
Expand Down
14 changes: 8 additions & 6 deletions src/LogExpert.Tests/SquareBracketColumnizerTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

using LogExpert.Classes.Columnizer;
using LogExpert.Classes.Log;
using LogExpert.Entities;

using NUnit.Framework;

using System;
using System.Collections.Generic;
using System.IO;
using LogExpert.Classes.Columnizer;
using LogExpert.Classes.Log;
using LogExpert.Entities;

namespace LogExpert
{
Expand All @@ -18,12 +20,12 @@ public class SquareBracketColumnizerTest
[TestCase(@".\TestData\SquareBracketColumnizerTest_05.txt", 3)]
public void GetPriority_HappyFile_ColumnCountMatches(string fileName, int count)
{
SquareBracketColumnizer squareBracketColumnizer = new SquareBracketColumnizer();
SquareBracketColumnizer squareBracketColumnizer = new();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);

LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
LogfileReader logFileReader = new(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
logFileReader.ReadFiles();
List<ILogLine> loglines = new List<ILogLine>
List<ILogLine> loglines = new()
{
// Sampling a few lines to select the correct columnizer
logFileReader.GetLogLine(0),
Expand Down
Loading