-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor Log class generation for system tests
- Loading branch information
1 parent
de0bc79
commit dea281c
Showing
7 changed files
with
170 additions
and
395 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
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
63 changes: 5 additions & 58 deletions
63
...or/Reqnroll.TestProjectGenerator/Factories/BindingsGenerator/CSharp10BindingsGenerator.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 |
---|---|---|
@@ -1,66 +1,13 @@ | ||
using Reqnroll.TestProjectGenerator.Data; | ||
using System; | ||
|
||
namespace Reqnroll.TestProjectGenerator.Factories.BindingsGenerator; | ||
|
||
public class CSharp10BindingsGenerator : CSharpBindingsGenerator | ||
{ | ||
public override ProjectFile GenerateLoggerClass(string pathToLogFile) | ||
protected override string GetLogFileContent(string pathToLogFile) | ||
{ | ||
string fileContent = $$""" | ||
using System; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
|
||
internal static class Log | ||
{ | ||
private const string LogFileLocation = @"{{pathToLogFile}}"; | ||
|
||
private static void Retry(int number, Action action) | ||
{ | ||
try | ||
{ | ||
action(); | ||
} | ||
catch (Exception) | ||
{ | ||
var i = number - 1; | ||
if (i == 0) | ||
throw; | ||
Thread.Sleep(500); | ||
Retry(i, action); | ||
} | ||
} | ||
internal static void LogStep([CallerMemberName] string stepName = null!) | ||
{ | ||
Retry(5, () => WriteToFile($@"-> step: {stepName}{Environment.NewLine}")); | ||
} | ||
|
||
internal static void LogHook([CallerMemberName] string stepName = null!) | ||
{ | ||
Retry(5, () => WriteToFile($@"-> hook: {stepName}{Environment.NewLine}")); | ||
} | ||
|
||
internal static void LogCustom(string category, string value, [CallerMemberName] string memberName = null) | ||
{ | ||
Retry(5, () => WriteToFile($@"-> {category}: {value}:{memberName}{Environment.NewLine}")); | ||
} | ||
|
||
static void WriteToFile(string line) | ||
{ | ||
using (FileStream fs = File.Open(LogFileLocation, FileMode.Append, FileAccess.Write, FileShare.None)) | ||
{ | ||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(line); | ||
fs.Write(bytes, 0, bytes.Length); | ||
fs.Close(); | ||
} | ||
} | ||
} | ||
"""; | ||
return new ProjectFile("Log.cs", "Compile", fileContent); | ||
string logFileContent = base.GetLogFileContent(pathToLogFile); | ||
logFileContent = "#nullable disable" + Environment.NewLine + logFileContent; | ||
return logFileContent; | ||
} | ||
|
||
} |
Oops, something went wrong.