Exemplo n.º 1
0
        protected CodeRoot CreateClassAndNamespace(IEnumerable <IBaseConstruct> children)
        {
            Class cl = new Class(controller, "Class1");

            foreach (IBaseConstruct child in children)
            {
                cl.AddChild(child);
            }
            cl.Index = 10;
            AttributeSection attrs = new AttributeSection(controller);

            attrs.Index = 5;
            Attribute attr = new Attribute(controller);

            attr.Index = 6;
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Index = 0;
            ns.Name  = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot userRoot = new CodeRoot(controller);

            userRoot.AddChild(ns);
            return(userRoot);
        }
        private CodeRootMap CreateBasicMap(out Class cl2)
        {
            CodeRootMap map = new CodeRootMap();

            Class     cl = new Class(controller, "Class1");
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            map.AddCodeRoot(root, Version.PrevGen);

            cl      = new Class(controller, "Class1");
            ns      = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            cl2 = new Class(controller, "Class2");
            ns.AddChild(cl2);
            root = new CodeRoot(controller);
            root.AddChild(ns);
            map.AddCodeRoot(root, Version.NewGen);
            return(map);
        }
        private CodeRoot GetPrevGenOrNewGenRoot()
        {
            Class cl = new Class(controller, "Class1");

            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);

            // Create another class to match to the user one.
            Class c3 = new Class(controller, "Class3");

            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c3);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            return(root);
        }
        public void Class()
        {
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
Exemplo n.º 5
0
        public void Class()
        {
            Class cl = new Class(controller, "Class1");

            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
        public void Matching_Successful()
        {
            controller.Reorder = true;
            Class cl = new Class(controller, "Class1");

            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            Class            c2    = new Class(controller, "Class2"); // Extra class in user
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c2);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);

            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);

            root = GetPrevGenOrNewGenRoot();
            map.AddCodeRoot(root, Version.PrevGen);

            root = GetPrevGenOrNewGenRoot();
            map.AddCodeRoot(root, Version.NewGen);

            bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3");

            Assert.That(matchResult, Is.True);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "Class2");
            Assertions.StringContains(result, "Class3", 0);
            int count = 0;

            foreach (CodeRootMapNode node in map.AllNodes)
            {
                if (node.IsTheSameReference(c2))
                {
                    count++;
                }
            }
            Assert.That(count, Is.EqualTo(1));
        }
Exemplo n.º 7
0
        public void MatchesSavedSuccessfully()
        {
            XmlDocument doc        = new XmlDocument();
            Controller  controller = new CSharpController();

            controller.Reorder = true;

            CodeRootMap map       = new CodeRootMap();
            CodeRoot    userCR    = new CodeRoot(controller);
            CodeRoot    newgenCR  = new CodeRoot(controller);
            CodeRoot    prevgenCR = new CodeRoot(controller);

            Class clazz = new Class(controller, "Class1");

            clazz.AddChild(new Class(controller, "InnerClass"));
            userCR.AddChild(clazz);

            clazz = new Class(controller, "Class2");
            clazz.AddChild(new Class(controller, "InnerClass"));
            newgenCR.AddChild(clazz);

            clazz = new Class(controller, "Class3");
            clazz.AddChild(new Class(controller, "InnerClass"));
            prevgenCR.AddChild(clazz);

            map.AddCodeRoot(userCR, Version.User);
            map.AddCodeRoot(newgenCR, Version.NewGen);
            map.AddCodeRoot(prevgenCR, Version.PrevGen);

            Assert.That(map.MatchConstructs("Class1", "Class2", "Class3"), "Matching constructs", Is.True);

            CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor();

            processor.SaveCustomMappings(doc, map, "Test.cs");
            XmlNodeList nodes = doc.SelectNodes("Manifest/Mappings/CodeRootMappings/CodeRootMap");

            Assert.IsNotNull(nodes, "Couldn't find the CodeRootMap nodes");
            Assert.That(nodes.Count, Is.EqualTo(1));

            Assert.That(nodes.Item(0).Attributes["filename"].Value, Is.EqualTo("Test.cs"));

            XmlNode mappingElement = nodes.Item(0);

            XmlNode userNode = mappingElement.SelectSingleNode(ManifestConstants.UserObjectElement);
            XmlNode newgNode = mappingElement.SelectSingleNode(ManifestConstants.NewGenObjectElement);
            XmlNode prevNode = mappingElement.SelectSingleNode(ManifestConstants.PrevGenObjectElement);

            Assert.That(userNode, Is.Not.Null);
            Assert.That(newgNode, Is.Not.Null);
            Assert.That(prevNode, Is.Not.Null);

            Assert.That(userNode.InnerText, Is.EqualTo("Class1"));
            Assert.That(newgNode.InnerText, Is.EqualTo("Class2"));
            Assert.That(prevNode.InnerText, Is.EqualTo("Class3"));
        }
