Пример #1
0
        public void CatchValueError()
        {
            ExceptCommand command = new ExceptCommand(new ConstantExpression(typeof(ValueError)), null);

            Assert.IsNotNull(command.Expression);
            Assert.IsNull(command.Command);
            Assert.IsTrue(command.CatchException(null, new ValueError(null)));
            Assert.IsFalse(command.CatchException(null, new SyntaxError(null)));
        }
Пример #2
0
        public void CatchAllExceptions()
        {
            ExceptCommand command = new ExceptCommand(null, null);

            Assert.IsNull(command.Expression);
            Assert.IsNull(command.Command);
            Assert.IsTrue(command.CatchException(null, new ValueError(null)));
            Assert.IsTrue(command.CatchException(null, new SyntaxError(null)));
            Assert.IsTrue(command.CatchException(null, new Exception()));
        }
Пример #3
0
        public void RaiseIfExpressionIsNotAnException()
        {
            ExceptCommand command = new ExceptCommand(new ConstantExpression(1), null);

            try
            {
                command.CatchException(null, new ValueError(null));
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(TypeError));
                Assert.AreEqual("catching classes that do not inherit from BaseException is not allowed", ex.Message);
            }
        }