예제 #1
0
        private ProductHeaderValue(ProductHeaderValue source)
        {
            Contract.Requires(source != null);

            _name = source._name;
            _version = source._version;
        }
예제 #2
0
        private ProductInfoHeaderValue(ProductInfoHeaderValue source)
        {
            Contract.Requires(source != null);

            _product = source._product;
            _comment = source._comment;
        }
예제 #3
0
		public ProductInfoHeaderValue (ProductHeaderValue product)
		{
			if (product == null)
				throw new ArgumentNullException ();

			Product = product;
		}
예제 #4
0
        private ProductHeaderValue(ProductHeaderValue source)
        {
            Contract.Requires(source != null);

            this.name = source.name;
            this.version = source.version;
        }
예제 #5
0
        private ProductInfoHeaderValue(ProductInfoHeaderValue source)
        {
            Contract.Requires(source != null);

            this.product = source.product;
            this.comment = source.comment;
        }
예제 #6
0
        private ProductHeaderValue(ProductHeaderValue source)
        {
            Debug.Assert(source != null);

            _name = source._name;
            _version = source._version;
        }
예제 #7
0
        private ProductInfoHeaderValue(ProductInfoHeaderValue source)
        {
            Debug.Assert(source != null);

            _product = source._product;
            _comment = source._comment;
        }
예제 #8
0
        public void ToString_UseDifferentRanges_AllSerializedCorrectly()
        {
            ProductHeaderValue product = new ProductHeaderValue("IRC", "6.9");
            Assert.Equal("IRC/6.9", product.ToString());

            product = new ProductHeaderValue("product");
            Assert.Equal("product", product.ToString());
        }
예제 #9
0
        public ProductInfoHeaderValue(ProductHeaderValue product)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            _product = product;
        }
예제 #10
0
        public ProductInfoHeaderValue(ProductHeaderValue product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            this.product = product;
        }
예제 #11
0
 private void CheckValidParsedValue(string input, int startIndex, ProductHeaderValue expectedResult,
     int expectedIndex)
 {
     HttpHeaderParser parser = GenericHeaderParser.MultipleValueProductParser;
     object result = null;
     Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
         string.Format("TryParse returned false. Input: '{0}'", input));
     Assert.Equal(expectedIndex, startIndex);
     Assert.Equal(result, expectedResult);
 }
        public void Equals()
        {
            var value = new ProductHeaderValue ("ab");
            Assert.AreEqual (value, new ProductHeaderValue ("ab"), "#1");
            Assert.AreEqual (value, new ProductHeaderValue ("AB"), "#2");
            Assert.AreNotEqual (value, new ProductHeaderValue ("AA"), "#3");

            value = new ProductHeaderValue ("ab", "DD");
            Assert.AreEqual (value, new ProductHeaderValue ("Ab", "DD"), "#4");
            Assert.AreNotEqual (value, new ProductHeaderValue ("AB"), "#5");
            Assert.AreEqual (value, new ProductHeaderValue ("Ab", "dd"), "#6");
        }
예제 #13
0
        public void GetHashCode_UseSameAndDifferentRanges_SameOrDifferentHashCodes()
        {
            ProductHeaderValue product1 = new ProductHeaderValue("custom", "1.0");
            ProductHeaderValue product2 = new ProductHeaderValue("custom");
            ProductHeaderValue product3 = new ProductHeaderValue("CUSTOM", "1.0");
            ProductHeaderValue product4 = new ProductHeaderValue("RTA", "x11");
            ProductHeaderValue product5 = new ProductHeaderValue("rta", "X11");

            Assert.NotEqual(product1.GetHashCode(), product2.GetHashCode());
            Assert.Equal(product1.GetHashCode(), product3.GetHashCode());
            Assert.NotEqual(product1.GetHashCode(), product4.GetHashCode());
            Assert.Equal(product4.GetHashCode(), product5.GetHashCode());
        }
