public override void Setup()
		{
			base.Setup();
			root = new AreaTreeNode("Root");
			controller = new ControllerTreeNode("HomeController", "ControllerNamespace");
			root.AddChild(controller);
		}
예제 #2
0
        public void AddViewSource_ViewForValidSubAreaController_AddsViewNode()
        {
            var node = new ControllerTreeNode("HomeController", "SomeNamespace");
            var root = new AreaTreeNode("Root");
            var area = new AreaTreeNode("Root");

            root.AddChild(area);
            area.AddChild(node);

            using (mocks.Unordered())
            {
                Expect.Call(treeService.FindNode("AreaController")).Return(null);
                Expect.Call(treeService.FindNode("AreaComponent")).Return(null);
                Expect.Call(treeService.FindNode("Area")).Return(area);
                treeService.PushNode(area);
                Expect.Call(treeService.FindNode("HomeController")).Return(node);
                treeService.PushNode(node);
                treeService.PopToRoot();
            }

            mocks.ReplayAll();
            mapper.AddViewSource(@"Projects\Eleutian.Web.Site\Views\Area\Home\Index.brail");
            mocks.VerifyAll();

            AssertHasViewNode(node);
        }
예제 #3
0
        public override void Visit(ControllerTreeNode node)
        {
            var type = GenerateTypeDeclaration(@namespace, node.PathNoSlashes + naming.ToActionWrapperName(node.Name));

            occurences = new Dictionary <string, short>();

            // We can only generate empty argument methods for actions that appear once and only once.
            foreach (var child in node.Children)
            {
                if (!(child is ActionTreeNode))
                {
                    continue;
                }

                if (!occurences.ContainsKey(child.Name))
                {
                    occurences[child.Name] = 0;
                }

                occurences[child.Name]++;
            }

            typeStack.Push(type);
            base.Visit(node);
            typeStack.Pop();
        }
예제 #4
0
        public override void Visit(ControllerTreeNode node)
        {
            var type        = source.GenerateTypeDeclaration(@namespace, node.PathNoSlashes + naming.ToControllerWrapperName(node.Name));
            var constructor = CreateServicesConstructor();

            constructor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression(naming.ToVariableName(serviceIdentifier)));

            type.BaseTypes.Add(source[node.PathNoSlashes + naming.ToActionWrapperName(node.Name)]);
            type.Members.Add(constructor);

            var parent = typeStack.Peek();

            source.AddFieldPropertyConstructorInitialize(parent, naming.ToControllerName(node.Name), type.Name);

            type.Members.Add(
                source.CreateReadOnlyProperty(
                    "Views",
                    new CodeTypeReference(node.PathNoSlashes + naming.ToViewWrapperName(node.Name)),
                    new CodeObjectCreateExpression(
                        new CodeTypeReference(node.PathNoSlashes + naming.ToViewWrapperName(node.Name)),
                        new CodeFieldReferenceExpression(source.This, naming.ToMemberVariableName(serviceIdentifier)))));

            type.Members.Add(
                source.CreateReadOnlyProperty("Actions",
                                              new CodeTypeReference(node.PathNoSlashes + naming.ToActionWrapperName(node.Name)), source.This));
        }
