public async void Patch_No_Errors() { ProjectGroupControllerMockFacade mock = new ProjectGroupControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiProjectGroupResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(true); mock.ServiceMock.Setup(x => x.Update(It.IsAny <string>(), It.IsAny <ApiProjectGroupRequestModel>())) .Callback <string, ApiProjectGroupRequestModel>( (id, model) => model.JSON.Should().Be("A") ) .Returns(Task.FromResult <UpdateResponse <ApiProjectGroupResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiProjectGroupResponseModel>(new ApiProjectGroupResponseModel())); ProjectGroupController controller = new ProjectGroupController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiProjectGroupModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiProjectGroupRequestModel>(); patch.Replace(x => x.JSON, "A"); IActionResult response = await controller.Patch(default(string), patch); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); mock.ServiceMock.Verify(x => x.Update(It.IsAny <string>(), It.IsAny <ApiProjectGroupRequestModel>())); }
public async void Patch_Record_Not_Found() { ProjectGroupControllerMockFacade mock = new ProjectGroupControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiProjectGroupResponseModel>(null)); ProjectGroupController controller = new ProjectGroupController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiProjectGroupRequestModel>(); patch.Replace(x => x.JSON, "A"); IActionResult response = await controller.Patch(default(string), patch); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <string>())); }