Exemplo n.º 1
0
        public void WhenConsecutiveCommandExecuted_StartAndEndPointSet()
        {
            //Prepare
            Size size = new Size { Height = 500, Width = 500 };
            Point[] line = new Point[] { new Point { X = 1, Y = 2 }, new Point { X = 3, Y = 4 } };
            LineQueryResult lineQueryResult = new LineQueryResult { Result = line, Success = true };

            Mock<ILineService> mockedLineService = new Mock<ILineService>();
            mockedLineService.Setup(x => x.GetCanvasSize()).Returns(size).Verifiable();
            mockedLineService.Setup(x => x.AddLineAsync(
                It.Is<Point>(y => y.X == 0 && y.Y == 0),
                It.Is<Point>(y => y.X == 0 && y.Y == 0),
                It.IsAny<PathAlgorithm>(),
                It.IsAny<CancellationToken>())).ReturnsAsync(lineQueryResult).Verifiable();

            mockedLineService.Setup(x => x.SelectPoint(It.Is<Point>(y => y.X == 0 && y.Y == 0))).
                Returns((Point y) => new PointQueryResult { Result = y, Success = true }).Verifiable();

            CanvasViewModel target = new CanvasViewModel(mockedLineService.Object);

            //Act
            MouseEventArgs e = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
            target.SelectPointCommand.Execute(e);
            target.SelectPointCommand.Execute(e);

            //Verify
            Assert.IsNull(target.StartPoint);
            Assert.IsNull(target.EndPoint);
            Assert.AreEqual(1, target.Lines.Count);
            Assert.AreEqual(1, target.Lines[0][0].X);
            Assert.AreEqual(2, target.Lines[0][0].Y);
            Assert.AreEqual(3, target.Lines[0][1].X);
            Assert.AreEqual(4, target.Lines[0][1].Y);
            mockedLineService.VerifyAll();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Compute and add a line to the underlying canvas model
 /// based on the submitted start and end points using selected .
 /// </summary>
 /// <param name="startPoint">The line start point.</param>
 /// <param name="endPoint">The line end point.</param>
 /// <param name="algorithm">Pathfinding algorithm to use, defualt is BFS.</param>
 /// <returns>The result of the operation.</returns>
 public LineQueryResult AddLine(Point startPoint, Point endPoint, PathAlgorithm algorithm = PathAlgorithm.BFS)
 {
     LineQueryResult result = new LineQueryResult();
     try
     {
         Stopwatch timer = new Stopwatch();
         timer.Start();
         Point[] computedLine = this.canvasModel.AddLine(startPoint, endPoint, algorithm);
         timer.Stop();
         result.Result = computedLine;
         result.Success = true;
         result.Time = timer.ElapsedMilliseconds;
     }
     catch (Exception ex)
     {
         Debug.Print(string.Format("Unable to add line: {0}", ex.Message));
         result.Message = string.Format("Unable to find a path between points using {0} algorithm.", algorithm);
         result.Success = false;
     }
     return result;
 }