[InlineData("2147483647", 2147483647)] // int.MaxValue public void TryParseNonNegativeInt32_Succeeds(string valueString, long expected) { int value = 1; Assert.True(HeaderUtilities.TryParseNonNegativeInt32(valueString, out value)); Assert.Equal(expected, value); }
[InlineData("2147483648")] // int.MaxValue + 1 public void TryParseNonNegativeInt32_Fails(string valueString) { int value = 1; Assert.False(HeaderUtilities.TryParseNonNegativeInt32(valueString, out value)); Assert.Equal(0, value); }
private static int?GetNullableNonNegativeInt32HeaderValue(this HttpRequest request, string headerName) { int?headerValue = null; StringValues rawHeaderValues = request.Headers[headerName]; if (!StringValues.IsNullOrEmpty(rawHeaderValues)) { int parsedHeaderValue; if (HeaderUtilities.TryParseNonNegativeInt32(rawHeaderValues[rawHeaderValues.Count - 1], out parsedHeaderValue)) { headerValue = parsedHeaderValue; } } return(headerValue); }
private static bool TrySetTimeSpan(NameValueHeaderValue nameValue, ref TimeSpan?timeSpan) { if (nameValue.Value == null) { return(false); } int seconds; if (!HeaderUtilities.TryParseNonNegativeInt32(nameValue.Value, out seconds)) { return(false); } timeSpan = new TimeSpan(0, 0, seconds); return(true); }