diff --git a/Tests/FrameworkTests/LifecycelyTest.cs b/Tests/FrameworkTests/LifecycelyTest.cs index 6c11e14f..e420a911 100644 --- a/Tests/FrameworkTests/LifecycelyTest.cs +++ b/Tests/FrameworkTests/LifecycelyTest.cs @@ -1,64 +1,65 @@ -//using NUnit.Framework; +using NUnit.Framework; -//namespace FrameworkTests -//{ -// [Parallelizable(ParallelScope.All)] -// [TestFixture(10)] -// [TestFixture(20)] -// [TestFixture(30)] -// public class LifecycelyTest -// { -// public LifecycelyTest(int num) -// { -// Log("ctor", GetCurrentTestName(), num); -// this.num = num; -// } +namespace FrameworkTests +{ + [Parallelizable(ParallelScope.All)] + [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] + [TestFixture(10)] + [TestFixture(20)] + [TestFixture(30)] + public class LifecycelyTest + { + public LifecycelyTest(int num) + { + Log("ctor", GetCurrentTestName(), num); + this.num = num; + } -// [SetUp] -// public void Setup() -// { -// Log(nameof(Setup), GetCurrentTestName()); -// } + [SetUp] + public void Setup() + { + Log(nameof(Setup), GetCurrentTestName()); + } -// [TearDown] -// public void TearDown() -// { -// Log(nameof(TearDown), GetCurrentTestName()); -// } + [TearDown] + public void TearDown() + { + Log(nameof(TearDown), GetCurrentTestName()); + } -// [Test] -// public void A() -// { -// Log(nameof(A), "Run"); -// SleepRandom(); -// Log(nameof(A), "Finish"); -// } + //[Test] + //public void A() + //{ + // Log(nameof(A), "Run"); + // SleepRandom(); + // Log(nameof(A), "Finish"); + //} -// [Test] -// public void B() -// { -// Log(nameof(B), "Run"); -// SleepRandom(); -// Log(nameof(B), "Finish"); -// } + //[Test] + //public void B() + //{ + // Log(nameof(B), "Run"); + // SleepRandom(); + // Log(nameof(B), "Finish"); + //} -// [Test] -// public void C() -// { -// Log(nameof(C), "Run"); -// SleepRandom(); -// Log(nameof(C), "Finish"); -// } + //[Test] + //public void C() + //{ + // Log(nameof(C), "Run"); + // SleepRandom(); + // Log(nameof(C), "Finish"); + //} -// [Test] -// [Combinatorial] -// public void Multi( -// [Values(1, 2, 3)] int num) -// { -// Log(nameof(Multi), "Run", num); -// SleepRandom(); -// Log(nameof(Multi), "Finish", num); -// } + [Test] + [Combinatorial] + public void Multi( + [Values(1, 2, 3)] int num) + { + Log(nameof(Multi), "Run", num); + SleepRandom(); + Log(nameof(Multi), "Finish", num); + } @@ -71,150 +72,148 @@ -// private static readonly Random r = new Random(); -// private readonly int num; + private static readonly Random r = new Random(); + private readonly int num; -// private void SleepRandom() -// { -// Thread.Sleep(TimeSpan.FromSeconds(5.0)); -// Thread.Sleep(TimeSpan.FromMilliseconds(r.Next(100, 1000))); -// } + private void SleepRandom() + { + Thread.Sleep(TimeSpan.FromSeconds(5.0)); + Thread.Sleep(TimeSpan.FromMilliseconds(r.Next(100, 1000))); + } -// private void Log(string scope, string msg) -// { -// ALog.Log($"{num} {scope} {msg}"); -// } + private void Log(string scope, string msg) + { + ALog.Log($"{num} {scope} {msg}"); + } -// private void Log(string scope, string msg, int num) -// { -// ALog.Log($"{this.num} {scope} {msg} {num}"); -// } + private void Log(string scope, string msg, int num) + { + ALog.Log($"{this.num} {scope} {msg} {num}"); + } -// private string GetCurrentTestName() -// { -// return $"[{TestContext.CurrentContext.Test.Name}]"; -// } -// } + private string GetCurrentTestName() + { + return $"[{TestContext.CurrentContext.Test.Name}]"; + } + } -// public class ALog -// { -// private static readonly object _lock = new object(); + public class ALog + { + private static readonly object _lock = new object(); -// public static void Log(string msg) -// { -// lock (_lock) -// { -// File.AppendAllLines("C:\\Users\\vexor\\Desktop\\Alog.txt", [msg]); -// } -// } -// } + public static void Log(string msg) + { + lock (_lock) + { + File.AppendAllLines("C:\\Users\\vexor\\Desktop\\Alog.txt", [msg]); + } + } + } + public interface ITestLifecycleComponent + { + } + public class Base + { + private readonly Dictionary> anyFields = new(); -// public class Base -// { -// private readonly Dictionary> anyFields = new(); + public void Setup() + { + var testId = 23; -// public void Setup() -// { -// var testId = 23; + var fields = new Dictionary(); + anyFields.Add(testId, fields); + YieldFields(field => + { + fields.Add(field.GetType(), field); + }); -// var fields = new Dictionary(); -// anyFields.Add(testId, fields); -// YieldFields(field => -// { -// fields.Add(field.GetType(), field); -// }); + } -// foreach (var field in fields.Values) -// { -// field.Start(); -// } -// } + public void TearDown() + { + var testId = 23; -// public void TearDown() -// { -// var testId = 23; + // foreach stop -// // foreach stop + anyFields.Remove(testId); + } -// anyFields.Remove(testId); -// } + public T Get() + { + int testId = 123; + var fields = anyFields[testId]; + var type = typeof(T); + var result = fields[type]; + return (T)result; + } -// public T Get() -// { -// int testId = 123; -// var fields = anyFields[testId]; -// var type = typeof(T); -// var result = fields[type]; -// return (T)result; -// } + public BaseFields GetBaseField() + { + return Get(); + } -// public BaseFields GetBaseField() -// { -// return Get(); -// } + protected virtual void YieldFields(Action giveField) + { + giveField(new BaseFields()); + } + } -// protected virtual void YieldFields(Action giveField) -// { -// giveField(new BaseFields()); -// } -// } + public class Mid : Base + { + protected override void YieldFields(Action giveField) + { + base.YieldFields(giveField); + giveField(new MidFields()); + } -// public class Mid : Base -// { -// protected override void YieldFields(Action giveField) -// { -// base.YieldFields(giveField); -// giveField(new MidFields()); -// } + public MidFields GetMid() + { + return Get(); + } + } -// public MidFields GetMid() -// { -// return Get(); -// } -// } + public class Top : Mid + { + protected override void YieldFields(Action giveField) + { + base.YieldFields(giveField); + giveField(new TopFields()); + } -// public class Top : Mid -// { -// protected override void YieldFields(Action giveField) -// { -// base.YieldFields(giveField); -// giveField(new TopFields()); -// } + public TopFields GetTop() + { + return Get(); + } + } -// public TopFields GetTop() -// { -// return Get(); -// } -// } + public class BaseFields : ITestLifecycleComponent + { + public string EntryPoint { get; set; } = string.Empty; + public string Log { get; set; } = string.Empty; + } -// public class BaseFields : ITestLifecycleComponent -// { -// public string EntryPoint { get; set; } = string.Empty; -// public string Log { get; set; } = string.Empty; -// } + public class MidFields : ITestLifecycleComponent + { + public string Nodes { get; set; } = string.Empty; + } -// public class MidFields : ITestLifecycleComponent -// { -// public string Nodes { get; set; } = string.Empty; -// } - -// public class TopFields : ITestLifecycleComponent -// { -// public string Geth { get; set; } = string.Empty; -// public string Contracts { get; set; } = string.Empty; -// } -//} + public class TopFields : ITestLifecycleComponent + { + public string Geth { get; set; } = string.Empty; + public string Contracts { get; set; } = string.Empty; + } +}