chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
//            Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using NUnit.Framework;
using OpenTap.Plugins.BasicSteps;
using OpenTap.Engine.UnitTests.TestTestSteps;
using OpenTap.EngineUnitTestUtils;
using OpenTap.UnitTests;
 
namespace OpenTap.Engine.UnitTests
{
    namespace SubSpace
    {
        public class TestStepTest : TestStep
        {
            public List<TestPoint> TestPoints { get; set; }
            public class TestPoint
            {
                public int Channel;
            }
            /// <summary>
            /// Initializes a new instance of the TestStepTest class.
            /// </summary>
            public TestStepTest()
            {
                TestPoints = new List<TestPoint>();
            }
            public override void Run()
            {
            }
        }
    }
    public class TestStepTest : TestStep
    {
        public List<TestPoint> TestPoints { get; set; }
        public class TestPoint
        {
            public int Channel { get; set; }
        }
        public class NestedStep : TestStep
        {
            public override void Run() { }
        }
        public string PublishArtifact;
        /// <summary>
        /// Initializes a new instance of the TestStepTest class.
        /// </summary>
        public TestStepTest()
        {
            TestPoints = new List<TestPoint>();
        }
        public override void Run()
        {
            Results.Publish("UnitTest", new List<string>() { "Channel", "Power [dBm]" }, 27, 1.11, 2, 0);
            Verdict = Verdict.Pass;
            if (string.IsNullOrEmpty(PublishArtifact) == false)
            {
                StepRun.PublishArtifact(PublishArtifact);
            }
        }
 
        public static TestPlan CreateGenericTestPlan()
        {
            TestPlan plan = new TestPlan();
            plan.Steps.Add(new TestStepTest());
            plan.Steps.Add(new SubSpace.TestStepTest());
            plan.Steps.Add(new TestStepTest2());
            return plan;
        }
 
    }
    public class TestStepTest2 : TestStep
    {
        public List<TestPoint> TestPoints { get; set; }
        public class TestPoint
        {
            public int Channel { get; set; }
        }
        public class NestedStep : TestStep
        {
            public override void Run() { }
        }
        public class SomeObject
        {
            public int Channel { get; set; }
        }
        public SomeObject ObjectProperty { get; set; }
 
        /// <summary>
        /// Initializes a new instance of the TestStepTest2 class.
        /// </summary>
        public TestStepTest2()
        {
            TestPoints = new List<TestPoint>();
        }
        public override void Run()
        {
        }
    }
 
    [AllowAsChildIn(typeof(RecursiveTestStep))]
    public class TestStepTest3 : TestStep
    {
        public List<TestPoint> TestPoints { get; set; }
 
 
        public class TestPoint
        {
            public int Channel { get; set; }
        }
        public class SomeObject
        {
            public int Channel { get; set; }
        }
        public SomeObject ObjectProperty { get; set; }
 
        /// <summary>
        /// Initializes a new instance of the TestStepTest2 class.
        /// </summary>
        public TestStepTest3()
        {
            TestPoints = new List<TestPoint>();
        }
        public override void Run()
        {
        }
    }
    public class RecursiveTestStep : TestStep
    {
        public int SomeInt { get; set; }
        public RecursiveTestStep()
        {
            SomeInt = 5;
        }
        public override void Run()
        {
 
        }
    }
 
    public class OpenCrash : Instrument
    {
 
        public override void Open()
        {
            base.Open();
            throw new Exception("intended");
        }
    }
 
    public class CloseCrash : Instrument
    {
        public override void Close()
        {
            base.Close();
            throw new Exception("intended");
        }
    }
 
    public class CreateCrash : Instrument
    {
        public CreateCrash()
        {
            throw new Exception("Intended");
        }
    }
 
    public class testInstr : TestStep
    {
        public IInstrument Inst { get; set; }
        public override void Run()
        {
 
        }
    }
 
 
    [System.ComponentModel.DisplayName(" Close Every Thing")]
    public class closeEveryThing : TestStep
    {
 
        public override void PrePlanRun()
        {
            base.PrePlanRun();
            Run();
        }
 
        public override void Run()
        {
            InstrumentSettings.Current
                .Concat<IResource>(ResultSettings.Current)
                .Concat(DutSettings.Current)
                .ToList()
                .ForEach(r => r.Close());
        }
 
    }
 
