2020-04-12 14:18:39 +05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace YY.EventLogAssistant.Services.Tests
|
|
|
|
{
|
|
|
|
public class StreamLineReaderTests
|
|
|
|
{
|
|
|
|
#region Private Member Variables
|
|
|
|
|
|
|
|
private string sampleDataDirectory;
|
|
|
|
private string sampleDatabaseFile;
|
2020-04-12 23:30:58 +05:00
|
|
|
private string[] sampleFilesLGP;
|
2020-04-12 14:18:39 +05:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
|
public StreamLineReaderTests()
|
|
|
|
{
|
|
|
|
string currentDirectory = Directory.GetCurrentDirectory();
|
|
|
|
sampleDataDirectory = Path.Combine(currentDirectory, "SampleData");
|
|
|
|
sampleDatabaseFile = Path.Combine(sampleDataDirectory, "LGFFormatEventLog", "1Cv8.lgf");
|
2020-04-12 23:30:58 +05:00
|
|
|
|
|
|
|
string dataDirectoryLGF = Path.Combine(sampleDataDirectory, "LGFFormatEventLog");
|
|
|
|
sampleFilesLGP = Directory.GetFiles(dataDirectoryLGF, "*.lgp");
|
2020-04-12 14:18:39 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public Methods
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GoToLine_Test()
|
|
|
|
{
|
|
|
|
string lineContent = string.Empty;
|
|
|
|
using (StreamReader reader = new StreamReader(sampleDatabaseFile))
|
|
|
|
{
|
2020-04-12 23:30:58 +05:00
|
|
|
using(StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
2020-04-12 14:18:39 +05:00
|
|
|
{
|
|
|
|
if(lineReader.GoToLine(1))
|
|
|
|
{
|
|
|
|
lineContent = lineReader.ReadLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Guid eventLogGuid = Guid.Empty;
|
|
|
|
Guid.TryParse(lineContent, out eventLogGuid);
|
|
|
|
|
|
|
|
Assert.NotEqual(Guid.Empty, eventLogGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetCount_Test()
|
|
|
|
{
|
|
|
|
long lineCounterNative = 0;
|
|
|
|
using (var reader = new StreamReader(sampleDatabaseFile))
|
|
|
|
{
|
|
|
|
while (reader.ReadLine() != null)
|
|
|
|
{
|
|
|
|
lineCounterNative++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long lineCounterLibrary = 0;
|
|
|
|
using (StreamReader reader = new StreamReader(sampleDatabaseFile))
|
|
|
|
{
|
2020-04-12 23:30:58 +05:00
|
|
|
using (StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
2020-04-12 14:18:39 +05:00
|
|
|
{
|
|
|
|
lineCounterLibrary = lineReader.GetCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Assert.Equal(lineCounterNative, lineCounterLibrary);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2020-04-12 23:30:58 +05:00
|
|
|
public void ReadLine_LGP_Test()
|
2020-04-12 14:18:39 +05:00
|
|
|
{
|
2020-04-12 23:30:58 +05:00
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
Encoding utf8 = Encoding.UTF8;
|
|
|
|
|
|
|
|
List<string> correctLines = new List<string>();
|
|
|
|
using (var reader = new StreamReader(sampleDatabaseFile, utf8))
|
2020-04-12 14:18:39 +05:00
|
|
|
{
|
2020-04-12 23:30:58 +05:00
|
|
|
string currentLine = reader.ReadLine();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
correctLines.Add(currentLine);
|
|
|
|
currentLine = reader.ReadLine();
|
|
|
|
} while (currentLine != null);
|
2020-04-12 14:18:39 +05:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:30:58 +05:00
|
|
|
List<string> resultLines = new List<string>();
|
|
|
|
using (StreamReader reader = new StreamReader(sampleDatabaseFile, utf8))
|
2020-04-12 14:18:39 +05:00
|
|
|
{
|
2020-04-12 23:30:58 +05:00
|
|
|
using (StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
2020-04-12 14:18:39 +05:00
|
|
|
{
|
2020-04-12 23:30:58 +05:00
|
|
|
string currentLine = lineReader.ReadLine();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
resultLines.Add(currentLine);
|
|
|
|
currentLine = lineReader.ReadLine();
|
|
|
|
} while (currentLine != null);
|
2020-04-12 14:18:39 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-12 23:30:58 +05:00
|
|
|
Assert.Equal(correctLines, resultLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReadLine_LGFs_Test()
|
|
|
|
{
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
Encoding utf8 = Encoding.UTF8;
|
|
|
|
|
|
|
|
List<string> correctLines = new List<string>();
|
|
|
|
List<string> resultLines = new List<string>();
|
|
|
|
|
|
|
|
foreach (string fileLGP in sampleFilesLGP)
|
|
|
|
{
|
|
|
|
using (var reader = new StreamReader(fileLGP, utf8))
|
|
|
|
{
|
|
|
|
string currentLine = reader.ReadLine();
|
|
|
|
while (currentLine != null)
|
|
|
|
{
|
|
|
|
correctLines.Add(currentLine);
|
|
|
|
currentLine = reader.ReadLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
using (StreamReader reader = new StreamReader(fileLGP, utf8))
|
|
|
|
{
|
|
|
|
using (StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
|
|
|
{
|
|
|
|
string currentLine = lineReader.ReadLine();
|
|
|
|
while (currentLine != null)
|
|
|
|
{
|
|
|
|
resultLines.Add(currentLine);
|
|
|
|
|
|
|
|
int cnt = resultLines.Count - 1;
|
|
|
|
if (correctLines[cnt] != resultLines[cnt])
|
|
|
|
{
|
|
|
|
int fff = 1;
|
|
|
|
} else if(cnt == 173)
|
|
|
|
{
|
|
|
|
int sdafdfa = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentLine = lineReader.ReadLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//for (int i = 0; i < correctLines.Count; i++)
|
|
|
|
//{
|
|
|
|
// if(correctLines[i] != resultLines[i])
|
|
|
|
// {
|
|
|
|
// int fff = 1;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
Assert.Equal(correctLines, resultLines);
|
2020-04-12 14:18:39 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|