private void CheckInvalidParse(string input) { Assert.Throws <FormatException>(() => { TransferCodingWithQualityHeaderValue.Parse(input); }); Assert.False(TransferCodingWithQualityHeaderValue.TryParse(input, out TransferCodingWithQualityHeaderValue result)); Assert.Null(result); }
private void CheckInvalidTryParse(string input) { TransferCodingWithQualityHeaderValue result = null; Assert.False(TransferCodingWithQualityHeaderValue.TryParse(input, out result)); Assert.Null(result); }
public void Parse_SetOfValidValueStrings_ParsedCorrectly() { TransferCodingWithQualityHeaderValue expected = new TransferCodingWithQualityHeaderValue("custom"); CheckValidParse(" custom ", expected); CheckValidParse("custom", expected); // We don't have to test all possible input strings, since most of the pieces are handled by other parsers. // The purpose of this test is to verify that these other parsers are combined correctly to build a // transfer-coding parser. expected.Parameters.Add(new NameValueHeaderValue("name", "value")); CheckValidParse(" custom ; name = value ", expected); CheckValidParse(" custom;name=value", expected); CheckValidParse(" custom ; name=value", expected); TransferCodingWithQualityHeaderValue value1 = new TransferCodingWithQualityHeaderValue("custom1"); value1.Parameters.Add(new NameValueHeaderValue("param1", "value1")); value1.Quality = 1.0; CheckValidParse("custom1 ; param1 =value1 ; q= 1.0 ", value1); TransferCodingWithQualityHeaderValue value2 = new TransferCodingWithQualityHeaderValue("custom2"); value2.Parameters.Add(new NameValueHeaderValue("param2", "value2")); value2.Quality = 0.5; CheckValidParse(" custom2; param2= value2; q =0.5 ", value2); }
public void Ctor() { var v = new TransferCodingWithQualityHeaderValue("value"); Assert.AreEqual("value", v.Value, "#1"); Assert.IsNull(v.Quality); }
private void CheckValidTryParse(string input, TransferCodingWithQualityHeaderValue expectedResult) { TransferCodingWithQualityHeaderValue result = null; Assert.True(TransferCodingWithQualityHeaderValue.TryParse(input, out result)); Assert.Equal(expectedResult, result); }
static GrpcProtocolConstants() { var userAgent = "grpc-dotnet"; // Use the assembly file version in the user agent. // We are not using `AssemblyInformationalVersionAttribute` because Source Link appends // the git hash to it, and sending a long user agent has perf implications. var assemblyVersion = typeof(GrpcProtocolConstants) .Assembly .GetCustomAttributes <AssemblyFileVersionAttribute>() .FirstOrDefault(); Debug.Assert(assemblyVersion != null); // Assembly file version attribute should always be present, // but in case it isn't then don't include version in user-agent. if (assemblyVersion != null) { userAgent += "/" + assemblyVersion.Version; } UserAgentHeader = ProductInfoHeaderValue.Parse(userAgent); TEHeader = new TransferCodingWithQualityHeaderValue("trailers"); DefaultMessageAcceptEncodingValue = IdentityGrpcEncoding + "," + string.Join(',', DefaultCompressionProviders.Select(p => p.Key)); }
public void Ctor_AddValueAndQuality_QualityParameterAdded() { TransferCodingWithQualityHeaderValue mediaType = new TransferCodingWithQualityHeaderValue("custom", 0.08); Assert.Equal(0.08, mediaType.Quality); Assert.Equal("custom", mediaType.Value); Assert.Equal(1, mediaType.Parameters.Count); }
public void Parse_Invalid() { try { TransferCodingWithQualityHeaderValue.Parse(null); Assert.Fail("#1"); } catch (FormatException) { } try { TransferCodingWithQualityHeaderValue.Parse(" "); Assert.Fail("#2"); } catch (FormatException) { } }
public void Parse() { var res = TransferCodingWithQualityHeaderValue.Parse("1.1"); Assert.AreEqual(0, res.Parameters.Count, "#1"); Assert.IsNull(res.Quality, "#1b"); Assert.AreEqual("1.1", res.Value, "#1c"); Assert.AreEqual("1.1", res.ToString(), "#1d"); res = TransferCodingWithQualityHeaderValue.Parse("a ; b "); Assert.AreEqual(1, res.Parameters.Count, "#2"); Assert.IsNull(res.Quality, "#2b"); Assert.AreEqual("a", res.Value, "#2c"); Assert.AreEqual("a; b", res.ToString(), "#2d"); }
public void Properties_Invalid() { try { new TransferCodingWithQualityHeaderValue("value", 4); Assert.Fail("#1"); } catch (ArgumentOutOfRangeException) { } var v = new TransferCodingWithQualityHeaderValue("value"); try { v.Quality = -1; Assert.Fail("#2"); } catch (ArgumentOutOfRangeException) { } }
public void Properties() { var v = new TransferCodingWithQualityHeaderValue("value", 0.412); Assert.AreEqual("value", v.Value, "#1"); Assert.AreEqual(0.412, v.Quality, "#2"); Assert.AreEqual("0.412", v.Parameters.First().Value, "#3"); v.Parameters.Add(new NameValueHeaderValue("q", "0.2")); Assert.AreEqual(0.412, v.Quality, "#4"); v = new TransferCodingWithQualityHeaderValue("value"); v.Parameters.Add(new NameValueHeaderValue("q", "0.112")); Assert.AreEqual(0.112, v.Quality, "#5"); v = new TransferCodingWithQualityHeaderValue("value"); v.Parameters.Add(new NameValueHeaderValue("q", "test")); Assert.IsNull(v.Quality, "#6"); }
public void Equals() { var tfhv = new TransferCodingWithQualityHeaderValue("abc"); Assert.AreEqual(tfhv, new TransferCodingWithQualityHeaderValue("abc"), "#1"); Assert.AreEqual(tfhv, new TransferCodingWithQualityHeaderValue("AbC"), "#2"); Assert.AreNotEqual(tfhv, new TransferCodingWithQualityHeaderValue("ab"), "#3"); Assert.AreNotEqual(tfhv, new TransferCodingWithQualityHeaderValue("ab", 1), "#3"); tfhv = new TransferCodingWithQualityHeaderValue("abc", 0.3); Assert.AreEqual(tfhv, new TransferCodingWithQualityHeaderValue("abc", 0.3), "#4"); Assert.AreEqual(tfhv, new TransferCodingWithQualityHeaderValue("AbC", 0.3), "#5"); Assert.AreNotEqual(tfhv, new TransferCodingWithQualityHeaderValue("abc"), "#6"); var custom_param = new TransferCodingHeaderValue("abc"); custom_param.Parameters.Add(new NameValueHeaderValue("q", "0.3")); Assert.AreEqual(tfhv, custom_param, "#7"); }
static GrpcProtocolConstants() { var userAgent = "grpc-dotnet"; var assemblyVersion = typeof(GrpcProtocolConstants) .Assembly .GetCustomAttributes <AssemblyInformationalVersionAttribute>() .FirstOrDefault(); Debug.Assert(assemblyVersion != null); // assembly version attribute should always be present // but in case it isn't then don't include version in user-agent if (assemblyVersion != null) { userAgent += "/" + assemblyVersion.InformationalVersion; } UserAgentHeader = ProductInfoHeaderValue.Parse(userAgent); TEHeader = new TransferCodingWithQualityHeaderValue("trailers"); }
public void Clone_Call_CloneFieldsMatchSourceFields() { // This test just verifies that TransferCodingWithQualityHeaderValue calls the correct base implementation. TransferCodingWithQualityHeaderValue source = new TransferCodingWithQualityHeaderValue("custom"); TransferCodingWithQualityHeaderValue clone = (TransferCodingWithQualityHeaderValue) ((ICloneable)source).Clone(); Assert.Equal(source.Value, clone.Value); Assert.Equal(0, clone.Parameters.Count); source.Quality = 0.1; clone = (TransferCodingWithQualityHeaderValue)((ICloneable)source).Clone(); Assert.Equal(source.Value, clone.Value); Assert.Equal(0.1, clone.Quality); Assert.Equal(1, clone.Parameters.Count); source.Parameters.Add(new NameValueHeaderValue("custom", "customValue")); clone = (TransferCodingWithQualityHeaderValue)((ICloneable)source).Clone(); Assert.Equal(source.Value, clone.Value); Assert.Equal(0.1, clone.Quality); Assert.Equal(2, clone.Parameters.Count); Assert.Equal("custom", clone.Parameters.ElementAt(1).Name); Assert.Equal("customValue", clone.Parameters.ElementAt(1).Value); }
public static bool TryParse (string input, out TransferCodingWithQualityHeaderValue parsedValue) { throw new NotImplementedException (); }
public static bool TryParse (string input, out TransferCodingWithQualityHeaderValue parsedValue) { return TryParse (input, out parsedValue, () => new TransferCodingWithQualityHeaderValue ()); }
public static bool TryParse(string input, out TransferCodingWithQualityHeaderValue parsedValue);
public static bool TryParse(string input, out TransferCodingWithQualityHeaderValue parsedValue) { return(TryParse(input, out parsedValue, () => new TransferCodingWithQualityHeaderValue())); }
private void CheckValidParse(string input, TransferCodingWithQualityHeaderValue expectedResult) { TransferCodingWithQualityHeaderValue result = TransferCodingWithQualityHeaderValue.Parse(input); Assert.Equal(expectedResult, result); }
private void CheckInvalidParse(string input) { Assert.Throws <FormatException>(() => { TransferCodingWithQualityHeaderValue.Parse(input); }); }
/// <summary> /// Sets the TE header of the request to the specified value. /// </summary> /// <param name="value">The TE header value.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest TE(this IWith @this, TransferCodingWithQualityHeaderValue value) => @this.AddHeaderValue(headers => headers.TE, value);