예제 #1
0
        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)));
        }
예제 #2
0
        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");
        }
예제 #3
0
        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");
        }
예제 #4
0
        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);
        }
예제 #5
0
        private Padding RoundTripPadding(Padding p)
        {
            PaddingConverter pc = new PaddingConverter();

            string s = (string)pc.ConvertTo(p, typeof(string));

            return((Padding)pc.ConvertFrom(s));
        }
예제 #6
0
        /// <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&lt;int&gt;(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)));
        }
예제 #7
0
        /// <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&lt;int&gt;(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)));
        }
예제 #8
0
        public void PaddingConverter_ConvertTo_InvalidDestinationType_ThrowsNotSupportedException(Type destinationType)
        {
            var converter = new PaddingConverter();

            Assert.Throws <NotSupportedException>(() => converter.ConvertTo(new Padding(), destinationType));
        }
예제 #9
0
        public void PaddingConverter_ConvertTo_ValueNotPadding_ThrowsNotSupportedException()
        {
            var converter = new PaddingConverter();

            Assert.Throws <NotSupportedException>(() => converter.ConvertTo(1, typeof(InstanceDescriptor)));
        }
예제 #10
0
        public void PaddingConverter_ConvertTo_NullDestinationType_ThrowsArgumentNullException()
        {
            var converter = new PaddingConverter();

            Assert.Throws <ArgumentNullException>("destinationType", () => converter.ConvertTo(new object(), null));
        }