コード例 #1
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);
        }
コード例 #2
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;");
        }
コード例 #3
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");
        }
コード例 #4
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, "{ }");
        }
コード例 #5
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");
        }
コード例 #6
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");
        }
コード例 #7
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; }");
        }
コード例 #8
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;");
        }
コード例 #9
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");
        }
コード例 #10
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));
        }
コード例 #11
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);
        }
コード例 #12
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; }");
        }
コード例 #13
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)]");
        }
コード例 #14
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);");
        }
コード例 #15
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; }");
        }
コード例 #16
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");
        }
コード例 #17
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;");
        }
コード例 #18
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);
        }
コード例 #19
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; }");
        }
コード例 #20
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)]");
        }
コード例 #21
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");
        }
コード例 #22
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");
        }
コード例 #23
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")));
        }
コード例 #24
0
        public void Event()
        {
            Event inter = new Event(controller);

            inter.Name = "FileAdded";
            inter.Modifiers.Add("public");
            inter.DataType = new DataType(controller, "EventHandler");
            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 event EventHandler FileAdded");
        }
コード例 #25
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);
        }
コード例 #26
0
        public void InterfaceEvent()
        {
            InterfaceEvent inter = new InterfaceEvent(controller);

            inter.Name          = "File";
            inter.DataType      = new DataType(controller, "EventHandler");
            inter.HasNewKeyword = true;

            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, "new event EventHandler File");
        }
コード例 #27
0
        public void Field()
        {
            Field inter = new Field(controller);

            inter.Name = "i";
            inter.Modifiers.Add("public");
            inter.DataType     = new DataType(controller, "int");
            inter.InitialValue = "1";
            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 int i = 1");
        }
コード例 #28
0
        public void InterfaceMethod_Renamed_Params()
        {
            CodeRoot root = CreateInterfaceAndMethod("i");

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);
            CodeRoot userRoot = CreateInterfaceAndMethod("i1");
            map.AddCodeRoot(userRoot, Version.User);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(userRoot.ToString()));
            Assert.That(result, Is.Not.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 i1);");
        }
コード例 #29
0
        public void InterfaceEvent()
        {
            InterfaceEvent inter = new InterfaceEvent(controller);
            inter.Name = "File";
            inter.DataType = new DataType(controller, "EventHandler");
            inter.HasNewKeyword = true;

            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, "new event EventHandler File");
        }
コード例 #30
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;");
        }
コード例 #31
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; }");
        }
コード例 #32
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));
        }
コード例 #33
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));
        }
コード例 #34
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");
        }
コード例 #35
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);
        }
コード例 #36
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");
        }
コード例 #37
0
 public void NoCodeRootsAdded()
 {
     CodeRootMap map = new CodeRootMap();
     map.GetMergedCodeRoot();
 }
コード例 #38
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);
        }
コード例 #39
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");
        }
コード例 #40
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);
        }
コード例 #41
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; }");
        }
コード例 #42
0
        public void Event()
        {
            Event inter = new Event(controller);
            inter.Name = "FileAdded";
            inter.Modifiers.Add("public");
            inter.DataType = new DataType(controller,"EventHandler");
            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 event EventHandler FileAdded");
        }
コード例 #43
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; }");
        }
コード例 #44
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);
        }
コード例 #45
0
        public void Field()
        {
            Field inter = new Field(controller);
            inter.Name = "i";
            inter.Modifiers.Add("public");
            inter.DataType = new DataType(controller,"int");
            inter.InitialValue = "1";
            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 int i = 1");
        }
コード例 #46
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;");
        }
コード例 #47
0
        public void NoCodeRootsAdded()
        {
            CodeRootMap map = new CodeRootMap();

            map.GetMergedCodeRoot();
        }
コード例 #48
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");
        }
コード例 #49
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");
        }
コード例 #50
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")));
        }
コード例 #51
0
        public void Operator_Renamed_Params()
        {
            CodeRoot root = CreateClassAndOperator("i");

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

            CodeRoot userRoot = CreateClassAndOperator("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, "public static int operator +(Class1 self, int i1)");
            Assertions.StringContains(result, "{ return 5; }");
        }
コード例 #52
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;");
        }
コード例 #53
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));
        }
コード例 #54
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, "{ }");
        }