public void parses_partial_wildcard()
        {
            var c = new AcceptComponent("text/*");

            Assert.AreEqual("text", c.MediaType);
            Assert.AreEqual("*", c.MediaSubtype);
            Assert.AreEqual("text/*", c.MediaRange);
            Assert.AreEqual(1f, c.Priority);
        }
        public void parses_generic_wildcard_with_priority_and_other_param()
        {
            var c = new AcceptComponent("*/*;q=0.4;z=7");

            Assert.AreEqual("*", c.MediaType);
            Assert.AreEqual("*", c.MediaSubtype);
            Assert.AreEqual("*/*", c.MediaRange);
            Assert.AreEqual(0.4f, c.Priority);
        }
        public void parses_generic_wildcard()
        {
            var c = new AcceptComponent("*/*");

            Assert.AreEqual("*", c.MediaType);
            Assert.AreEqual("*", c.MediaSubtype);
            Assert.AreEqual("*/*", c.MediaRange);
            Assert.AreEqual(1.0f, c.Priority);
        }
        private static bool TryParseInternal(string componentText, bool throwExceptions, out AcceptComponent result)
        {
            result = null;

            if (componentText == null)
            {
                if (throwExceptions)
                    throw new ArgumentNullException("componentText");
                return false;
            }
            if (componentText == "")
            {
                if (throwExceptions)
                    throw new ArgumentException("componentText");
                return false;
            }

            float priority = 1.0f; // default priority

            string[] parts = componentText.Split(';');
            string mediaRange = parts[0];

            string[] typeParts = mediaRange.Split(new[] { '/' }, 2);
            if (typeParts.Length != 2)
            {
                if (throwExceptions)
                    throw new ArgumentException("componentText");
                return false;
            }

            string mediaType = typeParts[0];
            string mediaSubtype = typeParts[1];
            string[] parameters = null;

            if (parts.Length > 1)
            {
                var firstPart = parts[1];
                var additionSkip = 0;
                if (firstPart.StartsWith("q="))
                {
                    var quality = firstPart.Substring(2);
                    float q;
                    if (float.TryParse(quality, NumberStyles.Float, CultureInfo.InvariantCulture, out q))
                    {
                        priority = q;
                        additionSkip = 1;
                    }
                }
                parameters = parts.Skip(1 + additionSkip).ToArray();
            }

            result = new AcceptComponent(mediaRange, mediaType, mediaSubtype, priority, parameters);
            return true;
        }
 public static bool TryParse(string componentText, out AcceptComponent result)
 {
     return TryParseInternal(componentText, false, out result);
 }
        public void parses_specific_media_range_with_priority()
        {
            var c = new AcceptComponent("application/xml;q=0.7");

            Assert.AreEqual("application", c.MediaType);
            Assert.AreEqual("xml", c.MediaSubtype);
            Assert.AreEqual("application/xml", c.MediaRange);
            Assert.AreEqual(0.7f, c.Priority);
        }