Beispiel #1
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);
        }
Beispiel #2
0
        public void CyclicScopeTest()
        {
            var seq   = new SequenceStep();
            var delay = new DelayStep()
            {
                DelaySecs = 1.5
            };

            seq.ChildTestSteps.Add(delay);

            var member = TypeData.GetTypeData(delay).GetMember("Time Delay");

            member.Parameterize(seq, delay, "something");

            var value  = AnnotationCollection.Annotate(delay).GetMember("DelaySecs").Get <IObjectValueAnnotation>();
            var value2 = AnnotationCollection.Annotate(seq).GetMember("something").Get <IObjectValueAnnotation>();

            try
            {
                member.Parameterize(delay, seq, "something");
                Assert.Fail("Parameterize should have thrown an exception.");
            }
            catch (ArgumentException)
            {
            }

            // Stack overflow...
            value  = AnnotationCollection.Annotate(delay).GetMember("DelaySecs").Get <IObjectValueAnnotation>();
            value2 = AnnotationCollection.Annotate(seq).GetMember("something").Get <IObjectValueAnnotation>();
            Assert.IsNotNull(value);
            Assert.IsNotNull(value2);
        }
        public static BitArray ProcessStep(SequenceStep step, Microprogram microprogram)
        {
            if (step.Type == SequenceStepType.MacroReference)
            {
                throw new MicroassemblerWriteException($"Unexpanded macro found on line {step.Line}");
            }
            SequenceAssertion assertion = step as SequenceAssertion;
            BitArray          array     = new BitArray((int)microprogram.ControlWordWidth);

            array[microprogram.BankSelectorMask] = (ulong)assertion.Bank;
            int bankOffset = microprogram.BankSelectorMask.Length;

            foreach (KeyValuePair <ControlWordLabel, Object> signal in assertion.AssertedSignals)
            {
                if (!(signal.Value is long))
                {
                    throw new MicroassemblerWriteException($"Invalid/unresolved symbol {signal.Value} in assertion on line {assertion.Line}");
                }
                long value = (long)signal.Value;
                if (value > (long)signal.Key.Mask.MaxValue)
                {
                    Console.WriteLine($"Warning: Asserted signal {signal.Key.Name} on line {assertion.Line} has a maximum value of {signal.Key.Mask.MaxValue} (actual assertion of {value} will be truncated)");
                }
                array[signal.Key.Mask, bankOffset] = (ulong)value;
            }
            return(array);
        }
        protected override ISequenceStep CreateSequenceStep()
        {
            SequenceStep step = new SequenceStep
            {
                StepType = SequenceStepType.TryFinallyBlock,
                SubSteps = new SequenceStepCollection()
            };
            SequenceStep tryBlock = new SequenceStep
            {
                Name     = "Try",
                Parent   = step,
                SubSteps = new SequenceStepCollection()
            };

            step.SubSteps.Add(tryBlock);

            SequenceStep finallyBlock = new SequenceStep
            {
                Name     = "Finally",
                Parent   = step,
                SubSteps = new SequenceStepCollection()
            };

            step.SubSteps.Add(finallyBlock);
            return(step);
        }
Beispiel #5
0
        public void BreakAbortStepRunNull()
        {
            TestPlan     testPlan = new TestPlan();
            SequenceStep step1    = new SequenceStep();
            SequenceStep step2    = new SequenceStep();
            SequenceStep step3    = new SequenceStep();

            testPlan.Steps.Add(step1);
            testPlan.Steps.Add(step2);
            testPlan.Steps.Add(step3);

            TapThread.WithNewContext(() =>
            {
                var planThread         = TapThread.Current;
                testPlan.BreakOffered += (s, e) => planThread.Abort();
                testPlan.Execute();
                Assert.IsTrue(TapThread.Current.AbortToken.IsCancellationRequested);
            });
            Assert.IsFalse(TapThread.Current.AbortToken.IsCancellationRequested);

            foreach (var step in testPlan.Steps)
            {
                Assert.IsNull(step.StepRun);
            }
        }
Beispiel #6
0
        public void IsMatchTest()
        {
            var parameter = InitMoqParameter();

            var sut1 = new SequenceStep()
            {
                ValidParameterNames = _names
            };

            Assert.False(sut1.IsMatch(parameter));

            var sut2 = new SequenceStep()
            {
                ValidParameterNames = _names2
            };

            Assert.True(sut2.IsMatch(parameter));

            var sut3 = new SequenceStep()
            {
                ParameterName = _name
            };

            Assert.False(sut3.IsMatch(parameter));

            var sut4 = new SequenceStep()
            {
                ParameterName = _name2
            };

            Assert.True(sut4.IsMatch(parameter));
        }
