internal static IEnumerable <IAutoCompletePattern> Generate(XmlGraphData <NodeUIData, ConversationEditorData> nodeData, DomainDomain source) { List <IAutoCompletePattern> result = new List <IAutoCompletePattern>(); List <IError> errors = new List <IError>(); var startNodes = nodeData.Nodes.Select(n => n.GraphData).Where(n => !HasParent(n) && !HasPrevious(n)); foreach (var startNode in startNodes) { var processed = Process(startNode, source, 0); processed.Do(a => result.Add(a), b => errors.Add(b)); } //TODO: How to expose errors to the user? return(result); }
private static void AssertDataEqual(XmlGraphData <UIRawData, EditorData> expected, XmlGraphData <UIRawData, EditorData> actual, IDataSource source) { Assert.That(actual.EditorData.Value, Is.EqualTo(expected.EditorData.Value)); Assert.That(actual.Errors, Is.Empty); var actualNodes = actual.Nodes.ToList(); foreach (var expectedNode in expected.Nodes) { //Get the corresponding actualNode var x = actualNodes.Where(n => n.GraphData.NodeId == expectedNode.GraphData.NodeId); Assert.That(x.Count(), Is.EqualTo(1)); var actualNode = x.First(); actualNodes.Remove(actualNode); Assert.That(actualNode.UIData.Value, Is.EqualTo(expectedNode.UIData.Value)); var actualConnectors = actualNode.GraphData.Connectors.ToList(); foreach (var connector in expectedNode.GraphData.Connectors) { //Get the corresponding connector var y = actualConnectors.Where(c => c.Id == connector.Id); Assert.That(y.Count(), Is.EqualTo(1)); var actualConnector = y.First(); actualConnectors.Remove(actualConnector); Assert.That(actualConnector.Connections.Select(c => c.Id), Is.EquivalentTo(connector.Connections.Select(c => c.Id))); } Assert.That(actualConnectors, Is.Empty); var actualParameters = actualNode.GraphData.Parameters.ToList(); foreach (var parameter in expectedNode.GraphData.Parameters) { var y = actualParameters.Where(p => p.Id == parameter.Id); Assert.That(y.Count(), Is.EqualTo(1)); var actualParameter = y.First(); actualParameters.Remove(actualParameter); Assert.That(actualParameter.Corrupted, Is.False); Assert.That(actualParameter.ValueAsString(), Is.EqualTo(parameter.ValueAsString())); } Assert.That(actualParameters, Is.Empty); } Assert.That(actualNodes, Is.Empty); }
public static void TestConsistency() { IDataSource source = new DataSource(); Func <Id <NodeTypeTemp>, bool> filter = a => true; XmlConversation <UIRawData, EditorData> .Serializer serializer = new XmlConversation <UIRawData, EditorData> .Serializer(new UIRawDataSerializer(), new EditorDataSerializer()); XmlConversation <UIRawData, EditorData> .Deserializer deserializer = new XmlConversation <UIRawData, EditorData> .Deserializer(source, new UIRawDataSerializer(), new EditorDataSerializer(), filter); object document = new object(); //Set up nodes var nodes = new[] { source.GetNode(GraphData.TYPE1).Generate(Id <NodeTemp> .Parse("65ea4337-3687-4b0c-a2c5-2c06109b5d86"), new NodeDataGeneratorParameterData[0], document) as GraphData, source.GetNode(GraphData.TYPE1).Generate(Id <NodeTemp> .Parse("028405e3-9668-4d3c-bfa7-816a08f62f5e"), new NodeDataGeneratorParameterData[0], document) as GraphData, source.GetNode(GraphData.TYPE2).Generate(Id <NodeTemp> .Parse("2362552e-cce6-407b-abc5-005f0450ad25"), new NodeDataGeneratorParameterData[0], document) as GraphData, source.GetNode(GraphData.TYPE3).Generate(Id <NodeTemp> .Parse("553daadb-bf55-401c-975c-a069fd54ac12"), new NodeDataGeneratorParameterData[0], document) as GraphData, source.GetNode(GraphData.TYPE3).Generate(Id <NodeTemp> .Parse("3a5c9ebb-2aba-4f67-94e1-7e5575b6a369"), new NodeDataGeneratorParameterData[0], document) as GraphData, }; //Set up connections nodes[0].Connectors.First().ConnectTo(nodes[1].Connectors.First(), false); nodes[0].Connectors.First().ConnectTo(nodes[2].Connectors.First(), false); nodes[2].Connectors.ElementAt(1).ConnectTo(nodes[3].Connectors.First(), false); nodes[2].Connectors.ElementAt(1).ConnectTo(nodes[3].Connectors.First(), false); //Set up parameters GraphData.DummyEnumeration referenceEnumeration = new GraphData.DummyEnumeration(); nodes[0].AudioParameter.SetValueAction(new Audio("anaudiopath")).Value.Redo(); nodes[0].BooleanParameter.SetValueAction(false)?.Redo(); //It defaults to null so the change action ends up being null nodes[0].DecimalParameter.SetValueAction(2345.7342m).Value.Redo(); nodes[0].DynamicEnumParameter.SetValueAction("djh")?.Redo(); nodes[0].EnumParameter.SetValueAction(referenceEnumeration.Options.ElementAt(1)).Value.Redo(); nodes[1].AudioParameter.SetValueAction(new Audio("anaudiopath")).Value.Redo(); nodes[1].BooleanParameter.SetValueAction(true).Value.Redo(); nodes[1].DecimalParameter.SetValueAction(986923.24m).Value.Redo(); nodes[1].DynamicEnumParameter.SetValueAction("fdjngb").Value.Redo(); nodes[1].EnumParameter.SetValueAction(referenceEnumeration.Options.ElementAt(0)).Value.Redo(); nodes[2].IntegerParameter.SetValueAction(354).Value.Redo(); nodes[2].LocalizedStringParameter.SetValueAction(Id <LocalizedText> .Parse("fd9b5426-a296-43bc-84a8-c633b9e88d3c")).Value.Redo(); nodes[2].SetParameter.SetValueAction(new ReadOnlySet <Guid>(referenceEnumeration.Options)).Value.Redo(); nodes[2].StringParameter.SetValueAction("lhgalkhalsd").Value.Redo(); nodes[3].StringParameter.SetValueAction("ljlkdskd").Value.Redo(); nodes[3].StringParameter2.SetValueAction("lkjgaslvgokvagaviua").Value.Redo(); nodes[4].StringParameter.SetValueAction("ljlkdsdfsdfsdskd").Value.Redo(); nodes[4].StringParameter2.SetValueAction("lkjgasafafflvgokvagaviua").Value.Redo(); var nodeData = new GraphAndUI <UIRawData>[] { new GraphAndUI <UIRawData>(nodes[0], new UIRawData { Value = "test ui raw data 0" }), new GraphAndUI <UIRawData>(nodes[1], new UIRawData { Value = "test ui raw data 1" }), new GraphAndUI <UIRawData>(nodes[2], new UIRawData { Value = "test ui raw data 2" }), new GraphAndUI <UIRawData>(nodes[3], new UIRawData { Value = "test ui raw data 3" }), new GraphAndUI <UIRawData>(nodes[4], new UIRawData { Value = "test ui raw data 4" }), }; var data = new XmlGraphData <UIRawData, EditorData>(nodeData, new EditorData { Value = "test editor data" }); using (var stream = new MemoryStream()) { serializer.Write(data, stream); stream.Position = 0; var resultData = deserializer.Read(stream); AssertDataEqual(data, resultData, source); } }