/// <summary> Create a relation between two members on two different objects. </summary> public static void Assign(ITestStepParent inputObject, IMemberData inputMember, ITestStepParent outputObject, IMemberData outputMember) { if (outputMember == null) { throw new ArgumentNullException(nameof(outputMember)); } if (inputMember == null) { throw new ArgumentNullException(nameof(inputMember)); } if (inputObject == null) { throw new ArgumentNullException(nameof(inputObject)); } if (outputObject == null) { throw new ArgumentNullException(nameof(outputObject)); } if (inputMember == outputMember && inputObject == outputObject) { throw new ArgumentException("An input/output may not be assigned to itself."); } if (outputMember.Readable == false) { throw new ArgumentException(nameof(outputMember) + " is not readable!", nameof(outputMember)); } if (inputMember.Writable == false) { throw new ArgumentException(nameof(inputMember) + " is not writeable!", nameof(inputMember)); } var connTo = getOutputRelations(inputObject).ToList(); var connFrom = getInputRelations(outputObject).ToList(); foreach (var connection in connTo) { if (connection.OutputObject == outputObject && connection.OutputMember == outputMember && inputMember == connection.InputMember) { throw new ArgumentException("Input already assigned", nameof(inputMember)); } } if (IsInput(inputObject, inputMember)) { throw new Exception("This input is already in use by another connection."); } // these two restrictions might not be necessary, but it might be good to leave it // in case we want to change the mechanism if (IsInput(outputObject, outputMember)) { throw new Exception("An output cannot also be an input"); } if (IsOutput(inputObject, inputMember)) { throw new Exception("An input cannot also be an output"); } var newSpec = new InputOutputRelation(inputObject, inputMember, outputObject, outputMember); connTo.Add(newSpec); connFrom.Add(newSpec); SetOutputRelations(inputObject, connTo.ToArray()); SetInputRelations(outputObject, connFrom.ToArray()); }
/// <summary> Unassign an input/output relation. </summary> /// <param name="relation"></param> internal static void Unassign(InputOutputRelation relation) { SetOutputRelations(relation.InputObject, getOutputRelations(relation.InputObject).Where(x => x != relation).ToArray()); SetInputRelations(relation.OutputObject, getInputRelations(relation.OutputObject).Where(x => x != relation).ToArray()); }