cs-codex-dist-tests/Core/DownloadedLog.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2023-04-13 09:30:19 +00:00
using Logging;
2023-09-12 11:32:06 +00:00
namespace Core
2023-04-13 09:30:19 +00:00
{
2023-06-27 13:28:00 +00:00
public interface IDownloadedLog
2023-04-13 09:30:19 +00:00
{
2023-09-12 11:32:06 +00:00
bool DoesLogContain(string expectedString);
string[] FindLinesThatContain(params string[] tags);
void DeleteFile();
2023-04-13 09:30:19 +00:00
}
2023-06-27 13:28:00 +00:00
public class DownloadedLog : IDownloadedLog
2023-04-13 09:30:19 +00:00
{
private readonly LogFile logFile;
2023-09-12 11:32:06 +00:00
public DownloadedLog(LogFile logFile)
2023-04-13 09:30:19 +00:00
{
this.logFile = logFile;
}
2023-09-12 11:32:06 +00:00
public bool DoesLogContain(string expectedString)
2023-04-13 09:30:19 +00:00
{
using var file = File.OpenRead(logFile.FullFilename);
using var streamReader = new StreamReader(file);
var line = streamReader.ReadLine();
while (line != null)
{
2023-09-12 11:32:06 +00:00
if (line.Contains(expectedString)) return true;
2023-04-13 09:30:19 +00:00
line = streamReader.ReadLine();
}
2023-09-12 11:32:06 +00:00
//Assert.Fail($"{owner} Unable to find string '{expectedString}' in CodexNode log file {logFile.FullFilename}");
return false;
2023-04-13 09:30:19 +00:00
}
public string[] FindLinesThatContain(params string[] tags)
{
var result = new List<string>();
using var file = File.OpenRead(logFile.FullFilename);
using var streamReader = new StreamReader(file);
var line = streamReader.ReadLine();
while (line != null)
{
if (tags.All(line.Contains))
{
result.Add(line);
}
line = streamReader.ReadLine();
}
return result.ToArray();
}
public void DeleteFile()
{
File.Delete(logFile.FullFilename);
}
2023-04-13 09:30:19 +00:00
}
}