コード例 #1
0
        public void InterfaceProperty()
        {
            InterfaceProperty inter = new InterfaceProperty(controller, "InterfaceProperty1");

            inter.Name     = "File";
            inter.DataType = new DataType(controller, "int");

            InterfaceAccessor acc = new InterfaceAccessor(controller);

            acc.AccessorType = InterfaceAccessor.AccessorTypes.Get;
            inter.AddChild(acc);

            acc = new InterfaceAccessor(controller);
            acc.AccessorType = InterfaceAccessor.AccessorTypes.Set;
            inter.AddChild(acc);

            CodeRoot root = CreateNamespaceAndInterface(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, "public interface Interface1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "int File");
            Assertions.StringContains(result, "get;");
            Assertions.StringContains(result, "set;");
        }
コード例 #2
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");
        }
コード例 #3
0
        public void Constant()
        {
            Constant con = new Constant(controller);

            con.DataType = new DataType(controller, "int");
            con.Modifiers.Add("public");
            con.Name       = "CONSTANT1";
            con.Expression = "5";

            CodeRoot root = CreateClassAndNamespace(con);

            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");
            Assertions.StringContains(result, "public const int CONSTANT1 = 5;");
        }
コード例 #4
0
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);

            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            CodeRoot root = CreateClassAndNamespace(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, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public delegate int File");
        }
コード例 #5
0
        public void Indexer_Renamed_Params()
        {
            CodeRoot root = CreateIndexer("i");

            CodeRootMap map = new CodeRootMap();

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

            CodeRoot userRoot = CreateIndexer("i1");

            map.AddCodeRoot(userRoot, Version.User);

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

            Assert.That(result, Is.Not.EqualTo(root.ToString()));
            Assert.That(result, Is.EqualTo(userRoot.ToString()));

            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "int this [int i1]");
            Assertions.StringContains(result, "get{ return file[i]; }");
            Assertions.StringContains(result, "set{ file[i] = value; }");
        }
コード例 #6
0
        public void Map_Contains_CodeRoot()
        {
            CodeRootMap    map      = new CodeRootMap();
            ICodeRoot      coderoot = mocks.StrictMock <ICodeRoot>();
            IBaseConstruct bc1      = mocks.DynamicMock <IBaseConstruct>();
            IBaseConstruct bc2      = mocks.DynamicMock <IBaseConstruct>();

            Utility.SetupBaseConstructs(mocks, bc1, bc2, coderoot);

            using (mocks.Playback())
            {
                map.AddCodeRoot(coderoot, Version.User);
            }

            Assert.That(map.ChildNodes, Has.Count(1));
            Assert.That(map.AllNodes, Has.Count(2));
            Assert.That(map.ChildNodes[0], Is.Not.Null);
            Assert.That(map.ChildNodes[0].IsTreeRoot, Is.False);
            Assert.That(map.ChildNodes[0].UserObj, Is.SameAs(bc1));
            Assert.That(map.ChildNodes[0].Omit, Is.False);
            Assert.That(map.ChildNodes[0].ParentNode, Is.SameAs(map));
            Assert.That(map.ChildNodes[0].ParentTree, Is.SameAs(map));

            CodeRootMapNode node = map.ChildNodes[0].ChildNodes[0];

            Assert.That(node, Is.Not.Null);
            Assert.That(node.IsTreeRoot, Is.False);
            Assert.That(node.UserObj, Is.SameAs(bc2));
            Assert.That(node.Omit, Is.False);
            Assert.That(node.ParentNode, Is.SameAs(map.ChildNodes[0]));
            Assert.That(node.ParentTree, Is.SameAs(map));
        }
コード例 #7
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");
        }
コード例 #8
0
        public void Constructor()
        {
            Constructor constructor = new Constructor(controller);

            constructor.Modifiers.Add("public");
            constructor.Name     = "Class1";
            constructor.BodyText = "{ }";
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            constructor.Parameters.Add(param);

            CodeRoot root = CreateClassAndNamespace(constructor);

            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");
            Assertions.StringContains(result, "public Class1");
            Assertions.StringContains(result, "{ }");
        }
