1
0
mirror of https://github.com/BDDSM/YY.EventLogReaderAssistant.git synced 2024-11-21 10:05:51 +02:00

Добавил unit-тесты для класса чтения логов (нового и старого формата)

This commit is contained in:
YPermitin 2020-04-13 14:50:30 +05:00
parent ae23b30ab7
commit f93f704231

View File

@ -0,0 +1,131 @@
using System.IO;
using Xunit;
namespace YY.EventLogAssistant.Tests
{
public class EventLogReaderTests
{
#region Private Member Variables
private readonly string sampleDataDirectory;
private readonly string sampleDatabaseFileLGF;
private readonly string[] sampleFilesLGP;
private readonly string sampleDatabaseFileLGD;
#endregion
#region Constructor
public EventLogReaderTests()
{
string currentDirectory = Directory.GetCurrentDirectory();
sampleDataDirectory = Path.Combine(currentDirectory, "SampleData");
sampleDatabaseFileLGF = Path.Combine(sampleDataDirectory, "LGFFormatEventLog", "1Cv8.lgf");
string dataDirectoryLGF = Path.Combine(sampleDataDirectory, "LGFFormatEventLog");
sampleFilesLGP = Directory.GetFiles(dataDirectoryLGF, "*.lgp");
sampleDatabaseFileLGD = Path.Combine(sampleDataDirectory, "SQLiteFormatEventLog", "1Cv8.lgd");
}
#endregion
#region Public Methods
[Fact]
public void ReadEventLogEvents_OldFormat_LGF_Test()
{
long countLogFiles = 0;
long countRecords = 0;
long countRecordsStepByStep = 0;
long countRecordsStepByStepAfterReset = 0;
long countRecordsStepByStepAfterSetPosition = 0;
using (EventLogReader reader = EventLogReader.CreateReader(sampleDatabaseFileLGF))
{
countRecords = reader.Count();
while(reader.Read())
{
countRecordsStepByStep += 1;
}
reader.Reset();
while (reader.Read())
{
countRecordsStepByStepAfterReset += 1;
}
reader.Reset();
EventLogPosition position = reader.GetCurrentPosition();
while (reader.Read());
reader.SetCurrentPosition(position);
while (reader.Read())
{
countRecordsStepByStepAfterSetPosition += 1;
}
reader.Reset();
EventLogLGFReader readerLGF = (EventLogLGFReader)reader;
while (readerLGF.CurrentFile != null)
{
reader.NextFile();
countLogFiles += 1;
}
}
Assert.NotEqual(0, countLogFiles);
Assert.NotEqual(0, countRecords);
Assert.NotEqual(0, countRecordsStepByStep);
Assert.NotEqual(0, countRecordsStepByStepAfterReset);
Assert.NotEqual(0, countRecordsStepByStepAfterSetPosition);
Assert.Equal(countRecords, countRecordsStepByStep);
Assert.Equal(countRecords, countRecordsStepByStepAfterReset);
Assert.Equal(countRecords, countRecordsStepByStepAfterSetPosition);
}
[Fact]
public void ReadEventLogEvents_NewFormat_LGD_Test()
{
long countRecords = 0;
long countRecordsStepByStep = 0;
long countRecordsStepByStepAfterReset = 0;
long countRecordsStepByStepAfterSetPosition = 0;
using (EventLogReader reader = EventLogReader.CreateReader(sampleDatabaseFileLGD))
{
countRecords = reader.Count();
while (reader.Read())
{
countRecordsStepByStep += 1;
}
reader.Reset();
while (reader.Read())
{
countRecordsStepByStepAfterReset += 1;
}
reader.Reset();
EventLogPosition position = reader.GetCurrentPosition();
while (reader.Read()) ;
reader.SetCurrentPosition(position);
while (reader.Read())
{
countRecordsStepByStepAfterSetPosition += 1;
}
}
Assert.NotEqual(0, countRecords);
Assert.NotEqual(0, countRecordsStepByStep);
Assert.NotEqual(0, countRecordsStepByStepAfterReset);
Assert.NotEqual(0, countRecordsStepByStepAfterSetPosition);
Assert.Equal(countRecords, countRecordsStepByStep);
Assert.Equal(countRecords, countRecordsStepByStepAfterReset);
Assert.Equal(countRecords, countRecordsStepByStepAfterSetPosition);
}
#endregion
}
}