public void TestParserControllerDefinition_Loading() { //Check the factory loads the controller definition ParserControllerDefinition defn = ParserDefintionFactory.GetControllerDefinition(TypeName); Assert.IsNotNull(defn); Assert.AreEqual(TypeName, defn.ControllerTypeName); Assert.IsNotNull(defn.ControllerType); Assert.AreEqual(typeof(TestParsedController), defn.ControllerType); Assert.IsNotNull(defn.Outlets); Assert.IsNotNull(defn.Actions); }
public void TestParserControllerDefinition_Actions() { ParserControllerDefinition defn = ParserDefintionFactory.GetControllerDefinition(TypeName); Assert.IsNotNull(defn); ParserControllerAction action; bool expected = true; //Simple declared method bool actual = defn.Actions.TryGetAction("SimpleAction", out action); Assert.AreEqual(expected, actual); Assert.IsNotNull(action); Assert.AreEqual("SimpleAction", action.Name); Assert.IsNotNull(action.ActionMethod); Assert.AreEqual(MemberTypes.Method, action.ActionMethod.MemberType); Assert.AreEqual("SimpleAction", action.ActionMethod.Name); expected = true; //Renamed method - SimpleActionOtherName actual = defn.Actions.TryGetAction("otheraction", out action); Assert.AreEqual(expected, actual); Assert.IsNotNull(action); Assert.AreEqual("otheraction", action.Name); Assert.IsNotNull(action.ActionMethod); Assert.AreEqual(MemberTypes.Method, action.ActionMethod.MemberType); Assert.AreEqual("SimpleActionOtherName", action.ActionMethod.Name); expected = false; //Explicit exclusion method - ExcludedAction actual = defn.Actions.TryGetAction("ExcludedAction", out action); Assert.AreEqual(expected, actual); Assert.IsNull(action); expected = false; //No attribute - NotAnAction actual = defn.Actions.TryGetAction("NotAnAction", out action); Assert.AreEqual(expected, actual); Assert.IsNull(action); expected = false; //static method - StaticNotAnAction actual = defn.Actions.TryGetAction("StaticNotAnAction", out action); Assert.AreEqual(expected, actual); Assert.IsNull(action); expected = false; //static method - ProtectedNotAnAction actual = defn.Actions.TryGetAction("ProtectedNotAnAction", out action); Assert.AreEqual(expected, actual); Assert.IsNull(action); expected = true; //overriden method no attribute on override - OverridenBaseAction actual = defn.Actions.TryGetAction("OverridenBaseAction", out action); Assert.AreEqual(expected, actual); Assert.IsNotNull(action); Assert.AreEqual("OverridenBaseAction", action.Name); Assert.IsNotNull(action.ActionMethod); Assert.AreEqual(MemberTypes.Method, action.ActionMethod.MemberType); Assert.AreEqual("OverridenBaseAction", action.ActionMethod.Name); expected = true; //Renamed overriden method - RenamedBaseAction actual = defn.Actions.TryGetAction("newActionName", out action); Assert.AreEqual(expected, actual); Assert.IsNotNull(action); Assert.AreEqual("newActionName", action.Name); Assert.IsNotNull(action.ActionMethod); Assert.AreEqual(MemberTypes.Method, action.ActionMethod.MemberType); Assert.AreEqual("RenamedBaseAction", action.ActionMethod.Name); expected = false; //overriden method attribute with IsAction=false - ExcludedBaseAction actual = defn.Actions.TryGetAction("ExcludedBaseAction", out action); Assert.AreEqual(expected, actual); Assert.IsNull(action); }
public void TestParserControllerDefinition_Outlets() { //Check the reported properties and fields on the definition itself ParserControllerDefinition defn = ParserDefintionFactory.GetControllerDefinition(TypeName); Assert.IsNotNull(defn); ParserControllerOutlet outlet; bool expected = true; //Field bool actual = defn.Outlets.TryGetOutlet("LabelField", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("LabelField", outlet.ID); Assert.IsNotNull(outlet.OutletMember); Assert.IsFalse(outlet.Required); Assert.AreEqual(MemberTypes.Field, outlet.OutletMember.MemberType); Assert.AreEqual("LabelField", outlet.OutletMember.Name); expected = true; //Property actual = defn.Outlets.TryGetOutlet("PlaceholderProperty", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("PlaceholderProperty", outlet.ID); Assert.IsNotNull(outlet.OutletMember); Assert.IsFalse(outlet.Required); Assert.AreEqual(MemberTypes.Property, outlet.OutletMember.MemberType); Assert.AreEqual("PlaceholderProperty", outlet.OutletMember.Name); expected = false; //should not be there. actual = defn.Outlets.TryGetOutlet("InvalidStaticField", out outlet); Assert.AreEqual(expected, actual); Assert.IsNull(outlet); expected = false; //should not be there. actual = defn.Outlets.TryGetOutlet("InvalidStaticProperty", out outlet); Assert.AreEqual(expected, actual); Assert.IsNull(outlet); expected = false; //should not be there. actual = defn.Outlets.TryGetOutlet("InvalidProtectedField", out outlet); Assert.AreEqual(expected, actual); Assert.IsNull(outlet); expected = false; //should not be there. actual = defn.Outlets.TryGetOutlet("InvalidProtectedProperty", out outlet); Assert.AreEqual(expected, actual); Assert.IsNull(outlet); expected = true; //Renamed actual = defn.Outlets.TryGetOutlet("mylabel", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("mylabel", outlet.ID); Assert.IsFalse(outlet.Required); Assert.IsNotNull(outlet.OutletMember); Assert.AreEqual(MemberTypes.Property, outlet.OutletMember.MemberType); Assert.AreEqual("LabelFieldOtherName", outlet.OutletMember.Name); expected = true; //Renamed and required actual = defn.Outlets.TryGetOutlet("otherlabel", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("otherlabel", outlet.ID); Assert.IsTrue(outlet.Required); Assert.IsNotNull(outlet.OutletMember); Assert.AreEqual(MemberTypes.Property, outlet.OutletMember.MemberType); Assert.AreEqual("RequiredLabelOtherName", outlet.OutletMember.Name); expected = false; //Explicit Exclusion actual = defn.Outlets.TryGetOutlet("ExplicitExcludedLabel", out outlet); Assert.AreEqual(expected, actual); Assert.IsNull(outlet); expected = true; //Property declared on base class actual = defn.Outlets.TryGetOutlet("BaseClassLabel", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("BaseClassLabel", outlet.ID); Assert.IsNotNull(outlet.OutletMember); Assert.IsFalse(outlet.Required); Assert.AreEqual(MemberTypes.Property, outlet.OutletMember.MemberType); Assert.AreEqual("BaseClassLabel", outlet.OutletMember.Name); expected = true; //Property declared on base class overriden on sub class - no attribute on override actual = defn.Outlets.TryGetOutlet("OverridenBaseClassLabel", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("OverridenBaseClassLabel", outlet.ID); Assert.IsNotNull(outlet.OutletMember); Assert.IsFalse(outlet.Required); Assert.AreEqual(MemberTypes.Property, outlet.OutletMember.MemberType); Assert.AreEqual("OverridenBaseClassLabel", outlet.OutletMember.Name); expected = true; //Property declared on base class, overriden on subclass - renamed actual = defn.Outlets.TryGetOutlet("renamedbaselabel", out outlet); Assert.AreEqual(expected, actual); Assert.IsNotNull(outlet); Assert.AreEqual("renamedbaselabel", outlet.ID); Assert.IsNotNull(outlet.OutletMember); Assert.IsFalse(outlet.Required); Assert.AreEqual(MemberTypes.Property, outlet.OutletMember.MemberType); Assert.AreEqual("RenamedBaseClassLabel", outlet.OutletMember.Name); expected = false; //Property declared on base class overriden on sub class - attribute IsOutlet=false actual = defn.Outlets.TryGetOutlet("ExcludedInSubClass", out outlet); Assert.AreEqual(expected, actual); Assert.IsNull(outlet); }