コード例 #9
0
        public void Matching_Successful()
        {
            CodeRootMap map = new CodeRootMap();

            CodeRoot userroot = CreateBasicRoot();

            map.AddCodeRoot(userroot, Version.User);

            CodeRoot prevroot = CreateBasicRoot();

            map.AddCodeRoot(prevroot, Version.PrevGen);

            CodeRoot templateroot = CreateBasicRoot();

            map.AddCodeRoot(templateroot, Version.NewGen);

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

            Assertions.StringContains(result, "class Class1", 1);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);

            map.MatchConstructs(map.GetExactNode(userroot.Namespaces[0]), userroot.Namespaces[0].Classes[0], null, prevroot.Namespaces[0].Classes[0]);
            map.Diff();

            Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(2));
            Assert.That(map.ChildNodes[0].ChildNodes[0].DetermineMissingConstructs(), Is.EqualTo(MissingObject.User | MissingObject.PrevGen));
            Assert.That(map.ChildNodes[0].ChildNodes[1].DetermineMissingConstructs(), Is.EqualTo(MissingObject.NewGen));

            ICodeRoot merged = map.GetMergedCodeRoot();

            result = merged.ToString();
            Assertions.StringContains(result, "class Class1", 2);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);
        }
コード例 #10
0
        public void AssertDiffType(string prevgenFilename, string userFilename, string templateFilename, TypeOfDiff typeOfDiff)
        {
            CodeRoot prevgen  = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, prevgenFilename));
            CodeRoot template = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, templateFilename));
            CodeRoot user     = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, userFilename));

            CodeRootMap map = new CodeRootMap();

            if (prevgen != null)
            {
                map.AddCodeRoot(prevgen, Version.PrevGen);
            }
            if (template != null)
            {
                map.AddCodeRoot(template, Version.NewGen);
            }
            if (user != null)
            {
                map.AddCodeRoot(user, Version.User);
            }

            TypeOfDiff diff = map.Diff();

            Assert.That(diff, Is.EqualTo(typeOfDiff));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        public void Enumeration()
        {
            Enumeration inter = new Enumeration(controller);

            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.Members.Add(new Enumeration.EnumMember(controller, "Read"));
            inter.Members.Add(new Enumeration.EnumMember(controller, "Write"));

            CodeRoot root = CreateClassAndNamespace(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()));
            Assert.That(result.Contains("Read"), Is.True, "Contains Read enum value");
            Assert.That(result.Contains("Write"), Is.True, "Contains Write enum value");
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "Read");
            Assertions.StringContains(result, "Write");
            Assertions.StringContains(result, "public enum File");
        }
コード例 #13
0
        public void Map_Contains_Both_CodeRoots()
        {
            CodeRootMap map = new CodeRootMap();
            ICodeRoot coderoot = mocks.StrictMock<ICodeRoot>();
            IBaseConstruct bc1 = mocks.DynamicMock<IBaseConstruct>();
            IBaseConstruct bc2 = mocks.DynamicMock<IBaseConstruct>();
            Utility.SetupBaseConstructs(mocks, bc1, bc2, coderoot);

            using (mocks.Playback())
            {
                map.AddCodeRoot(coderoot, Version.User);
                map.AddCodeRoot(coderoot, Version.NewGen);
            }

            Assert.That(map.ChildNodes, Has.Count(1));
            Assert.That(map.AllNodes, Has.Count(2));
            Assert.That(map.ChildNodes[0], Is.Not.Null);
            Assert.That(map.ChildNodes[0].IsTreeRoot, Is.False);
            Assert.That(map.ChildNodes[0].UserObj, Is.SameAs(bc1));
            Assert.That(map.ChildNodes[0].NewGenObj, Is.SameAs(bc1));
            Assert.That(map.ChildNodes[0].Omit, Is.False);
            Assert.That(map.ChildNodes[0].ParentNode, Is.SameAs(map));
            Assert.That(map.ChildNodes[0].ParentTree, Is.SameAs(map));

            CodeRootMapNode node = map.ChildNodes[0].ChildNodes[0];

            Assert.That(node, Is.Not.Null);
            Assert.That(node.IsTreeRoot, Is.False);
            Assert.That(node.UserObj, Is.SameAs(bc2));
            Assert.That(node.NewGenObj, Is.SameAs(bc2));
            Assert.That(node.Omit, Is.False);
            Assert.That(node.ParentNode, Is.SameAs(map.ChildNodes[0]));
            Assert.That(node.ParentTree, Is.SameAs(map));
        }
コード例 #14
0
        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 Returns_An_Empty_Collection()
        {
            CodeRootMap root = new CodeRootMap();
            root.AddCodeRoot(controller.Root, Version.NewGen);

            ReadOnlyCollection<IBaseConstruct> children =
                root.ChildNodes[0].GetSiblingsOfSameType(Version.User);

            Assert.That(children.Count, Is.EqualTo(0));
        }
コード例 #16
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"));
        }
        public void Returns_An_Empty_Collection()
        {
            CodeRootMap root = new CodeRootMap();

            root.AddCodeRoot(controller.Root, Version.NewGen);

            ReadOnlyCollection <IBaseConstruct> children =
                root.ChildNodes[0].GetSiblingsOfSameType(Version.User);

            Assert.That(children.Count, Is.EqualTo(0));
        }
コード例 #18
0
        public void User_File_Doesnt_Exist_Diff_Result_Is_Exact_Copy()
        {
            string original = Path.Combine(ResourcePath, "Class1.cs");

            CodeRootMap codeRootMap = new CodeRootMap();

            ICodeRoot codeRoot = Diffing_Two_Different_Basic_CSharp_Files.GetCodeRoot(original);
            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy));
        }
コード例 #19
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);
        }
コード例 #20
0
        public void Remove_Base_Construct()
        {
            Class       cl2;
            CodeRootMap map = CreateBasicMap(out cl2);

            Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(2));

            map.ChildNodes[0].ChildNodes[1].RemoveBaseConstruct(cl2, true);

            Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(1));
        }
コード例 #21
0
        public void Remove_Base_Construct_No_Tree_Cleanup()
        {
            Class       cl2;
            CodeRootMap map = CreateBasicMap(out cl2);

            Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(2));

            map.ChildNodes[0].ChildNodes[1].RemoveBaseConstruct(cl2, false);

            Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(2));
            Assert.That(map.ChildNodes[0].ChildNodes[1].GetFirstValidBaseConstruct(), Is.Null);
        }
コード例 #22
0
        public void User_File_Doesnt_Exist_Diff_Result_Is_Exact_Copy()
        {
            string original = Path.Combine(ResourcePath, "Class1.cs");

            CodeRootMap codeRootMap = new CodeRootMap();

            ICodeRoot codeRoot = Diffing_Two_Different_Basic_CSharp_Files.GetCodeRoot(original);

            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy));
        }
        public void Returns_Three_Siblings()
        {
            CodeRootMap root = new CodeRootMap();
            root.AddCodeRoot(controller.Root, Version.NewGen);

            ReadOnlyCollection<IBaseConstruct> children =
                root.ChildNodes[0].ChildNodes[0].GetSiblingsOfSameType(Version.NewGen);

            Assert.That(children.Count, Is.EqualTo(3));
            Assert.That(children.Contains(func2), "Contains second function");
            Assert.That(children.Contains(func3), "Contains third function");
            Assert.That(children.Contains(func4), "Contains fourth function");
        }
