Exemplo n.º 1
0
        public void ExecutePatchCallsDatabaseGateway()
        {
            var updateWorkerRequest = TestHelpers.CreateUpdateWorkersRequest();

            _mockWorkerGateway
            .Setup(x => x.GetWorkerByWorkerId(updateWorkerRequest.WorkerId))
            .Returns(TestHelpers.CreateWorker().ToDomain(true));

            _mockDatabaseGateway.Setup(x => x.UpdateWorker(updateWorkerRequest));

            _workersUseCase.ExecutePatch(updateWorkerRequest);

            _mockDatabaseGateway.Verify(x => x.UpdateWorker(updateWorkerRequest));
            _mockDatabaseGateway.Verify(x => x.UpdateWorker(It.Is <UpdateWorkerRequest>(w => w == updateWorkerRequest)), Times.Once());
        }
Exemplo n.º 2
0
        public IActionResult EditWorker([FromBody] UpdateWorkerRequest request)
        {
            var validator         = new UpdateWorkerRequestValidator();
            var validationResults = validator.Validate(request);

            if (!validationResults.IsValid)
            {
                return(BadRequest(validationResults.ToString()));
            }

            try
            {
                _workersUseCase.ExecutePatch(request);
                return(NoContent());
            }
            catch (PatchWorkerException e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (WorkerNotFoundException e)
            {
                return(UnprocessableEntity(e.Message));
            }
        }