コード例 #1
0
        public void IsNotAssignableFromType()
        {
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotAssignableFromType <string>(null));
            Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType <int>(1));
            Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType <long>(1));
            Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType <int>(new int?(1)));
            Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType <int>("hello"));

            Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotAssignableFromType(null, typeof(string)));
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotAssignableFromType("hello", null));
            Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType(1, typeof(int)));
            Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType(1, typeof(long)));
            Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType(new int?(1), typeof(int)));
            Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType("hello", typeof(int)));
        }