Esempio n. 1
0
        public void CanConvertFrom()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            Assert.IsTrue(vrt.CanConvertFrom(typeof(string)), "Conversion from a string instance must be supported.");
            Assert.IsFalse(vrt.CanConvertFrom(null));
        }
 public void ConvertFromPreservesExtraneousWhitespace()
 {
     object[] expected = new object[] {"1 ", " Foo ", " 3"};
     StringArrayConverter vrt = new StringArrayConverter();
     object actual = vrt.ConvertFrom("1 , Foo , 3");
     Assert.IsNotNull(actual);
     Assert.AreEqual(typeof (string[]), actual.GetType());
     Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[]) actual),
         "Individual array elements not correctly converted (check the whitespace?).");
 }
Esempio n. 3
0
        public void ConvertFromPreservesExtraneousWhitespace()
        {
            object[]             expected = new object[] { "1 ", " Foo ", " 3" };
            StringArrayConverter vrt      = new StringArrayConverter();
            object actual = vrt.ConvertFrom("1 , Foo , 3");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted (check the whitespace?).");
        }
 public void ConvertFrom()
 {
     object[] expected = new object[] {"1", "Foo", "3"};
     StringArrayConverter vrt = new StringArrayConverter();
     object actual = vrt.ConvertFrom("1,Foo,3");
     Assert.IsNotNull(actual);
     Assert.AreEqual(typeof (string[]), actual.GetType());
     Assert.AreEqual(3, ((string[]) actual).Length, "Wrong number of elements in the resulting array.");
     Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[]) actual),
         "Individual array elements not correctly converted.");
 }
Esempio n. 5
0
        public void ConvertFrom()
        {
            object[]             expected = new object[] { "1", "Foo", "3" };
            StringArrayConverter vrt      = new StringArrayConverter();
            object actual = vrt.ConvertFrom("1,Foo,3");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.AreEqual(3, ((string[])actual).Length, "Wrong number of elements in the resulting array.");
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted.");
        }
Esempio n. 6
0
        public void NullingTheListSeparatorMakesItRevertToTheDefault()
        {
            object[]             expected = new object[] { "1", "Foo", "3" };
            StringArrayConverter vrt      = new StringArrayConverter();

            vrt.ListSeparator = null;
            object actual = vrt.ConvertFrom("1,Foo,3");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted.");
        }
Esempio n. 7
0
        public void CustomListSeparator()
        {
            object[]             expected        = new object[] { "1", "Foo", "3" };
            StringArrayConverter vrt             = new StringArrayConverter();
            const string         customSeparator = "#";

            vrt.ListSeparator = customSeparator;
            object actual = vrt.ConvertFrom(string.Format("1{0}Foo{0}3", customSeparator));

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted.");
        }
Esempio n. 8
0
        /// <summary>
        /// Registers standard and configured type converters.
        /// </summary>
        static TypeConverterRegistry()
        {
            lock (syncRoot)
            {
                converters[typeof(string[])]            = new StringArrayConverter();
                converters[typeof(Type)]                = new RuntimeTypeConverter();
                converters[typeof(Color)]               = new RGBColorConverter();
                converters[typeof(Uri)]                 = new UriConverter();
                converters[typeof(FileInfo)]            = new FileInfoConverter();
                converters[typeof(NameValueCollection)] = new NameValueConverter();
                converters[typeof(ResourceManager)]     = new ResourceManagerConverter();
                converters[typeof(Regex)]               = new RegexConverter();
                converters[typeof(TimeSpan)]            = new TimeSpanConverter();
                converters[typeof(ICredentials)]        = new CredentialConverter();
                converters[typeof(NetworkCredential)]   = new CredentialConverter();

                // register user-defined type converters
            }
        }
