public async Task PostPoint_Should_ReturnOk()
        {
            // Arrange
            var adapterMock = new Mock <ITodoPointAdapter>();
            var loggerMock  = new Mock <ILogger <PointController> >();

            var testPoint = new TodoPointViewModel
            {
                PointId     = 3,
                TodoId      = 2,
                Description = "test point 3"
            };

            adapterMock.Setup(x => x.AddPoint(testPoint)).Returns(Task.FromResult(testPoint));
            var controller = new PointController(adapterMock.Object, loggerMock.Object);

            // Act
            var result = await controller.PostPoint(testPoint);

            // Assert
            var okResult    = Assert.IsAssignableFrom <OkObjectResult>(result);
            var returnValue = Assert.IsAssignableFrom <TodoPointViewModel>(okResult.Value);

            Assert.Equal(testPoint.Description, returnValue.Description);
        }
        public async Task <IActionResult> PutPoint(int id, [FromBody] TodoPointViewModel pointModel)
        {
            try
            {
                if (pointModel == null)
                {
                    logger.LogError("Point object sent from client is null.");
                    return(BadRequest("Point object is null"));
                }

                if (pointModel.IsCompleted == true && pointModel.DateOfComplition == null)
                {
                    pointModel.DateOfComplition = DateTime.UtcNow;
                }

                if (pointModel.IsCompleted == false && pointModel.DateOfComplition != null)
                {
                    pointModel.DateOfComplition = null;
                }

                await todoPointAdapter.UpdatePoint(pointModel);

                return(Ok(pointModel));
            }
            catch (Exception ex)
            {
                logger.LogError($"Something went wrong inside PutPoint action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task DeletePoint_Should_ReturnOk()
        {
            // Arrange
            var adapterMock = new Mock <ITodoPointAdapter>();
            var loggerMock  = new Mock <ILogger <PointController> >();

            var testPoint = new TodoPointViewModel
            {
                PointId     = 2,
                TodoId      = 1,
                Description = "test point 2"
            };
            var testPoints = GetTestPoints();

            adapterMock.Setup(x => x.DeletePoint(It.IsAny <int>()))
            .Callback(() => testPoints.Remove(testPoints.Where(x => x.PointId == testPoint.PointId).FirstOrDefault()));

            var controller = new PointController(adapterMock.Object, loggerMock.Object);

            // Act
            var result = await controller.DeletePoint(testPoint.PointId, testPoint);

            // Assert
            var actionResult = Assert.IsAssignableFrom <ActionResult <TodoPointViewModel> >(result);
            var returnValue  = Assert.IsAssignableFrom <OkResult>(actionResult.Result);

            Assert.Single(testPoints);
        }
        public async Task PutPoint_Should_ReturnOk()
        {
            // Arrange
            var adapterMock = new Mock <ITodoPointAdapter>();
            var loggerMock  = new Mock <ILogger <PointController> >();

            var testPoint = new TodoPointViewModel
            {
                PointId     = 2,
                TodoId      = 1,
                Description = "Updated"
            };
            var testPoints = GetTestPoints();

            adapterMock.Setup(x => x.UpdatePoint(It.IsAny <TodoPointViewModel>()))
            .Callback(() =>
            {
                var point         = testPoints.Where(x => x.PointId == testPoint.PointId).FirstOrDefault();
                point.Description = testPoint.Description;
            });

            var controller = new PointController(adapterMock.Object, loggerMock.Object);

            // Act
            var result = await controller.PutPoint(testPoint.PointId, testPoint);

            var pointAfterUpdate = testPoints.Where(x => x.PointId == testPoint.PointId).FirstOrDefault();

            // Assert
            var okResult    = Assert.IsAssignableFrom <OkObjectResult>(result);
            var returnValue = Assert.IsAssignableFrom <TodoPointViewModel>(okResult.Value);

            Assert.Equal(testPoint.Description, pointAfterUpdate.Description);
            Assert.Equal(2, testPoints.Count);
        }
        public async Task <ActionResult <TodoPointViewModel> > DeletePoint(int id, [FromBody] TodoPointViewModel pointModel)
        {
            try
            {
                await todoPointAdapter.DeletePoint(pointModel.PointId);

                return(Ok());
            }
            catch (Exception ex)
            {
                logger.LogError($"Something went wrong inside DeletePoint action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <ActionResult> PostPoint([FromBody] TodoPointViewModel pointModel)
        {
            try
            {
                if (pointModel == null)
                {
                    logger.LogError("Point object sent from client is null.");
                    return(BadRequest("Point object is null"));
                }
                await todoPointAdapter.AddPoint(pointModel);

                return(Ok(pointModel));
            }
            catch (Exception ex)
            {
                logger.LogError($"Something went wrong inside PostPoint action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
 public async Task UpdatePoint(TodoPointViewModel todoPointViewModel)
 {
     var updatedTodo = mapper.Map <TodoPoint>(todoPointViewModel);
     await todoPointService.UpdateAsync(updatedTodo);
 }
 public async Task AddPoint(TodoPointViewModel todoPointViewModel)
 {
     await todoPointService.CreateAsync(mapper.Map <TodoPoint>(todoPointViewModel));
 }