コード例 #24
0
        internal static void TestFiles_UserAndTemplate(string original, string changed, TypeOfDiff diffType)
        {
            CodeRootMap codeRootMap = new CodeRootMap();

            ICodeRoot codeRoot = GetCodeRoot(original);

            codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen);

            codeRoot = GetCodeRoot(changed);
            codeRootMap.AddCodeRoot(codeRoot, Version.User);
            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(diffType));
        }
        public void Returns_Three_Siblings()
        {
            CodeRootMap root = new CodeRootMap();

            root.AddCodeRoot(controller.Root, Version.NewGen);

            ReadOnlyCollection <IBaseConstruct> children =
                root.ChildNodes[0].ChildNodes[0].GetSiblingsOfSameType(Version.NewGen);

            Assert.That(children.Count, Is.EqualTo(3));
            Assert.That(children.Contains(func2), "Contains second function");
            Assert.That(children.Contains(func3), "Contains third function");
            Assert.That(children.Contains(func4), "Contains fourth function");
        }
コード例 #26
0
        public void AssertDiffType(string prevgenFilename, string userFilename, string templateFilename, TypeOfDiff typeOfDiff)
        {
            CodeRoot prevgen = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, prevgenFilename));
            CodeRoot template = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, templateFilename));
            CodeRoot user = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, userFilename));

            CodeRootMap map = new CodeRootMap();
            if(prevgen != null) map.AddCodeRoot(prevgen, Version.PrevGen);
            if (template != null) map.AddCodeRoot(template, Version.NewGen);
            if (user != null) map.AddCodeRoot(user, Version.User);

            TypeOfDiff diff = map.Diff();

            Assert.That(diff, Is.EqualTo(typeOfDiff));
        }
コード例 #27
0
        public void Diff_Result_Is_Exact_Copy()
        {
            string original = Path.Combine(ResourcePath, "Class1.cs");

            CodeRootMap codeRootMap = new CodeRootMap();

            CSharpParser formatter = new CSharpParser();
            formatter.ParseCode(File.ReadAllText(original));
            ICodeRoot codeRoot = formatter.CreatedCodeRoot;

            codeRootMap.AddCodeRoot(codeRoot, Version.User);
            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);
            codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy));
        }
コード例 #28
0
        private void PopulateGrid()
        {
            if (DesignMode)
            {
                return;
            }

            ucTextMergeEditor.FileInformation = null;
            ucTextMergeEditor.Fill();

            try
            {
                treeListObjects.BeginUpdate();
                treeListObjects.Nodes.Clear();

                Node root = new Node();
                treeListObjects.Nodes.Add(root);
                root.Text  = fileInformation.RelativeFilePath;
                root.Image = imageLoader.GetFileImage();

                CodeRootMap map = fileInformation.CodeRootMap;

                foreach (CodeRootMapNode node in map.ChildNodes)
                {
                    AddCodeRootNodeToTreeView(node, root);
                }
                root.Expanded = true;
            }
            finally
            {
                FilterNodes();
                treeListObjects.EndUpdate();
                if (treeListObjects.Nodes.Count > 0)
                {
                    Node nodeToSelect = treeListObjects.Nodes[0];
                    while (nodeToSelect != null)
                    {
                        if (nodeToSelect.Tag != null && ((CodeRootMapNode)nodeToSelect.Tag).DiffTypeExcludingChildren != TypeOfDiff.ExactCopy)
                        {
                            treeListObjects.SelectedNode = nodeToSelect;
                            break;
                        }
                        nodeToSelect = nodeToSelect.NextVisibleNode;
                    }
                }
            }
        }
コード例 #29
0
        public void Diff_Result_Is_Exact_Copy()
        {
            string original = Path.Combine(ResourcePath, "Class1.cs");

            CodeRootMap codeRootMap = new CodeRootMap();

            CSharpParser formatter = new CSharpParser();

            formatter.ParseCode(File.ReadAllText(original));
            ICodeRoot codeRoot = formatter.CreatedCodeRoot;

            codeRootMap.AddCodeRoot(codeRoot, Version.User);
            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);
            codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy));
        }
コード例 #30
0
        public void Function()
        {
            CodeRootMap map  = new CodeRootMap();
            CodeRoot    root = CreateFunctionAndClass("i");

            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, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public int GetVal(int i)");
            Assertions.StringContains(result, "{ return 5; }");
        }
コード例 #31
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)]");
        }
