Пример #1
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;");
        }
Пример #2
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");
        }
Пример #3
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, "{ }");
        }
Пример #4
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; }");
        }
Пример #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 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;");
        }
        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 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");
        }
Пример #9
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);
        }
Пример #10
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; }");
        }
        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)]");
        }
Пример #12
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);");
        }
Пример #13
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; }");
        }
Пример #14
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");
        }
Пример #15
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);
        }
Пример #16
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;");
        }
Пример #17
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; }");
        }
Пример #18
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");
        }
Пример #19
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)]");
        }
Пример #20
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")));
        }
Пример #21
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");
        }
Пример #22
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");
        }
Пример #23
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);
        }
Пример #24
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");
        }
Пример #25
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");
        }
Пример #26
0
        /// <summary>
        /// Performs the diff between the 3 files, even if some of them do not exist.
        /// </summary>
        protected override bool PerformDiffInternal()
        {
            //////////////////////////
            MergedFile = NewGenFile;

            if (!UserFile.IsFileOnDisk)
            {
                CurrentDiffResult.DiffType = TypeOfDiff.NewFile;
            }
            else if (UserFile.HexStringMD5() == NewGenFile.HexStringMD5())
            {
                CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy;
            }
            else
            {
                CurrentDiffResult.DiffType = TypeOfDiff.TemplateChangeOnly;
            }

            return(true);

            ///////////////////////////
            if (IntelliMerge == IntelliMergeType.Overwrite)
            {
                CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy;
                MergedFile = NewGenFile;
                return(true);
            }

            if (IntelliMerge == IntelliMergeType.CreateOnly)
            {
                CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy;
                MergedFile = UserFile.HasContents ? UserFile : NewGenFile;

                return(true);
            }

            if (UserFile.HasContents == false && PrevGenFile.HasContents == false && NewGenFile.HasContents == false)
            {
                throw new InvalidOperationException("Cannot perform a diff if there are no files!");
            }

            if (MergedFileExists)
            {
                CurrentDiffResult.DiffPerformedSuccessfully = true;
                CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy;
                CurrentDiffResult.DiffWarningDescription = CurrentDiffResult.ParserWarningDescription = "";

                return(true);
            }

            if (PrevGenFile.HasContents &&
                UserFile.HasContents &&
                NewGenFile.HasContents)
            {
                // Perform 3-way diff
                string fileBodyParent = PrevGenFile.GetContents();
                string fileBodyUser   = UserFile.GetContents();
                // Template code is not formatted until it is needed. Do the formatting here.

                string           fileBodyGenerated;
                string           mergedText;
                SlyceMergeResult slyceMerge;
                if (IntelliMerge == IntelliMergeType.CSharp)
                {
                    if (NewGenFile.GetContents().Trim() == string.Empty)
                    {
                        fileBodyGenerated = "";
                    }
                    else
                    {
                        CSharpParser formatter = new CSharpParser();
                        formatter.ParseCode(NewGenFile.FilePath, NewGenFile.GetContents());
                        if (formatter.ErrorOccurred)
                        {
                            CurrentDiffResult.ParserWarningDescription = formatter.GetFormattedErrors();
                            return(false);
                        }
                        CodeRoot codeRoot = (CodeRoot)formatter.CreatedCodeRoot;
                        fileBodyGenerated = codeRoot.ToString();
                    }
                    slyceMerge = SlyceMerge.Perform3wayDiff(fileBodyUser, fileBodyParent, fileBodyGenerated, out mergedText, false);
                }
                else
                {
                    fileBodyGenerated = NewGenFile.GetContents();
                    slyceMerge        = SlyceMerge.Perform3wayDiff(fileBodyUser, fileBodyParent, fileBodyGenerated, out mergedText, true);
                    MergedFile        = new TextFile(mergedText);
                }
                CurrentDiffResult.DiffType = slyceMerge.DiffType;

                if (slyceMerge.DiffType == TypeOfDiff.Warning)
                {
                    // TODO: What should be done here?
                    throw new Exception(
                              "There was a warning during the diff process when there shouldn't have been. Please report this to Slyce.");
                }

                if (slyceMerge.DiffType != TypeOfDiff.ExactCopy)
                {
                    return(PerformSuperDiff());
                }

                // File was exact copy - use user version
                MergedFile = new TextFile(fileBodyUser);
            }
            else if (PrevGenFile.HasContents &&
                     UserFile.HasContents == false &&
                     NewGenFile.HasContents)
            {
                // No user file, just use the template file
                CurrentDiffResult.DiffType = TypeOfDiff.Warning;
                CurrentDiffResult.DiffWarningDescription =
                    "The User's version of this file has been deleted or renamed, but the Template and previous version of this file still exist.";
                MergedFile = new TextFile(NewGenFile.GetContents());
            }
            else if (PrevGenFile.HasContents == false &&
                     UserFile.HasContents &&
                     NewGenFile.HasContents)
            {
                //CurrentDiffResult.DiffType = TypeOfDiff.Warning;
                //CurrentDiffResult.DiffWarningDescription =
                //    "User version of a file clashes with a new file the template is trying to create.";

                // Perform 2-way diff
                string fileBodyNewGen = NewGenFile.GetContents();
                string fileBodyUser   = UserFile.GetContents();
                CurrentDiffResult.DiffType = SlyceMerge.PerformTwoWayDiff(fileBodyNewGen, fileBodyUser);

                if (CurrentDiffResult.DiffType != TypeOfDiff.ExactCopy)
                {
                    // Also perform a super diff
                    return(PerformSuperDiff());
                }
                MergedFile = new TextFile(fileBodyUser);
            }
            else if (PrevGenFile.HasContents == false &&
                     UserFile.HasContents == false &&
                     NewGenFile.HasContents)
            {
                // The template has added a new file.
                CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy;
                MergedFile = new TextFile(NewGenFile.GetContents());
            }
            else
            {
                // Cases covered by this else:
                // * User and prevgen file exist, no template
                // * Prevgen, no user or template.
                // * User file, no template or prevgen
                // TODO: Shouldn't really be a warning...
                CurrentDiffResult.DiffType = TypeOfDiff.Warning;
                throw new Exception(string.Format("TODO: determine course of action, what should be copied to staging folder, because no file exists: \nparent file path:\"{0}\" : {1}\nuser file path:\"{2}\" : {3}\ntemplate file path:\"{4}\" : {5}", PrevGenFile.FilePath, PrevGenFile.HasContents, UserFile.FilePath, UserFile.HasContents, NewGenFile.FilePath, NewGenFile.HasContents));
            }

            return(true);
        }
        public void Namespace()
        {
            Namespace inter = new Namespace(controller);
            inter.Name = "ArchAngel.Tests";
            inter.AddChild(new UsingStatement(controller, "", "System"));
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(inter);

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

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

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

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

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

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

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

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "public void Method1()");
            Assertions.StringContains(result, "{ }");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }