示例#1
0
        public async void Patch_No_Errors()
        {
            ActionTemplateControllerMockFacade mock = new ActionTemplateControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiActionTemplateResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <string>(), It.IsAny <ApiActionTemplateRequestModel>()))
            .Callback <string, ApiActionTemplateRequestModel>(
                (id, model) => model.ActionType.Should().Be("A")
                )
            .Returns(Task.FromResult <UpdateResponse <ApiActionTemplateResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiActionTemplateResponseModel>(new ApiActionTemplateResponseModel()));
            ActionTemplateController controller = new ActionTemplateController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiActionTemplateModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiActionTemplateRequestModel>();

            patch.Replace(x => x.ActionType, "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 <ApiActionTemplateRequestModel>()));
        }
示例#2
0
        public async void Patch_Record_Not_Found()
        {
            ActionTemplateControllerMockFacade mock = new ActionTemplateControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiActionTemplateResponseModel>(null));
            ActionTemplateController controller = new ActionTemplateController(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 <ApiActionTemplateRequestModel>();

            patch.Replace(x => x.ActionType, "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>()));
        }