예제 #5
0
        /// <summary>
        /// Handles the DropDownItemClicked event of the uxAddControllerMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.ToolStripItemClickedEventArgs"/> instance containing the event data.</param>
        private void uxAddControllerMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            try
            {
                EmitterTreeNode parentNode = this.uxEffectTree.SelectedNode as EmitterTreeNode;

                IControllerPlugin plugin = e.ClickedItem.Tag as IControllerPlugin;

                AbstractEmitter parent = parentNode.Emitter;

                var args = new NewControllerEventArgs(parent, plugin);

                this.OnControllerAdded(args);

                if (args.AddedController != null)
                {
                    AbstractController controller = args.AddedController;

                    ControllerTreeNode node = new ControllerTreeNode(controller);

                    parentNode.Nodes.Add(node);

                    node.EnsureVisible();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #6
0
 public override void Setup()
 {
     base.Setup();
     _root       = new AreaTreeNode("Root");
     _controller = new ControllerTreeNode("HomeController", "ControllerNamespace");
     _root.AddChild(_controller);
 }
예제 #7
0
        public override void Visit(ControllerTreeNode node)
        {
            var type = GenerateTypeDeclaration(@namespace, node.PathNoSlashes + naming.ToRouteWrapperName(node.Name));

            typeStack.Push(type);
            base.Visit(node);
            typeStack.Pop();
        }
		public void VisitControllerNode_Always_CreatesType()
		{
			var node = new ControllerTreeNode("HomeController", "ControllerNamespace");

			generator.Visit(node);

			CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
		}
예제 #9
0
		public void ControllerTreeNode_ToString_GiveInformation()
		{
			var node = new ControllerTreeNode("HomeController", "ControllerServices");
			var rootNode = new AreaTreeNode("Root");
			rootNode.AddChild(node);
			Assert.AreNotEqual(node.GetType().FullName, node.ToString());
			Assert.AreEqual("ControllerServices", node.Namespace);
		}
예제 #10
0
		public override void Visit(ControllerTreeNode node)
		{
			var type = GenerateTypeDeclaration(@namespace, node.PathNoSlashes + naming.ToRouteWrapperName(node.Name));

			typeStack.Push(type);
			base.Visit(node);
			typeStack.Pop();
		}
예제 #11
0
        public void VisitControllerNode_Always_CreatesType()
        {
            var node = new ControllerTreeNode("HomeController", "ControllerNamespace");

            generator.Visit(node);

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
        }
예제 #12
0
        public override void Visit(ControllerTreeNode node)
        {
            CodeTypeDeclaration type = GenerateTypeDeclaration(_namespace, node.PathNoSlashes + _naming.ToViewWrapperName(node.Name));

            _typeStack.Push(type);
            base.Visit(node);
            _typeStack.Pop();
        }
예제 #13
0
        public void ControllerTreeNode_ToString_GiveInformation()
        {
            var node     = new ControllerTreeNode("HomeController", "ControllerServices");
            var rootNode = new AreaTreeNode("Root");

            rootNode.AddChild(node);
            Assert.AreNotEqual(node.GetType().FullName, node.ToString());
            Assert.AreEqual("ControllerServices", node.Namespace);
        }
예제 #14
0
        public void ControllerTreeNode_MultipleToString_GiveInformation()
        {
            ControllerTreeNode node     = new ControllerTreeNode("HomeController", "ControllerServices");
            AreaTreeNode       rootNode = new AreaTreeNode("Root");
            AreaTreeNode       areaNode = new AreaTreeNode("Area");

            areaNode.AddChild(node);
            rootNode.AddChild(areaNode);
            Assert.AreNotEqual(node.GetType().FullName, node.ToString());
        }
예제 #15
0
        public void VisitControllerNode_Always_CreatesType()
        {
            ControllerTreeNode node = new ControllerTreeNode("HomeController", "ControllerNamespace");

            _mocks.ReplayAll();
            _generator.Visit(node);
            _mocks.VerifyAll();

            CodeDomAssert.AssertHasField(_source.Ccu.Namespaces[0].Types[0], "_services");
        }
예제 #16
0
		public void ControllerTreeNodeArea_Always_WalksUpwards()
		{
			var node = new ControllerTreeNode("HomeController", "ControllerServices");
			var rootNode = new AreaTreeNode("Root");
			var area1Node = new AreaTreeNode("Area1");
			var area2Node = new AreaTreeNode("Area2");
			rootNode.AddChild(area1Node);
			area1Node.AddChild(area2Node);
			area2Node.AddChild(node);
			Assert.AreEqual("Area1/Area2", node.Area);
		}
예제 #17
0
        /// <summary>
        /// Handles the Click event of the uxCloneMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void uxCloneMenuItem_Click(object sender, EventArgs e)
        {
            var selectedNode = this.uxEffectTree.SelectedNode;

            if (selectedNode is EmitterTreeNode)
            {
                CloneEmitterEventArgs args = new CloneEmitterEventArgs((selectedNode as EmitterTreeNode).Emitter);

                this.OnEmitterCloned(args);

                if (args.AddedEmitter != null)
                {
                    EmitterTreeNode newNode = new EmitterTreeNode(args.AddedEmitter);

                    selectedNode.Parent.Nodes.Add(newNode);

                    newNode.Expand();

                    newNode.EnsureVisible();
                }
            }
            else if (selectedNode is ModifierTreeNode)
            {
                CloneModifierEventArgs args = new CloneModifierEventArgs((selectedNode as ModifierTreeNode).Modifier);

                this.OnModifierCloned(args);

                if (args.AddedModifier != null)
                {
                    ModifierTreeNode newNode = new ModifierTreeNode(args.AddedModifier);

                    selectedNode.Parent.Nodes.Add(newNode);

                    newNode.EnsureVisible();
                }
            }
            else if (selectedNode is ControllerTreeNode)
            {
                var args = new CloneControllerEventArgs((selectedNode as ControllerTreeNode).Controller);

                this.OnControllerCloned(args);

                if (args.AddedController != null)
                {
                    ControllerTreeNode newNode = new ControllerTreeNode(args.AddedController);

                    selectedNode.Parent.Nodes.Add(newNode);

                    newNode.Expand();

                    newNode.EnsureVisible();
                }
            }
        }
예제 #18
0
        public void ControllerTreeNodePath_Always_WalksUpwards()
        {
            ControllerTreeNode node      = new ControllerTreeNode("HomeController", "ControllerServices");
            AreaTreeNode       rootNode  = new AreaTreeNode("Root");
            AreaTreeNode       area1Node = new AreaTreeNode("Area1");
            AreaTreeNode       area2Node = new AreaTreeNode("Area2");

            rootNode.AddChild(area1Node);
            area1Node.AddChild(area2Node);
            area2Node.AddChild(node);
            Assert.AreEqual("Root/Area1/Area2", node.Path);
        }
예제 #19
0
        public void ControllerTreeNodeArea_Always_WalksUpwards()
        {
            var node      = new ControllerTreeNode("HomeController", "ControllerServices");
            var rootNode  = new AreaTreeNode("Root");
            var area1Node = new AreaTreeNode("Area1");
            var area2Node = new AreaTreeNode("Area2");

            rootNode.AddChild(area1Node);
            area1Node.AddChild(area2Node);
            area2Node.AddChild(node);
            Assert.AreEqual("Area1/Area2", node.Area);
        }
		public void VisitControllerTreeNode_Always_CreatesControllerType()
		{
			var node = new ControllerTreeNode("HomeController", "ControllerNamespace");
			_root.AddChild(node);

			mocks.ReplayAll();
			generator.Visit(_root);
			mocks.VerifyAll();

			var type = CodeDomAssert.AssertHasType(source.Ccu, "RootHomeControllerNode");
			CodeDomAssert.AssertNotHasField(type, "_services");
		}
		public void VisitControllerNode_Always_CreatesType()
		{
			var node = new ControllerTreeNode("HomeController", "ControllerNamespace");

			mocks.ReplayAll();
			generator.Visit(node);
			mocks.VerifyAll();

			CodeDomAssert.AssertHasProperty(source.Ccu.Namespaces[0].Types[0], "MyActions");
			CodeDomAssert.AssertHasProperty(source.Ccu.Namespaces[0].Types[0], "MyViews");
			CodeDomAssert.AssertHasProperty(source.Ccu.Namespaces[0].Types[0], "MyRoutes");
			CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[0], "PerformGeneratedInitialize");
		}
예제 #22
0
        public void VisitControllerNode_Always_CreatesType()
        {
            ControllerTreeNode node = new ControllerTreeNode("HomeController", "ControllerNamespace");

            _mocks.ReplayAll();
            _generator.Visit(node);
            _mocks.VerifyAll();

            CodeDomAssert.AssertHasProperty(_source.Ccu.Namespaces[0].Types[0], "MyActions");
            CodeDomAssert.AssertHasProperty(_source.Ccu.Namespaces[0].Types[0], "MyViews");
            CodeDomAssert.AssertHasProperty(_source.Ccu.Namespaces[0].Types[0], "MyRoutes");
            CodeDomAssert.AssertHasMethod(_source.Ccu.Namespaces[0].Types[0], "PerformGeneratedInitialize");
        }
예제 #23
0
        public void VisitMethodDeclaration_ActionMemberNoArgumentsIsVirtual_CreatesEntryInNode()
        {
            var method = new MethodDeclaration {
                Name = "Action", Modifier = Modifiers.Public | Modifiers.Virtual
            };
            var node = new ControllerTreeNode(ControllerName, ControllerNamespace);

            treeService.Expect(s => s.Peek).Return(node);

            visitor.VisitMethodDeclaration(method, null);

            Assert.AreEqual("Action", node.Children[0].Name);
            Assert.AreEqual(0, node.Children[0].Children.Count);
        }
예제 #24
0
        public void VisitControllerTreeNode_Always_CreatesControllerType()
        {
            var node = new ControllerTreeNode("HomeController", "ControllerNamespace");

            _root.AddChild(node);

            mocks.ReplayAll();
            generator.Visit(_root);
            mocks.VerifyAll();

            var type = CodeDomAssert.AssertHasType(source.Ccu, "RootHomeControllerNode");

            CodeDomAssert.AssertNotHasField(type, "_services");
        }
예제 #25
0
        private void BuildTestTree()
        {
            var parentAreaNode = new AreaTreeNode("Parent");

            _root.AddChild(parentAreaNode);

            var childAreaNode = new AreaTreeNode("Child");

            parentAreaNode.AddChild(childAreaNode);

            var controllerNode = new ControllerTreeNode("ChildController", "ControllerNamespace");

            parentAreaNode.AddChild(controllerNode);
        }
예제 #26
0
        public override void Visit(ControllerTreeNode node)
        {
            var type = source.GenerateTypeDeclaration(node.Namespace, node.Name);

            var actionWrapperName = @namespace + "." + node.PathNoSlashes + naming.ToControllerWrapperName(node.Name);

            type.Members.Add(
                source.CreateReadOnlyProperty(
                    "MyActions",
                    source[actionWrapperName],
                    new CodeObjectCreateExpression(
                        source[actionWrapperName],
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "CodeGeneratorServices"))));

            var viewWrapperName = @namespace + "." + node.PathNoSlashes + naming.ToViewWrapperName(node.Name);

            type.Members.Add(
                source.CreateReadOnlyProperty(
                    "MyViews",
                    source[viewWrapperName],
                    new CodeObjectCreateExpression(
                        source[viewWrapperName],
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "CodeGeneratorServices"))));

            var routeWrapperName = @namespace + "." + node.PathNoSlashes + naming.ToRouteWrapperName(node.Name);

            type.Members.Add(
                source.CreateReadOnlyProperty(
                    "MyRoutes",
                    source[routeWrapperName],
                    new CodeObjectCreateExpression(
                        source[routeWrapperName],
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "CodeGeneratorServices"))));

            var initialize = new CodeMemberMethod
            {
                Attributes = (MemberAttributes.Override | MemberAttributes.Family),
                Name       = "PerformGeneratedInitialize"
            };

            initialize.Statements.Add(new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), "PerformGeneratedInitialize"));
            initialize.Statements.Add(AddPropertyToPropertyBag("MyViews"));
            initialize.Statements.Add(AddPropertyToPropertyBag("MyActions"));
            initialize.Statements.Add(AddPropertyToPropertyBag("MyRoutes"));

            type.Members.Add(initialize);

            base.Visit(node);
        }
예제 #27
0
        public void VisitMethodDeclaration_ActionMemberNoArgumentsIsVirtual_CreatesEntryInNode()
        {
            MethodDeclaration  method = new MethodDeclaration("Action", Modifiers.Public | Modifiers.Virtual, null, new List <ParameterDeclarationExpression>(), new List <AttributeSection>());
            ControllerTreeNode node   = new ControllerTreeNode("SomeController", "SomeNamespace");

            using (_mocks.Unordered())
            {
                Expect.Call(_treeService.Peek).Return(node);
            }

            _mocks.ReplayAll();
            _visitor.VisitMethodDeclaration(method, null);
            _mocks.VerifyAll();

            Assert.AreEqual("Action", node.Children[0].Name);
            Assert.AreEqual(0, node.Children[0].Children.Count);
        }
		public override void Visit(ControllerTreeNode node)
		{
			var type = source.GenerateTypeDeclaration(node.Namespace, node.Name);

			var actionWrapperName = @namespace + "." + node.PathNoSlashes + naming.ToControllerWrapperName(node.Name);
			type.Members.Add(
				source.CreateReadOnlyProperty(
					"MyActions", 
					source[actionWrapperName],
				    new CodeObjectCreateExpression(
						source[actionWrapperName], 
						new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "CodeGeneratorServices"))));

			var viewWrapperName = @namespace + "." + node.PathNoSlashes + naming.ToViewWrapperName(node.Name);
			type.Members.Add(
				source.CreateReadOnlyProperty(
					"MyViews", 
					source[viewWrapperName],
					new CodeObjectCreateExpression(
						source[viewWrapperName],
						new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "CodeGeneratorServices"))));

			var routeWrapperName = @namespace + "." + node.PathNoSlashes + naming.ToRouteWrapperName(node.Name);
			type.Members.Add(
				source.CreateReadOnlyProperty(
					"MyRoutes", 
					source[routeWrapperName],
				    new CodeObjectCreateExpression(
						source[routeWrapperName],
						new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "CodeGeneratorServices"))));

			var initialize = new CodeMemberMethod
			{
				Attributes = (MemberAttributes.Override | MemberAttributes.Family),
				Name = "PerformGeneratedInitialize"
			};

			initialize.Statements.Add(new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), "PerformGeneratedInitialize"));
			initialize.Statements.Add(AddPropertyToPropertyBag("MyViews"));
			initialize.Statements.Add(AddPropertyToPropertyBag("MyActions"));
			initialize.Statements.Add(AddPropertyToPropertyBag("MyRoutes"));

			type.Members.Add(initialize);

			base.Visit(node);
		}