    public class IsOpenTestStep : TestStep
    {
        public IResource Resource { get; set; }
 
        public override void Run()
        {
            Assert.IsTrue(Resource.IsConnected);
        }
    }
 
    public class DummyDut : Dut
    {
        [MetaData]
        [Browsable(false)]
        public string Serial { get; set; }
 
        public override void Open()
        {
            base.Open();
            Serial = SerialNumber;
        }
        public override void Close()
        {
            base.Close();
            Serial = null;
        }
 
        public static string SerialNumber = "123456";
 
    }
 
    public class DummyInstrument : Instrument
    {
 
    }
 
    public class DummyReferencingInstrument : Instrument
    {
        public Instrument Other { get; set; }
    }
 
    [DisplayName("Test\\UnitTest resultListener2")]
    public class resultListener2 : ResultListener
    {
        public resultListener2()
        {
            Name = "resultListener2";
        }
    }
 
    /*public*/
    class ThrowExceptionSetting : ComponentSettings
    {
        public int exceptionTest
        {
            get
            {
                throw new Exception("Intended");
            }
            set
            {
                throw new Exception("Intended");
            }
 
        }
    }
 
    [Display("Enabled Check Boxes")]
    public class EnabledFormattedNameTest : TestStep
    {
        [Display("Checked Bool")]
        public Enabled<bool> CheckedBool { get; set; }
        [Display("Checked Bool Array")]
        public Enabled<bool[]> CheckedBoolArray { get; set; }
        [Display("Checked Double")]
        public Enabled<double> CheckedDouble { get; set; }
        [Display("Checked Double Array")]
        public Enabled<double[]> CheckedDoubleArray { get; set; }
        [Display("Checked String")]
        public Enabled<string> CheckedString { get; set; }
        [Display("Checked String Array")]
        public Enabled<string[]> CheckedStringArray { get; set; }
        [Display("Checked String List")]
        public Enabled<List<string>> CheckedStringList { get; set; }
        [Display("Checked Instrument")]
        public Enabled<Instrument> CheckedInstrument { get; set; }
 
        public EnabledFormattedNameTest()
        {
            CheckedBool = new Enabled<bool>() { IsEnabled = true, Value = false };
            CheckedBoolArray = new Enabled<bool[]>() { IsEnabled = true, Value = new bool[] { false, true } };
            CheckedDouble = new Enabled<double>() { IsEnabled = true, Value = 3.21 };
            CheckedDoubleArray = new Enabled<double[]>() { IsEnabled = true, Value = new double[] { 3.33, 45.6, 88.8 } };
            CheckedString = new Enabled<string>() { IsEnabled = true, Value = "Some comment" };
            CheckedStringArray = new Enabled<string[]>() { IsEnabled = true, Value = new string[] { "abc", "DEF", "GhI" } };
            CheckedStringList = new Enabled<List<string>>() { IsEnabled = true, Value = new List<string> { "One", "Two", "Three" } };
            CheckedInstrument = new Enabled<Instrument>() { IsEnabled = true };
        }
 
        public override void Run()
        {
            throw new NotImplementedException();
        }
    }
 
    public class NullArrayTest : TestStep
    {
        public int[] TestArray { get; set; }
        public override void Run()
        {
            throw new NotImplementedException();
        }
    }
 
    public class NullArrayInstrument : Instrument
    {
        public int[] TestArray { get; set; }
    }
 
    public class ResultStressTest : TestStep
    {
        public int Iterations { get; set; }
        public ResultStressTest()
        {
            Iterations = 100;
        }
        public override void Run()
        {
            for (double i = 0; i < Iterations; i++)
            {
                Results.Publish("UnitTest", new List<string>() { "Channel", "Power [dBm]" }, i, Math.Sin(i), 2, 0);
            }
            Verdict = Verdict.Pass;
        }
    }
 
    public class Result1DTest : TestStep
    {
        public int NResults { get; set; }
        public double Duration { get; set; }
        public Result1DTest()
        {
            NResults = 100;
        }
        public override void Run()
        {
            TapThread.Sleep((int)(1000 * Duration));
            for (double i = 0; i < NResults; i++)
            {
                Results.Publish("UnitTest", new List<string> { "Channel", "Power [dBm]" }, Math.Sin(i)/*,Math.Cos(i)*/);
            }
            Verdict = Verdict.Pass;
        }
    }
 
