コード例 #1
0
        public void ThrowsOfTShouldFailWhenAnExceptionIsNotThrown()
        {
            // arrange
            var assert = new Asserter();

            try
            {
                // act
                assert.Throws <Exception>(() => { });
            }
            catch (AssertFailedException ex)
            {
                // assert
                Assert.AreEqual($"Assert.Fail failed. An exception of type {typeof( Exception )} was expected, but not thrown.", ex.Message);
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
コード例 #2
0
        public void ThrowsOfTShouldFailWhenAnExceptionIsNotThrownWithMessage()
        {
            // arrange
            var assert = new Asserter();

            try
            {
                // act
                assert.Throws <Exception>(() => { }, "A '{0}' message.", "test");
            }
            catch (AssertFailedException ex)
            {
                // assert
                Assert.AreEqual("Assert.Fail failed. A 'test' message.", ex.Message);
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
コード例 #3
0
        public void ThrowsOfTShouldNotAllowNullTestMethodWithMessage()
        {
            // arrange
            var assert     = new Asserter();
            var testMethod = default(Action);

            try
            {
                // act
                assert.Throws <Exception>(testMethod, string.Empty);
            }
            catch (AssertFailedException ex)
            {
                // assert
                Assert.AreEqual(GetExpectedMessage(nameof(testMethod)), ex.Message);
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
コード例 #4
0
 internal void Throws_ActionNoThrowFail()
 {
     Tools.Asserter.Throws <AssertException>(
         () => _testInstance.Throws <InvalidOperationException>(() => { }));
 }