public void UpdateWorkerReturnsIsNotValidForInvalidRequest()
        {
            const string longEmail = "*****@*****.**";

            var badRequests = new List <(UpdateWorkerRequest, string)>
            {
                (TestHelpers.CreateUpdateWorkersRequest(workerId: 0), "Worker id must be grater than 0"),
                (TestHelpers.CreateUpdateWorkersRequest(modifiedBy: ""), "Created by email address must be valid"),
                (TestHelpers.CreateUpdateWorkersRequest(modifiedBy: longEmail), "Created by email address must be no longer than 62 characters"),
                (TestHelpers.CreateUpdateWorkersRequest(firstName: ""), "First name must be provided"),
                (TestHelpers.CreateUpdateWorkersRequest(firstName: _faker.Random.String2(101)), "First name must be no longer than 100 characters"),
                (TestHelpers.CreateUpdateWorkersRequest(lastName: ""), "Last name must be provided"),
                (TestHelpers.CreateUpdateWorkersRequest(lastName: _faker.Random.String2(101)), "Last name must be no longer than 100 characters"),
                (TestHelpers.CreateUpdateWorkersRequest(contextFlag: ""), $"Context flag must be provided{Environment.NewLine}Context flag must be 'A' or 'C'"),
                (TestHelpers.CreateUpdateWorkersRequest(contextFlag: _faker.Random.String2(2, "AC")), "Context flag must be no longer than 1 character"),
                (TestHelpers.CreateUpdateWorkersRequest(contextFlag: "B"), "Context flag must be 'A' or 'C'"),
                (TestHelpers.CreateUpdateWorkersRequest(role: _faker.Random.String2(201)), "Role provided is too long (more than 200 characters)"),
                (TestHelpers.CreateUpdateWorkersRequest(dateStart: DateTime.Now.AddMinutes(1)), "Date cannot be set in the future"),
                (TestHelpers.CreateUpdateWorkersRequest(teamName: _faker.Random.String2(201)), "Team name must be no more than 200 characters"),
                (TestHelpers.CreateUpdateWorkersRequest(teamId: 0), "Team ID must be greater than 0")
            };

            var validator = new UpdateWorkerRequestValidator();

            foreach (var(request, errorMessage) in badRequests)
            {
                var validationResponse = validator.Validate(request);

                validationResponse.IsValid.Should().Be(false);
                validationResponse.ToString().Should().Be(errorMessage);
            }
        }
        public void UpdateWorkerReturnsIsValidForValidRequest()
        {
            var request   = TestHelpers.CreateUpdateWorkersRequest();
            var validator = new UpdateWorkerRequestValidator();

            var validationResponse = validator.Validate(request);

            validationResponse.IsValid.Should().Be(true);
        }
Exemplo n.º 3
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));
            }
        }