Esempio n. 9
0
        public void EnsureCultureListSeparatorIsIgnored()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                CultureInfo frenchCulture = new CultureInfo("fr-FR");
                Thread.CurrentThread.CurrentCulture = frenchCulture;
                object[]             expected = new object[] { "1", "Foo", "3" };
                StringArrayConverter vrt      = new StringArrayConverter();
                // France uses the ';' (semi-colon) to separate list items...
                object actual = vrt.ConvertFrom("1,Foo,3");
                Assert.IsNotNull(actual);
                Assert.AreEqual(typeof(string[]), actual.GetType());
                Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                              "Individual array elements not correctly converted.");
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Registers standard and configured type converters.
        /// </summary>
        static TypeConverterRegistry()
        {
            lock (converters.SyncRoot)
            {
                converters[typeof(string[])] = new StringArrayConverter();
                converters[typeof(Type)] = new RuntimeTypeConverter();
                converters[typeof(Color)] = new RGBColorConverter();
                converters[typeof(Uri)] = new UriConverter();
                converters[typeof(FileInfo)] = new FileInfoConverter();
                converters[typeof(Stream)] = new StreamConverter();
                converters[typeof(NameValueCollection)] = new NameValueConverter();
                converters[typeof(ResourceManager)] = new ResourceManagerConverter();
                converters[typeof(Regex)] = new RegexConverter();
                converters[typeof(TimeSpan)] = new TimeSpanConverter();
                converters[typeof(ICredentials)] = new CredentialConverter();
                converters[typeof(NetworkCredential)] = new CredentialConverter();
                converters[typeof(RegistryKey)] = new RegistryKeyConverter();

                // register user-defined type converters
                ConfigurationUtils.GetSection(TypeConvertersSectionName);
            }
        }
 public void ConvertFromNonSupportedOptionBails()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     vrt.ConvertFrom(12);
 }
        public void EmptyListSeparator()
	    {
	        StringArrayConverter vrt = new StringArrayConverter();
            Assert.Throws<ArgumentException>(() => vrt.ListSeparator = string.Empty);
        }
 public void TooLongListSeparator()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     Assert.Throws<ArgumentException>(() => vrt.ListSeparator = "  ");
 }
 public void CustomListSeparator()
 {
     object[] expected = new object[] {"1", "Foo", "3"};
     StringArrayConverter vrt = new StringArrayConverter();
     const string customSeparator = "#";
     vrt.ListSeparator = customSeparator;
     object actual = vrt.ConvertFrom(string.Format("1{0}Foo{0}3", customSeparator));
     Assert.IsNotNull(actual);
     Assert.AreEqual(typeof (string[]), actual.GetType());
     Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[]) actual),
         "Individual array elements not correctly converted.");
 }
Esempio n. 15
0
        public void TooLongListSeparator()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            vrt.ListSeparator = "  ";
        }
	    public void NullingTheListSeparatorMakesItRevertToTheDefault()
	    {
            object[] expected = new object[] {"1", "Foo", "3"};
	        StringArrayConverter vrt = new StringArrayConverter();
            vrt.ListSeparator = null;
            object actual = vrt.ConvertFrom("1,Foo,3");
            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof (string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[]) actual),
                "Individual array elements not correctly converted.");
	    }
Esempio n. 17
0
        public void ConvertFromNonSupportedOptionBails()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            vrt.ConvertFrom(12);
        }
Esempio n. 18
0
        public void ConvertFromNullReference()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            Assert.Throws <NotSupportedException>(() => vrt.ConvertFrom(null));
        }
 public void TooLongListSeparator()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     vrt.ListSeparator = "  ";
 }
 public void EnsureCultureListSeparatorIsIgnored()
 {
     CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
     try
     {
         CultureInfo frenchCulture = new CultureInfo("fr-FR");
         Thread.CurrentThread.CurrentCulture = frenchCulture;
         object[] expected = new object[] {"1", "Foo", "3"};
         StringArrayConverter vrt = new StringArrayConverter();
         // France uses the ';' (semi-colon) to separate list items...
         object actual = vrt.ConvertFrom("1,Foo,3");
         Assert.IsNotNull(actual);
         Assert.AreEqual(typeof (string[]), actual.GetType());
         Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[]) actual),
                       "Individual array elements not correctly converted.");
     }
     finally
     {
         Thread.CurrentThread.CurrentCulture = originalCulture;
     }
 }
 public void ConvertFromNonSupportedOptionBails()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     Assert.Throws<NotSupportedException>(() => vrt.ConvertFrom(12));
 }
 public void ConvertFromNullReference()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     Assert.Throws<NotSupportedException>(() => vrt.ConvertFrom(null));
 }
 public void ConvertFromNullReference()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     vrt.ConvertFrom(null);
 }
Esempio n. 24
0
        public void ConvertFromNonSupportedOptionBails()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            Assert.Throws <NotSupportedException>(() => vrt.ConvertFrom(12));
        }
Esempio n. 25
0
        public void ConvertFromNullReference()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            vrt.ConvertFrom(null);
        }
Esempio n. 26
0
        public void EmptyListSeparator()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            vrt.ListSeparator = string.Empty;
        }
Esempio n. 27
0
        public void EmptyListSeparator()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            Assert.Throws <ArgumentException>(() => vrt.ListSeparator = string.Empty);
        }
 public void CanConvertFrom()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     Assert.IsTrue(vrt.CanConvertFrom(typeof (string)), "Conversion from a string instance must be supported.");
     Assert.IsFalse(vrt.CanConvertFrom(null));
 }
Esempio n. 29
0
        public void TooLongListSeparator()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            Assert.Throws <ArgumentException>(() => vrt.ListSeparator = "  ");
        }
	    public void EmptyListSeparator()
	    {
	        StringArrayConverter vrt = new StringArrayConverter();
            vrt.ListSeparator = string.Empty;
        }