Beispiel #7
0
        public void RunHierarchical2()
        {
            TestPlan testplan = new TestPlan();

            var grandParent = new SequenceStep();

            testplan.Steps.Add(grandParent);

            var parent = new SequenceStep();

            grandParent.ChildTestSteps.Add(parent);

            var child1 = new WithEvents();

            parent.ChildTestSteps.Add(child1);

            var child2 = new WithEvents();

            parent.ChildTestSteps.Add(child2);

            testplan.BreakOffered += _testplan_TestStepPaused;

            _pausedDetectedCount   = 0;
            _startingDetectedCount = 0;

            testplan.Execute();

            // Since only two of the steps are with events, we get
            // _starting = total
            // _pausedCount = 2;
            var test = TotalEnabledStepsInTestPlan(testplan);

            Assert.IsTrue(_startingDetectedCount == TotalEnabledStepsInTestPlan(testplan));
            Assert.IsTrue(_pausedDetectedCount == 2);
        }
Beispiel #8
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()}"));
        }
Beispiel #9
0
        public void ScopeStepTest()
        {
            var diag = new DialogStep()
            {
                UseTimeout = true
            };
            var    diag2         = new DialogStep();
            var    scope         = new SequenceStep();
            string parameterName = "Scope\"" + DisplayAttribute.GroupSeparator + "Title"; // name intentionally weird to mess with the serializer.

            scope.ChildTestSteps.Add(diag);
            scope.ChildTestSteps.Add(diag2);
            var member = TypeData.GetTypeData(diag).GetMember("Title");

            member.Parameterize(scope, diag, parameterName);
            member.Parameterize(scope, diag2, parameterName);
            TypeData.GetTypeData(diag).GetMember("Timeout").Parameterize(scope, diag, "Group\\The Timeout");

            var annotation  = AnnotationCollection.Annotate(scope);
            var titleMember = annotation.GetMember(parameterName);

            titleMember.Get <IStringValueAnnotation>().Value = "New title";
            annotation.Write();
            Assert.AreEqual("New title", diag.Title);
            Assert.AreEqual("New title", diag2.Title);

            var timeoutMember = annotation.GetMember("Group\\The Timeout");

            Assert.IsFalse(timeoutMember.Get <IAccessAnnotation>().IsReadOnly);
            Assert.AreEqual("Group", TypeData.GetTypeData(scope).GetMember("Group\\The Timeout").GetDisplayAttribute().Group[0]);

            var plan = new TestPlan();

            plan.Steps.Add(scope);
            var str          = new TapSerializer().SerializeToString(plan);
            var plan2        = (TestPlan) new TapSerializer().DeserializeFromString(str);
            var scope2       = plan2.Steps[0];
            var annotation2  = AnnotationCollection.Annotate(scope2);
            var titleMember2 = annotation2.GetMember(parameterName);

            Assert.IsNotNull(titleMember2);
            titleMember2.Get <IStringValueAnnotation>().Value = "New Title 2";
            annotation2.Write();
            foreach (var step in scope2.ChildTestSteps.Cast <DialogStep>())
            {
                Assert.AreEqual(step.Title, "New Title 2");
            }

            var forwardedMember = (ParameterMemberData)TypeData.GetTypeData(scope2).GetMember(parameterName);

            Assert.IsNotNull(forwardedMember);

            member.Unparameterize(forwardedMember, scope2.ChildTestSteps[0]);
            Assert.IsNotNull(TypeData.GetTypeData(scope2).GetMember(parameterName));
            member.Unparameterize(forwardedMember, scope2.ChildTestSteps[1]);
            Assert.IsNull(TypeData.GetTypeData(scope2).GetMember(parameterName)); // last 'Title' removed.
        }
Beispiel #10
0
        public void HasMultipleValidParameterNamesTest()
        {
            var sut = new SequenceStep()
            {
                ValidParameterNames = _names
            };

            Assert.True(sut.HasMultipleValidParameterNames());
        }
        protected override ISequenceStep CreateSequenceStep()
        {
            SequenceStep step = new SequenceStep()
            {
                StepType = SequenceStepType.ConditionStatement,
                SubSteps = new SequenceStepCollection()
            };

            return(step);
        }
Beispiel #12
0
        protected override ISequenceStep CreateSequenceStep()
        {
            SequenceStep step = new SequenceStep()
            {
                StepType = SequenceStepType.ConditionBlock,
                SubSteps = new SequenceStepCollection(),
                Name     = "ConditionBlock"
            };
            SequenceStep conditionStatement = new SequenceStep()
            {
                StepType = SequenceStepType.ConditionStatement,
                SubSteps = new SequenceStepCollection()
            };

            step.SubSteps.Add(conditionStatement);
            return(step);
        }
        protected override ISequenceStep CreateSequenceStep()
        {
            SequenceStep step = new SequenceStep
            {
                StepType    = SequenceStepType.ConditionLoop,
                SubSteps    = new SequenceStepCollection(),
                Name        = "ConditionLoop",
                LoopCounter = new LoopCounter()
                {
                    CounterEnabled  = true,
                    CounterVariable = string.Empty,
                    MaxValue        = 0,
                    Name            = "ConditionLoop"
                }
            };

            return(step);
        }
Beispiel #14
0
        public void AutoRemoveParameters()
        {
            var plan = new TestPlan();
            var step = new DelayStep();

            plan.ChildTestSteps.Add(step);
            var member    = TypeData.GetTypeData(step).GetMember(nameof(step.DelaySecs));
            var parameter = member.Parameterize(plan, step, "delay");

            Assert.IsNotNull(TypeData.GetTypeData(plan).GetMember(parameter.Name));
            plan.ChildTestSteps.Remove(step);
            Assert.IsNull(TypeData.GetTypeData(plan).GetMember(parameter.Name));

            var seq = new SequenceStep();

            plan.ChildTestSteps.Add(seq);
            seq.ChildTestSteps.Add(step);
            parameter = member.Parameterize(seq, step, "delay");
            Assert.IsNotNull(TypeData.GetTypeData(seq).GetMember(parameter.Name));
            seq.ChildTestSteps.Remove(step);
            Assert.IsNull(TypeData.GetTypeData(seq).GetMember(parameter.Name));

            seq.ChildTestSteps.Add(step);
            parameter = member.Parameterize(seq, step, "delay");
            var member2 = TypeData.GetTypeData(seq).GetMember(parameter.Name);

            Assert.IsNotNull(member2);
            Assert.AreEqual(member2, parameter);
            var parameter2 = member2.Parameterize(plan, seq, "delay");

            Assert.IsNotNull(TypeData.GetTypeData(plan).GetMember(parameter2.Name));
            plan.ChildTestSteps.Remove(seq);
            Assert.IsNull(TypeData.GetTypeData(plan).GetMember(parameter2.Name));
            Assert.IsNotNull(TypeData.GetTypeData(seq).GetMember(parameter.Name));

            plan.ChildTestSteps.Add(seq);
            parameter2 = member2.Parameterize(plan, seq, "delay");
            Assert.IsNotNull(TypeData.GetTypeData(plan).GetMember(parameter2.Name));
            Assert.IsNotNull(TypeData.GetTypeData(seq).GetMember(parameter.Name));
            seq.ChildTestSteps.Remove(step);
            Assert.IsNull(TypeData.GetTypeData(plan).GetMember(parameter2.Name));
            Assert.IsNull(TypeData.GetTypeData(seq).GetMember(parameter.Name));
        }
Beispiel #15
0
        public void GeneralPerformanceTest(int count)
        {
            void buildSequence(ITestStepParent parent, int levels)
            {
                parent.ChildTestSteps.Add(new ManySettingsStep());
                parent.ChildTestSteps.Add(new DeferringResultStep());
                parent.ChildTestSteps.Add(new VirtualPropertiesStep());
                for (int i = 0; i < levels; i++)
                {
                    var seq = new SequenceStep();
                    parent.ChildTestSteps.Add(seq);
                    buildSequence(seq, levels / 2);
                }
            }

            var plan = new TestPlan {
                CacheXml = true
            };

            buildSequence(plan, 6);
            var total = Utils.FlattenHeirarchy(plan.ChildTestSteps, x => x.ChildTestSteps).Count();

            plan.Execute(); // warm up

            TimeSpan timeSpent = TimeSpan.Zero;

            for (int i = 0; i < count; i++)
            {
                using (TypeData.WithTypeDataCache())
                {
                    timeSpent += plan.Execute().Duration;
                }
            }


            var proc    = Process.GetCurrentProcess();
            var time    = proc.TotalProcessorTime;
            var time2   = DateTime.Now - proc.StartTime;
            var spentMs = timeSpent.TotalMilliseconds / count;

            Console.WriteLine("Time spent per plan: {0}ms", spentMs);
            Console.WriteLine("Time spent per step: {0}ms", spentMs / plan.Steps.Count);
        }