    public class SomeClass { }
 
    public class NullPropertyTest : TestStep
    {
        public SomeClass Property { get; set; }
 
 
        public override void Run()
        {
            for (double i = 0; i < 5; i++)
            {
                Results.Publish("UnitTest", new List<string> { "Channel", "Power [dBm]" }, Math.Sin(i), Math.Cos(i));
            }
        }
    }
 
    public class GetParamsSub : Resource
    {
        [MetaData]
        public int Index { get; set; }
        public int Index2 { get; set; }
        public GetParamsSub()
        {
            Index = 10;
        }
    }
 
    public class GetParameters : TestStep
    {
        public double Param1 { get; set; }
        public GetParamsSub sub { get; set; }
        public GetParameters()
        {
            sub = new GetParamsSub();
        }
        public override void Run()
        {
 
            Param1 = 5;
            var param = ResultParameters.GetParams(this);
            var dict = param.ToDictionary();
            Assert.IsTrue((double)dict["Param1"] == Param1);
            Assert.IsTrue(dict.ContainsKey("sub/Index"));
            Assert.IsTrue(dict.ContainsKey("sub/Index2") == false);
            Console.WriteLine(param);
        }
    }
 
    public class ReadOnlyTests
    {
        public class ReadOnlyParams
        {
            [Browsable(true)] public int X => GetHashCode();
            public string Message => X + " example"; // immutable value.
 
            public int Value { get; set; } // this value is mutable.
        }
 
        public class ReadOnlyListTest : TestStep
        {
            List<ReadOnlyParams> elements = new List<ReadOnlyParams>
            {
                new ReadOnlyParams(), new ReadOnlyParams(), new ReadOnlyParams(),
            };
            public IReadOnlyList<ReadOnlyParams> Elements
            {
                get => elements.AsReadOnly();
                set { elements = value.ToList(); }
            }
            public override void Run() { }
        }
 
        [Test]
        public void TestReadOnlyList()
        {
            var plan = new TestPlan();
            var step1 = new ReadOnlyListTest();
            step1.Elements = Enumerable.Range(0, 5).Select(i => new ReadOnlyParams() {Value = i}).ToList();
            Assert.AreEqual(5, step1.Elements.Count);
            plan.Steps.Add(step1);
 
            var listener = new TestTraceListener();
            Log.AddListener(listener);
            var xml = plan.SerializeToString();
            var plan2 = Utils.DeserializeFromString<TestPlan>(xml);
            Log.RemoveListener(listener);
            listener.AssertErrors(new List<string>());
                
            var step2 = (ReadOnlyListTest) plan2.Steps[0];
            Assert.AreEqual(step1.Elements.Count, step2.Elements.Count);
            bool allEqualValues = step1.Elements
                .Zip(step2.Elements, (x, y) => x.Value == y.Value)
                .All(x => x);
            Assert.IsTrue(allEqualValues);
        }
    }
 
    [TestFixture]
    public class TestStepTestFixture 
    {
        [Test]
        public void SetStepNameToNullThrows()
        {
            Assert.Throws<ArgumentNullException>(() => new DelayStep { Name = null });
        }
    }
 
