public void Replace_OperatorWithoutConnectionsWithOperatorWithoutConnections_NewOpHasInternalIdOfOldOp() { var internalOldID = Guid.NewGuid(); var floatMetaOld = OperatorTests.CreateMetaFloatWithoutConnections(); var floatMetaNew = OperatorTests.CreateMetaFloatWithoutConnections(); var metacompositionOp = new MetaOperator(Guid.NewGuid()); metacompositionOp.AddOperator(floatMetaOld, internalOldID); MetaManager.Instance.AddMetaOperator(metacompositionOp.ID, metacompositionOp); MetaManager.Instance.AddMetaOperator(floatMetaNew.ID, floatMetaNew); MetaManager.Instance.AddMetaOperator(floatMetaOld.ID, floatMetaOld); var replaceCommand = new ReplaceOperatorCommand(metacompositionOp, floatMetaOld, floatMetaNew, internalOldID); replaceCommand.Do(); Assert.AreEqual(metacompositionOp.Operators.Count, 1); Assert.IsFalse(metacompositionOp.Operators.ContainsKey(internalOldID)); Assert.AreEqual(metacompositionOp.Operators.Values.Count(value => value.Item1 == floatMetaNew), 1); Assert.AreEqual(metacompositionOp.Operators.Values.Count(value => value.Item1 == floatMetaOld), 0); MetaManager.Instance.RemoveMetaOperator(metacompositionOp.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaNew.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaOld.ID); }
public void Replace_OperatorWith1InWithOperatorWith1In_ConnectionHasSameSourceAndNewOpAsTarget() { var internalSourceID = Guid.NewGuid(); var targetOpPartID = Guid.NewGuid(); var sourceOpPartID = Guid.NewGuid(); var connectionSourceOp = new MetaOperator(internalSourceID); var metaOutput = new MetaOutput(sourceOpPartID, "targetOutput", new MetaOperatorPart(Guid.NewGuid())); connectionSourceOp.AddOutput(metaOutput); var internalOldID = Guid.NewGuid(); var floatMetaOld = OperatorTests.CreateMetaFloatWithoutConnections(); var floatInput = new MetaInput(targetOpPartID, "targetInputOld", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false); floatMetaOld.AddInput(floatInput); var floatMetaNew = OperatorTests.CreateMetaFloatWithoutConnections(); floatMetaNew.AddInput(new MetaInput(Guid.NewGuid(), "targetInputNew", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false)); var metacompositionOp = new MetaOperator(Guid.NewGuid()); metacompositionOp.AddOperator(connectionSourceOp); metacompositionOp.AddOperator(floatMetaOld, internalOldID); metacompositionOp.Connections = new[] { new MetaConnection(internalSourceID, sourceOpPartID, internalOldID, targetOpPartID) }.ToList(); MetaManager.Instance.AddMetaOperator(floatMetaOld.ID, floatMetaOld); MetaManager.Instance.AddMetaOperator(floatMetaNew.ID, floatMetaNew); MetaManager.Instance.AddMetaOperator(metacompositionOp.ID, metacompositionOp); var replaceCommand = new ReplaceOperatorCommand(metacompositionOp, floatMetaOld, floatMetaNew, internalOldID); replaceCommand.Do(); var targetID = metacompositionOp.Connections.ElementAt(0).TargetOpID; Assert.AreEqual(metacompositionOp.Connections.Count, 1); Assert.AreEqual(metacompositionOp.Operators[targetID].Item1, floatMetaNew); MetaManager.Instance.RemoveMetaOperator(metacompositionOp.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaNew.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaOld.ID); }
public void UndoReplace_OperatorWith1InAnd1OutWithOperatorWith1InAnd1Out_OldOperatorIsPartOfConnectionsAgain() { var internalSourceID = Guid.NewGuid(); var sourceOpPartID = Guid.NewGuid(); var connectionSourceOp = new MetaOperator(internalSourceID); var metaOutput = new MetaOutput(sourceOpPartID, "targetOutput", new MetaOperatorPart(Guid.NewGuid())); connectionSourceOp.AddOutput(metaOutput); var internalTargetID = Guid.NewGuid(); var targetOpPartID = Guid.NewGuid(); var connectionTargetOp = new MetaOperator(internalTargetID); var floatInput = new MetaInput(targetOpPartID, "targetInput", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false); connectionTargetOp.AddInput(floatInput); var internalOldID = Guid.NewGuid(); var sourceOpPartIDOld = Guid.NewGuid(); var targetOpPartIDOld = Guid.NewGuid(); var floatMetaOld = OperatorTests.CreateMetaFloatWithoutConnections(); var floatOutput = new MetaOutput(sourceOpPartIDOld, "sourceOutputOld", new MetaOperatorPart(Guid.NewGuid())); floatMetaOld.AddOutput(floatOutput); var floatInputOld = new MetaInput(targetOpPartIDOld, "targetInputOld", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false); floatMetaOld.AddInput(floatInputOld); var floatMetaNew = OperatorTests.CreateMetaFloatWithoutConnections(); floatMetaNew.AddInput(new MetaInput(Guid.NewGuid(), "targetInputNew", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false)); floatMetaNew.AddOutput(new MetaOutput(Guid.NewGuid(), "sourceOutputNew", new MetaOperatorPart(Guid.NewGuid()))); var metacompositionOp = new MetaOperator(Guid.NewGuid()); metacompositionOp.AddOperator(connectionTargetOp); metacompositionOp.AddOperator(connectionSourceOp); metacompositionOp.AddOperator(floatMetaOld, internalOldID); metacompositionOp.Connections = new[] { new MetaConnection(internalSourceID, sourceOpPartID, internalOldID, targetOpPartIDOld), new MetaConnection(internalOldID, sourceOpPartIDOld, internalTargetID, targetOpPartID) }.ToList(); MetaManager.Instance.AddMetaOperator(floatMetaOld.ID, floatMetaOld); MetaManager.Instance.AddMetaOperator(floatMetaNew.ID, floatMetaNew); MetaManager.Instance.AddMetaOperator(metacompositionOp.ID, metacompositionOp); var replaceCommand = new ReplaceOperatorCommand(metacompositionOp, floatMetaOld, floatMetaNew, internalOldID); replaceCommand.Do(); replaceCommand.Undo(); var targetID = metacompositionOp.Connections.Single(connection => connection.SourceOpID == internalSourceID).TargetOpID; var sourceID = metacompositionOp.Connections.Single(connection => connection.TargetOpID == internalTargetID).SourceOpID; Assert.AreEqual(metacompositionOp.Connections.Count, 2); Assert.AreEqual(metacompositionOp.Operators[targetID].Item1, floatMetaOld); Assert.AreEqual(metacompositionOp.Operators[sourceID].Item1, floatMetaOld); MetaManager.Instance.RemoveMetaOperator(metacompositionOp.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaNew.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaOld.ID); }