Exemplo n.º 1
0
        public void GetConvertToException()
        {
            MockTypeConverter converter = new MockTypeConverter();

            try {
                converter.GetConvertToException(null, typeof(DateTime));
                Assert.Fail("#A1");
            } catch (NotSupportedException ex) {
                // 'MockTypeConverter' is unable to convert '(null)'
                // to 'System.DateTime'
                Assert.AreEqual(typeof(NotSupportedException), ex.GetType(), "#A2");
                Assert.IsNull(ex.InnerException, "#A3");
                Assert.IsNotNull(ex.Message, "#A4");
                Assert.IsTrue(ex.Message.IndexOf("'" + typeof(MockTypeConverter).Name + "'") != -1, "#A5");
                Assert.IsTrue(ex.Message.IndexOf("'(null)'") != -1, "#A6");
                Assert.IsTrue(ex.Message.IndexOf("'" + typeof(DateTime).FullName + "'") != -1, "#A7");
            }

            try {
                converter.GetConvertToException("B", typeof(DateTime));
                Assert.Fail("#B1");
            } catch (NotSupportedException ex) {
                // 'MockTypeConverter' is unable to convert 'System.String'
                // to 'System.DateTime'
                Assert.AreEqual(typeof(NotSupportedException), ex.GetType(), "#B2");
                Assert.IsNull(ex.InnerException, "#B3");
                Assert.IsNotNull(ex.Message, "#B4");
                Assert.IsTrue(ex.Message.IndexOf(typeof(MockTypeConverter).Name) != -1, "#B5");
                Assert.IsTrue(ex.Message.IndexOf(typeof(string).FullName) != -1, "#B6");
            }
        }
Exemplo n.º 2
0
        public void GetConvertFromException()
        {
            MockTypeConverter converter = new MockTypeConverter();

            try {
                converter.GetConvertFromException(null);
                Assert.Fail("#A1");
            } catch (NotSupportedException ex) {
                // MockTypeConverter cannot convert from (null)
                Assert.AreEqual(typeof(NotSupportedException), ex.GetType(), "#A2");
                Assert.IsNull(ex.InnerException, "#A3");
                Assert.IsNotNull(ex.Message, "#A4");
                Assert.IsTrue(ex.Message.IndexOf(typeof(MockTypeConverter).Name) != -1, "#A5");
                Assert.IsTrue(ex.Message.IndexOf("(null)") != -1, "#A6");
            }

            try {
                converter.GetConvertFromException("B");
                Assert.Fail("#B1");
            } catch (NotSupportedException ex) {
                // MockTypeConverter cannot convert from System.String
                Assert.AreEqual(typeof(NotSupportedException), ex.GetType(), "#B2");
                Assert.IsNull(ex.InnerException, "#B3");
                Assert.IsNotNull(ex.Message, "#B4");
                Assert.IsTrue(ex.Message.IndexOf(typeof(MockTypeConverter).Name) != -1, "#B5");
                Assert.IsTrue(ex.Message.IndexOf(typeof(string).FullName) != -1, "#B6");
            }
        }
Exemplo n.º 3
0
        public void GetConvertToException_DestinationType_Null()
        {
            MockTypeConverter converter = new MockTypeConverter();

            converter.GetConvertToException("B", (Type)null);
        }