예제 #29
0
        public void VisitMethodDeclaration_ActionMemberStandardArgument_CreatesEntryInNode()
        {
            var method = new MethodDeclaration {
                Name = "Action", Modifier = Modifiers.Public
            };

            method.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("bool"), "parameter"));
            var node = new ControllerTreeNode(ControllerName, ControllerNamespace);

            treeService.Expect(s => s.Peek).Return(node);
            typeResolver.Expect(r => r.Resolve(Arg <TypeReference> .Matches(t => t.SystemType == "System.Boolean"))).Return("System.Boolean");

            visitor.VisitMethodDeclaration(method, null);

            Assert.AreEqual("Action", node.Children[0].Name);
            Assert.AreEqual("parameter", node.Children[0].Children[0].Name);
        }
예제 #30
0
        public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (!IsController(typeDeclaration))
            {
                return(null);
            }

            string area          = GetArea(typeDeclaration);
            string typeNamespace = GetNamespace(typeDeclaration);

            if (!String.IsNullOrEmpty(area))
            {
                string[] areas = area.Split('/');
                for (int i = 0; i < areas.Length; i++)
                {
                    TreeNode areaNode = _treeService.FindNode(areas[i]);
                    if (areaNode == null)
                    {
                        areaNode = new AreaTreeNode(areas[i]);
                    }
                    _treeService.PushNode(areaNode);
                }
            }

            ControllerTreeNode node = IsWizardController(typeDeclaration)
                                                        ? new WizardControllerTreeNode(typeDeclaration.Name, typeNamespace, new string[0])
                                                        : new ControllerTreeNode(typeDeclaration.Name, typeNamespace);

            _treeService.PushNode(node);

            object r = base.VisitTypeDeclaration(typeDeclaration, data);

            if (!String.IsNullOrEmpty(area))
            {
                string[] areas = area.Split('/');
                for (int i = 0; i < areas.Length; i++)
                {
                    _treeService.PopNode();
                }
            }
            _treeService.PopNode();

            return(r);
        }
