public override void Setup()
 {
   base.Setup();
   _root = new AreaTreeNode("Root");
   _controller = new ControllerTreeNode("HomeController", "ControllerNamespace");
   _root.AddChild(_controller);
 }
    public void AddViewSource_ViewForValidSubAreaController_AddsViewNode()
    {
      ControllerTreeNode node = new ControllerTreeNode("HomeController", "SomeNamespace");
      AreaTreeNode root = new AreaTreeNode("Root");
      AreaTreeNode 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);
    }
		public override void Visit(ControllerTreeNode node)
		{
			CodeTypeDeclaration type = GenerateTypeDeclaration(_namespace, node.PathNoSlashes + _naming.ToRouteWrapperName(node.Name));

			_typeStack.Push(type);
			base.Visit(node);
			_typeStack.Pop();
		}
 public void ControllerTreeNode_ToString_GiveInformation()
 {
   ControllerTreeNode node = new ControllerTreeNode("HomeController", "ControllerServices");
   AreaTreeNode rootNode = new AreaTreeNode("Root");
   rootNode.AddChild(node);
   Assert.AreNotEqual(node.GetType().FullName, node.ToString());
   Assert.AreEqual("ControllerServices", node.Namespace);
 }
    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");
    }
 public void ControllerTreeNodeArea_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("Area1/Area2", node.Area);
 }
    public void VisitControllerTreeNode_Always_CreatesControllerType()
    {
      ControllerTreeNode node = new ControllerTreeNode("HomeController", "ControllerNamespace");
      _root.AddChild(node);

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

      CodeTypeDeclaration type = CodeDomAssert.AssertHasType(_source.Ccu, "RootHomeControllerNode");
      CodeDomAssert.AssertNotHasField(type, "_services");
    }
		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");
		}
		public override void Visit(ControllerTreeNode node)
		{
			CodeTypeDeclaration type = _source.GenerateTypeDeclaration(node.Namespace, node.Name);

			string 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"))));

			string 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"))));

			string 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"))));

			CodeMemberMethod initialize = new CodeMemberMethod();
			initialize.Attributes = MemberAttributes.Override | MemberAttributes.Family;
			initialize.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);
		}
		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)))));
		}
		public override void Visit(ControllerTreeNode node)
		{
			CodeTypeDeclaration 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 (TreeNode child in node.Children)
			{
				if (child is ActionTreeNode)
				{
					if (!_occurences.ContainsKey(child.Name))
					{
						_occurences[child.Name] = 0;
					}
					_occurences[child.Name]++;
				}
			}

			_typeStack.Push(type);
			base.Visit(node);
			_typeStack.Pop();
		}
    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 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);
    }
Exemple #14
0
		public virtual void Visit(ControllerTreeNode node)
		{
			Accept(node.Children);
		}
  	private void BuildTestTree()
  	{
  		AreaTreeNode parentAreaNode = new AreaTreeNode("Parent");
  		_root.AddChild(parentAreaNode);

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

  		ControllerTreeNode controllerNode = new ControllerTreeNode("ChildController", "ControllerNamespace");
  		parentAreaNode.AddChild(controllerNode);
  	}
 private static void AssertHasViewNode(ControllerTreeNode node)
 {
   Assert.IsInstanceOfType(typeof(ViewTreeNode), node.Children[0]);
   Assert.AreEqual("Index", node.Children[0].Name);
 }