Exemplo n.º 8
0
        public void PrevGen_Is_Skipped_Where_No_Template_Or_User_Exist()
        {
            Class cl = new Class(controller, "Class1");

            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            Class            c2    = new Class(controller, "Class2"); // Extra class in prevgen
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c2);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);

            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.PrevGen);

            cl           = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            attrs = new AttributeSection(controller);
            attr  = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            ns      = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns);

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            // make sure that the deleted class Class2 was not included int he merged code root.
            Assertions.StringContains(result, "Class2", 0);
        }
        protected CodeRoot CreateBasicRoot()
        {
            Class cl = new Class(controller, "Class1");
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);

            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            return root;
        }
        protected CodeRoot CreateBasicRoot()
        {
            Class     cl = new Class(controller, "Class1");
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);

            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            return(root);
        }
        public void Attributes()
        {
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(attrs);
            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "[Serializable(true)]");
        }
Exemplo n.º 12
0
        public void User_Is_Missing_Others_Are_Exact_Copy()
        {
            Function func = new Function(controller);

            func.Name = "Method1";
            func.Modifiers.Add("public");
            func.ReturnType = new DataType(controller, "void");
            func.BodyText   = "{ }";

            Class cl = new Class(controller, "Class1");

            cl.AddChild(func);
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.PrevGen);
            map.AddCodeRoot(root, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "public void Method1()");
            Assertions.StringContains(result, "{ }");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
Exemplo n.º 13
0
        public void UsingStatements()
        {
            CodeRoot       root = CreateClassAndNamespace(new IBaseConstruct[0]);
            UsingStatement st   = new UsingStatement(controller, "", "System");

            st.Index = 0;
            root.AddChild(st);

            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "using System;");
        }
Exemplo n.º 14
0
        protected CodeRoot ConstructRootWithClass(IBaseConstruct childOfClass)
        {
            Class cl = new Class(controller, "Class1");

            cl.AddChild(childOfClass);
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            return(root);
        }
Exemplo n.º 15
0
        public void Namespace()
        {
            Namespace inter = new Namespace(controller);

            inter.Name = "ArchAngel.Tests";
            inter.AddChild(new UsingStatement(controller, "", "System"));
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(inter);

            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "using System");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
Exemplo n.º 16
0
        public void Attributes()
        {
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(attrs);
            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "[Serializable(true)]");
        }
