コード例 #1
0
ファイル: PipelineViewModelTest.cs プロジェクト: Kha/YUV.KA
        public void CanAddInput()
        {
            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>());

            PipelineViewModel vm = MainViewModelTest.GetInstance(
                container => container.ComposeExportedValue <IGetPosition>(posMock.Object)
                ).PipelineViewModel;

            var node0 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node0);
            vm.Parent.Model.Graph.AddNode(node0.Model);
            var node1 = new NodeViewModel(new WeightedAveragedMergeNode(), vm);

            vm.Nodes.Add(node1);
            vm.Parent.Model.Graph.AddNode(node1.Model);

            Assert.Equal(0, node1.Model.Inputs.Count);
            Assert.Equal(1, node1.Inputs.Count());

            vm.InOutputMouseDown(node0.Outputs.First());
            vm.InOutputMouseUp(node1.Inputs.Last());

            Assert.Equal(1, node1.Model.Inputs.Count);
            Assert.Equal(2, node1.Inputs.Count());
            Assert.Equal(node1.Inputs.First(), vm.Edges.Single().StartViewModel);
        }
コード例 #2
0
ファイル: PipelineViewModelTest.cs プロジェクト: Kha/YUV.KA
        public void CanDragEdge()
        {
            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>());

            PipelineViewModel vm = MainViewModelTest.GetInstance(
                container => container.ComposeExportedValue <IGetPosition>(posMock.Object)
                ).PipelineViewModel;

            var node0 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node0);
            vm.Parent.Model.Graph.AddNode(node0.Model);
            var node1 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node1);
            vm.Parent.Model.Graph.AddNode(node1.Model);

            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));

            // 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);

            // Move node0

            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(22, 12), edge.StartPoint);
            Assert.Equal(new Point(22, 12), edge.EndPoint);

            // Drag edge

            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);

            // Drag edge over node0 input

            var e = new RoutedEventArgs(Mouse.MouseMoveEvent);

            vm.InOutputMouseMove(node0.Inputs.Single(), e);

            Assert.Equal(new Point(32, 12), edge.EndPoint);
            Assert.Equal(EdgeStatus.Invalid, edge.Status);

            // Drag edge over node1 input

            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(22, 12), vm.Edges.Single().EndPoint);
            Assert.NotNull(vm.Edges.Single().Geometry);
        }