Beispiel #1
0
        public void DoesThrow_UsingInvoking_ThrowInvalidOperationException()
        {
            // Arrange
            var subject = new Thrower();

            // Act
            Action act = subject.Invoking(e => e.DoesThrow());

            // Assert
            act.Should().Throw <InvalidOperationException>();
        }
Beispiel #2
0
        public void DoesThrow_WrappedInAction_ThrowInvalidOperationException()
        {
            // Arrange
            var subject = new Thrower();

            // Act
            Action act = () => subject.DoesThrow();

            // Assert
            act.Should().Throw <InvalidOperationException>();
        }
Beispiel #3
0
        public void DoesNotThrow_Return42()
        {
            // Arrange
            var subject = new Thrower();

            // Act
            Func <int> act = () => subject.DoesNotThrow();

            // Assert
            act.Should().NotThrow()
            .Which.Should().Be(42);
        }
Beispiel #4
0
        public void DoesThrow_ThrowInvalidOperationAdvanced()
        {
            // *  Throw InvalidOperationException,
            //  * which exception message contains "foobar"
            // * the InvalidOperationException has an InnerException,
            //  * which is exactly DivideByZeroException,
            //  * which exception message contains "Dark Side"

            // Arrange
            var subject = new Thrower();

            // Act
            Action act = () => subject.DoesThrow();

            // Assert
            act.Should().Throw <InvalidOperationException>()
            .WithMessage("*foobar*")
            .WithInnerExceptionExactly <DivideByZeroException>()
            .WithMessage("*Dark Side*");
        }