예제 #1
0
            public void RejectMessagePattern()
            {
                Action fnFailAORException = () => OAssert.Throws <MyArgumentException>(ThrowException, NotMatchingPattern);
                Action fnFailArgException = () => OAssert.Throws <ArgumentException>(ThrowException, NotMatchingPattern);

                XAssert.Throws <ArgumentException>(fnFailAORException);
                XAssert.Throws <ArgumentException>(fnFailArgException);

                string expectedMessage = string.Format("Exception message '{0}' did not match expected pattern '{1}'", ExceptionMessage, NotMatchingPattern);

                try
                {
                    fnFailAORException();
                    throw new Exception("Action did not throw an exception!");
                }
                catch (Exception ex)
                {
                    XAssert.Equal(expectedMessage, ex.Message);
                }

                try
                {
                    fnFailArgException();
                    throw new Exception("Action did not throw an exception!");
                }
                catch (Exception ex)
                {
                    XAssert.Equal(expectedMessage, ex.Message);
                }
            }
예제 #2
0
            public void MatchMessagePattern()
            {
                // This should NOT throw an exception (Ockham.Assert.Throws passes)
                // Exact exception type and message
                OAssert.Throws <MyArgumentException>(ThrowException, ExceptionExactPattern);
                // Verifying we got this far
                XAssert.True(true);

                // This should NOT throw an exception (Ockham.Assert.Throws passes)
                // Exact exception type, pattern match
                OAssert.Throws <MyArgumentException>(ThrowException, ExceptionPattern);
                // Verifying we got this far
                XAssert.True(true);

                // This should NOT throw an exception (Ockham.Assert.Throws passes)
                // Parent exception type, exact message
                OAssert.Throws <ArgumentException>(ThrowException, ExceptionExactPattern);
                // Verifying we got this far
                XAssert.True(true);

                // This should NOT throw an exception (Ockham.Assert.Throws passes)
                // Parent exception type, pattern match
                OAssert.Throws <ArgumentException>(ThrowException, ExceptionPattern);
                // Verifying we got this far
                XAssert.True(true);
            }
예제 #3
0
            public void RejectNoException()
            {
                Action fnFailNoException = () => OAssert.Throws <DivideByZeroException>(() => { }, ExceptionExactPattern);

                XAssert.Throws <Exception>(fnFailNoException);

                string expectedMessage = "Action did not throw an exception";

                try
                {
                    fnFailNoException();
                    throw new Exception("Action did not throw an exception!");
                }
                catch (Exception ex)
                {
                    XAssert.Equal(expectedMessage, ex.Message);
                }
            }
예제 #4
0
            public void RejectWrongExType()
            {
                Action fnFailType = () => OAssert.Throws <DivideByZeroException>(ThrowException, ExceptionExactPattern);

                XAssert.Throws <Exception>(fnFailType);

                string expectedMessage = "Action threw exception of type " + typeof(MyArgumentException).Name + ", which does not inherit from expected exception type " + typeof(DivideByZeroException).Name;

                try
                {
                    fnFailType();
                    throw new Exception("Action did not throw an exception!");
                }
                catch (Exception ex)
                {
                    XAssert.Equal(expectedMessage, ex.Message);
                }
            }
예제 #5
0
            public void RejectInvalidRegex()
            {
                Action fnFailPattern = () => OAssert.Throws <Exception>(ThrowException, "^(");

                XAssert.Throws <ArgumentException>(fnFailPattern);

                string expectedMessage = "Error pattern '^(' is not valid regular expressions pattern";

                try
                {
                    fnFailPattern();
                    throw new Exception("Action did not throw an exception!");
                }
                catch (Exception ex)
                {
                    XAssert.Equal(expectedMessage, ex.Message);
                }
            }
예제 #6
0
            public void ExecuteTest()
            {
                bool closureCalled             = false;
                MyArgumentException exCaptured = null;

                Action <MyArgumentException> test = ex =>
                {
                    closureCalled = true;
                    exCaptured    = ex;
                };

                OAssert.Throws <MyArgumentException>(ThrowException, test);
                // Verifying we got this far
                XAssert.True(true);

                // Test that test was called:
                XAssert.True(closureCalled);
                XAssert.NotNull(exCaptured);
                XAssert.Equal(ExceptionMessage, exCaptured.Message);
            }
예제 #7
0
            public void RejectFailedTest()
            {
                bool closureCalled             = false;
                MyArgumentException exCaptured = null;

                Action <MyArgumentException> test = ex =>
                {
                    closureCalled = true;
                    exCaptured    = ex;
                    XAssert.Equal("no", ex.ActualValue);
                };

                Action fnFailTest = () => OAssert.Throws <MyArgumentException>(ThrowException, test);

                XAssert.Throws <Xunit.Sdk.EqualException>(fnFailTest);

                // Test that test was called:
                XAssert.True(closureCalled);
                XAssert.NotNull(exCaptured);
                XAssert.Equal(ExceptionMessage, exCaptured.Message);
            }
예제 #8
0
 public void RejectMissingAction()
 {
     XAssert.Throws <ArgumentNullException>(() => OAssert.Throws <Exception>(null, ""));
 }