Пример #1
0
        public void Throws_ThrowsException_WhenDerivedException()
        {
            var sut = new AClassWithExceptions();

            Assert.Throws <ThrowsException>(() =>
                                            Assert.Throws <BaseException>(
                                                () => sut.Throw(new DerivedException("DerivedException")))
                                            );
        }
Пример #2
0
        public void ThrowsAny_ThrowsException_WhenNoExceptiontThrown()
        {
            var sut = new AClassWithExceptions();

            Assert.Throws <ThrowsException>(() =>
                                            Assert.ThrowsAny <BaseException>(
                                                () => sut.Throw(null))
                                            );
        }
Пример #3
0
        public void ThrowsAny_DerivedException()
        {
            var sut = new AClassWithExceptions();

            var ex = Assert.ThrowsAny <BaseException>(
                () => sut.Throw(new DerivedException("DerivedMessage")));

            Assert.NotNull(ex);
            Assert.IsType <DerivedException>(ex);
            Assert.Equal("DerivedMessage", ex.Message);
        }
Пример #4
0
        public void Throws()
        {
            var sut = new AClassWithExceptions();

            var ex = Assert.Throws <BaseException>(
                () => sut.Throw(new BaseException("BaseMessage")));

            Assert.NotNull(ex);
            Assert.IsType <BaseException>(ex);
            Assert.Equal("BaseMessage", ex.Message);
        }