    [TestFixture]
    public class BasicTestStepTests
    {
        public class FunkyArrayStep : TestStep
        {
            public object[] Array { get; set; }
            public override void Run()
            {
                throw new NotImplementedException();
            }
            public FunkyArrayStep()
            {
                Array = new object[] { new object(), null, 5.0, "Test" };
            }
        }
        [Test]
        public void TestNameFormat()
        {
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            try
            {
                DelayStep delay = new DelayStep();
                delay.DelaySecs = 1.0;
                delay.Name = "Delay of {Time Delay} and {Time Delay}";
                var result = delay.GetFormattedName();
                Assert.AreEqual(result, "Delay of 1 s and 1 s");
 
                delay.Name = "Delay of {} and {Time Delay2}";
                result = delay.GetFormattedName();
                Assert.AreEqual(result, delay.Name);
                delay.Name = "Delay of {{}} and {{Time Delay2}}";
                result = delay.GetFormattedName();
                Assert.AreEqual(result, delay.Name);
                delay.Name = "Delay of {{}} and {{Time Delay}}";
                result = delay.GetFormattedName();
                Assert.AreEqual(result, "Delay of {{}} and {1 s}");
                DialogStep diag = new DialogStep();
                diag.Name = "Timeout of {Timeout Timeout}";
                diag.Timeout = 2;
                var result2 = diag.GetFormattedName();
                Assert.AreEqual(result2, "Timeout of 2 s");
 
                SCPIRegexStep scpiRegex = new SCPIRegexStep();
                scpiRegex.RegularExpressionPattern = new Enabled<string> { Value = "asd", IsEnabled = true };
                scpiRegex.Name = "|{Set Verdict Regular Expression}|";
                var result3 = scpiRegex.GetFormattedName();
                Assert.AreEqual(result3, "|asd|");
 
                scpiRegex.Instrument = null;
                scpiRegex.Name = "|{Instrument}|";
                var result4 = scpiRegex.GetFormattedName();
                Assert.AreEqual(result4, "|Not Set|");
 
                scpiRegex.Name = "|{asdwasd}|";
                var result5 = scpiRegex.GetFormattedName();
                Assert.AreEqual(result5, scpiRegex.Name);
 
                var arrayStep = new NullArrayTest() { TestArray = new int[] { 1, 3 } };
                arrayStep.Name = "{TestArray}";
                var result6 = arrayStep.GetFormattedName();
                Assert.AreEqual(result6, "1, 3");
 
                var funkyArray = new FunkyArrayStep();
                funkyArray.Name = "{Array}";
                var result7 = funkyArray.GetFormattedName();
                Assert.AreEqual(result7.Count(x => x == ','), funkyArray.Array.Length - 1);
                Assert.IsTrue(result7.Contains(", Test"));
                
                var sweep = new SweepParameterStep();
                // Sweep {Parameters} -> 'Sweep' when parameters is empty.
                Assert.AreEqual("Sweep", sweep.GetFormattedName());
 
            }
            finally
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            }
        }
 
        [Test]
        public void TestNameFormat2()
        {
            var plan = new TestPlan();
            var repeat = new RepeatStep { Count =  10, Action = RepeatStep.RepeatStepAction.Fixed_Count};
            repeat.Name = "Repeat : {Iteration}";
            plan.ChildTestSteps.Add(repeat);
            var logStep = new LogStep();
            repeat.ChildTestSteps.Add(logStep);
            var log = new TestTraceListener();
            
            Log.AddListener(log);
            var run = plan.Execute();
            Assert.AreEqual(Verdict.NotSet, run.Verdict);
            Log.RemoveListener(log);
            var thelog = log.GetLog();
 
            for (int i = 0; i < repeat.Count; i++)
            {
                var str = string.Format("Repeat : {0} of {1}", i, repeat.Count);
                Assert.IsTrue(thelog.Contains(str));    
            }
        }
        
        [Test]
        public void TestNameFormat3()
        {
            var step = new VerdictStep() {Name = "Delay: {Resulting Verdict}", VerdictOutput =  Verdict.NotSet};
            var fmt = step.GetFormattedName();
            Assert.AreEqual("Delay: Not Set", fmt); 
        }
 
        [TestCase(Verdict.Pass)]
        [TestCase(Verdict.Fail)]
        [TestCase(Verdict.Error)]
        [TestCase(Verdict.Inconclusive)]
        [TestCase(Verdict.NotSet)]
        public void BasicVerdictTest(Verdict verdict)
        {
            var plan = new TestPlan();
            var step = new VerdictStep()
            {
                VerdictOutput = verdict
            };
            var seq = new SequenceStep();
            plan.ChildTestSteps.Add(seq);
 
            seq.ChildTestSteps.Add(step);
            var run = plan.Execute();
            Assert.AreEqual(verdict, run.Verdict);
        }
 
