Пример #1
0
        public void ScopedInputAnnotationWithSweepTestSerialized()
        {
            var plan      = new TestPlan();
            var sweepStep = new SweepParameterStep();

            plan.Steps.Add(sweepStep);
            var verdictStep = new VerdictStep();

            sweepStep.ChildTestSteps.Add(verdictStep);
            var ifStep = new IfStep();

            sweepStep.ChildTestSteps.Add(ifStep);
            var member = TypeData.GetTypeData(ifStep).GetMember(nameof(IfStep.InputVerdict));
            var parameterizedMember = member.Parameterize(sweepStep, ifStep, member.Name);

            var annotation       = AnnotationCollection.Annotate(sweepStep);
            var memberAnnotation = annotation.GetMember(nameof(sweepStep.SweepValues));
            var col = memberAnnotation.Get <ICollectionAnnotation>();

            col.AnnotatedElements = new[] { col.NewElement() };
            annotation.Write();
            annotation.Read();
            var sweepValuesMember = TypeData.GetTypeData(sweepStep).GetMember(nameof(sweepStep.SweepValues));

            sweepValuesMember.Parameterize(plan, sweepStep, "SweepValues");
            var planstr = plan.SerializeToString();
            var plan2   = Utils.DeserializeFromString <TestPlan>(planstr);
            var ext     = plan2.ExternalParameters.Get("SweepValues");

            Assert.IsNotNull(ext);
        }
Пример #2
0
        public void ScopedInputAnnotationWithSweepTest()
        {
            var sweepStep   = new SweepParameterStep();
            var verdictStep = new VerdictStep();

            sweepStep.ChildTestSteps.Add(verdictStep);
            var ifStep = new IfStep();

            sweepStep.ChildTestSteps.Add(ifStep);
            var member = TypeData.GetTypeData(ifStep).GetMember(nameof(IfStep.InputVerdict));
            var parameterizedMember = member.Parameterize(sweepStep, ifStep, member.Name);

            var annotation       = AnnotationCollection.Annotate(sweepStep);
            var memberAnnotation = annotation.GetMember(nameof(sweepStep.SweepValues));
            var col = memberAnnotation.Get <ICollectionAnnotation>();

            col.AnnotatedElements = new[] { col.NewElement() };
            annotation.Write();
            annotation.Read();
            var member2Annotation = col.AnnotatedElements.FirstOrDefault().GetMember(parameterizedMember.Name);
            var avail             = member2Annotation.Get <IAvailableValuesAnnotation>();

            Assert.IsNotNull(avail);

            // available values: None, verdict from itself, verdict from SetVerdict.

            Assert.AreEqual(3, avail.AvailableValues.Cast <object>().Count());
            var strings = avail.AvailableValues.Cast <object>().Select(x => x.ToString()).ToArray();

            Assert.IsTrue(strings.Contains($"Verdict from {ifStep.GetFormattedName()}"));
            Assert.IsTrue(strings.Contains("None"));
            Assert.IsTrue(strings.Contains($"Verdict from {verdictStep.GetFormattedName()}"));
        }
Пример #3
0
        public void ScopedInputAnnotationTest()
        {
            var seqStep     = new SequenceStep();
            var verdictStep = new VerdictStep();

            seqStep.ChildTestSteps.Add(verdictStep);
            var ifStep = new IfStep();

            seqStep.ChildTestSteps.Add(ifStep);
            var member = TypeData.GetTypeData(ifStep).GetMember(nameof(IfStep.InputVerdict));
            var parameterizedMember = member.Parameterize(seqStep, ifStep, member.Name);

            var annotation       = AnnotationCollection.Annotate(seqStep);
            var memberAnnotation = annotation.GetMember(parameterizedMember.Name);
            var avail            = memberAnnotation.Get <IAvailableValuesAnnotation>();

            Assert.IsNotNull(avail);

            // available values: None, verdict from itself, verdict from SetVerdict.

            Assert.AreEqual(3, avail.AvailableValues.Cast <object>().Count());
            var strings = avail.AvailableValues.Cast <object>().Select(x => x.ToString()).ToArray();

            Assert.IsTrue(strings.Contains($"Verdict from {ifStep.GetFormattedName()}"));
            Assert.IsTrue(strings.Contains("None"));
            Assert.IsTrue(strings.Contains($"Verdict from {verdictStep.GetFormattedName()}"));
        }
Пример #4
0
        public void ContinueLoop()
        {
            var sequence = 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 verdict2 = new VerdictStep()
            {
                VerdictOutput = Verdict.Fail
            };

            sequence.ChildTestSteps.Add(verdict1);
            sequence.ChildTestSteps.Add(ifstep);   // instructed to skip the last verdict step
            sequence.ChildTestSteps.Add(verdict2); // if this step runs the plan will get the verdict 'fail'.
            var plan = new TestPlan();

            plan.ChildTestSteps.Add(sequence);

            var run = plan.Execute();

            Assert.AreEqual(Verdict.Pass, run.Verdict);
        }