Beispiel #16
0
    private void SaveActionOriginalState(SequenceStep step, SequenceAction action, RectTransform xform)
    {
        switch (action.Type)
        {
        case ActionType.Move:
        case ActionType.Fly:
        case ActionType.Shake:
            action.OrigVector = xform.anchoredPosition3D;
            break;

        case ActionType.RotateZ:
            action.OrigVector = xform.rotation.eulerAngles;
            break;

        case ActionType.Scale:
            action.OrigVector = xform.localScale;
            break;

        case ActionType.Fade:
        {
            var cg      = step.Target.GetComponent <CanvasGroup>();
            var graphic = step.Target.GetComponent <Graphic>();
            if (cg != null)
            {
                action.OrigFloat = cg.alpha;
            }
            else if (graphic != null)
            {
                action.OrigFloat = graphic.color.a;
            }
            break;
        }

        case ActionType.Hide:
        case ActionType.Show:
            action.OrigFloat = step.Target.activeSelf ? 1 : 0;
            break;

        default:
            break;
        }
    }
Beispiel #17
0
        public void ListOfStringAnnotation2()
        {
            var obj          = new ClassWithListOfString();
            var targetObject = new SequenceStep();
            var obj2         = new ClassWithListOfString();

            targetObject.ChildTestSteps.Add(obj);
            targetObject.ChildTestSteps.Add(obj2);
            obj2.List.Add("C");
            var selectedMember = TypeData.GetTypeData(obj).GetMember(nameof(ClassWithListOfString.Selected));

            selectedMember.Parameterize(targetObject, obj, selectedMember.Name);
            selectedMember.Parameterize(targetObject, obj2, selectedMember.Name);

            // TODO:
            var b     = AnnotationCollection.Annotate(targetObject);
            var avail = b.GetMember(selectedMember.Name).Get <IAvailableValuesAnnotation>();

            Assert.AreEqual(2, avail.AvailableValues.Cast <object>().Count());
        }
Beispiel #18
0
        public void BreakJumpToStepRunNull()
        {
            testplanJumpToStep = new TestPlan();
            SequenceStep step1 = new SequenceStep();
            SequenceStep step2 = new SequenceStep();
            SequenceStep step3 = new SequenceStep();

            testplanJumpToStep.Steps.Add(step1);
            testplanJumpToStep.Steps.Add(step2);
            testplanJumpToStep.Steps.Add(step3);

            testplanJumpToStep.BreakOffered += Testplan_BreakOffered;

            firstBreak = true;
            testplanJumpToStep.Execute();

            foreach (var step in testplanJumpToStep.Steps)
            {
                Assert.IsNull(step.StepRun);
            }
        }
Beispiel #19
0
    private void ResetActionToInitialState(SequenceStep step, SequenceAction action)
    {
        var xform     = step.Target.GetComponent <Transform>();
        var rectxform = step.Target.GetComponent <RectTransform>();

        switch (action.Type)
        {
        case ActionType.Move:
        case ActionType.Fly:
        case ActionType.Shake:
            rectxform.anchoredPosition3D = action.OrigVector;
            break;

        case ActionType.RotateZ:
            xform.rotation = Quaternion.Euler(action.OrigVector);
            break;

        case ActionType.Scale:
            xform.localScale = action.OrigVector;
            break;

        case ActionType.Fade:
            var cg      = step.Target.GetComponent <CanvasGroup>();
            var graphic = step.Target.GetComponent <Graphic>();
            if (cg != null)
            {
                cg.alpha = action.OrigFloat;
            }
            else if (graphic != null)
            {
                graphic.color = graphic.color.WithA(action.OrigFloat);
            }
            break;

        case ActionType.Show:
        case ActionType.Hide:
            step.Target.SetActive(action.OrigFloat > 0f);
            break;
        }
    }
