public void PaddingConverter_ConvertTo_String_ReturnsExpected() { var converter = new PaddingConverter(); Assert.Equal("1, 2, 3, 4", converter.ConvertTo(new Padding(1, 2, 3, 4), typeof(string))); Assert.Equal("1, 2, 3, 4", converter.ConvertTo(null, null, new Padding(1, 2, 3, 4), typeof(string))); }
public void ConvertTo() { PaddingConverter pc = new PaddingConverter(); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "1{0} 2{0} 3{0} 4", CultureInfo.CurrentCulture.TextInfo.ListSeparator), (string)pc.ConvertTo(new Padding(1, 2, 3, 4), typeof(string)), "A1"); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "1{0} 1{0} 1{0} 1", CultureInfo.CurrentCulture.TextInfo.ListSeparator), (string)pc.ConvertTo(new Padding(1), typeof(string)), "A2"); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "0{0} 0{0} 0{0} 0", CultureInfo.CurrentCulture.TextInfo.ListSeparator), (string)pc.ConvertTo(Padding.Empty, typeof(string)), "A3"); }
public void ConvertTo_InstanceDescriptor() { PaddingConverter c = new PaddingConverter(); Padding originalPadding = new Padding(1, 10, 5, 9); InstanceDescriptor instanceDescriptor = (InstanceDescriptor)c.ConvertTo(originalPadding, typeof(InstanceDescriptor)); Padding resultedPadding = (Padding)instanceDescriptor.Invoke(); Assert.AreEqual(originalPadding, resultedPadding, "#1"); originalPadding = new Padding(99); instanceDescriptor = (InstanceDescriptor)c.ConvertTo(originalPadding, typeof(InstanceDescriptor)); resultedPadding = (Padding)instanceDescriptor.Invoke(); Assert.AreEqual(originalPadding, resultedPadding, "#2"); }
public void PaddingConverter_ConvertTo_InstanceDescriptor_ReturnsExpected() { var converter = new PaddingConverter(); InstanceDescriptor descriptor = Assert.IsType <InstanceDescriptor>(converter.ConvertTo(new Padding(1, 2, 3, 4), typeof(InstanceDescriptor))); Assert.Equal(typeof(Padding).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }), descriptor.MemberInfo); Assert.Equal(new object[] { 1, 2, 3, 4 }, descriptor.Arguments); }
private Padding RoundTripPadding(Padding p) { PaddingConverter pc = new PaddingConverter(); string s = (string)pc.ConvertTo(p, typeof(string)); return((Padding)pc.ConvertFrom(s)); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// paddingconverter.ConvertTo<int>(context, culture, value); /// </example> /// </summary> public static T ConvertTo <T>(this PaddingConverter paddingconverter, System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value) { if (paddingconverter == null) { throw new ArgumentNullException("paddingconverter"); } return((T)paddingconverter.ConvertTo(context, culture, value, typeof(T))); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typeconverter.ConvertTo<int>(value); /// </example> /// </summary> public static T ConvertTo <T>(this PaddingConverter typeconverter, Object value) { if (typeconverter == null) { throw new ArgumentNullException("typeconverter"); } return((T)typeconverter.ConvertTo(value, typeof(T))); }
public void PaddingConverter_ConvertTo_InvalidDestinationType_ThrowsNotSupportedException(Type destinationType) { var converter = new PaddingConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertTo(new Padding(), destinationType)); }
public void PaddingConverter_ConvertTo_ValueNotPadding_ThrowsNotSupportedException() { var converter = new PaddingConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertTo(1, typeof(InstanceDescriptor))); }
public void PaddingConverter_ConvertTo_NullDestinationType_ThrowsArgumentNullException() { var converter = new PaddingConverter(); Assert.Throws <ArgumentNullException>("destinationType", () => converter.ConvertTo(new object(), null)); }