public void Validate_MultipleBodiesSet_ReturnsSingleError(bool jsonBody, bool xmlBody, bool stringBody, string bodyList) { // Arrange var validator = new ResponseValidator(); var json = jsonBody ? new JsonElement?(JsonDocument.Parse("{}").RootElement) : null; string xml = xmlBody ? "<year>1999</year>" : null; string str = stringBody ? "Plain text! Hooray!" : null; var section = new Response { JsonBody = json, XmlBody = xml, StringBody = str }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format($"$", $"Only one type of body can be set per response. {bodyList} are set."), error); }
public void AddError_AddSingleError_FormatsCorrectly() { // Arrange var result = new ValidationResult(); // Act result.AddError(new SectionName("sectionName"), "Something broke"); // Assert var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("sectionName", "Something broke"), error); }
public void Validate_NullSection_ReturnsSingleError() { // Arrange var validator = new EndpointActionValidator(_responseValidator.Object); // Act var result = validator.Validate(null, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$", "Action is null"), error); }
public void Validate_EmptyActions_ReturnsSingleError() { // Arrange var validator = new EndpointActionValidator(_responseValidator.Object); var section = new EndpointAction { Responses = new List <Response>() }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.responses", $"Responses array must have at least one item"), error); }
public void Validate_NullResponses_ReturnsSingleError() { // Arrange var validator = new EndpointActionValidator(_responseValidator.Object); var section = new EndpointAction { Responses = null }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.responses", $"Action must have a responses array"), error); }
public void Validate_NullEndpointsArray_ReturnsSingleError() { // Arrange var validator = new EndpointsRootValidator(_endpointValidator.Object); var section = new EndpointsRoot { Endpoints = null }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.endpoints", "Endpoints array is null"), error); }
public void Validate_InvalidMethod_ReturnsSingleError(string method) { // Arrange var validator = new EndpointActionValidator(_responseValidator.Object); var section = new EndpointAction { Method = method, Responses = _defaultValidResponses }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.method", $"Invalid method '{method}'. Method can only contain A-Z, a-z."), error); }
public void Validate_InvalidMode_ReturnsSingleError(string mode) { // Arrange var validator = new EndpointActionValidator(_responseValidator.Object); var section = new EndpointAction { Mode = mode, Responses = _defaultValidResponses }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.mode", $"Invalid mode '{mode}'. Mode must be one of SINGLE, RANDOM, INTERCEPT."), error); }
public void Validate_InvalidPath_ReturnsSingleError(string path) { // Arrange var validator = new EndpointValidator(_actionValidator.Object); var section = new Endpoint { Path = path, Actions = _defaultValidActionList }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.path", $"Invalid path '{path}'. Path can only contain A-Z, a-z, 0-9 and slashes (/)."), error); }
public void Validate_NullAndWhitespacePath_ReturnsSingleError(string path) { // Arrange var validator = new EndpointValidator(_actionValidator.Object); var section = new Endpoint { Path = path, Actions = _defaultValidActionList }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.path", "Endpoint must have a path"), error); }
public void Validate_NullActions_ReturnsSingleError() { // Arrange var validator = new EndpointValidator(_actionValidator.Object); var section = new Endpoint { Path = _defaultValidPath, Actions = null }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format("$.actions", $"Endpoints must have an actions array"), error); }
public void Validate_SingleNonAsciiHeaderValue_ReturnsSingleError(string key, string value) { // Arrange var validator = new ResponseValidator(); var section = new Response { Headers = new Dictionary <string, string> { { key, value } } }; // Act var result = validator.Validate(section, _name); // Assert Assert.True(result.HasErrors); var error = Assert.Single(result.Errors); Assert.Equal(ErrorMessageFormatter.Format($"$.headers[{key}]", $"Invalid header value '{value}'. Headers can only contain ASCII characters."), error); }