public void Test30() { //Step 1: Construct any Pipeline MainViewModel mvm = MainViewModelTest.GetInstance(); ColorInputNode colorInput = new ColorInputNode(); mvm.Model.Graph.AddNode(colorInput); InverterNode inverter = new InverterNode(); mvm.Model.Graph.AddNode(inverter); mvm.Model.Graph.AddEdge(colorInput.Outputs[0], inverter.Inputs[0]); Assert.Contains(colorInput, mvm.Model.Graph.Nodes); Assert.Contains(inverter, mvm.Model.Graph.Nodes); Assert.Equal(colorInput.Outputs[0], inverter.Inputs[0].Source); //Step 2: Save Pipeline using (var stream = File.Create(@"..\..\..\..\output\test30.yuvka")) new NetDataContractSerializer().Serialize(stream, mvm.Model); Assert.True(File.Exists(@"..\..\..\..\output\test30.yuvka")); //Step 3: Clear Pipeline mvm.Clear(); Assert.Empty(mvm.Model.Graph.Nodes); //Step 4: Reload Pipeline using (var stream = File.OpenRead(@"..\..\..\..\output\test30.yuvka")) mvm.Model = (PipelineState) new NetDataContractSerializer().Deserialize(stream); Assert.True(mvm.Model.Graph.Nodes[0] is ColorInputNode); Assert.True(mvm.Model.Graph.Nodes[1] is InverterNode); Assert.Equal(mvm.Model.Graph.Nodes[0].Outputs[0], mvm.Model.Graph.Nodes[1].Inputs[0].Source); }
public void GlobalTest10() { MainViewModel mvm = MainViewModelTest.GetInstance(); PipelineViewModel pvm = mvm.PipelineViewModel; // Step 1: The user clicks "New" to create a new pipeline mvm.Clear(); Assert.Empty(mvm.Model.Graph.Nodes); var mock = new Mock <IDragEventInfo>(); // Step 2: Create each type of node once by drag-and-drop VideoInputNode vin = (VideoInputNode)AddNode <VideoInputNode>(pvm, mock, new Point(10, 30)); AdditiveMergeNode amn = (AdditiveMergeNode)AddNode <AdditiveMergeNode>(pvm, mock, new Point(30, 30)); BlurNode bn = (BlurNode)AddNode <BlurNode>(pvm, mock, new Point(50, 30)); BrightnessContrastSaturationNode bcsn = (BrightnessContrastSaturationNode)AddNode <BrightnessContrastSaturationNode>(pvm, mock, new Point(70, 30)); ColorInputNode cin = (ColorInputNode)AddNode <ColorInputNode>(pvm, mock, new Point(10, 50)); DelayNode dln = (DelayNode)AddNode <DelayNode>(pvm, mock, new Point(90, 30)); DiagramNode dgn = (DiagramNode)AddNode <DiagramNode>(pvm, mock, new Point(110, 30)); DifferenceNode dfn = (DifferenceNode)AddNode <DifferenceNode>(pvm, mock, new Point(30, 50)); HistogramNode hn = (HistogramNode)AddNode <HistogramNode>(pvm, mock, new Point(50, 50)); ImageInputNode imin = (ImageInputNode)AddNode <ImageInputNode>(pvm, mock, new Point(70, 50)); InverterNode invn = (InverterNode)AddNode <InverterNode>(pvm, mock, new Point(90, 50)); NoiseInputNode nin = (NoiseInputNode)AddNode <NoiseInputNode>(pvm, mock, new Point(110, 50)); OverlayNode on = (OverlayNode)AddNode <OverlayNode>(pvm, mock, new Point(10, 70)); RgbSplitNode rgbsn = (RgbSplitNode)AddNode <RgbSplitNode>(pvm, mock, new Point(30, 70)); WeightedAveragedMergeNode wamn = (WeightedAveragedMergeNode)AddNode <WeightedAveragedMergeNode>(pvm, mock, new Point(50, 70)); // Step 3: Create the edges mvm.Model.Graph.AddEdge(vin.Outputs[0], bn.Inputs[0]); Assert.Equal(vin.Outputs[0], bn.Inputs[0].Source); amn.Inputs.Add(new Node.Input()); mvm.Model.Graph.AddEdge(vin.Outputs[0], amn.Inputs[0]); Assert.Equal(vin.Outputs[0], amn.Inputs[0].Source); mvm.Model.Graph.AddEdge(bn.Outputs[0], dln.Inputs[0]); Assert.Equal(bn.Outputs[0], dln.Inputs[0].Source); mvm.Model.Graph.AddEdge(dln.Outputs[0], dfn.Inputs[0]); Assert.Equal(dln.Outputs[0], dfn.Inputs[0].Source); mvm.Model.Graph.AddEdge(imin.Outputs[0], dfn.Inputs[1]); Assert.Equal(imin.Outputs[0], dfn.Inputs[1].Source); mvm.Model.Graph.AddEdge(dfn.Outputs[0], invn.Inputs[0]); Assert.Equal(dfn.Outputs[0], invn.Inputs[0].Source); mvm.Model.Graph.AddEdge(invn.Outputs[0], on.Inputs[0]); Assert.Equal(invn.Outputs[0], on.Inputs[0].Source); mvm.Model.Graph.AddEdge(vin.Outputs[0], on.Inputs[1]); Assert.Equal(vin.Outputs[0], on.Inputs[1].Source); mvm.Model.Graph.AddEdge(vin.Outputs[0], rgbsn.Inputs[0]); Assert.Equal(vin.Outputs[0], rgbsn.Inputs[0].Source); mvm.Model.Graph.AddEdge(rgbsn.Outputs[2], hn.Inputs[0]); Assert.Equal(rgbsn.Outputs[2], hn.Inputs[0].Source); }
public void Test50() { // Some necessary initializations. MainViewModel mvm = MainViewModelTest.GetInstance(); var windowManMock = new Mock <IWindowManagerEx>(); var vm = MainViewModelTest.GetInstance(cont => cont.ComposeExportedValue <IWindowManagerEx>(windowManMock.Object)); var conductorMock = new Mock <IConductor>(); // Step 1: Create simple pipeline. // // [color]---[overlay] // \ / // X // / \ // [noise]---[diagram] NoiseInputNode noise = new NoiseInputNode(); mvm.Model.Graph.AddNode(noise); ColorInputNode color = new ColorInputNode(); mvm.Model.Graph.AddNode(color); DiagramNode diagram = new DiagramNode(); diagram.Inputs.Add(new Node.Input()); diagram.Inputs.Add(new Node.Input()); mvm.Model.Graph.AddNode(diagram); OverlayNode overlay = new OverlayNode(); mvm.Model.Graph.AddNode(overlay); Assert.Contains(noise, mvm.Model.Graph.Nodes); Assert.Contains(color, mvm.Model.Graph.Nodes); Assert.Contains(diagram, mvm.Model.Graph.Nodes); Assert.Contains(overlay, mvm.Model.Graph.Nodes); mvm.Model.Graph.AddEdge(noise.Outputs[0], overlay.Inputs[0]); mvm.Model.Graph.AddEdge(noise.Outputs[0], diagram.Inputs[0]); mvm.Model.Graph.AddEdge(color.Outputs[0], overlay.Inputs[1]); mvm.Model.Graph.AddEdge(color.Outputs[0], diagram.Inputs[1]); Assert.Equal(noise.Outputs[0], overlay.Inputs[0].Source); Assert.Equal(noise.Outputs[0], diagram.Inputs[0].Source); Assert.Equal(color.Outputs[0], overlay.Inputs[1].Source); Assert.Equal(color.Outputs[0], diagram.Inputs[1].Source); // Step 2: Disable diagram node and open overlay node. diagram.IsEnabled = false; IGraphType pixelDiff = new PixelDiff(); IGraphType psnr = new PeakSignalNoiseRatio(); IoC.GetAllInstances = type => new List <IGraphType> { pixelDiff, psnr }; var overlayWindow = new OverlayViewModel(overlay) { Parent = conductorMock.Object }; var diagramWindow = new DiagramViewModel(diagram) { Parent = conductorMock.Object }; ((IActivate)overlayWindow).Activate(); conductorMock.Setup(c => c.DeactivateItem(overlayWindow, true)) .Callback(() => ((IDeactivate)overlayWindow).Deactivate(close: true)) .Verifiable(); mvm.OpenWindow(overlayWindow); Assert.Contains(overlayWindow, mvm.OpenWindows); // Step 3: Start pipeline and add an overlay in the overlay node. mvm.Model.Start(mvm.Model.Graph.Nodes); overlay.Type = new ArtifactsOverlay(); // Step 4: Remove selected overlay. overlay.Type = new NoOverlay(); // Step 5: Stop pipeline and close overlay node. mvm.Model.Stop(); mvm.CloseWindows(overlay); Assert.DoesNotContain(overlayWindow, mvm.OpenWindows); // Step 6: Re-enable diagram node and open it. diagram.IsEnabled = true; mvm.OpenWindow(diagramWindow); Assert.Contains(diagramWindow, mvm.OpenWindows); // Step 7: Choose a reference video and add a diagram graph. diagramWindow.Reference = new Tuple <string, Node.Input>(diagramWindow.GetVideoName(diagram.Inputs[0]), diagram.Inputs[0]); diagramWindow.ChosenVideo = new Tuple <string, Node.Input>(diagramWindow.GetVideoName(diagram.Inputs[1]), diagram.Inputs[1]); diagramWindow.AddGraph(); diagramWindow.Graphs.ElementAt(0).CurrentType = new GraphTypeViewModel(pixelDiff); // Step 8: Start pipeline again and change diagram graph type. mvm.Model.Start(mvm.Model.Graph.Nodes); diagramWindow.Graphs.ElementAt(0).CurrentType = new GraphTypeViewModel(psnr); // Step 9: Remove the diagram graph. DiagramGraphViewModel dgvm = diagramWindow.Graphs.ElementAt(0); diagramWindow.DeleteGraph(dgvm); Assert.DoesNotContain(dgvm, diagramWindow.Graphs); }
public void DiagramNodeDeleteNode() { IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() }; var posMock = new Mock <IGetPosition>(); posMock.Setup(p => p.GetElementSize(It.IsAny <IViewAware>())).Returns(new Size(4, 4)); posMock.Setup(p => p.ViewLoaded(It.IsAny <IViewAware>())).Returns(Observable.Never <Unit>()); var mvm = MainViewModelTest.GetInstance( container => container.ComposeExportedValue(posMock.Object) ); var vm = mvm.PipelineViewModel; var mock = new Mock <IDragEventInfo>(); // Add Nodes like so // vin0 // // // vin1 dn // // // vin2 var vin0 = AddNodeModel <VideoInputNode>(vm, mock); var vin1 = AddNodeModel <VideoInputNode>(vm, mock); var vin2 = AddNodeModel <VideoInputNode>(vm, mock); var dn = AddNodeModel <DiagramNode>(vm, mock); var dnvm = new DiagramViewModel(dn.Model); // Add Edge like so // vin0 // \ // \ // vin1 dn // // // vin2 // Start edge from vin0 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin0.Outputs.First()) ); var edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over dn input var e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(dn.Inputs.First(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on dn input vm.InOutputMouseUp(dn.Inputs.First()); Assert.Equal(1, vm.Edges.Count()); Assert.Equal(1, dn.Model.Inputs.Count()); // DiagramNode has one fake input. Assert.Equal(2, dn.Inputs.Count()); // Add Edge like so // vin0 // \ // \ // vin1--dn // // // vin2 // Start edge from vin1 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin1.Outputs.First()) ); edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over dn input e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(dn.Inputs.Last(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on dn input vm.InOutputMouseUp(dn.Inputs.Last()); Assert.Equal(2, vm.Edges.Count()); Assert.Equal(2, dn.Model.Inputs.Count()); Assert.Equal(3, dn.Inputs.Count()); // Add PixelDiff-graph of vin1 and set reference to vin0 Assert.Equal(4, vm.Nodes.Count()); dnvm.Reference = dnvm.Videos.First(); dnvm.ChosenVideo = dnvm.Videos.Last(); dnvm.AddGraph(); dnvm.Graphs.Single().CurrentType = dnvm.Graphs.Single().AvailableTypes.First(); Assert.Equal(1, dnvm.Graphs.Count()); Assert.NotNull(dnvm.Reference); // Add Edge like so // vin0 // \ // \ // vin1--dn // / // / // vin2 // Start edge from vin2 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin2.Outputs.First()) ); edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over dn input e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(dn.Inputs.Last(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on dn input vm.InOutputMouseUp(dn.Inputs.Last()); Assert.Equal(3, vm.Edges.Count()); Assert.Equal(3, dn.Model.Inputs.Count()); Assert.Equal(4, dn.Inputs.Count()); // Add PixelDiff-graph of vin2 dnvm.ChosenVideo = dnvm.Videos.Last(); dnvm.AddGraph(); dnvm.Graphs.Last().CurrentType = dnvm.Graphs.Last().AvailableTypes.First(); Assert.Equal(2, dnvm.Graphs.Count()); Assert.NotNull(dnvm.Reference); Assert.True(dnvm.Graphs.All(graph => graph.CurrentType != null)); // Delete Node like so // vin0 // \ // \ // vin1--dn // // // Assert.PropertyChanged(vm, "Edges", vin2.RemoveNode); Assert.DoesNotContain(vin2, vm.Nodes); Assert.DoesNotContain(vin2.Model, vm.Parent.Model.Graph.Nodes); Assert.Equal(2, vm.Edges.Count()); Assert.Equal(2, dn.Model.Inputs.Count()); Assert.Equal(3, dn.Inputs.Count()); Assert.Equal(3, vm.Nodes.Count()); Assert.NotNull(dnvm.Reference); Assert.Equal(1, dnvm.Graphs.Count()); // Delete Node like so // // // // vin1--dn // // // Assert.PropertyChanged(vm, "Edges", vin0.RemoveNode); Assert.DoesNotContain(vin0, vm.Nodes); Assert.DoesNotContain(vin0.Model, vm.Parent.Model.Graph.Nodes); Assert.Equal(1, vm.Edges.Count()); Assert.Equal(1, dn.Model.Inputs.Count()); Assert.Equal(2, dn.Inputs.Count()); Assert.Equal(2, vm.Nodes.Count()); Assert.Null(dnvm.Reference); Assert.Equal(1, dnvm.Graphs.Count()); }
public void WAMNDeleteNode() { var posMock = new Mock <IGetPosition>(); posMock.Setup(p => p.GetElementSize(It.IsAny <IViewAware>())).Returns(new Size(4, 4)); posMock.Setup(p => p.ViewLoaded(It.IsAny <IViewAware>())).Returns(Observable.Never <Unit>()); var vm = MainViewModelTest.GetInstance( container => container.ComposeExportedValue(posMock.Object) ).PipelineViewModel; var mock = new Mock <IDragEventInfo>(); // Add Nodes like so // vin0 // // wamn // //vin1 var vin0 = AddNodeModel <VideoInputNode>(vm, mock); var vin1 = AddNodeModel <VideoInputNode>(vm, mock); var wamn = AddNodeModel <WeightedAveragedMergeNode>(vm, mock); // Add Edge like so // vin0 // \ // wamn // //vin1 // Start edge from vin0 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin0.Outputs.First()) ); var edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over vin1 input var e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(wamn.Inputs.First(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on vin1 input vm.InOutputMouseUp(wamn.Inputs.First()); Assert.Equal(1, vm.Edges.Count()); Assert.Equal(1, wamn.Model.Inputs.Count()); // WAMN-ViewModel has one fake input. Assert.Equal(2, wamn.Inputs.Count()); // Add Edge like so // vin0 // \ // wamn // / //vin1 // Start edge from vin1 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin1.Outputs.First()) ); edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over wamn input e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(wamn.Inputs.Last(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on wamn input vm.InOutputMouseUp(wamn.Inputs.Last()); Assert.Equal(2, vm.Edges.Count()); Assert.Equal(2, wamn.Model.Inputs.Count()); Assert.Equal(3, wamn.Inputs.Count()); // Remove Node like so // // // wamn // / //vin1 Assert.PropertyChanged(vm, "Edges", vin0.RemoveNode); Assert.DoesNotContain(vin0, vm.Nodes); Assert.DoesNotContain(vin0.Model, vm.Parent.Model.Graph.Nodes); Assert.Equal(1, vm.Edges.Count()); Assert.Equal(1, wamn.Model.Inputs.Count()); Assert.Equal(2, wamn.Inputs.Count()); }
public void WAMNDeleteEdge() { var posMock = new Mock <IGetPosition>(); posMock.Setup(p => p.GetElementSize(It.IsAny <IViewAware>())).Returns(new Size(4, 4)); posMock.Setup(p => p.ViewLoaded(It.IsAny <IViewAware>())).Returns(Observable.Never <Unit>()); var vm = MainViewModelTest.GetInstance( container => container.ComposeExportedValue(posMock.Object) ).PipelineViewModel; var mock = new Mock <IDragEventInfo>(); // Add Nodes like so // vin0 // // wamn // //vin1 var vin0 = AddNodeModel <VideoInputNode>(vm, mock); var vin1 = AddNodeModel <VideoInputNode>(vm, mock); var wamn = AddNodeModel <WeightedAveragedMergeNode>(vm, mock); // Add Edge like so // vin0 // \ // wamn // //vin1 // Start edge from vin0 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin0.Outputs.First()) ); var edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over wamn input var e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(wamn.Inputs.First(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on wamn input vm.InOutputMouseUp(wamn.Inputs.First()); Assert.Equal(1, vm.Edges.Count()); Assert.Equal(1, wamn.Model.Inputs.Count()); // WAMN-ViewModel has one fake input. Assert.Equal(2, wamn.Inputs.Count()); // Add Edge like so // vin0 // \ // wamn // / //vin1 // Start edge from vin1 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(vin1.Outputs.First()) ); edge = vm.DraggedEdge; Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over wamn input e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(wamn.Inputs.Last(), e); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on wamn input vm.InOutputMouseUp(wamn.Inputs.Last()); Assert.Equal(2, vm.Edges.Count()); Assert.Equal(2, wamn.Model.Inputs.Count()); Assert.Equal(3, wamn.Inputs.Count()); // Delete Edge like so // vin0 // // wamn // / //vin1 // Pick up edge from wamn input Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(wamn.Inputs.First()) ); edge = vm.DraggedEdge; // drag edge to empty space var mouseMock = new Mock <IMouseEventInfo>(); mouseMock.Setup(m => m.GetPosition(vm)).Returns(new Point(50, 50)); mouseMock.SetupGet(m => m.LeftButton).Returns(MouseButtonState.Pressed); vm.MouseMove(mouseMock.Object); Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // let go vm.MouseUp(); Assert.Equal(1, vm.Edges.Count()); Assert.Equal(1, wamn.Model.Inputs.Count()); Assert.Equal(2, wamn.Inputs.Count()); }
public void Test40() { // Step 1: create an arbitrary acyclical pipeline with an input and a manipulation node MainViewModel mvm = MainViewModelTest.GetInstance(); VideoInputNode video = new VideoInputNode(); BlurNode blur = new BlurNode() { Type = BlurType.Gaussian, Radius = 3 }; DisplayNode display = new DisplayNode(); // We'll have to dump this node's output later, so we need a ViewModel NodeViewModel blurVM = new NodeViewModel(blur, mvm.PipelineViewModel); mvm.Model.Graph.AddNode(video); mvm.Model.Graph.AddNode(blur); mvm.Model.Graph.AddNode(display); mvm.Model.Graph.AddEdge(video.Outputs[0], blur.Inputs[0]); mvm.Model.Graph.AddEdge(blur.Outputs[0], display.Inputs[0]); // Assert that the graph is well-formed Assert.Contains(video, mvm.Model.Graph.Nodes); Assert.Contains(blur, mvm.Model.Graph.Nodes); Assert.Contains(display, mvm.Model.Graph.Nodes); Assert.Equal(blur.Inputs[0].Source, video.Outputs[0]); Assert.Equal(display.Inputs[0].Source, blur.Outputs[0]); // Step 2: change the video input data Assert.False(display.InputIsValid); video.FileName = new FilePath(@"..\..\..\..\resources\americanFootball_352x240_125.yuv"); Assert.True(display.InputIsValid); // Step 3: open the DisplayNode's output and play the video DisplayViewModel output = display.Window; Assert.Equal(display, output.NodeModel); Assert.False(mvm.Model.IsPlaying); mvm.ReplayStateViewModel.PlayPause(); Assert.True(mvm.Model.IsPlaying); // Step 4: Change a node's options while the video is playing blur.Radius = 0; Assert.True(mvm.Model.IsPlaying); Assert.True(display.InputIsValid); // Step 5: change replay speed while video is playing int oldSpeed = mvm.Model.Speed; mvm.ReplayStateViewModel.Slower(); Assert.True(oldSpeed > mvm.Model.Speed); // Step 6: pause the video mvm.ReplayStateViewModel.PlayPause(); Assert.False(mvm.Model.IsPlaying); // Step 7: resumes the video mvm.ReplayStateViewModel.PlayPause(); Assert.True(mvm.Model.IsPlaying); // Step 8: resets the video playing state mvm.ReplayStateViewModel.Stop(); Assert.Equal(0, mvm.Model.CurrentTick); Assert.False(mvm.Model.IsPlaying); // Step 9: save the video as yuv file blurVM.SaveNodeOutput(blur.Outputs[0]); // Since we can't create a FileChooser here, we'll have to invoke the SaveNodeOutputViewModel directly System.IO.MemoryStream stream = new System.IO.MemoryStream(); SaveNodeOutputViewModel saveVM = new SaveNodeOutputViewModel(blur.Outputs[0], stream, mvm.Model); Assert.Equal(mvm.Model.Graph.TickCount, saveVM.TickCount); // I'm sorry for this. I really am. I found no better way of testing this. System.Threading.Thread.Sleep(1000); try { Assert.NotEqual(0, stream.Capacity); } catch (ObjectDisposedException) { // This means the SaveNodeOutputViewModel is already done and has disposed of its stream // That's just another possibility that's just as valid, and signifies proper execution } }
public void Test20() { var posMock = new Mock <IGetPosition>(); posMock.Setup(p => p.GetElementSize(It.IsAny <IViewAware>())).Returns(new Size(4, 4)); posMock.Setup(p => p.ViewLoaded(It.IsAny <IViewAware>())).Returns(Observable.Never <Unit>()); var vm = MainViewModelTest.GetInstance( container => container.ComposeExportedValue <IGetPosition>(posMock.Object) ).PipelineViewModel; // Step 1: User creates a random pipeline with three nodes and one edge connecting them. // Add BlurNode var mock = new Mock <IDragEventInfo>(); mock.Setup(info => info.GetData <NodeType>()).Returns(new NodeType { Type = typeof(BlurNode) }); mock.Setup(info => info.GetPosition(vm)).Returns(new Point(30, 10)); mock.SetupProperty(info => info.Effects, DragDropEffects.Copy); vm.CheckClearance(mock.Object); Assert.Equal(DragDropEffects.Copy, mock.Object.Effects); vm.Drop(mock.Object); var node0 = vm.Nodes.Single(); Assert.True(node0.Model is BlurNode); Assert.Equal(30, node0.Model.X); Assert.Equal(10, node0.Model.Y); //Add Second BlurNode mock = new Mock <IDragEventInfo>(); mock.Setup(info => info.GetData <NodeType>()).Returns(new NodeType { Type = typeof(BlurNode) }); mock.Setup(info => info.GetPosition(vm)).Returns(new Point(40, 10)); mock.SetupProperty(info => info.Effects, DragDropEffects.Copy); vm.CheckClearance(mock.Object); Assert.Equal(DragDropEffects.Copy, mock.Object.Effects); vm.Drop(mock.Object); var node1 = vm.Nodes.Last(); Assert.True(node1.Model is BlurNode); Assert.Equal(40, node1.Model.X); Assert.Equal(10, node1.Model.Y); //Add third BlurNode mock = new Mock <IDragEventInfo>(); mock.Setup(info => info.GetData <NodeType>()).Returns(new NodeType { Type = typeof(BlurNode) }); mock.Setup(info => info.GetPosition(vm)).Returns(new Point(0, 10)); mock.SetupProperty(info => info.Effects, DragDropEffects.Copy); vm.CheckClearance(mock.Object); Assert.Equal(DragDropEffects.Copy, mock.Object.Effects); vm.Drop(mock.Object); var node2 = vm.Nodes.Last(); Assert.True(node1.Model is BlurNode); Assert.Equal(0, node2.Model.X); Assert.Equal(10, node2.Model.Y); //Add Edge posMock.Setup(p => p.GetElementPosition(node0.Outputs.Single(), vm)).Returns(new Point(10, 10)); posMock.Setup(p => p.GetElementPosition(node0.Inputs.Single(), vm)).Returns(new Point(30, 10)); posMock.Setup(p => p.GetElementPosition(node1.Inputs.Single(), vm)).Returns(new Point(40, 10)); posMock.Setup(p => p.GetElementPosition(node2.Inputs.Single(), vm)).Returns(new Point(0, 10)); // Start edge from node0 output Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(node0.Outputs.First())); var edge = vm.DraggedEdge; Assert.Equal(new Point(12, 12), edge.StartPoint); Assert.Equal(new Point(12, 12), edge.EndPoint); Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over node1 input var e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(node1.Inputs.Single(), e); Assert.Equal(new Point(42, 12), edge.EndPoint); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on node1 input vm.InOutputMouseUp(node1.Inputs.Single()); Assert.Equal(new Point(42, 12), vm.Edges.Single().StartPoint); Assert.Equal(new Point(12, 12), vm.Edges.Single().EndPoint); Assert.NotNull(vm.Edges.Single().Geometry); // Step 2: User moves a node via drag-and-drop posMock.Setup(p => p.GetElementPosition(node0.Outputs.Single(), vm)).Returns(new Point(20, 10)); Assert.PropertyChanged(edge, "Geometry", () => node0.Position = new Point(-1, -1) // Trigger ViewPositionChanged ); Assert.Equal(new Point(-1, -1), node0.Position); // Step 3: User changes the end of an edge via drag-and-drop // Pick up edge from node1 input Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(node1.Inputs.First())); edge = vm.DraggedEdge; Assert.Equal(new Point(22, 12), edge.StartPoint); Assert.Equal(new Point(42, 12), edge.EndPoint); Assert.Equal(EdgeStatus.Indeterminate, edge.Status); // Drag edge over node2 input e = new RoutedEventArgs(Mouse.MouseMoveEvent); vm.InOutputMouseMove(node2.Inputs.Single(), e); Assert.Equal(new Point(2, 12), edge.EndPoint); Assert.Equal(EdgeStatus.Valid, edge.Status); // Drop edge on node2 input vm.InOutputMouseUp(node2.Inputs.Single()); Assert.Equal(new Point(2, 12), vm.Edges.Single().StartPoint); Assert.Equal(new Point(22, 12), vm.Edges.Single().EndPoint); Assert.NotNull(vm.Edges.Single().Geometry); // Step 4: user removes an edge // Pick up edge from node2 input Assert.PropertyChanged(vm, "DraggedEdge", () => vm.InOutputMouseDown(node2.Inputs.First())); edge = vm.DraggedEdge; Assert.Equal(new Point(22, 12), edge.StartPoint); Assert.Equal(new Point(2, 12), edge.EndPoint); // drag edge to empty space var mouseMock = new Mock <IMouseEventInfo>(); mouseMock.Setup(m => m.GetPosition(vm)).Returns(new Point(50, 50)); mouseMock.SetupGet(m => m.LeftButton).Returns(MouseButtonState.Pressed); vm.MouseMove(mouseMock.Object); Assert.Equal(EdgeStatus.Indeterminate, edge.Status); Assert.Equal(new Point(50, 50), edge.EndPoint); // let go vm.MouseUp(); Assert.Equal(0, vm.Edges.Count()); // Step 5: user changes the configuration of a manipulation-node ((BlurNode)node0.Model).Radius = 2; // Step 6: user deletes a node Assert.PropertyChanged(vm, "Edges", node0.RemoveNode); Assert.DoesNotContain(node0, vm.Nodes); Assert.DoesNotContain(node0.Model, vm.Parent.Model.Graph.Nodes); }