예제 #31
0
		public void AddViewSource_ViewForValidTopLevelController_AddsViewNode()
		{
			var node = new ControllerTreeNode("HomeController", "SomeNamespace");
			var root = new AreaTreeNode("Root");
			root.AddChild(node);

			using (mocks.Unordered())
			{
				Expect.Call(treeService.FindNode("HomeController")).Return(node);
				treeService.PushNode(node);
				treeService.PopToRoot();
			}

			mocks.ReplayAll();
			mapper.AddViewSource(@"Projects\Eleutian.Web.Site\Views\Home\Index.brail");
			mocks.VerifyAll();

			AssertHasViewNode(node);
		}
예제 #32
0
        public void AddViewSource_ViewForValidTopLevelController_AddsViewNode()
        {
            ControllerTreeNode node = new ControllerTreeNode("HomeController", "SomeNamespace");
            AreaTreeNode       root = new AreaTreeNode("Root");

            root.AddChild(node);

            using (_mocks.Unordered())
            {
                Expect.Call(_treeService.FindNode("HomeController")).Return(node);
                _treeService.PushNode(node);
                _treeService.PopToRoot();
            }

            _mocks.ReplayAll();
            _mapper.AddViewSource(@"Projects\Eleutian.Web.Site\Views\Home\Index.brail");
            _mocks.VerifyAll();

            AssertHasViewNode(node);
        }
