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?)."); }
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."); }
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."); }
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 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."); }
/// <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 } }
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; } }
/// <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."); }
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 ConvertFromNullReference() { StringArrayConverter vrt = new StringArrayConverter(); Assert.Throws <NotSupportedException>(() => vrt.ConvertFrom(null)); }
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); }
public void ConvertFromNonSupportedOptionBails() { StringArrayConverter vrt = new StringArrayConverter(); Assert.Throws <NotSupportedException>(() => vrt.ConvertFrom(12)); }
public void EmptyListSeparator() { StringArrayConverter vrt = new StringArrayConverter(); vrt.ListSeparator = string.Empty; }
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)); }
public void TooLongListSeparator() { StringArrayConverter vrt = new StringArrayConverter(); Assert.Throws <ArgumentException>(() => vrt.ListSeparator = " "); }