public ReflectionResult Get(string property) { ReflectionException lastException = null; foreach (VariableScope scope in SCOPE_ORDER) { IModel model = GetModel(scope); if (model != null) { ReflectionResult reflectionResult = model.Get(property); if (reflectionResult.Partial || reflectionResult.Full) { return(reflectionResult); } if (lastException == null || (reflectionResult.ReflectionException != null && lastException.Nesting < reflectionResult.ReflectionException.Nesting) ) { lastException = reflectionResult.ReflectionException; } } } if (lastException != null) { return(new ReflectionResult { ReflectionException = lastException }); } return(new ReflectionResult()); }
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")); }
public void TestListPropertyOutOfRangeToLarge() { _subject.Nested = new TestSubject(); _subject.StringList = new List <string>(); _subject.StringList.Add("first"); _subject.StringList.Add("second"); _subject.StringList.Add("third"); try { object value = _reflection["StringList.4"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.IndexOutOfBounds(typeof(List <string>), 4).Message)); } try { object value = _reflection["StringList.-1"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.IndexOutOfBounds(typeof(List <string>), -1).Message)); } }
public void TestEnumerablePropertyOutOfRangeToLarge() { var list = new List <string>(); list.Add("first"); list.Add("second"); list.Add("third"); _subject.StringEnumerable = new EnumerableWrapper <string>(list); try { object value = _reflection["StringEnumerable.4"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo( ReflectionException.IndexOutOfBounds(typeof(EnumerableWrapper <string>), 4).Message)); } try { object value = _reflection["StringEnumerable.-1"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.IndexOutOfBounds(typeof(List <string>), -1).Message)); } }
public void TestNonpublicInjectionMapping() { TestDelegate testDelegate = delegate() { reflector.Get <NonpublicInjection> (); }; ReflectionException ex = Assert.Throws <ReflectionException>(testDelegate); Assert.That(ex.type == ReflectionExceptionType.CANNOT_INJECT_INTO_NONPUBLIC_SETTER); }
public void TestReflectAnInterface() { TestDelegate testDelegate = delegate() { reflector.Get <ISimpleInterface> (); }; ReflectionException ex = Assert.Throws <ReflectionException>(testDelegate); Assert.That(ex.type == ReflectionExceptionType.CANNOT_REFLECT_INTERFACE); }
public object Evaluate(TagModel model) { try { return(_expression.Evaluate(model)); } catch (ReflectionException Re) { throw ReflectionException.DecorateWithContext(Re, Context); } }
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)); } }
public void TestNoProperty() { try { object result = _reflection[null]; Assert.Fail("Expected an exception"); } catch (ReflectionException Re) { ReflectionException test = ReflectionException.NoPropertyAvailable(); Assert.That(Re.Message, Is.EqualTo(test.Message)); } }
public void SET_TestNullReferenceListProperty() { _subject.StringEnumerable = null; try { _reflection["StringList.1"] = "first"; } catch (ReflectionException Re) { ReflectionException test = ReflectionException.NoSourceAvailable("1"); Assert.That(Re.Message, Is.EqualTo(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)); } }
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)); } }
public void SET_TestNullReferenceDictionaryProperty() { _subject.StringDictionary = null; try { _reflection["StringDictionary.a"] = "first"; } catch (ReflectionException Re) { Console.WriteLine(Re.Message); ReflectionException test = ReflectionException.NoSourceAvailable("a"); Assert.That(Re.Message, Is.EqualTo(test.Message)); } }
public void SET_TestNoSourceProvidedNested() { try { _reflection = new Reflection(_subject); _reflection["Nested.SimpleString"] = "a"; Assert.Fail("Expected an exception"); } catch (ReflectionException Re) { ReflectionException test = ReflectionException.NoSourceAvailable("SimpleString"); Assert.That(Re.Message, Is.EqualTo(test.Message)); } }
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 NonExistingNestedResolveTest() { var model = new TagModel(new Reflection(new Hashtable())); model.Model["a"] = new Hashtable(); model.Page["a"] = new Hashtable(); try { object o = model["a.b"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.NoSourceAvailable("b").Message)); } }
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)); }
public void NonExistingNestedResolve_Prefers_Deepest_Nesting_Second_One_Deepested_Nesting() { var model = new TagModel(new Reflection(new Hashtable())); model.Model["a"] = new Hashtable(); model.Page["a"] = new Hashtable { { "b", new Hashtable() } }; try { object o = model["a.b.c"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.NoSourceAvailable("c").Message)); } }
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)); }
public void TestSetNestedNonExistingDictionaryKey() { _subject.ComplexDictionary = new Dictionary <string, TestSubject>(); _subject.ComplexDictionary.Add("a", new TestSubject()); _subject.ComplexDictionary.Add("b", new TestSubject()); _subject.ComplexDictionary.Add("c", new TestSubject()); _subject.ComplexDictionary["a"].SimpleString = "first"; _subject.ComplexDictionary["b"].SimpleString = "second"; _subject.ComplexDictionary["c"].SimpleString = "third"; try { _reflection["ComplexDictionary.e.SimpleString"] = null; Assert.Fail("Expected exception"); } catch (ReflectionException Re) { Assert.AreEqual(Re.Message, ReflectionException.NoSourceAvailable("SimpleString").Message); } }
public void TestSetNestedNonExistingListItem() { _subject.ComplexList = new List <TestSubject>(); _subject.ComplexList.Add(new TestSubject()); _subject.ComplexList.Add(new TestSubject()); _subject.ComplexList.Add(new TestSubject()); _subject.ComplexList[0].SimpleString = "first"; _subject.ComplexList[1].SimpleString = "second"; _subject.ComplexList[2].SimpleString = "third"; try { _reflection["ComplexList.3.SimpleString"] = null; Assert.Fail("Expected exception"); } catch (ReflectionException Re) { Console.WriteLine(Re.Message); Assert.AreEqual(Re.Message, ReflectionException.IndexOutOfBounds(typeof(List <TestSubject>), 3).Message); } }
public void TestSetNestedNonExistingArrayItem() { _subject.ComplexArray = new TestSubject[3]; _subject.ComplexArray[0] = new TestSubject(); _subject.ComplexArray[1] = new TestSubject(); _subject.ComplexArray[2] = new TestSubject(); _subject.ComplexArray[0].SimpleString = "first"; _subject.ComplexArray[1].SimpleString = "second"; _subject.ComplexArray[2].SimpleString = "third"; try { _reflection["ComplexArray.3.SimpleString"] = null; Assert.Fail("Expected exception"); } catch (ReflectionException Re) { Console.WriteLine(Re.Message); Assert.AreEqual(Re.Message, ReflectionException.IndexOutOfBounds(typeof(TestSubject[]), 3).Message); } }
public void TestArrayPropertyOutOfRangeToLarge() { _subject.StringArray = new string[3]; _subject.StringArray[0] = "first"; _subject.StringArray[1] = "second"; _subject.StringArray[2] = "third"; try { object value = _reflection["StringArray.4"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.IndexOutOfBounds(typeof(string[]), 4).Message)); } try { object value = _reflection["StringArray.-1"]; } catch (ReflectionException Re) { Assert.That(Re.Message, Is.EqualTo(ReflectionException.IndexOutOfBounds(typeof(string[]), -1).Message)); } }