Пример #5
0
        public void RunRepeat()
        {
            // plan:
            //    repeat1 (count 3)
            //       repeat2 (count 3)
            //         setVer  - sets verdict to pass
            //         checkif - breaks repeat 2
            //         setVer2 - is never executed.
            // total number of step runs:
            // repeat1: 1
            // repeat2: 3
            // setVer: 3
            // checkif: 3
            // setVer2: 0
            // Total: 10

            var rlistener = new PlanRunCollectorListener();

            var repeat1 = new RepeatStep {
                Action = RepeatStep.RepeatStepAction.Fixed_Count, Count = 3
            };
            var repeat2 = new RepeatStep {
                Action = RepeatStep.RepeatStepAction.Fixed_Count, Count = 3
            };
            var setVer = new TestTestSteps.VerdictStep()
            {
                VerdictOutput = Verdict.Pass
            };
            var checkif = new IfStep()
            {
                Action = IfStep.IfStepAction.BreakLoop, TargetVerdict = setVer.VerdictOutput
            };
            var setVer2 = new TestTestSteps.VerdictStep(); // this one is never executed.

            repeat2.ChildTestSteps.AddRange(new ITestStep[] { setVer, checkif, setVer2 });
            repeat1.ChildTestSteps.Add(repeat2);
            var plan = new TestPlan();

            plan.ChildTestSteps.Add(repeat1);

            checkif.InputVerdict.Step     = setVer;
            checkif.InputVerdict.Property = TypeData.FromType(typeof(TestStep)).GetMember(nameof(TestStep.Verdict));



            var planrun = plan.Execute(new[] { rlistener });

            Assert.AreEqual(10, rlistener.StepRuns.Count);
            Assert.AreEqual(5, planrun.StepsWithPrePlanRun.Count);
        }
        public void SetValuesTest()
        {
            var delayStep1 = new DelayStep();
            var delayStep2 = new DelayStep();
            var logStep    = new LogStep();
            var logStep2   = new LogStep();
            var fileStep   = new MacroFilePathTestStep();
            var fileStep2  = new MacroFilePathTestStep();
            var ifstep     = new IfStep();

            fileStep.PathToThing.Text = "<TESTPLANDIR>\\asdasd";
            TestPlan plan = new TestPlan();

            plan.ChildTestSteps.Add(delayStep1);
            plan.ChildTestSteps.Add(delayStep2);
            plan.ChildTestSteps.Add(logStep);
            plan.ChildTestSteps.Add(logStep2);
            plan.ChildTestSteps.Add(fileStep);
            plan.ChildTestSteps.Add(fileStep2);
            plan.ChildTestSteps.Add(ifstep);
            ifstep.InputVerdict.Step     = delayStep2;
            ifstep.InputVerdict.Property = TypeData.GetTypeData(delayStep1).GetMember("Verdict");
            var delayInfo    = TypeData.GetTypeData(delayStep1);
            var logInfo      = TypeData.GetTypeData(logStep);
            var fileStepInfo = TypeData.GetTypeData(fileStep);

            plan.ExternalParameters.Add(delayStep1, delayInfo.GetMember("DelaySecs"));
            plan.ExternalParameters.Add(delayStep2, delayInfo.GetMember("DelaySecs"), "Time Delay");
            plan.ExternalParameters.Add(logStep, logInfo.GetMember("Severity"), Name: "Severity");
            plan.ExternalParameters.Add(logStep2, logInfo.GetMember("Severity"), Name: "Severity");
            plan.ExternalParameters.Add(fileStep, fileStepInfo.GetMember("PathToThing"), Name: "Path1");
            plan.ExternalParameters.Add(fileStep2, fileStepInfo.GetMember("PathToThing"), Name: "Path1");
            plan.ExternalParameters.Add(ifstep, TypeData.GetTypeData(ifstep).GetMember(nameof(IfStep.InputVerdict)), Name: "InputVerdict");
            for (int j = 0; j < 5; j++)
            {
                for (double x = 0.01; x < 10; x += 3.14)
                {
                    plan.ExternalParameters.Get("Time Delay").Value = x;
                    Assert.AreEqual(x, delayStep1.DelaySecs);
                    Assert.AreEqual(x, delayStep2.DelaySecs);
                }

                plan.ExternalParameters.Get("Severity").Value = LogSeverity.Error;
                Assert.AreEqual(LogSeverity.Error, logStep.Severity);
                Assert.AreEqual(LogSeverity.Error, logStep2.Severity);

                plan.ExternalParameters.Get("Path1").Value = plan.ExternalParameters.Get("Path1").Value;

                string planstr = null;
                using (var memstream = new MemoryStream())
                {
                    plan.Save(memstream);
                    planstr = Encoding.UTF8.GetString(memstream.ToArray());
                }
                Assert.IsTrue(planstr.Contains(@"Parameter=""Time Delay"""));
                Assert.IsTrue(planstr.Contains(@"Parameter=""Severity"""));
                Assert.IsTrue(planstr.Contains(@"Parameter=""Path1"""));

                using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(planstr)))
                    plan = TestPlan.Load(memstream, planstr);

                delayStep1 = (DelayStep)plan.ChildTestSteps[0];
                delayStep2 = (DelayStep)plan.ChildTestSteps[1];
                logStep    = (LogStep)plan.ChildTestSteps[2];
                logStep2   = (LogStep)plan.ChildTestSteps[3];
                fileStep   = (MacroFilePathTestStep)plan.ChildTestSteps[4];
                fileStep2  = (MacroFilePathTestStep)plan.ChildTestSteps[5];
                ifstep     = (IfStep)plan.ChildTestSteps[6];
                Assert.IsTrue(fileStep2.PathToThing.Context == fileStep2);
                Assert.AreEqual(fileStep2.PathToThing.Text, fileStep.PathToThing.Text);
                Assert.AreEqual(delayStep2, ifstep.InputVerdict.Step);
            }
        }