コード例 #32
0
        /// <summary>
        /// Loads custom mappings from the XmlDocument and applies them to the CodeRootMap.
        /// Returns a list of mappings that could not be applied.
        /// </summary>
        /// <param name="doc">The XmlDocument to load from.</param>
        /// <param name="map">The CodeRootMap to apply the mappings to.</param>
        /// <param name="filenameForMap">The filename to use when looking for mappings for this CodeRootMap</param>
        public void LoadCustomMappings(XmlDocument doc, CodeRootMap map, string filenameForMap)
        {
            string xpathQuery = string.Format("{0}/{1}/{2}/{3}[@filename='{4}']", Con.ManifestElement, Con.MappingsElement, Con.CodeRootMappingsElement, Con.CodeRootMappingElement, filenameForMap);

            XmlNodeList nodes = doc.SelectNodes(xpathQuery);
            if (nodes == null) return;

            foreach(XmlNode node in nodes)
            {
                XmlNode userNode = node.SelectSingleNode(Con.UserObjectElement);
                XmlNode newgNode = node.SelectSingleNode(Con.NewGenObjectElement);
                XmlNode prevNode = node.SelectSingleNode(Con.PrevGenObjectElement);

                map.MatchConstructs(string.IsNullOrEmpty(userNode.InnerText) ? null : userNode.InnerText,
                                    string.IsNullOrEmpty(newgNode.InnerText) ? null : newgNode.InnerText,
                                    string.IsNullOrEmpty(prevNode.InnerText) ? null : prevNode.InnerText);
            }
        }
コード例 #33
0
        public void InterfaceMethod()
        {
            CodeRoot root = CreateInterfaceAndMethod("i");

            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, "public interface Interface1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "int Method1 (int i);");
        }
コード例 #34
0
        public void Operator()
        {
            CodeRoot root = CreateClassAndOperator("i");

            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");
            Assertions.StringContains(result, "public static int operator +(Class1 self, int i)");
            Assertions.StringContains(result, "{ return 5; }");
        }
コード例 #35
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");
        }
コード例 #36
0
        public void MatchesLoadedSuccessfully()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            CodeRootMap map = mocks.StrictMock <CodeRootMap>();

            using (mocks.Record())
            {
                Expect.Call(map.MatchConstructs("Namespace|Class|Function1(string, int)", "Namespace|Class|Function2(string, int)", "Namespace|Class|Function3(string, int)")).Repeat.Once().Return(true);
                Expect.Call(map.MatchConstructs("Namespace|Class|Field1", "Namespace|Class|Field2", "Namespace|Class|Field3")).Repeat.Once().Return(true);
            }

            using (mocks.Playback())
            {
                CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor();
                processor.LoadCustomMappings(doc, map, "Test.cs");
            }
        }
コード例 #37
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;");
        }
コード例 #38
0
        public void EmptyPlaceholder()
        {
            EmptyPlaceholder inter = new EmptyPlaceholder(controller, "asdfasd", 2);

            CodeRoot root = CreateClassAndNamespace(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, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "asdfasd", 0);
        }
コード例 #39
0
        public void Map_Is_Initially_Empty()
        {
            CodeRootMap map = new CodeRootMap();

            Assert.That(map.ChildNodes, Is.Not.Null);
            Assert.That(map.AllNodes, Is.Not.Null);
            Assert.That(map.ChildNodes, Is.Empty);
            Assert.That(map.AllNodes, Is.Empty);
            Assert.That(map.IsTreeRoot, Is.True);
            Assert.That(map.Omit, Is.False);
            Assert.That(map.ParentNode, Is.Null);
            Assert.That(map.ParentTree, Is.SameAs(map));

            Assert.That(map.PrevGenCodeRoot, Is.Null);
            Assert.That(map.UserCodeRoot, Is.Null);
            Assert.That(map.NewGenCodeRoot, Is.Null);
            Assert.That(map.PrevGenObj, Is.Null);
            Assert.That(map.UserObj, Is.Null);
            Assert.That(map.NewGenObj, Is.Null);
        }
