private static IReadOnlyCollection <ImageSizeParam> ParseImageSizeParameters(HttpRequestMessage request) { NameValueCollection queryString = request.RequestUri.ParseQueryString(); string[] sizeParams = queryString.GetValues("size"); if (sizeParams == null || sizeParams.Length == 0) { throw new ArgumentException { Data = { { "ValidationData", new { Query = new { Size = "Required" } } } } } } ; return(sizeParams.Select(sizeParam => { if (!ImageSizeParam.TryParse(sizeParam, out ImageSizeParam size)) { throw new ArgumentException { Data = { { "ValidationData", new { Query = new { Size = "Incorrect size format. It should be \"${width}x${height}q${quality}\"" } } } } } } ; return size; }).ToList()); }
public void ShouldFailForWrongParameters(string input) { bool parsed = ImageSizeParam.TryParse(input, out ImageSizeParam size); Assert.False(parsed); }