예제 #14
0
        public void Ctor_SetValidHeaderValues_InstanceCreatedCorrectly()
        {
            ProductHeaderValue product = new ProductHeaderValue("HTTP", "2.0");
            Assert.Equal("HTTP", product.Name);
            Assert.Equal("2.0", product.Version);

            product = new ProductHeaderValue("HTTP");
            Assert.Equal("HTTP", product.Name);
            Assert.Null(product.Version);

            product = new ProductHeaderValue("HTTP", ""); // null and string.Empty are equivalent
            Assert.Equal("HTTP", product.Name);
            Assert.Null(product.Version);
        }
예제 #15
0
        public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions()
        {
            ProductHeaderValue product1 = new ProductHeaderValue("custom", "1.0");
            ProductHeaderValue product2 = new ProductHeaderValue("custom");
            ProductHeaderValue product3 = new ProductHeaderValue("CUSTOM", "1.0");
            ProductHeaderValue product4 = new ProductHeaderValue("RTA", "x11");
            ProductHeaderValue product5 = new ProductHeaderValue("rta", "X11");

            Assert.False(product1.Equals(null), "custom/1.0 vs. <null>");
            Assert.False(product1.Equals(product2), "custom/1.0 vs. custom");
            Assert.False(product2.Equals(product1), "custom/1.0 vs. custom");
            Assert.True(product1.Equals(product3), "custom/1.0 vs. CUSTOM/1.0");
            Assert.False(product1.Equals(product4), "custom/1.0 vs. rta/X11");
            Assert.True(product4.Equals(product5), "RTA/x11 vs. rta/X11");
        }
예제 #16
0
		static bool TryParseElement (Lexer lexer, out ProductHeaderValue parsedValue, out Token t)
		{
			parsedValue = null;

			t = lexer.Scan ();
			if (t != Token.Type.Token)
				return false;

			parsedValue = new ProductHeaderValue ();
			parsedValue.Name = lexer.GetStringValue (t);

			t = lexer.Scan ();
			if (t == Token.Type.SeparatorSlash) {
				t = lexer.Scan ();
				if (t != Token.Type.Token)
					return false;

				parsedValue.Version = lexer.GetStringValue (t);
				t = lexer.Scan ();
			}

			return true;
		}
예제 #17
0
		public static bool TryParse (string input, out ProductHeaderValue parsedValue)
		{
			var lexer = new Lexer (input);
			Token token;
			if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End)
				return true;

			parsedValue = null;
			return false;
		}
예제 #18
0
        public ProductInfoHeaderValue(ProductHeaderValue product)
        {
            ArgumentNullException.ThrowIfNull(product);

            _product = product;
        }
 public ProductInfoHeaderValue(string productName, string productVersion)
 {
     Product = new ProductHeaderValue(productName, productVersion);
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress)
     : this(new GitHubClient(productInformation, credentialStore, baseAddress))
 {
 }
예제 #21
0
 private void CheckValidParse(string input, ProductHeaderValue expectedResult)
 {
     ProductHeaderValue result = ProductHeaderValue.Parse(input);
     Assert.Equal(expectedResult, result);
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation)
     : this(new GitHubClient(productInformation))
 {
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation, Uri baseAddress)
     : this(new GitHubClient(productInformation, baseAddress))
 {
 }
예제 #24
0
		public ProductInfoHeaderValue (string productName, string productVersion)
		{
			Product = new ProductHeaderValue (productName, productVersion);
		}
예제 #25
0
 private void CheckValidTryParse(string input, ProductHeaderValue expectedResult)
 {
     ProductHeaderValue result = null;
     Assert.True(ProductHeaderValue.TryParse(input, out result));
     Assert.Equal(expectedResult, result);
 }
예제 #26
0
 private static void CallGetProductLength(string input, int startIndex, int expectedLength,
     out ProductHeaderValue result)
 {
     Assert.Equal(expectedLength, ProductHeaderValue.GetProductLength(input, startIndex, out result));
 }