Exemplo n.º 17
0
        protected CodeRoot CreateNamespaceAndInterface(IBaseConstruct inter)
        {
            Interface interface1 = new Interface(controller, "Interface1");

            interface1.Modifiers.Add("public");
            interface1.AddChild(inter);
            AttributeSection attrs = new AttributeSection(controller);
            Attribute        attr  = new Attribute(controller);

            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            interface1.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);

            ns.Name = "ArchAngel.Tests";
            ns.AddChild(interface1);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns);
            return(root);
        }
        public void Matching_Successful()
        {
            controller.Reorder = true;
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            Class c2 = new Class(controller, "Class2"); // Extra class in user
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c2);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);

            root = GetPrevGenOrNewGenRoot();
            map.AddCodeRoot(root, Version.PrevGen);

            root = GetPrevGenOrNewGenRoot();
            map.AddCodeRoot(root, Version.NewGen);

            bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3");

            Assert.That(matchResult, Is.True);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "Class2");
            Assertions.StringContains(result, "Class3", 0);
            int count = 0;
            foreach (CodeRootMapNode node in map.AllNodes)
            {
                if (node.IsTheSameReference(c2))
                    count++;
            }
            Assert.That(count, Is.EqualTo(1));
        }
        public void Namespace()
        {
            Namespace inter = new Namespace(controller);
            inter.Name = "ArchAngel.Tests";
            inter.AddChild(new UsingStatement(controller, "", "System"));
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(inter);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "using System");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
        public void PrevGen_Is_Skipped_Where_No_Template_Or_User_Exist()
        {
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            Class c2 = new Class(controller, "Class2"); // Extra class in prevgen
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c2);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            attrs = new AttributeSection(controller);
            attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns);

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            // make sure that the deleted class Class2 was not included int he merged code root.
            Assertions.StringContains(result, "Class2", 0);
        }
        public void User_Is_Missing_Others_Are_Exact_Copy()
        {
            Function func = new Function(controller);
            func.Name = "Method1";
            func.Modifiers.Add("public");
            func.ReturnType = new DataType(controller, "void");
            func.BodyText = "{ }";

            Class cl = new Class(controller, "Class1");
            cl.AddChild(func);
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.PrevGen);
            map.AddCodeRoot(root, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "public void Method1()");
            Assertions.StringContains(result, "{ }");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
 protected CodeRoot ConstructRootWithClass(IBaseConstruct childOfClass)
 {
     Class cl = new Class(controller, "Class1");
     cl.AddChild(childOfClass);
     AttributeSection attrs = new AttributeSection(controller);
     Attribute attr = new Attribute(controller);
     attr.PositionalArguments.Add("true");
     attr.Name = "Serializable";
     attrs.AddAttribute(attr);
     cl.AddAttributeSection(attrs);
     Namespace ns = new Namespace(controller);
     ns.Name = "ArchAngel.Tests";
     ns.AddChild(cl);
     CodeRoot root = new CodeRoot(controller);
     root.AddChild(ns);
     return root;
 }
 protected CodeRoot CreateClassAndNamespace(IEnumerable<IBaseConstruct> children)
 {
     Class cl = new Class(controller, "Class1");
     foreach(IBaseConstruct child in children)
         cl.AddChild(child);
     cl.Index = 10;
     AttributeSection attrs = new AttributeSection(controller);
     attrs.Index = 5;
     Attribute attr = new Attribute(controller);
     attr.Index = 6;
     attr.PositionalArguments.Add("true");
     attr.Name = "Serializable";
     attrs.AddAttribute(attr);
     cl.AddAttributeSection(attrs);
     Namespace ns = new Namespace(controller);
     ns.Index = 0;
     ns.Name = "ArchAngel.Tests";
     ns.AddChild(cl);
     CodeRoot userRoot = new CodeRoot(controller);
     userRoot.AddChild(ns);
     return userRoot;
 }
        public void Matching_Successful()
        {
            CodeRootMap map = new CodeRootMap();

            Class     cl  = new Class(controller, "Class1");
            Namespace ns1 = new Namespace(controller);

            ns1.Name = "ArchAngel.Tests";
            ns1.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);

            root.AddChild(ns1);
            map.AddCodeRoot(root, Version.User);

            cl = new Class(controller, "Class1");
            Namespace ns2 = new Namespace(controller);

            ns2.Name = "Slyce.Tests";
            ns2.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns2);
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            Namespace ns3 = new Namespace(controller);

            ns3.Name = "Slyce.Tests";
            ns3.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns3);
            map.AddCodeRoot(root, Version.NewGen);

            map.MatchConstructs(map, ns1, ns3, ns2);

            foreach (CodeRootMapNode child in map.AllNodes)
            {
                Assert.That(child.PrevGenObj, Is.Not.Null,
                            string.Format("PrevGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
                Assert.That(child.NewGenObj, Is.Not.Null,
                            string.Format("NewGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
                Assert.That(child.UserObj, Is.Not.Null,
                            string.Format("User in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
            }

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly));
            Assertions.StringContains(result, "class Class1", 1);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);
            Assertions.StringContains(result, "namespace Slyce.Tests", 0);

            int count = 0;

            foreach (CodeRootMapNode node in map.AllNodes)
            {
                if (node.IsTheSameReference(ns1))
                {
                    count++;
                }
            }
            Assert.That(count, Is.EqualTo(1));
        }
        private CodeRootMap CreateBasicMap(out Class cl2)
        {
            CodeRootMap map = new CodeRootMap();

            Class cl = new Class(controller, "Class1");
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            cl2 = new Class(controller, "Class2");
            ns.AddChild(cl2);
            root = new CodeRoot(controller);
            root.AddChild(ns);
            map.AddCodeRoot(root, Version.NewGen);
            return map;
        }
        public void Matching_Successful()
        {
            CodeRootMap map = new CodeRootMap();

            Class cl = new Class(controller, "Class1");
            Namespace ns1 = new Namespace(controller);
            ns1.Name = "ArchAngel.Tests";
            ns1.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns1);
            map.AddCodeRoot(root, Version.User);

            cl = new Class(controller, "Class1");
            Namespace ns2 = new Namespace(controller);
            ns2.Name = "Slyce.Tests";
            ns2.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns2);
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            Namespace ns3 = new Namespace(controller);
            ns3.Name = "Slyce.Tests";
            ns3.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns3);
            map.AddCodeRoot(root, Version.NewGen);

            map.MatchConstructs(map, ns1, ns3, ns2);

            foreach (CodeRootMapNode child in map.AllNodes)
            {
                Assert.That(child.PrevGenObj, Is.Not.Null,
                            string.Format("PrevGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
                Assert.That(child.NewGenObj, Is.Not.Null,
                            string.Format("NewGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
                Assert.That(child.UserObj, Is.Not.Null,
                            string.Format("User in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
            }

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly));
            Assertions.StringContains(result, "class Class1", 1);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);
            Assertions.StringContains(result, "namespace Slyce.Tests", 0);

            int count = 0;
            foreach (CodeRootMapNode node in map.AllNodes)
            {
                if (node.IsTheSameReference(ns1))
                    count++;
            }
            Assert.That(count, Is.EqualTo(1));
        }
        private CodeRoot GetPrevGenOrNewGenRoot()
        {
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);

            // Create another class to match to the user one.
            Class c3 = new Class(controller, "Class3");

            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c3);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            return root;
        }
        public void MatchesSavedSuccessfully()
        {
            XmlDocument doc = new XmlDocument();
            Controller controller = new CSharpController();
            controller.Reorder = true;

            CodeRootMap map = new CodeRootMap();
            CodeRoot userCR = new CodeRoot(controller);
            CodeRoot newgenCR = new CodeRoot(controller);
            CodeRoot prevgenCR = new CodeRoot(controller);

            Class clazz = new Class(controller, "Class1");
            clazz.AddChild(new Class(controller, "InnerClass"));
            userCR.AddChild(clazz);

            clazz = new Class(controller, "Class2");
            clazz.AddChild(new Class(controller, "InnerClass"));
            newgenCR.AddChild(clazz);

            clazz = new Class(controller, "Class3");
            clazz.AddChild(new Class(controller, "InnerClass"));
            prevgenCR.AddChild(clazz);

            map.AddCodeRoot(userCR,		Version.User);
            map.AddCodeRoot(newgenCR,	Version.NewGen);
            map.AddCodeRoot(prevgenCR,	Version.PrevGen);

            Assert.That(map.MatchConstructs("Class1", "Class2", "Class3"), "Matching constructs", Is.True);

            CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor();
            processor.SaveCustomMappings(doc, map, "Test.cs");
            XmlNodeList nodes = doc.SelectNodes("Manifest/Mappings/CodeRootMappings/CodeRootMap");
            Assert.IsNotNull(nodes, "Couldn't find the CodeRootMap nodes");
            Assert.That(nodes.Count, Is.EqualTo(1));

            Assert.That(nodes.Item(0).Attributes["filename"].Value, Is.EqualTo("Test.cs"));

            XmlNode mappingElement = nodes.Item(0);

            XmlNode userNode = mappingElement.SelectSingleNode(ManifestConstants.UserObjectElement);
            XmlNode newgNode = mappingElement.SelectSingleNode(ManifestConstants.NewGenObjectElement);
            XmlNode prevNode = mappingElement.SelectSingleNode(ManifestConstants.PrevGenObjectElement);

            Assert.That(userNode, Is.Not.Null);
            Assert.That(newgNode, Is.Not.Null);
            Assert.That(prevNode, Is.Not.Null);

            Assert.That(userNode.InnerText, Is.EqualTo("Class1"));
            Assert.That(newgNode.InnerText, Is.EqualTo("Class2"));
            Assert.That(prevNode.InnerText, Is.EqualTo("Class3"));
        }
 protected CodeRoot CreateNamespaceAndInterface(IBaseConstruct inter)
 {
     Interface interface1 = new Interface(controller, "Interface1");
     interface1.Modifiers.Add("public");
     interface1.AddChild(inter);
     AttributeSection attrs = new AttributeSection(controller);
     Attribute attr = new Attribute(controller);
     attr.PositionalArguments.Add("true");
     attr.Name = "Serializable";
     attrs.AddAttribute(attr);
     interface1.AddAttributeSection(attrs);
     Namespace ns = new Namespace(controller);
     ns.Name = "ArchAngel.Tests";
     ns.AddChild(interface1);
     CodeRoot root = new CodeRoot(controller);
     root.AddChild(ns);
     return root;
 }