Beispiel #20
0
        public void MultiLevelScopeSerialization()
        {
            var plan  = new TestPlan();
            var seq1  = new SequenceStep();
            var seq2  = new SequenceStep();
            var delay = new DelayStep();

            plan.ChildTestSteps.Add(seq1);
            seq1.ChildTestSteps.Add(seq2);
            seq2.ChildTestSteps.Add(delay);

            var member1 = TypeData.GetTypeData(delay).GetMember(nameof(DelayStep.DelaySecs))
                          .Parameterize(seq2, delay, "delay");

            member1.Parameterize(seq1, seq2, "delay");
            var str = new TapSerializer().SerializeToString(plan);

            var plan2   = (TestPlan) new TapSerializer().DeserializeFromString(str);
            var member2 = TypeData.GetTypeData(plan2.ChildTestSteps[0]).GetMember(member1.Name);
            var val     = member2.GetValue(plan2.ChildTestSteps[0]);

            Assert.AreEqual(delay.DelaySecs, val);
        }
        public void SaveAndLoadExternalScopeParameters()
        {
            var plan     = new TestPlan();
            var sequence = new SequenceStep();
            var delay    = new DelayStep();

            plan.Steps.Add(sequence);
            sequence.ChildTestSteps.Add(delay);
            var newmember = TypeData.GetTypeData(delay).GetMember(nameof(DelayStep.DelaySecs))
                            .Parameterize(sequence, delay, nameof(DelayStep.DelaySecs));
            var fwd = newmember.Parameterize(plan, sequence, nameof(DelayStep.DelaySecs));

            Assert.AreEqual(1, plan.ExternalParameters.Entries.Count);
            TestPlan newplan;

            using (var mem = new MemoryStream())
            {
                plan.Save(mem);
                mem.Seek(0, SeekOrigin.Begin);
                newplan = TestPlan.Load(mem, "Test.TapPlan");
            }
            Assert.AreEqual(1, newplan.ExternalParameters.Entries.Count);
        }
Beispiel #22
0
        public void MenuAnnotationTest()
        {
            var currentUserInterface = UserInput.Interface;
            var menuInterface        = new MenuTestUserInterface();

            UserInput.SetInterface(menuInterface);
            try
            {
                var plan         = new TestPlan();
                var sequenceRoot = new SequenceStep();
                var sequence     = new SequenceStep();
                var step         = new DelayStep();
                plan.Steps.Add(sequenceRoot);
                sequenceRoot.ChildTestSteps.Add(sequence);
                var step2 = new DelayStep();
                sequenceRoot.ChildTestSteps.Add(step);
                sequence.ChildTestSteps.Add(step2);

                { // basic functionalities test
                    var member = AnnotationCollection.Annotate(step2).GetMember(nameof(DelayStep.DelaySecs));
                    var menu   = member.Get <MenuAnnotation>();

                    var items = menu.MenuItems;

                    var icons = items.ToLookup(item =>
                                               item.Get <IIconAnnotation>()?.IconName ?? "");
                    var parameterizeOnTestPlan = icons[IconNames.ParameterizeOnTestPlan].First();
                    Assert.IsNotNull(parameterizeOnTestPlan);

                    // invoking this method should
                    var method = parameterizeOnTestPlan.Get <IMethodAnnotation>();
                    method.Invoke();
                    Assert.IsNotNull(plan.ExternalParameters.Get("Parameters \\ Time Delay"));

                    var unparameterize = icons[IconNames.Unparameterize].First();
                    unparameterize.Get <IMethodAnnotation>().Invoke();
                    Assert.IsNull(plan.ExternalParameters.Get("Parameters \\ Time Delay"));

                    var createOnParent = icons[IconNames.ParameterizeOnParent].First();
                    Assert.IsNotNull(createOnParent);
                    createOnParent.Get <IMethodAnnotation>().Invoke();
                    Assert.IsNotNull(TypeData.GetTypeData(sequence).GetMember("Parameters \\ Time Delay"));

                    unparameterize.Get <IMethodAnnotation>().Invoke();
                    Assert.IsNull(TypeData.GetTypeData(sequence).GetMember("Parameters \\ Time Delay"));

                    menuInterface.SelectName = "A";

                    var parameterize = icons[IconNames.Parameterize].First();
                    parameterize.Get <IMethodAnnotation>().Invoke();
                    Assert.IsTrue(menuInterface.WasInvoked);

                    var newParameter = TypeData.GetTypeData(sequence).GetMember("A");
                    Assert.IsNotNull(newParameter);
                    unparameterize.Get <IMethodAnnotation>().Invoke();
                    Assert.IsNull(TypeData.GetTypeData(sequence).GetMember("A"));
                    parameterize.Get <IMethodAnnotation>().Invoke();

                    var editParameter = AnnotationCollection.Annotate(sequence).GetMember("A").Get <MenuAnnotation>()
                                        .MenuItems
                                        .FirstOrDefault(x => x.Get <IconAnnotationAttribute>()?.IconName == IconNames.EditParameter);

                    menuInterface.SelectName = "B";
                    editParameter.Get <IMethodAnnotation>().Invoke();

                    Assert.IsNull(TypeData.GetTypeData(sequence).GetMember("A"));
                    Assert.IsNotNull(TypeData.GetTypeData(sequence).GetMember("B"));
                }

                { // test multi-select
                    var memberMulti = AnnotationCollection.Annotate(new[] { step, step2 })
                                      .GetMember(nameof(DelayStep.DelaySecs));
                    var menuMulti = memberMulti.Get <MenuAnnotation>();
                    Assert.IsNotNull(menuMulti);

                    var icons2 = menuMulti.MenuItems.ToLookup(x => x.Get <IIconAnnotation>()?.IconName ?? "");
                    var parmeterizeOnTestPlanMulti = icons2[IconNames.ParameterizeOnTestPlan].First();
                    parmeterizeOnTestPlanMulti.Get <IMethodAnnotation>().Invoke();
                    Assert.AreEqual(2, plan.ExternalParameters.Entries.FirstOrDefault().Properties.Count());

                    var unparmeterizePlanMulti = icons2[IconNames.Unparameterize].First();
                    unparmeterizePlanMulti.Get <IMethodAnnotation>().Invoke();
                    Assert.IsNull(plan.ExternalParameters.Entries.FirstOrDefault());

                    var parmeterizeOnParentMulti = icons2[IconNames.ParameterizeOnParent].First();
                    Assert.IsFalse(parmeterizeOnParentMulti.Get <IEnabledAnnotation>().IsEnabled);
                }

                { // Test Plan Enabled Items Locked
                    var annotation = AnnotationCollection.Annotate(step);
                    var menu       = annotation.GetMember(nameof(DelayStep.DelaySecs))
                                     .Get <MenuAnnotation>();
                    var icons = menu.MenuItems.ToLookup(x => x.Get <IIconAnnotation>()?.IconName ?? "");
                    icons[IconNames.ParameterizeOnTestPlan].First().Get <IMethodAnnotation>().Invoke();
                    annotation.Read();

                    Assert.IsFalse(icons[IconNames.ParameterizeOnTestPlan].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.Parameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.ParameterizeOnParent].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsTrue(icons[IconNames.Unparameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.EditParameter].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.RemoveParameter].First().Get <IEnabledAnnotation>().IsEnabled);

                    var planAnnotation = AnnotationCollection.Annotate(plan);
                    var planMenu       = planAnnotation.GetMember("Parameters \\ Time Delay")
                                         .Get <MenuAnnotation>();
                    var planIcons = planMenu.MenuItems.ToLookup(x => x.Get <IIconAnnotation>()?.IconName ?? "");
                    Assert.IsFalse(planIcons[IconNames.ParameterizeOnTestPlan].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.Parameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsTrue(planIcons[IconNames.EditParameter].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.ParameterizeOnParent].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.Unparameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsTrue(planIcons[IconNames.RemoveParameter].First().Get <IEnabledAnnotation>().IsEnabled);

                    plan.Locked = true;
                    menu        = AnnotationCollection.Annotate(step).GetMember(nameof(DelayStep.DelaySecs))
                                  .Get <MenuAnnotation>();
                    icons = menu.MenuItems.ToLookup(x => x.Get <IIconAnnotation>()?.IconName ?? "");
                    Assert.IsFalse(icons[IconNames.ParameterizeOnTestPlan].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.Parameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.ParameterizeOnParent].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.Unparameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(icons[IconNames.EditParameter].First().Get <IEnabledAnnotation>().IsEnabled);
                    planAnnotation = AnnotationCollection.Annotate(plan);
                    planMenu       = planAnnotation.GetMember("Parameters \\ Time Delay")
                                     .Get <MenuAnnotation>();
                    planIcons = planMenu.MenuItems.ToLookup(x => x.Get <IIconAnnotation>()?.IconName ?? "");
                    Assert.IsFalse(planIcons[IconNames.ParameterizeOnTestPlan].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.Parameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.EditParameter].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.ParameterizeOnParent].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.Unparameterize].First().Get <IEnabledAnnotation>().IsEnabled);
                    Assert.IsFalse(planIcons[IconNames.RemoveParameter].First().Get <IEnabledAnnotation>().IsEnabled);
                }
                {
                    // remove parameter
                    plan.Locked = false;
                    var planAnnotation = AnnotationCollection.Annotate(plan);
                    var menu           = planAnnotation.GetMember("Parameters \\ Time Delay").Get <MenuAnnotation>();
                    var removeItem     = menu.MenuItems.First(x => x.Get <IconAnnotationAttribute>()?.IconName == IconNames.RemoveParameter);
                    removeItem.Get <IMethodAnnotation>().Invoke();
                    planAnnotation = AnnotationCollection.Annotate(plan);
                    // after removing there is not Time Delay parameter..
                    Assert.IsNull(planAnnotation.GetMember("Parameters \\ Time Delay"));
                }
                {// Break Conditions
                    var member = AnnotationCollection.Annotate(step2).GetMember("BreakConditions");
                    Assert.NotNull(member);
                    var menu = member.Get <MenuAnnotation>();
                    Assert.NotNull(menu);
                    var parameterize = menu.MenuItems.FirstOrDefault(x =>
                                                                     x.Get <IIconAnnotation>()?.IconName == IconNames.ParameterizeOnTestPlan);
                    Assert.IsTrue(parameterize.Get <IAccessAnnotation>().IsVisible);

                    Assert.AreEqual(1, TypeData.GetTypeData(plan).GetMembers().Count(x => x.Name.Contains("BreakConditions") || x.Name.Contains("BreakConditions")));
                    parameterize.Get <IMethodAnnotation>().Invoke();
                    Assert.AreEqual(2, TypeData.GetTypeData(plan).GetMembers().Count(x => x.Name.Contains("Break Conditions") || x.Name.Contains("BreakConditions")));
                }
            }
            finally
            {
                UserInput.SetInterface(currentUserInterface as IUserInputInterface);
            }
        }
