Exemplo n.º 1
0
        public PointsList RemovePoint(RemovePointFromListRequest model)
        {
            var pointsList = _unitOfWork.PointsListRepository.Get(model.PointsListId);

            if (pointsList == null)
            {
                throw new NotFoundException("Points list does not exist");
            }

            var pointToRemove = new Point {
                X = model.X, Y = model.Y
            };

            if (!pointsList.Points.Contains(pointToRemove))
            {
                throw new NotFoundException("Point does not exist in the list");
            }

            _unitOfWork.PointsListRepository.RemovePoint(pointsList, pointToRemove);
            //O(Squares.Count) now instead of O(points.Count^2) later
            _unitOfWork.PointsListRepository.UpdateSquares(pointsList,
                                                           RemoveSquaresAfterDeletedPoint(pointsList.Squares, pointToRemove));
            _unitOfWork.Commit();

            return(pointsList);
        }
Exemplo n.º 2
0
 public IActionResult RemovePoint(RemovePointFromListRequest model)
 {
     try
     {
         return(Ok(_pointsListService.RemovePoint(model)));
     }
     catch (NotFoundException e)
     {
         return(NotFound(e.Message));
     }
 }
Exemplo n.º 3
0
        public void RemovePoint_PointExists_CallsRepoMethod()
        {
            // Arrange
            var mockedService = this.CreateServiceMock();

            mockedService.Setup(s => s.RemoveSquaresAfterDeletedPoint(It.IsAny <List <Square> >(), It.IsAny <Point>())).Returns(new List <Square>());
            mockPointsListRepository.Setup(r => r.RemovePoint(It.IsAny <PointsList>(), It.IsAny <Point>()));
            mockPointsListRepository.Setup(r => r.UpdateSquares(It.IsAny <PointsList>(), It.IsAny <List <Square> >()));
            RemovePointFromListRequest model = new RemovePointFromListRequest {
                PointsListId = 1, X = 0, Y = 0
            };

            // Act
            var result = mockedService.Object.RemovePoint(model);

            // Assert
            mockPointsListRepository.Verify(x => x.RemovePoint(It.IsAny <PointsList>(), new Point {
                X = 0, Y = 0
            }), Times.Exactly(1));
            mockedService.Verify(x => x.RemoveSquaresAfterDeletedPoint(It.IsAny <List <Square> >(), It.IsAny <Point>()), Times.Exactly(1));
        }