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); }
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()}")); }
public void SweepLoopNoValuesSelected() { var plan = new TestPlan(); var sweep = new SweepParameterStep(); var step = new DelayStep(); plan.ChildTestSteps.Add(sweep); sweep.ChildTestSteps.Add(step); Assert.Throws(typeof(InvalidOperationException), sweep.PrePlanRun); // Select parameter to sweep TypeData.GetTypeData(step).GetMember(nameof(DelayStep.DelaySecs)).Parameterize(sweep, step, nameof(DelayStep.DelaySecs)); try { sweep.PrePlanRun(); Assert.Fail("An exception should have been thrown."); } catch (InvalidOperationException ex) { Assert.AreEqual(ex.Message, "No values selected to sweep"); } }
public void SweepLoop2Test() { var plan = new TestPlan(); var sweep = new SweepParameterStep(); var step = new ScopeTestStep(); plan.ChildTestSteps.Add(sweep); sweep.ChildTestSteps.Add(step); sweep.SweepValues.Add(new SweepRow()); sweep.SweepValues.Add(new SweepRow()); TypeData.GetTypeData(step).GetMember(nameof(ScopeTestStep.A)).Parameterize(sweep, step, "Parameters \\ A"); TypeData.GetTypeData(step).GetMember(nameof(ScopeTestStep.EnabledTest)).Parameterize(sweep, step, nameof(ScopeTestStep.EnabledTest)); var td1 = TypeData.GetTypeData(sweep.SweepValues[0]); var memberA = td1.GetMember("Parameters \\ A"); memberA.SetValue(sweep.SweepValues[0], 10); memberA.SetValue(sweep.SweepValues[1], 20); { // verify Enabled<T> works with SweepParameterStep. var annotation = AnnotationCollection.Annotate(sweep); var col = annotation.GetMember(nameof(SweepParameterStep.SelectedParameters)).Get <IStringReadOnlyValueAnnotation>().Value; Assert.AreEqual("A, EnabledTest", col); var elements = annotation.GetMember(nameof(SweepParameterStep.SweepValues)) .Get <ICollectionAnnotation>().AnnotatedElements .Select(elem => elem.GetMember(nameof(ScopeTestStep.EnabledTest))) .ToArray(); annotation.Write(); Assert.IsFalse((bool)elements[0].GetMember("IsEnabled").Get <IObjectValueAnnotation>().Value); elements[0].GetMember("IsEnabled").Get <IObjectValueAnnotation>().Value = true; annotation.Write(); Assert.IsFalse((bool)elements[1].GetMember("IsEnabled").Get <IObjectValueAnnotation>().Value); Assert.IsTrue((bool)elements[0].GetMember("IsEnabled").Get <IObjectValueAnnotation>().Value); } var str = new TapSerializer().SerializeToString(plan); var plan2 = (TestPlan) new TapSerializer().DeserializeFromString(str); var sweep2 = (SweepParameterStep)plan2.Steps[0]; var td2 = TypeData.GetTypeData(sweep2); var members2 = td2.GetMembers(); var rows = sweep2.SweepValues; Assert.AreEqual(2, rows.Count); var msgmem = TypeData.GetTypeData(rows[0]).GetMember("Parameters \\ A"); Assert.AreEqual(10, msgmem.GetValue(rows[0])); // this feature was disabled. //var annotated = AnnotationCollection.Annotate(sweep2); //var messageMember = annotated.GetMember(nameof(ScopeTestStep.A)); //Assert.IsFalse(messageMember.Get<IEnabledAnnotation>().IsEnabled); var run = plan2.Execute(); Assert.AreEqual(Verdict.Pass, run.Verdict); Assert.IsTrue(((ScopeTestStep)sweep2.ChildTestSteps[0]).Collection.SequenceEqual(new[] { 10, 20 })); var name = sweep.GetFormattedName(); Assert.AreEqual("Sweep A, EnabledTest", name); }
public SweepRowTypeData(SweepParameterStep sweepParameterLoop) { this.SweepParameterLoop = sweepParameterLoop; }