Exemple #1
0
        public void TestTypeResovlerForProxies()
        {
            var nested = new TestSubject();

            nested.SimpleString = "String in proxy";
            _subject.Proxy      = new Proxy(nested);
            try
            {
                object value = _reflection["Proxy.SimpleString"];
                Assert.Fail("Expected exception");
            }
            catch (ReflectionException Re)
            {
                Assert.That(Re.Message,
                            Text.StartsWith(ReflectionException.PropertyNotFound("SimpleString", typeof(Proxy)).Message));
            }
            _reflection.ObjectResolver = delegate(object source)
            {
                if (source is Proxy)
                {
                    return(((Proxy)source).Source);
                }
                else
                {
                    return(source);
                }
            };
            Assert.That(_reflection["Proxy.SimpleString"], Is.EqualTo("String in proxy"));
        }
Exemple #2
0
 public void TestSetNonExisting()
 {
     try
     {
         _reflection["NonExisting"] = null;
         Assert.Fail("Expected exception");
     }
     catch (ReflectionException Re)
     {
         Assert.That(Re.Message, Text.StartsWith(ReflectionException.PropertyNotFound("NonExisting", typeof(TestSubject)).Message));
     }
 }
Exemple #3
0
 public void TestSetNestedNonExistingProperty()
 {
     _subject.Nested = new TestSubject();
     _subject.Nested.SimpleString = "42";
     try
     {
         _reflection["NonExisting.SimpleString"] = null;
         Assert.Fail("Expected exception");
     }
     catch (ReflectionException Re)
     {
         Assert.That(Re.Message, Text.StartsWith(ReflectionException.PropertyNotFound("NonExisting", typeof(TestSubject)).Message));
     }
 }
Exemple #4
0
 public void TestNonExistingProperty()
 {
     try
     {
         object result = _reflection["NonExistingProperty"];
         Assert.Fail("Expected an exception");
     }
     catch (ReflectionException Re)
     {
         ReflectionException test =
             ReflectionException.PropertyNotFound("NonExistingProperty", typeof(TestSubject));
         Assert.That(Re.Message, Text.StartsWith(test.Message));
     }
 }
 public void TestParseOfUnKnownAttribute()
 {
     try
     {
         Base().Parse(
             "<c:if someTest=\"true\">Y</c:if>");
         Assert.Fail("Expected exception");
     }
     catch (ReflectionException Re)
     {
         Assert.That(Re.Message,
                     Text.StartsWith(ReflectionException.PropertyNotFound("SomeTest", typeof(If)).Message));
     }
 }
Exemple #6
0
        public void TestCatchOfException()
        {
            var modelData = new Hashtable();

            modelData.Add("Existing", "Hi");
            modelData.Add("Model", new Hashtable());
            var tag = new Catch();

            tag.Var  = new MockAttribute(new Constant("error"));
            tag.Body = new MockAttribute(new Property("Broken.Point"));
            var model = new TagModel(new Broken());

            Assert.That(tag.Evaluate(model), Is.EqualTo(String.Empty));
            Assert.That(((ReflectionException)model["Model.error"]).Message,
                        Text.StartsWith(ReflectionException.PropertyNotFound("Broken", typeof(Broken)).Message));
        }
Exemple #7
0
        public void TestCatchOfExceptionDifferentPageScope()
        {
            var modelData = new Hashtable();

            modelData.Add("PageScope", VariableScope.Page.ToString());
            modelData.Add("Broken", new Broken());
            modelData.Add("Page", new Hashtable());
            var tag = new Catch();

            tag.Var   = new MockAttribute(new Constant("error"));
            tag.Body  = new MockAttribute(new Property("Broken.Banana"));
            tag.Scope = new MockAttribute(new Property("PageScope"));
            var model = new TagModel(modelData);

            Assert.That(tag.Evaluate(model), Is.EqualTo(String.Empty));
            Assert.That(model["Model.error"], Is.Null);
            Assert.That(((ReflectionException)model["Page.error"]).Message,
                        Text.StartsWith(ReflectionException.PropertyNotFound("Banana", typeof(Broken)).Message));
        }