        [Test]
        public void UpgradeVerdictRaceCondition()
        {
            var plan = new TestPlan();
            var failStep = new VerdictStep()
            {
                VerdictOutput = Verdict.Fail
            };
            
            var parallel = new ParallelStep();
            parallel.ChildTestSteps.AddRange(new []{failStep});
            for (int i = 0; i < 20; i++)
            {
                var passStep = new VerdictStep
                {
                    VerdictOutput = Verdict.Pass
                };
                parallel.ChildTestSteps.Add(passStep);
            }
            plan.ChildTestSteps.Add(parallel);
            for (int i = 0; i < 10; i++)
            {
                var run = plan.Execute();
                Assert.AreEqual(Verdict.Fail, run.Verdict);
            }
        }
        
        
        [Test]
        public void ContinueLoop()
        {
            var repeat = new RepeatStep() {Action = RepeatStep.RepeatStepAction.Fixed_Count};
            
            var passStep = new VerdictStep {VerdictOutput = Verdict.Pass};
            var ifstep = new IfStep() {Action = IfStep.IfStepAction.ContinueLoop, TargetVerdict = Verdict.Pass};
            ifstep.InputVerdict.Property = TypeData.GetTypeData(passStep).GetMember(nameof(VerdictStep.Verdict));
            ifstep.InputVerdict.Step = passStep;
            var verdict2 = new VerdictStep() {VerdictOutput = Verdict.Fail};
            repeat.ChildTestSteps.Add(passStep);
            repeat.ChildTestSteps.Add(ifstep); // instructed to skip the last verdict step
            repeat.ChildTestSteps.Add(verdict2); // if this step runs the plan will get the verdict 'fail'.
            var plan = new TestPlan();
            plan.ChildTestSteps.Add(repeat);
            var run = plan.Execute();
            Assert.AreEqual(Verdict.Pass, run.Verdict);
        }
 
        [Test]
        public void ContinueLoop2()
        {
            var repeat = new RepeatStep()
            {
                Action = RepeatStep.RepeatStepAction.Fixed_Count,
                Count = 3
            };
            var sequence = new SequenceStep();
            repeat.ChildTestSteps.Add(sequence);
            // add some arbitrary depth to the loop.
            var seq2 = new SequenceStep();
            var seq3 = new SequenceStep();
            var seq4 = new SequenceStep();
 
            var verdict1 = new VerdictStep {VerdictOutput = Verdict.Pass};
            var ifstep = new IfStep() {Action = IfStep.IfStepAction.ContinueLoop, TargetVerdict = Verdict.Pass};
            ifstep.InputVerdict.Property = TypeData.GetTypeData(verdict1).GetMember(nameof(VerdictStep.Verdict));
            ifstep.InputVerdict.Step = verdict1;
            var failStep = new VerdictStep() {VerdictOutput = Verdict.Fail};
            sequence.ChildTestSteps.Add(verdict1);
            sequence.ChildTestSteps.Add(seq2);
            seq2.ChildTestSteps.Add(seq3);
            seq3.ChildTestSteps.Add(seq4);
            seq4.ChildTestSteps.Add(ifstep); // instructed to skip the last verdict step
            sequence.ChildTestSteps.Add(failStep); // if this step runs the plan will get the verdict 'fail'.
            var plan = new TestPlan();
            plan.ChildTestSteps.Add(repeat);
 
            var run = plan.Execute();
            Assert.AreEqual(Verdict.Pass, run.Verdict);
        } 
        
        class ThrowsOnValidationErrorStep : TestStep
        {
            public bool ValidationFails { get; set; }
 
            public ThrowsOnValidationErrorStep()
            {
                Rules.Add(() => !ValidationFails, "Validation Failed", nameof(ValidationFails));
            }
            public override void Run()
            {
                ThrowOnValidationError(false);
                UpgradeVerdict(Verdict.Pass);
            }
        }
 
        [Test]
        public void ThrowOnValidationErrorStepTest()
        {
            var plan = new TestPlan();
            var step = new ThrowsOnValidationErrorStep() {ValidationFails = true};
            plan.ChildTestSteps.Add(step);
 
            var run = plan.Execute();
            Assert.AreEqual(Verdict.Error, run.Verdict);
            step.ValidationFails = false;
            var run2 = plan.Execute();
            Assert.AreEqual(Verdict.Pass, run2.Verdict);
        }
        
