예제 #1
0
        public void TestMethodResourceSettingNullReference()
        {
            TestTraceListener tapTraceListener = new TestTraceListener();
            DummyDut          device           = new DummyDut();

            try
            {
                Log.AddListener(tapTraceListener);
                DutSettings.Current.Add(device);

                // this works
                var testPlan = new TestPlan();
                var step     = new DummyInstrumentAndDutStep()
                {
                    Device = device, Instrument = null
                };
                testPlan.ChildTestSteps.Add(step);
                var run = testPlan.Execute();

                Assert.AreEqual(Verdict.Error, run.Verdict);
                tapTraceListener.ExpectWarnings("TestPlan aborted.");
                tapTraceListener.ExpectErrors(
                    $"Resource setting {nameof(DummyInstrumentAndDutStep.Instrument)} not set on step {nameof(DummyInstrumentAndDutStep)}. Please configure or disable step.");
            }
            finally
            {
                tapTraceListener.Flush();
                Log.RemoveListener(tapTraceListener);
                DutSettings.Current.Remove(device);
            }
        }
        public void SerializeDeserializeWithDutExternalParameter()
        {
            var plan = new TestPlan();
            var step = new TestPlanTest.DutStep();
            var dut1 = new DummyDut {
                Name = "DUT1"
            };
            var dut2 = new DummyDut {
                Name = "DUT2"
            };

            DutSettings.Current.AddRange(new [] { dut1, dut2 });
            try
            {
                step.Dut = dut1;
                plan.ChildTestSteps.Add(step);
                plan.ExternalParameters.Add(step,
                                            TypeData.GetTypeData(step).GetMember(nameof(TestPlanTest.DutStep.Dut)), "dut");

                using (var memstr = new MemoryStream())
                {
                    plan.Save(memstr);

                    var serializer = new TapSerializer();
                    var ext        = serializer.GetSerializer <ExternalParameterSerializer>();
                    ext.PreloadedValues["dut"] = "DUT2";

                    memstr.Seek(0, SeekOrigin.Begin);
                    plan = (TestPlan)serializer.Deserialize(memstr);
                }

                step = (TestPlanTest.DutStep)plan.ChildTestSteps[0];
                Assert.AreEqual(step.Dut, dut2);
            }
            finally
            {
                DutSettings.Current.Remove(dut1);
                DutSettings.Current.Remove(dut2);
            }
        }