public async void Patch_No_Errors()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiDocumentResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <Guid>(), It.IsAny <ApiDocumentRequestModel>()))
            .Callback <Guid, ApiDocumentRequestModel>(
                (id, model) => model.ChangeNumber.Should().Be(1)
                )
            .Returns(Task.FromResult <UpdateResponse <ApiDocumentResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).Returns(Task.FromResult <ApiDocumentResponseModel>(new ApiDocumentResponseModel()));
            DocumentController controller = new DocumentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiDocumentModelMapper());

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

            var patch = new JsonPatchDocument <ApiDocumentRequestModel>();

            patch.Replace(x => x.ChangeNumber, 1);

            IActionResult response = await controller.Patch(default(Guid), patch);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            mock.ServiceMock.Verify(x => x.Update(It.IsAny <Guid>(), It.IsAny <ApiDocumentRequestModel>()));
        }
        public async void BulkInsert_No_Errors()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();

            var mockResponse = new CreateResponse <ApiDocumentResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiDocumentResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiDocumentRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiDocumentResponseModel> >(mockResponse));
            DocumentController controller = new DocumentController(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 records = new List <ApiDocumentRequestModel>();

            records.Add(new ApiDocumentRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as List <ApiDocumentResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDocumentRequestModel>()));
        }
        public async void Get_Not_Exists()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).Returns(Task.FromResult <ApiDocumentResponseModel>(null));
            DocumentController controller = new DocumentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

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

            IActionResult response = await controller.Get(default(Guid));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <Guid>()));
        }
        public async void Delete_Errors()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <Guid>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            DocumentController controller = new DocumentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

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

            IActionResult response = await controller.Delete(default(Guid));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <Guid>()));
        }
        public async void All_Not_Exists()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();

            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiDocumentResponseModel> >(new List <ApiDocumentResponseModel>()));
            DocumentController controller = new DocumentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

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

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiDocumentResponseModel>;

            items.Should().BeEmpty();
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        public async void Update_NotFound()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiDocumentResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <Guid>(), It.IsAny <ApiDocumentRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiDocumentResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).Returns(Task.FromResult <ApiDocumentResponseModel>(null));
            DocumentController controller = new DocumentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiDocumentModelMapper());

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

            IActionResult response = await controller.Update(default(Guid), new ApiDocumentRequestModel());

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <Guid>()));
        }
        public async void Patch_Record_Not_Found()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).Returns(Task.FromResult <ApiDocumentResponseModel>(null));
            DocumentController controller = new DocumentController(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 <ApiDocumentRequestModel>();

            patch.Replace(x => x.ChangeNumber, 1);

            IActionResult response = await controller.Patch(default(Guid), patch);

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <Guid>()));
        }
        public async void Create_Errors()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiDocumentResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiDocumentResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiDocumentRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiDocumentResponseModel> >(mockResponse.Object));
            DocumentController controller = new DocumentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

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

            IActionResult response = await controller.Create(new ApiDocumentRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDocumentRequestModel>()));
        }