예제 #27
0
        internal static int GetProductLength(string input, int startIndex, out ProductHeaderValue parsedValue)
        {
            Contract.Requires(startIndex >= 0);

            parsedValue = null;

            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return 0;
            }

            // Parse the name string: <name> in '<name>/<version>'.
            int nameLength = HttpRuleParser.GetTokenLength(input, startIndex);

            if (nameLength == 0)
            {
                return 0;
            }

            ProductHeaderValue result = new ProductHeaderValue();
            result._name = input.Substring(startIndex, nameLength);
            int current = startIndex + nameLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            if ((current == input.Length) || (input[current] != '/'))
            {
                parsedValue = result;
                return current - startIndex;
            }

            current++; // Skip '/' delimiter.
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            // Parse the name string: <version> in '<name>/<version>'.
            int versionLength = HttpRuleParser.GetTokenLength(input, current);

            if (versionLength == 0)
            {
                return 0; // If there is a '/' separator it must be followed by a valid token.
            }

            result._version = input.Substring(current, versionLength);

            current = current + versionLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            parsedValue = result;
            return current - startIndex;
        }
        public void Properties()
        {
            var value = new ProductHeaderValue ("s", "p");
            Assert.AreEqual ("s", value.Name, "#1");
            Assert.AreEqual ("p", value.Version, "#2");

            value = new ProductHeaderValue ("s");
            Assert.AreEqual ("s", value.Name, "#3");
            Assert.IsNull (value.Version, "#4");
        }
예제 #29
0
        public static bool TryParse(string input, out ProductHeaderValue parsedValue)
        {
            int index = 0;
            object output;
            parsedValue = null;

            if (GenericHeaderParser.SingleValueProductParser.TryParseValue(input, null, ref index, out output))
            {
                parsedValue = (ProductHeaderValue)output;
                return true;
            }
            return false;
        }
예제 #30
0
 public static bool TryParse(string input, out ProductHeaderValue parsedValue)
 {
 }
예제 #31
0
        public void Clone_Call_CloneFieldsMatchSourceFields()
        {
            ProductHeaderValue source = new ProductHeaderValue("SHTTP", "1.3");
            ProductHeaderValue clone = (ProductHeaderValue)((ICloneable)source).Clone();

            Assert.Equal(source.Name, clone.Name);
            Assert.Equal(source.Version, clone.Version);

            source = new ProductHeaderValue("SHTTP", null);
            clone = (ProductHeaderValue)((ICloneable)source).Clone();

            Assert.Equal(source.Name, clone.Name);
            Assert.Null(clone.Version);
        }
예제 #32
0
 public static void AddProductToUserAgent(this RestAgent restAgent, ProductHeaderValue product)
 {
     ((HttpRequestHeaders)restAgent.DefaultRequestHeaders).UserAgent.Add(new ProductInfoHeaderValue(product));
 }
예제 #33
0
		static bool TryParseElement (Lexer lexer, out ProductInfoHeaderValue parsedValue)
		{
			string comment;
			parsedValue = null;
			Token t;

			if (lexer.ScanCommentOptional (out comment, out t)) {
				if (comment == null)
					return false;

				parsedValue = new ProductInfoHeaderValue ();
				parsedValue.Comment = comment;
				return true;
			}

			if (t == Token.Type.End)
				return true;

			if (t != Token.Type.Token)
				return false;

			var value = new ProductHeaderValue ();
			value.Name = lexer.GetStringValue (t);

			var pos = lexer.Position;
			t = lexer.Scan ();
			if (t == Token.Type.SeparatorSlash) {

				t = lexer.Scan ();
				if (t != Token.Type.Token)
					return false;

				value.Version = lexer.GetStringValue (t);
			} else {
				lexer.Position = pos;
			}

			parsedValue = new ProductInfoHeaderValue (value);
			return true;
		}
예제 #34
0
 internal static int GetProductLength(string input, int startIndex, out ProductHeaderValue parsedValue)
 {
 }