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
using System.Linq;
 
namespace OpenTap
{
    class AssignOutputDialog : ValidatingObject
    {
        public struct ScopeItem
        {
            public ITestStepParent Scope;
            public override string ToString()
            {
                if (Scope is TestPlan) return "Test Plan";
                if (Scope is ITestStep step) return step.GetFormattedName();
                return Scope?.ToString() ?? "";
            }
 
            static public ScopeItem Create(ITestStepParent item) => new ScopeItem() {Scope = item};
        }
 
        public string Name => "Please select an output.";
        public ScopeItem[] AvailableScopes => new[]{initScope}.Concat(initScope.GetParents()).Select(ScopeItem.Create).ToArray();
 
        [AvailableValues(nameof(AvailableScopes))]
        [Display(nameof(Scope), "The scope at which the output will be selected.", Order: 0)]
        public ScopeItem Scope { get => ScopeItem.Create(scope);
            set
            {
                scope = value.Scope;
                if (AvailableOutputs.Contains(Output) == false)
                {
                    Output = AvailableOutputs.FirstOrDefault() ?? Output;
                }
            } 
        }
 
        ITestStepParent scope;
        public class SelectedOutputItem
        {
            public readonly ITestStepParent Step;
            public readonly IMemberData Member;
 
            SelectedOutputItem(ITestStepParent testStepParent, IMemberData mem)
            {
                Step = testStepParent;
                Member = mem;
            }
 
            public static SelectedOutputItem Create(ITestStepParent testStepParent, IMemberData mem)
            {
                return new SelectedOutputItem(testStepParent, mem);
            }
 
            public override string ToString() => $"{Member.GetDisplayAttribute().GetFullName()} from {(Step as ITestStep)?.GetFormattedName() ?? "test plan"}";
 
            public override bool Equals(object obj)
            {
                if (obj is SelectedOutputItem sel)
                    return sel.Step == Step && sel.Member == Member;
                return false;
            }
 
            public override int GetHashCode() => (7771239 + Step.GetHashCode() * 13 + Member.GetHashCode()) * 19;
        }
 
        public static SelectedOutputItem[] GetAvailableOutputs(ITestStepParent scope, ITestStepParent[] steps, ITypeData outputType)
        {
            var list = scope.ChildTestSteps
 
                .SelectMany(childStep =>
                {
                    return TypeData.GetTypeData(childStep).GetMembers()
                        .Where(y => y.HasAttribute<OutputAttribute>() && InputOutputRelation.CanConvert(outputType,y.TypeDescriptor ))
                        .Select(mem => SelectedOutputItem.Create(childStep, mem));
                })
                .Where(item => steps.Contains(item.Step) == false)
                .ToList();
            
            // Add the current scope
            list.AddRange(TypeData.GetTypeData(scope).GetMembers()
                .Where(y => y.HasAttribute<OutputAttribute>() && InputOutputRelation.CanConvert(outputType, y.TypeDescriptor))
                .Select(mem => SelectedOutputItem.Create(scope, mem)));
 
            return list.ToArray();
        }
 
        public SelectedOutputItem[] GetAvailableOutputs() => GetAvailableOutputs(scope, steps, inputMember.TypeDescriptor);
 
        public SelectedOutputItem[] AvailableOutputs => GetAvailableOutputs(); 
 
        [AvailableValues(nameof(AvailableOutputs))]
        
        [Display(nameof(Output), "The output property selected." , Order: 1)]
        public SelectedOutputItem Output { get; set; }
        
        [Layout(LayoutMode.FloatBottom | LayoutMode.FullRow)]
        [Submit]
        public ParameterManager.OkCancel Response { get; set; }
 
        ITestStepParent[] steps;
        IMemberData inputMember;
        ITestStepParent initScope;
        public AssignOutputDialog(IMemberData member, ITestStepParent initScope, ITestStepParent[] steps)
        {
            this.steps = steps;
            inputMember = member;
            this.initScope = initScope;
            scope = initScope;
            
            Output = AvailableOutputs.FirstOrDefault();
        }
    }
}