コード例 #40
0
        public void Struct()
        {
            Struct inter = new Struct(null);
            inter.Name = "Struct1";
            inter.BaseNames.Add("ValueType");
            inter.GenericTypes.Add("T");
            CodeRoot root = CreateClassAndNamespace(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, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "struct Struct1<T> : ValueType");
        }
コード例 #41
0
        public void Diff_Does_Not_Modify_Base_Constructs()
        {
            string original = Path.Combine(ResourcePath, "Class1.cs");
            string changed = Path.Combine(ResourcePath, "Class1_WithConstructor.cs");

            ICodeRoot userCR = GetCodeRoot(original);
            ICodeRoot newgenCR = GetCodeRoot(changed);
            ICodeRoot prevgenCR = GetCodeRoot(changed);

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

            map.Diff();

            ICodeRoot withoutDiff = GetCodeRoot(changed);

            Assert.That(map.PrevGenCodeRoot.ToString(), Is.EqualTo(withoutDiff.ToString()));
            Assert.That(map.NewGenCodeRoot.ToString(), Is.EqualTo(withoutDiff.ToString()));
        }
コード例 #42
0
        public void User_Added_Modifier()
        {
            CodeRootMap map = new CodeRootMap();
            CodeRoot root = CreateFunctionAndClass("i");
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            Function userFunction;
            CodeRoot userRoot = CreateFunctionAndClass("i1", out userFunction);
            userFunction.Modifiers.Add("static");
            map.AddCodeRoot(userRoot, Version.User);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.Not.EqualTo(root.ToString()));
            Assert.That(result, Is.EqualTo(userRoot.ToString()));
            Assertions.StringContains(result, "class Class1", 1);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);
            Assertions.StringContains(result, "public static int GetVal(int i1)", 1);
            Assertions.StringContains(result, "{ return 5; }", 1);
        }
コード例 #43
0
 public void Exception_Raised()
 {
     CodeRootMap map = new CodeRootMap();
     map.Diff();
 }
コード例 #44
0
        public void Matching_Successful()
        {
            CodeRootMap map = new CodeRootMap();

            CodeRoot userroot = CreateBasicRoot();
            map.AddCodeRoot(userroot, Version.User);

            CodeRoot prevroot = CreateBasicRoot();
            map.AddCodeRoot(prevroot, Version.PrevGen);

            CodeRoot templateroot = CreateBasicRoot();
            map.AddCodeRoot(templateroot, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assertions.StringContains(result, "class Class1", 1);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);

            map.MatchConstructs(map.GetExactNode(userroot.Namespaces[0]), userroot.Namespaces[0].Classes[0], null, prevroot.Namespaces[0].Classes[0]);
            map.Diff();

            Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(2));
            Assert.That(map.ChildNodes[0].ChildNodes[0].DetermineMissingConstructs(), Is.EqualTo(MissingObject.User | MissingObject.PrevGen));
            Assert.That(map.ChildNodes[0].ChildNodes[1].DetermineMissingConstructs(), Is.EqualTo(MissingObject.NewGen));

            ICodeRoot merged = map.GetMergedCodeRoot();
            result = merged.ToString();
            Assertions.StringContains(result, "class Class1", 2);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);
        }
コード例 #45
0
        public void Property()
        {
            Property inter = new Property(controller);
            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.DataType = new DataType(controller, "string");

            PropertyAccessor acc = new PropertyAccessor(controller);
            acc.Modifier = "public";
            acc.BodyText = "{ return file; }";
            acc.AccessorType = PropertyAccessor.AccessorTypes.Get;
            inter.AddChild(acc);

            acc = new PropertyAccessor(controller);
            acc.Modifier = "protected";
            acc.BodyText = "{ file = value; }";
            acc.AccessorType = PropertyAccessor.AccessorTypes.Set;
            inter.AddChild(acc);

            CodeRoot root = CreateClassAndNamespace(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, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public string File");
            Assertions.StringContains(result, "get{ return file; }");
            Assertions.StringContains(result, "set{ file = value; }");
        }
コード例 #46
0
        public void Constant()
        {
            Constant con = new Constant(controller);
            con.DataType = new DataType(controller,"int");
            con.Modifiers.Add("public");
            con.Name = "CONSTANT1";
            con.Expression = "5";

            CodeRoot root = CreateClassAndNamespace(con);

            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");
            Assertions.StringContains(result, "public const int CONSTANT1 = 5;");
        }
コード例 #47
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;");
        }