        [Test]
        public void RefInstrumentDeletedTest()
        {
            using (Session.Create())
            {
                InstrumentSettings.Current.Clear();
                var inst1 = new DummyInstrument();
                var inst2 = new DummyReferencingInstrument
                {
                    Other = inst1
                };
                InstrumentSettings.Current.AddRange([inst1, inst2]);
 
                InstrumentSettings.Current.Remove(inst1);
 
                var plan = new TestPlan();
                plan.ChildTestSteps.Add(new AnnotationTest.InstrumentStep {Instrument = inst2});
                var r = plan.Execute();
                Assert.IsTrue(r.FailedToStart);
                
                var xml = new TapSerializer().SerializeToString(InstrumentSettings.Current);
                var inst3 = (new TapSerializer().DeserializeFromString(xml) as InstrumentSettings)[0] as DummyReferencingInstrument;
                Assert.IsNull(inst3.Other);
            }
        }
 
        
    }
 
    public class FormattedNameTests
    {
        public class TestNameFormat1
        {
            const string testStepName = "Enabled Check Boxes";
            private EnabledFormattedNameTest step;
 
            [Test]
            public void TestNameEnabledType()
            {
                step = new EnabledFormattedNameTest();
                AssertFormatName("{Checked Bool}", "False");
                AssertFormatName("{Checked Bool Array}", "False, True");
                AssertFormatName("{Checked Double}", "3.21");
                AssertFormatName("{Checked Double Array}", "3.33, 45.6, 88.8");
                AssertFormatName("{Checked String}", "Some comment");
                AssertFormatName("{Checked String Array}", "abc, DEF, GhI");
                AssertFormatName("{Checked String List}", "One, Two, Three");
                AssertFormatName("{Checked Instrument}", "NULL");
 
                //Uncheck a property
                step.CheckedBoolArray.IsEnabled = false;
                AssertFormatName("{Checked Bool Array}", "False, True (disabled)");
 
                //Remove all value of the properties
                step.CheckedDoubleArray.Value = new double[] { };
                AssertFormatName("{Checked Double Array}", "");
 
                step.CheckedDoubleArray.IsEnabled = false;
                AssertFormatName("{Checked Double Array}", " (disabled)");
 
                step.CheckedStringArray.Value = null;
                AssertFormatName("{Checked String Array}", "NULL");
            }
 
            private void AssertFormatName(string formatName, string expectedOutput)
            {
                step.Name = testStepName + " " + formatName;
                var result = step.GetFormattedName();
                Assert.AreEqual((testStepName + " " + expectedOutput).TrimEnd(), result);
            }
        }
 
        public class TestNameFormat2
        {
            const string testStepName = "Handle Input";
            private HandleInputStep inputStep;
 
            [Test]
            public void TestNameInputOutputType()
            {
                GenerateOutputStep outputStep = new GenerateOutputStep();
                inputStep = new HandleInputStep();
                var plan = new TestPlan();
                plan.ChildTestSteps.Add(outputStep);
                plan.ChildTestSteps.Add(inputStep);
 
                var annotation = AnnotationCollection.Annotate(inputStep);
                var inputAnnotation = annotation.GetMember(nameof(HandleInputStep.InputBoolArray));
                SetOutputProperty(inputAnnotation);
                inputAnnotation = annotation.GetMember(nameof(HandleInputStep.InputDouble));
                SetOutputProperty(inputAnnotation);
                inputAnnotation = annotation.GetMember(nameof(HandleInputStep.InputDoubleArray));
                SetOutputProperty(inputAnnotation);
                inputAnnotation = annotation.GetMember(nameof(HandleInputStep.InputString));
                SetOutputProperty(inputAnnotation);
                inputAnnotation = annotation.GetMember(nameof(HandleInputStep.InputStringArray));
                SetOutputProperty(inputAnnotation);
                inputAnnotation = annotation.GetMember(nameof(HandleInputStep.InputStringList));
                SetOutputProperty(inputAnnotation);
 
                annotation.Write(inputStep);
                
 
                AssertFormatName("{Input Bool Array}", "False, True");
                AssertFormatName("{Input Double}", "1");
                AssertFormatName("{Input Double Array}", "1, 2.2");
                AssertFormatName("{Input String}", "Something");
                AssertFormatName("{Input String Array}", "tom, dick");
                AssertFormatName("{Input String List}", "One, Two, Three");
            }
            
 
            private void SetOutputProperty(AnnotationCollection inputAnnotation)
            {
                var avail = inputAnnotation.Get<IAvailableValuesAnnotation>();
                var setVal = avail as IAvailableValuesSelectedAnnotation;
                var options = avail.AvailableValues.Cast<object>().ToArray();
 
                setVal.SelectedValue = options[1];
            }
 
            private void AssertFormatName(string formatName, string expectedOutput)
            {
                inputStep.Name = testStepName + " " + formatName;
                var result = inputStep.GetFormattedName();
                Assert.AreEqual(result, testStepName + " " + expectedOutput);
            }
        }
    }
}