Пример #1
0
        public async void Patch_No_Errors()
        {
            InvitationControllerMockFacade mock = new InvitationControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiInvitationResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <string>(), It.IsAny <ApiInvitationRequestModel>()))
            .Callback <string, ApiInvitationRequestModel>(
                (id, model) => model.InvitationCode.Should().Be("A")
                )
            .Returns(Task.FromResult <UpdateResponse <ApiInvitationResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiInvitationResponseModel>(new ApiInvitationResponseModel()));
            InvitationController controller = new InvitationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiInvitationModelMapper());

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

            var patch = new JsonPatchDocument <ApiInvitationRequestModel>();

            patch.Replace(x => x.InvitationCode, "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 <ApiInvitationRequestModel>()));
        }
Пример #2
0
        public async void Patch_Record_Not_Found()
        {
            InvitationControllerMockFacade mock = new InvitationControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

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

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