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 PutPoint_Should_ReturnBadRequest() { // Arrange var adapterMock = new Mock <ITodoPointAdapter>(); var loggerMock = new Mock <ILogger <PointController> >(); var controller = new PointController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.PutPoint(5, null); // Assert var actionResult = Assert.IsAssignableFrom <IActionResult>(result); var returnValue = Assert.IsAssignableFrom <BadRequestObjectResult>(actionResult); Assert.Equal("Point object is null", returnValue.Value); }