Exemplo n.º 1
0
        public void FromFile__GamesDotPgn_ApplicationXChessPgn()
        {
            var act = InternetMediaType.FromFile(new FileInfo("games.pgn"));
            var exp = TestStruct;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 2
0
        public void FromFile_NullString_Empty()
        {
            var act = InternetMediaType.FromFile((String)null);
            var exp = InternetMediaType.Empty;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 3
0
        public void TyrParse_StringValue_IsNotValid()
        {
            string str = "string";

            Assert.IsFalse(InternetMediaType.TryParse(str, out var val), "Valid");
            Assert.AreEqual(string.Empty, val.ToString(), "Value");
        }
Exemplo n.º 4
0
        public void FromFile__TestDotUnknown_Unknown()
        {
            var act = InternetMediaType.FromFile(new FileInfo("test.unknown"));
            var exp = InternetMediaType.Unknown;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 5
0
        public void TyrParse_Questionmark_IsValid()
        {
            string str = "?";

            Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid");
            Assert.IsTrue(val.IsUnknown(), "Value");
        }
Exemplo n.º 6
0
        public void TyrParse_StringValue_IsValid()
        {
            string str = "application/atom+xml";

            Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid");
            Assert.AreEqual(str, val.ToString(), "Value");
        }
Exemplo n.º 7
0
        public void TyrParse_StringEmpty_IsValid()
        {
            string str = string.Empty;

            Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid");
            Assert.AreEqual(string.Empty, val.ToString(), "Value");
        }
Exemplo n.º 8
0
        public void Equals_FormattedAndUnformatted_IsTrue()
        {
            var l = InternetMediaType.Parse("application/x-chess-pgn");
            var r = InternetMediaType.Parse("application/X-chess-PGN");

            Assert.IsTrue(l.Equals(r));
        }
        public static string GetContentType(this InternetMediaType mime)
        {
            Attribute[] attributes = mime.GetAttributes();

            MimeAttribute attr = null;

            for (int i = 0; i < attributes.Length; i++)
            {
                if (attributes[i].GetType() == typeof(MimeAttribute))
                {
                    attr = (MimeAttribute)attributes[i];
                    break;
                }
            }

            if (attr == null)
            {
                string contentType = "";
                foreach (char c in mime.ToString())
                {
                    if (Char.IsUpper(c) && contentType.Length > 0)
                    {
                        contentType += "/";
                    }

                    contentType += c;
                }
                return(contentType.ToLower());
            }
            else
            {
                return(attr.ContentType);
            }
        }
Exemplo n.º 10
0
        public void FromFile_NullFileInfo_Empty()
        {
            var act = InternetMediaType.FromFile((FileInfo)null);
            var exp = InternetMediaType.Empty;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 11
0
        public void FromFile__StringEmpty_Empty()
        {
            var act = InternetMediaType.FromFile(string.Empty);
            var exp = InternetMediaType.Empty;

            Assert.AreEqual(exp, act);
        }
        private static Attribute[] GetAttributes(this InternetMediaType mime)
        {
            var fi = mime.GetType().GetField(mime.ToString());

            Attribute[] attributes = (Attribute[])fi.GetCustomAttributes(typeof(Attribute), false);

            return(attributes);
        }
Exemplo n.º 13
0
        public void IsRegistered_VideoSlashXDotTest_IsFalse()
        {
            var mime = InternetMediaType.Parse("video/x.test");
            var exp  = false;
            var act  = mime.IsRegistered;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 14
0
        public void Suffix_ApplicationAtomXml_Xml()
        {
            var mime = InternetMediaType.Parse("application/atom+xml");

            var exp = InternetMediaSuffixType.xml;
            var act = mime.Suffix;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 15
0
        public void TyrParse_Null_IsValid()
        {
            InternetMediaType val;

            string str = null;

            Assert.IsTrue(InternetMediaType.TryParse(str, out val), "Valid");
            Assert.AreEqual(string.Empty, val.ToString(), "Value");
        }
Exemplo n.º 16
0
 public void Parse_Unknown_AreEqual()
 {
     using (new CultureInfoScope("en-GB"))
     {
         var act = InternetMediaType.Parse("?");
         var exp = InternetMediaType.Unknown;
         Assert.AreEqual(exp, act);
     }
 }
Exemplo n.º 17
0
        public void TryParse_InvalidInput_DefaultValue()
        {
            using (new CultureInfoScope("en-GB"))
            {
                var exp = default(InternetMediaType);
                var act = InternetMediaType.TryParse("InvalidInput");

                Assert.AreEqual(exp, act);
            }
        }
Exemplo n.º 18
0
        public void TryParse_TestStructInput_AreEqual()
        {
            using (new CultureInfoScope("en-GB"))
            {
                var exp = TestStruct;
                var act = InternetMediaType.TryParse(exp.ToString());

                Assert.AreEqual(exp, act);
            }
        }
        /// <summary>Converts a string to an internet media type, using the specified
        /// context and culture information.
        /// </summary>
        /// <param name="context">
        /// An System.ComponentModel.ITypeDescriptorContext that provides a format context.
        /// </param>
        /// <param name="culture">
        /// The System.Globalization.CultureInfo to use as the current culture.
        /// </param>
        /// <param name="value">
        /// The System.Object to convert.
        /// </param>
        /// <returns>
        /// An System.Object that represents the converted value.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// The conversion cannot be performed.
        /// </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var str = value as string;

            if (value == null || str != null)
            {
                return(InternetMediaType.Parse(str));
            }
            return(base.ConvertFrom(context, culture, value));
        }
Exemplo n.º 20
0
 public void Parse_InvalidInput_ThrowsFormatException()
 {
     using (new CultureInfoScope("en-GB"))
     {
         Assert.Catch <FormatException>
             (() =>
         {
             InternetMediaType.Parse("InvalidInput");
         },
             "Not a valid internet media type");
     }
 }
Exemplo n.º 21
0
        public void OrderByDescending_InternetMediaType_AreEqual()
        {
            var item0 = InternetMediaType.Parse("audio/mp3");
            var item1 = InternetMediaType.Parse("image/jpeg");
            var item2 = InternetMediaType.Parse("text/x-markdown");
            var item3 = InternetMediaType.Parse("video/quicktime");

            var inp = new List <InternetMediaType> {
                InternetMediaType.Empty, item3, item2, item0, item1, InternetMediaType.Empty
            };
            var exp = new List <InternetMediaType> {
                item3, item2, item1, item0, InternetMediaType.Empty, InternetMediaType.Empty
            };
            var act = inp.OrderByDescending(item => item).ToList();

            CollectionAssert.AreEqual(exp, act);
        }
        public static bool IsBinary(this InternetMediaType mime)
        {
            Attribute[] attributes = mime.GetAttributes();

            IsBinaryAttribute attr = null;

            for (int i = 0; i < attributes.Length; i++)
            {
                if (attributes[i].GetType() == typeof(IsBinaryAttribute))
                {
                    attr = (IsBinaryAttribute)attributes[i];
                    break;
                }
            }

            if (attr == null)
            {
                return(false);
            }
            else
            {
                return(attr.IsBinary);
            }
        }
        public static string[] GetFileExtensions(this InternetMediaType mime)
        {
            Attribute[] attributes = mime.GetAttributes();

            FileExtensionAttribute attr = null;

            for (int i = 0; i < attributes.Length; i++)
            {
                if (attributes[i].GetType() == typeof(FileExtensionAttribute))
                {
                    attr = (FileExtensionAttribute)attributes[i];
                    break;
                }
            }

            if (attr == null)
            {
                return(new string[0]);
            }
            else
            {
                return(attr.FileExtensions);
            }
        }
Exemplo n.º 24
0
 public void IsValid_Data_IsFalse()
 {
     Assert.IsFalse(InternetMediaType.IsValid("test/d"), "Complex");
     Assert.IsFalse(InternetMediaType.IsValid((String)null), "(String)null");
     Assert.IsFalse(InternetMediaType.IsValid(string.Empty), "string.Empty");
 }
Exemplo n.º 25
0
 /// <summary>Sets the content type.</summary>
 public static void SetContentType(this HttpResponseBase reponse, InternetMediaType mediaType)
 {
     Guard.NotNull(reponse, "reponse");
     reponse.ContentType = mediaType.ToString();
 }
Exemplo n.º 26
0
 /// <summary>Sets the content type.</summary>
 public static void SetContentType(this HttpRequestBase request, InternetMediaType mediaType)
 {
     Guard.NotNull(request, "request");
     request.ContentType = mediaType.ToString();
 }
Exemplo n.º 27
0
 public static void SetContentType(this HttpResponse reponse, InternetMediaType mediaType)
 {
     Guard.NotNull(reponse, "reponse");
     new HttpResponseWrapper(reponse).SetContentType(mediaType);
 }
Exemplo n.º 28
0
 public static void SetContentType(this HttpRequest request, InternetMediaType mediaType)
 {
     Guard.NotNull(request, "request");
     new HttpRequestWrapper(request).SetContentType(mediaType);
 }
Exemplo n.º 29
0
 public void IsValid_Data_IsTrue()
 {
     Assert.IsTrue(InternetMediaType.IsValid("application/x-chess-pgn"));
     Assert.IsTrue(InternetMediaType.IsValid("VIDEO/Mp3"));
 }