cs-codex-dist-tests/Logging/TestLog.cs

42 lines
1.0 KiB
C#
Raw Permalink Normal View History

2023-04-12 11:53:55 +00:00
using NUnit.Framework;
namespace Logging
{
2023-04-14 12:53:39 +00:00
public class TestLog : BaseLog
2023-04-12 11:53:55 +00:00
{
2023-04-14 12:53:39 +00:00
private readonly string methodName;
private readonly string fullName;
2023-04-12 11:53:55 +00:00
public TestLog(string folder, bool debug, string name = "")
2023-04-25 09:31:15 +00:00
: base(debug)
2023-04-12 11:53:55 +00:00
{
2023-07-18 07:02:41 +00:00
methodName = NameUtils.GetTestMethodName(name);
2023-04-14 12:53:39 +00:00
fullName = Path.Combine(folder, methodName);
2023-04-12 11:53:55 +00:00
Log($"*** Begin: {methodName}");
2023-04-12 11:53:55 +00:00
}
2023-06-28 13:11:20 +00:00
public override void EndTest()
2023-04-12 11:53:55 +00:00
{
var result = TestContext.CurrentContext.Result;
Log($"*** Finished: {methodName} = {result.Outcome.Status}");
2023-04-12 11:53:55 +00:00
if (!string.IsNullOrEmpty(result.Message))
{
Log(result.Message);
Log($"{result.StackTrace}");
}
if (result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed)
{
2023-04-14 12:53:39 +00:00
MarkAsFailed();
2023-04-12 11:53:55 +00:00
}
}
2023-06-28 13:11:20 +00:00
protected override string GetFullName()
2023-04-12 11:53:55 +00:00
{
2023-06-28 13:11:20 +00:00
return fullName;
2023-04-12 11:53:55 +00:00
}
}
}