public void VisitActionNode_OneParameters_CreatesMethod() { var node = new ActionTreeNode("Index"); controller.AddChild(node); node.AddChild(new ParameterTreeNode("id", "System.Int32")); generator.Visit(controller); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[0], "Index"); }
public void VisitActionNode_OneParameters_CreatesMethod() { var node = new ActionTreeNode("Index"); controller.AddChild(node); node.AddChild(new ParameterTreeNode("id", "System.Int32")); generator.Visit(controller); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[0], "Index"); }
public void VisitRouteNode_NoParameters_CreatesMethod() { var node = new StaticRouteTreeNode("Index", "index"); var actionTreeNode = new ActionTreeNode("action"); actionTreeNode.AddChild(node); controller.AddChild(actionTreeNode); generator.Visit(controller); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "Index"); }
public void VisitRouteNode_OneParameters_CreatesMethod() { var node = new StaticRouteTreeNode("AuthenticateLogIn", "login/authenticate/<userName:string>/<password:string>"); var actionTreeNode = new ActionTreeNode("action"); actionTreeNode.AddChild(node); controller.AddChild(actionTreeNode); node.AddChild(new ParameterTreeNode("userName", "System.String")); generator.Visit(controller); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "AuthenticateLogIn"); }
public void VisitRouteNode_NoParameters_CreatesMethod() { var node = new StaticRouteTreeNode("Index", "index"); var actionTreeNode = new ActionTreeNode("action"); actionTreeNode.AddChild(node); controller.AddChild(actionTreeNode); generator.Visit(controller); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "Index"); }
public void VisitRouteNode_OneParameters_CreatesMethod() { var node = new StaticRouteTreeNode("AuthenticateLogIn", "login/authenticate/<userName:string>/<password:string>"); var actionTreeNode = new ActionTreeNode("action"); actionTreeNode.AddChild(node); controller.AddChild(actionTreeNode); node.AddChild(new ParameterTreeNode("userName", "System.String")); generator.Visit(controller); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "AuthenticateLogIn"); }
public void VisitActionNode_OneParameters_CreatesMethod() { ActionTreeNode node = new ActionTreeNode("Index"); _controller.AddChild(node); node.AddChild(new ParameterTreeNode("id", typeof(Int32))); using (_mocks.Unordered()) { } _mocks.ReplayAll(); _generator.Visit(_controller); _mocks.VerifyAll(); CodeDomAssert.AssertHasField(_source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(_source.Ccu.Namespaces[0].Types[0], "Index"); }
public void VisitRouteNode_OneParameters_CreatesMethod() { RouteTreeNode node = new StaticRouteTreeNode("AuthenticateLogIn", "login/authenticate/<userName:string>/<password:string>"); ActionTreeNode actionTreeNode = new ActionTreeNode("action"); actionTreeNode.AddChild(node); controller.AddChild(actionTreeNode); node.AddChild(new ParameterTreeNode("userName", typeof(string))); using (mocks.Unordered()) { } mocks.ReplayAll(); generator.Visit(controller); mocks.VerifyAll(); CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services"); CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "AuthenticateLogIn"); }
public void VisitActionNode_NullableParameter_CreatesMethod() { var node = new ActionTreeNode("Index"); controller.AddChild(node); node.AddChild(new ParameterTreeNode("id", "System.Nullable<System.Int32>")); generator.Visit(controller); var type = source.Ccu.Namespaces[0].Types[0]; CodeDomAssert.AssertHasField(type, "_services"); CodeDomAssert.AssertHasMethod(type, "Index"); var method = type.Members.OfType<CodeMemberMethod>().First(m => m.Name == "Index"); CodeDomAssert.AssertHasParameter(method, "id"); var parameter = method.Parameters.OfType<CodeParameterDeclarationExpression>().First(p => p.Name == "id"); Assert.AreEqual("System.Nullable`1", parameter.Type.BaseType); Assert.AreEqual(1, parameter.Type.TypeArguments.Count); Assert.AreEqual("System.Int32", parameter.Type.TypeArguments[0].BaseType); }
public void VisitActionNode_NullableParameter_CreatesMethod() { var node = new ActionTreeNode("Index"); controller.AddChild(node); node.AddChild(new ParameterTreeNode("id", "System.Nullable<System.Int32>")); generator.Visit(controller); var type = source.Ccu.Namespaces[0].Types[0]; CodeDomAssert.AssertHasField(type, "_services"); CodeDomAssert.AssertHasMethod(type, "Index"); var method = type.Members.OfType <CodeMemberMethod>().First(m => m.Name == "Index"); CodeDomAssert.AssertHasParameter(method, "id"); var parameter = method.Parameters.OfType <CodeParameterDeclarationExpression>().First(p => p.Name == "id"); Assert.AreEqual("System.Nullable`1", parameter.Type.BaseType); Assert.AreEqual(1, parameter.Type.TypeArguments.Count); Assert.AreEqual("System.Int32", parameter.Type.TypeArguments[0].BaseType); }
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { if ((methodDeclaration.Modifier & Modifiers.Public) != Modifiers.Public) return null; var controllerNode = (ControllerTreeNode) treeService.Peek; if (controllerNode is WizardControllerTreeNode) { var wizardControllerInterface = typeof (IWizardController); var methodInfos = wizardControllerInterface.GetMethods(BindingFlags.Public | BindingFlags.Instance); if ((methodDeclaration.Name == "GetSteps") && (methodDeclaration.Body.Children.Count > 0)) { (controllerNode as WizardControllerTreeNode).WizardStepPages = GetWizardStepPages(methodDeclaration.Body); return null; } if (Array.Exists(methodInfos, methodInfo => methodInfo.Name == methodDeclaration.Name)) return null; } var action = new ActionTreeNode(methodDeclaration.Name); foreach (var parameter in methodDeclaration.Parameters) { var type = TypeResolver.Resolve(parameter.TypeReference); action.AddChild(new ParameterTreeNode(parameter.ParameterName, type)); } foreach (var attributeSection in methodDeclaration.Attributes) { var attributes = attributeSection.Attributes.FindAll(attribute => attribute.Name == "StaticRoute"); foreach (var attribute in attributes) { var name = (PrimitiveExpression) attribute.PositionalArguments[0]; var pattern = (PrimitiveExpression) attribute.PositionalArguments[1]; var routeTreeNode = new StaticRouteTreeNode((string) name.Value, (string) pattern.Value); action.AddChild(routeTreeNode); } attributes = attributeSection.Attributes.FindAll(attribute => attribute.Name == "PatternRoute"); foreach (var attribute in attributes) { var name = (PrimitiveExpression) attribute.PositionalArguments[0]; var pattern = (PrimitiveExpression) attribute.PositionalArguments[1]; var defaults = new string[attribute.PositionalArguments.Count - 2]; for (var i = 0; i < defaults.Length; i++) defaults[i] = (string) ((PrimitiveExpression) attribute.PositionalArguments[2 + i]).Value; var routeTreeNode = new PatternRouteTreeNode((string) name.Value, (string) pattern.Value, defaults); action.AddChild(routeTreeNode); } } if ((controllerNode.RestRoutesDescriptor != null) && (RestActions.Contains(methodDeclaration.Name.ToLower()))) { var name = controllerNode.RestRoutesDescriptor.Name + "_" + methodDeclaration.Name; if (!action.Children.Any(c => c.Name == name)) { var pattern = CollectionRestActions.Contains(methodDeclaration.Name.ToLower()) ? controllerNode.RestRoutesDescriptor.Collection : controllerNode.RestRoutesDescriptor.Collection + controllerNode.RestRoutesDescriptor.Identifier; var node = new RestRouteTreeNode( name, pattern, RestVerbs[Array.IndexOf(RestActions, methodDeclaration.Name.ToLower())], controllerNode.RestRoutesDescriptor.RestVerbResolverType); action.AddChild(node); } } controllerNode.AddChild(action, true); return base.VisitMethodDeclaration(methodDeclaration, data); }
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { if ((methodDeclaration.Modifier & Modifiers.Public) != Modifiers.Public) { return(null); } ControllerTreeNode controllerNode = (ControllerTreeNode)_treeService.Peek; if (controllerNode is WizardControllerTreeNode) { Type wizardControllerInterface = typeof(IWizardController); MethodInfo[] methodInfos = wizardControllerInterface.GetMethods(BindingFlags.Public | BindingFlags.Instance); if ((methodDeclaration.Name == "GetSteps") && (methodDeclaration.Body.Children.Count > 0)) { (controllerNode as WizardControllerTreeNode).WizardStepPages = GetWizardStepPages(methodDeclaration.Body); return(null); } else if ( Array.Exists(methodInfos, delegate(MethodInfo methodInfo) { return(methodInfo.Name == methodDeclaration.Name); })) { return(null); } } ActionTreeNode action = new ActionTreeNode(methodDeclaration.Name); foreach (ParameterDeclarationExpression parameter in methodDeclaration.Parameters) { Type type = TypeResolver.Resolve(parameter.TypeReference, true); action.AddChild(new ParameterTreeNode(parameter.ParameterName, type)); } foreach (AttributeSection attributeSection in methodDeclaration.Attributes) { List <Attribute> attributes = attributeSection.Attributes.FindAll( delegate(Attribute attribute) { return(attribute.Name == "StaticRoute"); }); foreach (Attribute attribute in attributes) { PrimitiveExpression name = (PrimitiveExpression)attribute.PositionalArguments[0]; PrimitiveExpression pattern = (PrimitiveExpression)attribute.PositionalArguments[1]; StaticRouteTreeNode routeTreeNode = new StaticRouteTreeNode((string)name.Value, (string)pattern.Value); action.AddChild(routeTreeNode); } attributes = attributeSection.Attributes.FindAll( delegate(Attribute attribute) { return(attribute.Name == "PatternRoute"); }); foreach (Attribute attribute in attributes) { PrimitiveExpression name = (PrimitiveExpression)attribute.PositionalArguments[0]; PrimitiveExpression pattern = (PrimitiveExpression)attribute.PositionalArguments[1]; string[] defaults = new string[attribute.PositionalArguments.Count - 2]; for (int i = 0; i < defaults.Length; i++) { defaults[i] = (string)((PrimitiveExpression)attribute.PositionalArguments[2 + i]).Value; } PatternRouteTreeNode routeTreeNode = new PatternRouteTreeNode((string)name.Value, (string)pattern.Value, defaults); action.AddChild(routeTreeNode); } } controllerNode.AddChild(action, true); return(base.VisitMethodDeclaration(methodDeclaration, data)); }
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { if ((methodDeclaration.Modifier & Modifiers.Public) != Modifiers.Public) { return(null); } var controllerNode = (ControllerTreeNode)treeService.Peek; if (controllerNode is WizardControllerTreeNode) { var wizardControllerInterface = typeof(IWizardController); var methodInfos = wizardControllerInterface.GetMethods(BindingFlags.Public | BindingFlags.Instance); if ((methodDeclaration.Name == "GetSteps") && (methodDeclaration.Body.Children.Count > 0)) { (controllerNode as WizardControllerTreeNode).WizardStepPages = GetWizardStepPages(methodDeclaration.Body); return(null); } if (Array.Exists(methodInfos, methodInfo => methodInfo.Name == methodDeclaration.Name)) { return(null); } } var action = new ActionTreeNode(methodDeclaration.Name); foreach (var parameter in methodDeclaration.Parameters) { var type = TypeResolver.Resolve(parameter.TypeReference); action.AddChild(new ParameterTreeNode(parameter.ParameterName, type)); } foreach (var attributeSection in methodDeclaration.Attributes) { var attributes = attributeSection.Attributes.FindAll(attribute => attribute.Name == "StaticRoute"); foreach (var attribute in attributes) { var name = (PrimitiveExpression)attribute.PositionalArguments[0]; var pattern = (PrimitiveExpression)attribute.PositionalArguments[1]; var routeTreeNode = new StaticRouteTreeNode((string)name.Value, (string)pattern.Value); action.AddChild(routeTreeNode); } attributes = attributeSection.Attributes.FindAll(attribute => attribute.Name == "PatternRoute"); foreach (var attribute in attributes) { var name = (PrimitiveExpression)attribute.PositionalArguments[0]; var pattern = (PrimitiveExpression)attribute.PositionalArguments[1]; var defaults = new string[attribute.PositionalArguments.Count - 2]; for (var i = 0; i < defaults.Length; i++) { defaults[i] = (string)((PrimitiveExpression)attribute.PositionalArguments[2 + i]).Value; } var routeTreeNode = new PatternRouteTreeNode((string)name.Value, (string)pattern.Value, defaults); action.AddChild(routeTreeNode); } } if ((controllerNode.RestRoutesDescriptor != null) && (RestActions.Contains(methodDeclaration.Name.ToLower()))) { var name = controllerNode.RestRoutesDescriptor.Name + "_" + methodDeclaration.Name; if (!action.Children.Any(c => c.Name == name)) { var pattern = CollectionRestActions.Contains(methodDeclaration.Name.ToLower()) ? controllerNode.RestRoutesDescriptor.Collection : controllerNode.RestRoutesDescriptor.Collection + controllerNode.RestRoutesDescriptor.Identifier; var node = new RestRouteTreeNode( name, pattern, RestVerbs[Array.IndexOf(RestActions, methodDeclaration.Name.ToLower())], controllerNode.RestRoutesDescriptor.RestVerbResolverType); action.AddChild(node); } } controllerNode.AddChild(action, true); return(base.VisitMethodDeclaration(methodDeclaration, data)); }