private void CheckInvalidParse(string input) { Assert.Throws <FormatException>(() => { StringWithQualityHeaderValue.Parse(input); }); Assert.False(StringWithQualityHeaderValue.TryParse(input, out StringWithQualityHeaderValue result)); Assert.Null(result); }
public void TryParse_Invalid() { StringWithQualityHeaderValue res; Assert.IsFalse(StringWithQualityHeaderValue.TryParse("", out res), "#1"); Assert.IsNull(res, "#2"); }
private void CheckInvalidTryParse(string input) { StringWithQualityHeaderValue result = null; Assert.False(StringWithQualityHeaderValue.TryParse(input, out result)); Assert.Null(result); }
private void CheckValidTryParse(string input, StringWithQualityHeaderValue expectedResult) { StringWithQualityHeaderValue result = null; Assert.True(StringWithQualityHeaderValue.TryParse(input, out result)); Assert.Equal(expectedResult, result); }
public void TryParse() { StringWithQualityHeaderValue res; Assert.IsTrue(StringWithQualityHeaderValue.TryParse("a", out res), "#1"); Assert.AreEqual("a", res.Value, "#2"); Assert.IsNull(res.Quality, "#3"); }
private void CheckValidParse(string input, StringWithQualityHeaderValue expectedResult) { StringWithQualityHeaderValue result = StringWithQualityHeaderValue.Parse(input); Assert.Equal(expectedResult, result); Assert.True(StringWithQualityHeaderValue.TryParse(input, out result)); Assert.Equal(expectedResult, result); // New lines are never allowed for (int i = 0; i < input.Length; i++) { CheckInvalidParse(input.Insert(i, "\r")); CheckInvalidParse(input.Insert(i, "\n")); CheckInvalidParse(input.Insert(i, "\r\n")); CheckInvalidParse(input.Insert(i, "\r\n ")); } }
public static IEnumerable <StringWithQualityHeaderValue> GetAcceptLanguage(this IHttpRequest req) => req.GetHeaders("Accept-Language") .TryWhere( (string acceptString, out StringWithQualityHeaderValue acceptHeader) => StringWithQualityHeaderValue.TryParse(acceptString, out acceptHeader)) .Select(tpl => tpl.@out);