Beispiel #23
0
        /// <summary>
        /// Fill the various structures with step data from the BPEL XML file
        /// </summary>
        /// <param name="workflowContext"> workflowcontextModel class</param>
        /// <param name="startElement">Integer value representing the starting element in the nodeList.</param>
        /// <param name="nodeList">XmlNodeList containing the BPEL data from the BPEL file</param>
        /// <param name="cancelEventHandlerName">cancelEventHandlerName</param>
        private void FillStepList(WorkflowContext workflowContext, List <IWorkflowStep> workflowStepList, int startElement, XmlNodeList nodeList, ref string cancelEventHandlerName)
        {
            for (int i = startElement; i < nodeList.Count; i++)
            {
                var currentStep = nodeList[i];

                if (!string.IsNullOrEmpty(currentStep.Prefix))
                {
                    currentStep.Prefix = "bpel";
                }

                if (currentStep is XmlComment)
                {
                    continue;
                }

                if (currentStep.LocalName == "invoke")
                {
                    var workflowStep = new InvokeStep(currentStep.Attributes);
                    workflowStepList.Add(workflowStep);
                }
                else if (currentStep.LocalName == "sequence")
                {
                    var sequenceStep = new SequenceStep(currentStep.Attributes);
                    workflowStepList.Add(sequenceStep);
                    FillStepList(workflowContext, sequenceStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "scope")
                {
                    // can't get tool to produce invoke without having it enclosed in a scope.
                    // just ignore scope for now but get the internals as if at the same level.
                    FillStepList(workflowContext, workflowStepList, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "receive")
                {
                    var receiveStep = new ReceiveStep(currentStep.Attributes);
                    workflowStepList.Add(receiveStep);
                    string messageName = String.Empty;
                    string timesetTime = String.Empty;
                    if (currentStep.Attributes != null)
                    {
                        foreach (XmlAttribute attrib in currentStep.Attributes)
                        {
                            if (attrib.LocalName == "timeout")
                            {
                                timesetTime = attrib.Value;
                            }
                            if (attrib.LocalName == "variable")
                            {
                                messageName = attrib.Value;
                            }
                        }
                    }
                    if (!timeoutParameters.ContainsKey(messageName))
                    {
                        timeoutParameters.Add(messageName, timesetTime);
                    }
                }
                else if (currentStep.LocalName == "switch")
                {
                    var switchStep = new SwitchStep(currentStep.Attributes);
                    workflowStepList.Add(switchStep);

                    // Fill case/otherwise steps inside of switch step
                    FillStepList(workflowContext, switchStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "case")
                {
                    var caseStep = new CaseStep(currentStep.Attributes, false);
                    workflowStepList.Add(caseStep);
                    FillStepList(workflowContext, caseStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "otherwise")
                {
                    var caseStep = new CaseStep(currentStep.Attributes, true);
                    workflowStepList.Add(caseStep);
                    FillStepList(workflowContext, caseStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "while")
                {
                    var whileStep = new WhileStep(currentStep.Attributes);
                    workflowStepList.Add(whileStep);
                    FillStepList(workflowContext, whileStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "pick")
                {
                    var pickStep = new PickStep(currentStep.Attributes);
                    workflowStepList.Add(pickStep);
                    FillStepList(workflowContext, pickStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "eventHandlers")
                {
                    //we will handle this section as same as handl scope
                    FillStepList(workflowContext, workflowStepList, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "onMessage")
                {
                    var messageStep = new OnMessageStep(currentStep.Attributes);
                    workflowStepList.Add(messageStep);

                    string messageName = String.Empty;
                    string timesetTime = String.Empty;
                    if (currentStep.Attributes != null)
                    {
                        foreach (XmlAttribute attrib in currentStep.Attributes)
                        {
                            if (attrib.LocalName == "timeout")
                            {
                                timesetTime = attrib.Value;
                            }
                            if (attrib.LocalName == "variable")
                            {
                                messageName = attrib.Value;
                            }
                        }
                    }
                    if (!timeoutParameters.ContainsKey(messageName))
                    {
                        timeoutParameters.Add(messageName, timesetTime);
                    }

                    FillStepList(workflowContext, messageStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "onEvent")
                {
                    var onEventStep = new OnEventStep(currentStep.Attributes);
                    workflowContext.MessageTimeoutEventHanlderDict.Add(onEventStep.EventKey, onEventStep.StepId);
                    workflowStepList.Add(onEventStep);
                    FillStepList(workflowContext, onEventStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "partnerLinks")
                {
                    FillPartnerLinkList(workflowContext, currentStep);
                }
                else if (currentStep.LocalName == "variables")
                {
                    FillVariableList(workflowContext, currentStep);
                }
                else if (currentStep.LocalName == "faultHandlers")
                {
                    foreach (XmlNode childNode in currentStep.ChildNodes)
                    {
                        var faultHandler = new FaultHandler(childNode);
                        workflowStepList.Add(faultHandler);
                        FillStepList(workflowContext, faultHandler.WorkflowSteps, 0, childNode.ChildNodes, ref cancelEventHandlerName);
                    }
                }
                else
                {
                    Debug.Fail("Unhandled " + currentStep.Name + " of " + currentStep.InnerText);
                }
            }
        }
Beispiel #24
0
        static void Main()
        {
            // If you have plugins in directories different from the location of your TAP_PATH, then add those directories here.
            // PluginManager.DirectoriesToSearch.Add(@"C:\SomeOtherDirectory");

            // Start finding plugins.
            PluginManager.SearchAsync();

            // Point to log file to be used.
            SessionLogs.Initialize("console_log.txt");

            // Create a new Test Plan.
            TestPlan myTestPlan = new TestPlan();

            // All Test Plan steps are added as child steps.
            myTestPlan.ChildTestSteps.Add(new DelayStep {
                DelaySecs = .1, Name = "Delay1"
            });

            // Sequences can be created and added to TestPlan.
            SequenceStep mySequenceStep = new SequenceStep();

            mySequenceStep.ChildTestSteps.Add(new DelayStep {
                DelaySecs = .2, Name = "Delay2"
            });

            LogStep logStep = new LogStep
            {
                Name       = "SomeName",
                LogMessage = "Hello from myTestPlan at " + DateTime.Now.ToLongTimeString(),
                Severity   = LogSeverity.Info
            };

            mySequenceStep.ChildTestSteps.Add(logStep);

            // Sequences are added to the Test Plan like any other step.
            myTestPlan.ChildTestSteps.Add(mySequenceStep);

            // The Test Plan can be saved for later reuse.
            string myFilePath = Path.Combine(AssemblyDirectory, myTestPlan.Name + ".TapPlan");

            myTestPlan.Save(myFilePath);

            // Add any ResultListeners that should be used.
            // If not specified, a list of ResultListeners with a single LogResultListener will be created.
            // Alternatively, the ResultListeners could be defined in settings files.
            List <ResultListener> resultListeners = new List <ResultListener>();

            resultListeners.Add(new LogResultListener());
            //resultListeners.Add(new Keysight.OpenTap.Plugins.Csv.CsvResultListener());

            // Execute the TestPlan. This is the equivalent of the Run button in the TAP GUI.
            myTestPlan.Execute(resultListeners);

            // After the TestPlan has been run Macros, if used, can be expanded.
            SessionLogs.Rename(EngineSettings.Current.SessionLogPath.Expand(date: DateTime.Now));

            Console.WriteLine("This example builds a TestPlan programmatically.");
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
Beispiel #25
0
 private void StartStep(SequenceStep step, string animationSequence)
 {
     _step = step;
     AnimationEngine.Sequence = AnimationDataManager.Sequences[animationSequence];
 }