Ejemplo n.º 1
0
        public void VisitControllerNode_Always_CreatesType()
        {
            var node = new ControllerTreeNode("HomeController", "ControllerNamespace");

            generator.Visit(node);

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
        }
Ejemplo n.º 2
0
        public void VisitControllerNode_Always_CreatesType()
        {
            var node = new WizardControllerTreeNode("HomeController", "ControllerNamespace", new[] { "Step1" });

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

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
        }
Ejemplo n.º 3
0
        public void VisitAreaNode_NoParent_CreatesType()
        {
            AreaTreeNode node = new AreaTreeNode("Root");

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

            CodeDomAssert.AssertHasField(_source.Ccu.Namespaces[0].Types[0], "_services");
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
0
        public void VisitActionNode_NoParameters_CreatesMethod()
        {
            var node = new ActionTreeNode("Index");

            controller.AddChild(node);

            generator.Visit(controller);

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[0], "Index");
        }
Ejemplo n.º 6
0
        public void VisitAreaNode_AreaAsParent_CreatesType()
        {
            var node = new AreaTreeNode("Area");

            _root.AddChild(node);

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

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
        }
Ejemplo n.º 7
0
        public void VisitControllerTreeNode_AreaExistsWithSameNameAsController_AppendsSuffixToAreaNodeField()
        {
            BuildTestTree();

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

            CodeTypeDeclaration type      = CodeDomAssert.AssertHasType(_source.Ccu, "RootParentAreaNode");
            CodeMemberField     areaField = (CodeMemberField)type.Members[3];

            Assert.AreEqual("_childArea", areaField.Name);
        }
Ejemplo n.º 8
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");
        }
Ejemplo n.º 9
0
        public void VisitControllerTreeNode_AreaExistsWithSameNameAsController_AppendsSuffixToControllerNodeField()
        {
            BuildTestTree();

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

            var type            = CodeDomAssert.AssertHasType(source.Ccu, "RootParentAreaNode");
            var controllerField = (CodeMemberField)type.Members[5];

            Assert.AreEqual("_childController", controllerField.Name);
        }
Ejemplo n.º 10
0
        public void VisitViewNode_NoParameters_CreatesMethod()
        {
            ViewTreeNode node = new ViewTreeNode("Index");

            _controller.AddChild(node);

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

            CodeDomAssert.AssertHasField(_source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasProperty(_source.Ccu.Namespaces[0].Types[0], "Index");
        }
Ejemplo n.º 11
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");
        }
Ejemplo n.º 12
0
        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");
        }
Ejemplo n.º 13
0
        public void VisitRouteNode_NoParameters_CreatesMethod()
        {
            RouteTreeNode  node           = new StaticRouteTreeNode("Index", "index");
            ActionTreeNode actionTreeNode = new ActionTreeNode("action");

            actionTreeNode.AddChild(node);
            controller.AddChild(actionTreeNode);

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

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "Index");
        }
Ejemplo n.º 14
0
        public void VisitControllerTreeNode_AreaExistsWithSameNameAsController_AppendsSuffixToControllerNodeProperty()
        {
            BuildTestTree();

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

            CodeTypeDeclaration type = CodeDomAssert.AssertHasType(_source.Ccu, "RootParentAreaNode");
            CodeMemberProperty  controllerProperty = (CodeMemberProperty)type.Members[4];

            Assert.AreEqual("ChildController", controllerProperty.Name);
            CodeMethodReturnStatement statement = (CodeMethodReturnStatement)controllerProperty.GetStatements[0];

            Assert.AreEqual("_childController", ((CodeFieldReferenceExpression)statement.Expression).FieldName);
        }
Ejemplo n.º 15
0
        public void VisitViewNode_OneParameters_CreatesMethod()
        {
            ViewTreeNode node = new ViewTreeNode("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.AssertHasProperty(_source.Ccu.Namespaces[0].Types[0], "Index");
        }
Ejemplo n.º 16
0
        public void VisitViewNode_OneParameters_CreatesMethod()
        {
            var node = new ViewTreeNode("Index");

            controller.AddChild(node);
            node.AddChild(new ParameterTreeNode("id", "System.Int32"));

            using (mocks.Unordered())
            {
            }

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

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasProperty(source.Ccu.Namespaces[0].Types[0], "Index");
        }
Ejemplo n.º 17
0
        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");
        }
Ejemplo n.º 18
0
        public void VisitControllerTreeNode_AreaExistsWithSameNameAsController_AppendsSuffixToConstructorFieldReferences()
        {
            BuildTestTree();

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

            var type        = CodeDomAssert.AssertHasType(source.Ccu, "RootParentAreaNode");
            var constructor = (CodeConstructor)type.Members[1];

            Assert.AreEqual(3, constructor.Statements.Count);

            var areaAssignment     = (CodeAssignStatement)constructor.Statements[1];
            var areaFieldReference = (CodeFieldReferenceExpression)areaAssignment.Left;

            Assert.AreEqual("_childArea", areaFieldReference.FieldName);

            var controllerAssignment     = (CodeAssignStatement)constructor.Statements[2];
            var controllerFieldReference = (CodeFieldReferenceExpression)controllerAssignment.Left;

            Assert.AreEqual("_childController", controllerFieldReference.FieldName);
        }
Ejemplo n.º 19
0
        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);
        }