public UpdateSourceCommand Map(UpdateSourceRequest request) { var id = new Guid(request.RouteId); var valuePairs = _jsonProvider.ToDictionary(request.BodyPatch); Optional <string> name = valuePairs.GetOptional("name"); Optional <string> description = valuePairs.GetOptional("description"); Optional <IEnumerable <string> > sourceBusinessUnits = valuePairs.GetOptionalEnumerable("businessUnits"); var version = ToVersion(request.HeaderIfMatch); var result = new UpdateSourceCommand(id, name, description, sourceBusinessUnits, version); return(result); }
public void ShouldContainNoErrorsWhenNoBusinessUnits() { // Arrange var id = Guid.NewGuid(); Optional <string> name = new Optional <string>("Name"); Optional <string> description = new Optional <string>("Description"); var businessUnits = new Optional <IEnumerable <string> >(new List <string>()); var version = 0; var command = new UpdateSourceCommand(id, name, description, businessUnits, version); // Act var validationResult = _validator.Validate(command); var exists = validationResult.Errors.Count > 0; // Assert exists.Should().BeFalse(); }
public void ShouldHaveFlowNameCannotStartOrEndWithWhiteSpaceValidationErrorWhenNameStartsOrEndsWithWhiteSpace(string symbols) { // Arrange var id = Guid.NewGuid(); Optional <string> name = new Optional <string>(symbols); Optional <string> description = new Optional <string>("description"); var businessUnits = new Optional <IEnumerable <string> >(new List <string>()); var version = 0; var command = new UpdateSourceCommand(id, name, description, businessUnits, version); // Act var validationResult = _validator.Validate(command); var exists = validationResult.Errors.Any(a => a.PropertyName.Equals("Name") && a.ErrorMessage.Contains(ValidationFailures.SourceNameCannotStartOrEndWithWhiteSpace)); // Assert exists.Should().BeTrue(); }
public void ShouldHaveSourceNameCannotBeEmptyValidationFailureWhenNameIsEmpty() { // Arrange var id = Guid.NewGuid(); Optional <string> name = new Optional <string>(string.Empty); Optional <string> description = new Optional <string>("Description"); var businessUnits = new Optional <IEnumerable <string> >(new List <string>()); var version = 0; var command = new UpdateSourceCommand(id, name, description, businessUnits, version); // Act var validationResult = _validator.Validate(command); var exists = validationResult.Errors.Any( a => a.PropertyName.Equals("Name") && a.ErrorMessage.Contains(ValidationFailures.SourceNameCannotBeEmpty)); // Assert exists.Should().BeTrue(); }