コード例 #48
0
        public void ClearMap()
        {
            MockRepository mocks = new MockRepository();
            CodeRootMap map = new CodeRootMap();
            IBaseConstruct bc;
            using(mocks.Record())
            {
                bc = mocks.DynamicMock<IBaseConstruct>();
                Expect.Call(bc.WalkChildren()).Return(new List<IBaseConstruct>().AsReadOnly());
            }

            map.AddBaseConstructAsNewChild(bc, Version.User);

            Assert.That(map.AllNodes, Has.Count(1));
            Assert.That(map.ChildNodes, Has.Count(1));

            map.Clear();

            Assert.That(map.AllNodes, Has.Count(0));
            Assert.That(map.ChildNodes, Has.Count(0));
        }
コード例 #49
0
        public void Map_Is_Initially_Empty()
        {
            CodeRootMap map = new CodeRootMap();

            Assert.That(map.ChildNodes, Is.Not.Null);
            Assert.That(map.AllNodes, Is.Not.Null);
            Assert.That(map.ChildNodes, Is.Empty);
            Assert.That(map.AllNodes, Is.Empty);
            Assert.That(map.IsTreeRoot, Is.True);
            Assert.That(map.Omit, Is.False);
            Assert.That(map.ParentNode, Is.Null);
            Assert.That(map.ParentTree, Is.SameAs(map));

            Assert.That(map.PrevGenCodeRoot, Is.Null);
            Assert.That(map.UserCodeRoot, Is.Null);
            Assert.That(map.NewGenCodeRoot, Is.Null);
            Assert.That(map.PrevGenObj, Is.Null);
            Assert.That(map.UserObj, Is.Null);
            Assert.That(map.NewGenObj, Is.Null);
        }
コード例 #50
0
        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));
        }
コード例 #51
0
        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));
        }
コード例 #52
0
        public void Regions()
        {
            controller.Reorder = false;
            Region region = new Region(controller, "Start", 11);

            CodeRoot root = CreateClassAndNamespace(new IBaseConstruct[]{region});

            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");
            Assertions.StringContains(result, "#region Start");
            Assertions.StringContains(result, "#endregion");
            Assert.That(result.IndexOf("#region Start"), Is.LessThan(result.IndexOf("#endregion")));
        }
コード例 #53
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);
        }