예제 #33
0
		public override void Visit(ControllerTreeNode node)
		{
			var type = GenerateTypeDeclaration(@namespace, node.PathNoSlashes + naming.ToActionWrapperName(node.Name));

			occurences = new Dictionary<string, short>();

			// We can only generate empty argument methods for actions that appear once and only once.
			foreach (var child in node.Children)
			{
				if (!(child is ActionTreeNode)) continue;

				if (!occurences.ContainsKey(child.Name))
					occurences[child.Name] = 0;
				
				occurences[child.Name]++;
			}

			typeStack.Push(type);
			base.Visit(node);
			typeStack.Pop();
		}
예제 #34
0
        public override void Visit(ControllerTreeNode node)
        {
            // CodeTypeDeclaration type = GenerateTypeDeclaration(_namespace, _naming.ToControllerWrapperName(node.Name));
            CodeTypeDeclaration type =
                _source.GenerateTypeDeclaration(_namespace, node.PathNoSlashes + _naming.ToControllerWrapperName(node.Name));
            CodeConstructor constructor = CreateServicesConstructor();

            constructor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression(_naming.ToVariableName(_serviceIdentifier)));
            type.BaseTypes.Add(_source[node.PathNoSlashes + _naming.ToActionWrapperName(node.Name)]);
            type.Members.Add(constructor);

            CodeTypeDeclaration parent = _typeStack.Peek();

            _source.AddFieldPropertyConstructorInitialize(parent, _naming.ToControllerName(node.Name), type.Name);

            type.Members.Add(
                _source.CreateReadOnlyProperty("Views",
                                               new CodeTypeReference(node.PathNoSlashes + _naming.ToViewWrapperName(node.Name)),
                                               new CodeObjectCreateExpression(
                                                   new CodeTypeReference(node.PathNoSlashes + _naming.ToViewWrapperName(node.Name)),
                                                   new CodeFieldReferenceExpression(_source.This, _naming.ToMemberVariableName(_serviceIdentifier)))));

            /*
             * type.Members.Add(
             *      _source.CreateReadOnlyProperty("Actions", new CodeTypeReference(node.PathNoSlashes + _naming.ToActionWrapperName(node.Name)),
             *                                                 new CodeObjectCreateExpression(
             *                                                       new CodeTypeReference( _naming.ToActionWrapperName(node.Name)),
             *                                                       new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), _naming.ToMemberVariableName(_serviceIdentifier)))));
             */

            type.Members.Add(_source.CreateReadOnlyProperty("Actions",
                                                            new CodeTypeReference(node.PathNoSlashes + _naming.ToActionWrapperName(node.Name)), _source.This));

            //type.Members.Add(_source.CreateReadOnlyProperty("Routes",
            //    new CodeTypeReference(node.PathNoSlashes + _naming.ToRouteWrapperName(node.Name)),
            //    new CodeObjectCreateExpression(
            //        new CodeTypeReference(node.PathNoSlashes + _naming.ToRouteWrapperName(node.Name)),
            //        new CodeFieldReferenceExpression(_source.This, _naming.ToMemberVariableName( _serviceIdentifier)))));
        }
