Esempio n. 1
0
        public static void TestGetNodeRemoveActions()
        {
            IEnumerable <IParameter> someCorrupt = new IParameter[]
            {
                new DummyParameter(false),
                new DummyParameter(true),
            };
            IConversationNodeData data1 = new DummyConversationNodeData(someCorrupt, Id <NodeTemp> .Parse("558d4788-7b8c-4fc2-a822-f8ea90a2c84e"));
            IConversationNodeData data2 = new DummyConversationNodeData(someCorrupt, Id <NodeTemp> .Parse("af594e64-e788-4873-9d01-0e13ba430c14"));
            IConversationNodeData data3 = new DummyConversationNodeData(someCorrupt, Id <NodeTemp> .Parse("d3bbcc20-f8c5-4e40-8ad4-bee06b6f28a7"));
            Func <ConversationNode <DummyUI>, DummyUI> nodeUI      = n => new DummyUI(n, false);
            Func <ConversationNode <DummyUI>, DummyUI> corruptedUI = n => new DummyUI(n, true);
            ConversationNode <DummyUI> node1 = new ConversationNode <DummyUI>(data1, nodeUI, corruptedUI);
            ConversationNode <DummyUI> node2 = new ConversationNode <DummyUI>(data2, nodeUI, corruptedUI);
            ConversationNode <DummyUI> node3 = new ConversationNode <DummyUI>(data3, nodeUI, corruptedUI);
            var nodes = new[] { node1, node2, node3 };

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int a = i + 1; a < 3; a++)
                    {
                        for (int b = 0; b < 3; b++)
                        {
                            nodes[i].Data.Connectors.ElementAt(j).ConnectTo(nodes[a].Data.Connectors.ElementAt(b), false);
                        }
                    }
                }
            }

            List <Output> allConnectors = new List <Output>();
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        allConnectors.Add(nodes[i].Data.Connectors.ElementAt(j));
                    }
                }
            }

            Action CheckAllConnected = () =>
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        Assert.That(nodes[i].Data.Connectors.ElementAt(j).Connections, Is.EquivalentTo(allConnectors.Where(x => x.Parent != nodes[i].Data)));
                    }
                }
            };

            CheckAllConnected();

            var actions = node1.GetNodeRemoveActions();

            //TODO: Test that localizations are removed/readded correctly

            CheckAllConnected();

            actions.Redo();
            for (int i = 1; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Assert.That(nodes[i].Data.Connectors.ElementAt(j).Connections, Is.EquivalentTo(allConnectors.Where(x => x.Parent != nodes[i].Data && x.Parent != node1.Data)));
                }
            }

            for (int j = 0; j < 3; j++)
            {
                Assert.That(node1.Data.Connectors.ElementAt(j).Connections, Is.Empty);
            }

            actions.Undo();
            CheckAllConnected();
        }