コード例 #54
0
        /// <summary>
        /// Saves the custom mappings in the given CodeRootMap to the XmlDocument.
        /// </summary>
        /// <param name="doc">The XmlDocument to save the mappings to.</param>
        /// <param name="map">The CodeRootMap to inspect for custom mappings.</param>
        /// <param name="filenameForMap">The filename to use when saving mappings for this CodeRootMap</param>
        public void SaveCustomMappings(XmlDocument doc, CodeRootMap map, string filenameForMap)
        {
            // Get each of the nodes marked as a custom match.
            // Note that it is vitally important that these are in order.
            // The parent nodes should come before the child nodes.
            IList<CodeRootMapNode> customNodes = map.GetCustomMatchedNodes();

            // Create or find the node that we need to add to.
            XmlNode root = doc.SelectSingleNode(Con.ManifestElement);
            if(root == null)
            {
                root = doc.CreateElement(Con.ManifestElement);
                doc.AppendChild(root);
            }

            XmlNode mappingsNode = root.SelectSingleNode(Con.MappingsElement);
            if(mappingsNode == null)
            {
                mappingsNode = doc.CreateElement(Con.MappingsElement);
                root.AppendChild(mappingsNode);
            }

            XmlNode crMappingsNode = root.SelectSingleNode(Con.CodeRootMappingsElement);
            if(crMappingsNode == null)
            {
                crMappingsNode = doc.CreateElement(Con.CodeRootMappingsElement);
                mappingsNode.AppendChild(crMappingsNode);
            }

            // Clear the old custom mappings for this file.
            XmlNodeList oldMappings = crMappingsNode.SelectNodes(string.Format("{0}[@{1}='{2}']",
                Con.CodeRootMappingElement, Con.CodeRootMappingFilenameAttribute, filenameForMap));
            if(oldMappings != null)
            {
                foreach(XmlNode node in oldMappings)
                {
                    node.ParentNode.RemoveChild(node);
                }
            }

            // Add each of them to the custom map document
            foreach(CodeRootMapNode node in customNodes)
            {
                XmlNode crmnMappingNode = doc.CreateElement(Con.CodeRootMappingElement);
                XmlAttribute attr = doc.CreateAttribute(Con.CodeRootMappingFilenameAttribute);
                attr.Value = filenameForMap;
                crmnMappingNode.Attributes.Append(attr);

                XmlNode userNode = doc.CreateElement(ManifestConstants.UserObjectElement);
                userNode.InnerText = node.UserObj == null ? "" : node.UserObj.FullyQualifiedIdentifer;

                XmlNode newgNode = doc.CreateElement(ManifestConstants.NewGenObjectElement);
                newgNode.InnerText = node.NewGenObj == null ? "" : node.NewGenObj.FullyQualifiedIdentifer;

                XmlNode prevNode = doc.CreateElement(ManifestConstants.PrevGenObjectElement);
                prevNode.InnerText = node.PrevGenObj == null ? "" : node.PrevGenObj.FullyQualifiedIdentifer;

                crmnMappingNode.AppendChild(userNode);
                crmnMappingNode.AppendChild(newgNode);
                crmnMappingNode.AppendChild(prevNode);

                crMappingsNode.AppendChild(crmnMappingNode);
            }
        }
コード例 #55
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");
        }
コード例 #56
0
        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;
        }
コード例 #57
0
        public void PrevGen_Is_Missing_Others_Are_Different_BodyText()
        {
            CodeRootMap map = new CodeRootMap();

            Function inter = new Function(controller);
            inter.Name = "GetVal";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            inter.BodyText = "{ return 5; }";
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            CodeRoot root = ConstructRootWithClass(inter);

            map.AddCodeRoot(root, Version.User);

            inter = new Function(controller);
            inter.Name = "GetVal";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            inter.BodyText = "{ return 6; }"; // Modified Body Text
            param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            root = ConstructRootWithClass(inter);

            map.AddCodeRoot(root, Version.NewGen);

            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.Conflict));
        }
コード例 #58
0
        internal static void AssertFilesAreSame(string original, string changed)
        {
            CodeRootMap codeRootMap = new CodeRootMap();

            CSharpParser formatter = new CSharpParser();
            formatter.FormatSettings.ReorderBaseConstructs = true;
            formatter.ParseCode(File.ReadAllText(original));
            ICodeRoot codeRoot = formatter.CreatedCodeRoot;

            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);
            codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen);

            formatter = new CSharpParser();
            formatter.FormatSettings.ReorderBaseConstructs = true;
            formatter.ParseCode(File.ReadAllText(changed));
            codeRoot = formatter.CreatedCodeRoot;

            codeRootMap.AddCodeRoot(codeRoot, Version.User);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy));
        }
コード例 #59
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"));
        }
コード例 #60
0
        internal static void TestFiles_UserAndTemplate(string original, string changed, TypeOfDiff diffType)
        {
            CodeRootMap codeRootMap = new CodeRootMap();

            ICodeRoot codeRoot = GetCodeRoot(original);
            codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen);

            codeRoot = GetCodeRoot(changed);
            codeRootMap.AddCodeRoot(codeRoot, Version.User);
            codeRootMap.AddCodeRoot(codeRoot, Version.NewGen);

            Assert.That(codeRootMap.Diff(), Is.EqualTo(diffType));
        }