예제 #35
0
        public void VisitMethodDeclaration_ActionMemberStandardArgument_CreatesEntryInNode()
        {
            MethodDeclaration method = new MethodDeclaration("Action", Modifiers.Public, null, new List <ParameterDeclarationExpression>(), new List <AttributeSection>());

            method.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("bool"), "parameter"));
            ControllerTreeNode node = new ControllerTreeNode("SomeController", "SomeNamespace");

            using (_mocks.Unordered())
            {
                Expect.Call(_treeService.Peek).Return(node);
                Expect.Call(_typeResolver.Resolve(new TypeReference("bool"), true))
                .Constraints(
                    Is.Matching(new Predicate <TypeReference>(delegate(TypeReference reference) { return(reference.SystemType == "System.Boolean"); })),
                    Is.Matching(new Predicate <bool>(delegate(bool throwOnFail) { return(throwOnFail); })))
                .Return(typeof(bool));
            }

            _mocks.ReplayAll();
            _visitor.VisitMethodDeclaration(method, null);
            _mocks.VerifyAll();

            Assert.AreEqual("Action", node.Children[0].Name);
            Assert.AreEqual("parameter", node.Children[0].Children[0].Name);
        }
		public override void Visit(ControllerTreeNode node)
		{
			var type = source.GenerateTypeDeclaration(@namespace, node.PathNoSlashes + naming.ToControllerWrapperName(node.Name));
			var constructor = CreateServicesConstructor();
			constructor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression(naming.ToVariableName(serviceIdentifier)));
			
			type.BaseTypes.Add(source[node.PathNoSlashes + naming.ToActionWrapperName(node.Name)]);
			type.Members.Add(constructor);

			var parent = typeStack.Peek();
			source.AddFieldPropertyConstructorInitialize(parent, naming.ToControllerName(node.Name), type.Name);

			type.Members.Add(
				source.CreateReadOnlyProperty(
					"Views",
					new CodeTypeReference(node.PathNoSlashes + naming.ToViewWrapperName(node.Name)),
					new CodeObjectCreateExpression(
						new CodeTypeReference(node.PathNoSlashes + naming.ToViewWrapperName(node.Name)),
						new CodeFieldReferenceExpression(source.This, naming.ToMemberVariableName(serviceIdentifier)))));
			
			type.Members.Add(
				source.CreateReadOnlyProperty("Actions", 
												new CodeTypeReference(node.PathNoSlashes + naming.ToActionWrapperName(node.Name)), source.This));
		}
예제 #37
0
        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));
        }
예제 #38
0
 private static void AssertHasViewNode(ControllerTreeNode node)
 {
     Assert.IsInstanceOfType(typeof(ViewTreeNode), node.Children[0]);
     Assert.AreEqual("Index", node.Children[0].Name);
 }
예제 #39
0
		public virtual void Visit(ControllerTreeNode node)
		{
			Accept(node.Children);
		}
		private void BuildTestTree()
		{
			var parentAreaNode = new AreaTreeNode("Parent");
			_root.AddChild(parentAreaNode);

			var childAreaNode = new AreaTreeNode("Child");
			parentAreaNode.AddChild(childAreaNode);

			var controllerNode = new ControllerTreeNode("ChildController", "ControllerNamespace");
			parentAreaNode.AddChild(controllerNode);
		}
		public void VisitMethodDeclaration_ActionMemberStandardArgument_CreatesEntryInNode()
		{
			var method = new MethodDeclaration { Name = "Action", Modifier = Modifiers.Public };
			method.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("bool"), "parameter"));
			var node = new ControllerTreeNode(ControllerName, ControllerNamespace);

			treeService.Expect(s => s.Peek).Return(node);
			typeResolver.Expect(r => r.Resolve(Arg<TypeReference>.Matches(t => t.SystemType == "System.Boolean"))).Return("System.Boolean");

			visitor.VisitMethodDeclaration(method, null);

			Assert.AreEqual("Action", node.Children[0].Name);
			Assert.AreEqual("parameter", node.Children[0].Children[0].Name);
		}
		public void VisitMethodDeclaration_ActionMemberNoArgumentsIsVirtual_CreatesEntryInNode()
		{
			var method = new MethodDeclaration { Name = "Action", Modifier = Modifiers.Public | Modifiers.Virtual };
			var node = new ControllerTreeNode(ControllerName, ControllerNamespace);

			treeService.Expect(s => s.Peek).Return(node);

			visitor.VisitMethodDeclaration(method, null);
			
			Assert.AreEqual("Action", node.Children[0].Name);
			Assert.AreEqual(0, node.Children[0].Children.Count);
		}
예제 #43
0
		private static void AssertHasViewNode(ControllerTreeNode node)
		{
			Assert.IsInstanceOfType(typeof (ViewTreeNode), node.Children[0]);
			Assert.AreEqual("Index", node.Children[0].Name);
		}
예제 #44
0
 public virtual void Visit(ControllerTreeNode node)
 {
     Accept(node.Children);
 }