Beispiel #1
0
        public void CreateAndExecuteTryCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand body = new SetCommand("a", new ConstantExpression(1));
            TryCommand command = new TryCommand(body);

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("a"));
        }
Beispiel #2
0
        public void ExecuteFinallyEvenWhenRaiseException()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand body = new SetCommand("a", new NameExpression("c"));
            ICommand @finally = new SetCommand("b", new ConstantExpression(2));
            TryCommand command = new TryCommand(body);
            command.SetFinally(@finally);

            try
            {
                command.Execute(environment);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(NameError));
                Assert.AreEqual("name 'c' is not defined", ex.Message);
            }

            Assert.IsNull(environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }