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

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