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.");
 }
 /// <summary>
 /// Registers standard and configured type converters.
 /// </summary>
 static TypeConverterRegistry()
 {
     lock (_syncRoot)
     {
         _converters[typeof(string[])] = new StringArrayConverter();
         _converters[typeof(Type)] = new RuntimeTypeConverter();
         _converters[typeof(Uri)] = new UriConverter();
         _converters[typeof(FileInfo)] = new FileInfoConverter();
         _converters[typeof(NameValueCollection)] = new NameValueConverter();
         _converters[typeof(Regex)] = new RegexConverter();
         _converters[typeof(TimeSpan)] = new TimeSpanConverter();
     }
 }
示例#4
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(Uri)]                 = new UriConverter();
         _converters[typeof(FileInfo)]            = new FileInfoConverter();
         _converters[typeof(NameValueCollection)] = new NameValueConverter();
         _converters[typeof(Regex)]               = new RegexConverter();
         _converters[typeof(TimeSpan)]            = new TimeSpanConverter();
     }
 }
 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.");
 }
 public void ConvertFromNullReference()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     vrt.ConvertFrom(null);
 }
 public void ConvertFromNonSupportedOptionBails()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     vrt.ConvertFrom(12);
 }
 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 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.");
 }
 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 EmptyListSeparator()
 {
     StringArrayConverter vrt = new StringArrayConverter();
     vrt.ListSeparator = string.Empty;
 }