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"); }
private CodeRootMap CreateBasicMap(out Class cl2) { CodeRootMap map = new CodeRootMap(); Class cl = new Class(controller, "Class1"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.PrevGen); cl = new Class(controller, "Class1"); ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); cl2 = new Class(controller, "Class2"); ns.AddChild(cl2); root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.NewGen); return(map); }
public void 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, "{ }"); }
public void AssertDiffType(string prevgenFilename, string userFilename, string templateFilename, TypeOfDiff typeOfDiff) { CodeRoot prevgen = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, prevgenFilename)); CodeRoot template = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, templateFilename)); CodeRoot user = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, userFilename)); CodeRootMap map = new CodeRootMap(); if (prevgen != null) { map.AddCodeRoot(prevgen, Version.PrevGen); } if (template != null) { map.AddCodeRoot(template, Version.NewGen); } if (user != null) { map.AddCodeRoot(user, Version.User); } TypeOfDiff diff = map.Diff(); Assert.That(diff, Is.EqualTo(typeOfDiff)); }
public void Class() { Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); }
public void 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"); }
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 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; }"); }
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); }
public void Map_Contains_Both_CodeRoots() { CodeRootMap map = new CodeRootMap(); ICodeRoot coderoot = mocks.StrictMock <ICodeRoot>(); IBaseConstruct bc1 = mocks.DynamicMock <IBaseConstruct>(); IBaseConstruct bc2 = mocks.DynamicMock <IBaseConstruct>(); Utility.SetupBaseConstructs(mocks, bc1, bc2, coderoot); using (mocks.Playback()) { map.AddCodeRoot(coderoot, Version.User); map.AddCodeRoot(coderoot, Version.NewGen); } Assert.That(map.ChildNodes, Has.Count(1)); Assert.That(map.AllNodes, Has.Count(2)); Assert.That(map.ChildNodes[0], Is.Not.Null); Assert.That(map.ChildNodes[0].IsTreeRoot, Is.False); Assert.That(map.ChildNodes[0].UserObj, Is.SameAs(bc1)); Assert.That(map.ChildNodes[0].NewGenObj, Is.SameAs(bc1)); Assert.That(map.ChildNodes[0].Omit, Is.False); Assert.That(map.ChildNodes[0].ParentNode, Is.SameAs(map)); Assert.That(map.ChildNodes[0].ParentTree, Is.SameAs(map)); CodeRootMapNode node = map.ChildNodes[0].ChildNodes[0]; Assert.That(node, Is.Not.Null); Assert.That(node.IsTreeRoot, Is.False); Assert.That(node.UserObj, Is.SameAs(bc2)); Assert.That(node.NewGenObj, Is.SameAs(bc2)); Assert.That(node.Omit, Is.False); Assert.That(node.ParentNode, Is.SameAs(map.ChildNodes[0])); Assert.That(node.ParentTree, Is.SameAs(map)); }
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;"); }
public void Matching_Successful() { controller.Reorder = true; Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); Class c2 = new Class(controller, "Class2"); // Extra class in user AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c2); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.PrevGen); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.NewGen); bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3"); Assert.That(matchResult, Is.True); string result = map.GetMergedCodeRoot().ToString(); Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly)); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "Class2"); Assertions.StringContains(result, "Class3", 0); int count = 0; foreach (CodeRootMapNode node in map.AllNodes) { if (node.IsTheSameReference(c2)) { count++; } } Assert.That(count, Is.EqualTo(1)); }
public void MatchesSavedSuccessfully() { XmlDocument doc = new XmlDocument(); Controller controller = new CSharpController(); controller.Reorder = true; CodeRootMap map = new CodeRootMap(); CodeRoot userCR = new CodeRoot(controller); CodeRoot newgenCR = new CodeRoot(controller); CodeRoot prevgenCR = new CodeRoot(controller); Class clazz = new Class(controller, "Class1"); clazz.AddChild(new Class(controller, "InnerClass")); userCR.AddChild(clazz); clazz = new Class(controller, "Class2"); clazz.AddChild(new Class(controller, "InnerClass")); newgenCR.AddChild(clazz); clazz = new Class(controller, "Class3"); clazz.AddChild(new Class(controller, "InnerClass")); prevgenCR.AddChild(clazz); map.AddCodeRoot(userCR, Version.User); map.AddCodeRoot(newgenCR, Version.NewGen); map.AddCodeRoot(prevgenCR, Version.PrevGen); Assert.That(map.MatchConstructs("Class1", "Class2", "Class3"), "Matching constructs", Is.True); CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor(); processor.SaveCustomMappings(doc, map, "Test.cs"); XmlNodeList nodes = doc.SelectNodes("Manifest/Mappings/CodeRootMappings/CodeRootMap"); Assert.IsNotNull(nodes, "Couldn't find the CodeRootMap nodes"); Assert.That(nodes.Count, Is.EqualTo(1)); Assert.That(nodes.Item(0).Attributes["filename"].Value, Is.EqualTo("Test.cs")); XmlNode mappingElement = nodes.Item(0); XmlNode userNode = mappingElement.SelectSingleNode(ManifestConstants.UserObjectElement); XmlNode newgNode = mappingElement.SelectSingleNode(ManifestConstants.NewGenObjectElement); XmlNode prevNode = mappingElement.SelectSingleNode(ManifestConstants.PrevGenObjectElement); Assert.That(userNode, Is.Not.Null); Assert.That(newgNode, Is.Not.Null); Assert.That(prevNode, Is.Not.Null); Assert.That(userNode.InnerText, Is.EqualTo("Class1")); Assert.That(newgNode.InnerText, Is.EqualTo("Class2")); Assert.That(prevNode.InnerText, Is.EqualTo("Class3")); }
public void 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); }
internal static void TestFiles_UserAndTemplate(string original, string changed, TypeOfDiff diffType) { CodeRootMap codeRootMap = new CodeRootMap(); ICodeRoot codeRoot = GetCodeRoot(original); codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen); codeRoot = GetCodeRoot(changed); codeRootMap.AddCodeRoot(codeRoot, Version.User); codeRootMap.AddCodeRoot(codeRoot, Version.NewGen); Assert.That(codeRootMap.Diff(), Is.EqualTo(diffType)); }
public void AssertDiffType(string prevgenFilename, string userFilename, string templateFilename, TypeOfDiff typeOfDiff) { CodeRoot prevgen = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, prevgenFilename)); CodeRoot template = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, templateFilename)); CodeRoot user = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, userFilename)); CodeRootMap map = new CodeRootMap(); if(prevgen != null) map.AddCodeRoot(prevgen, Version.PrevGen); if (template != null) map.AddCodeRoot(template, Version.NewGen); if (user != null) map.AddCodeRoot(user, Version.User); TypeOfDiff diff = map.Diff(); Assert.That(diff, Is.EqualTo(typeOfDiff)); }
public void Map_Contains_CodeRoot() { CodeRootMap map = new CodeRootMap(); ICodeRoot coderoot = mocks.StrictMock<ICodeRoot>(); IBaseConstruct bc1 = mocks.DynamicMock<IBaseConstruct>(); IBaseConstruct bc2 = mocks.DynamicMock<IBaseConstruct>(); Utility.SetupBaseConstructs(mocks, bc1, bc2, coderoot); using(mocks.Playback()) { map.AddCodeRoot(coderoot, Version.User); } Assert.That(map.ChildNodes, Has.Count(1)); Assert.That(map.AllNodes, Has.Count(2)); Assert.That(map.ChildNodes[0], Is.Not.Null); Assert.That(map.ChildNodes[0].IsTreeRoot, Is.False); Assert.That(map.ChildNodes[0].UserObj, Is.SameAs(bc1)); Assert.That(map.ChildNodes[0].Omit, Is.False); Assert.That(map.ChildNodes[0].ParentNode, Is.SameAs(map)); Assert.That(map.ChildNodes[0].ParentTree, Is.SameAs(map)); CodeRootMapNode node = map.ChildNodes[0].ChildNodes[0]; Assert.That(node, Is.Not.Null); Assert.That(node.IsTreeRoot, Is.False); Assert.That(node.UserObj, Is.SameAs(bc2)); Assert.That(node.Omit, Is.False); Assert.That(node.ParentNode, Is.SameAs(map.ChildNodes[0])); Assert.That(node.ParentTree, Is.SameAs(map)); }
public void Diff_Result_Is_Exact_Copy() { string original = Path.Combine(ResourcePath, "Class1.cs"); CodeRootMap codeRootMap = new CodeRootMap(); CSharpParser formatter = new CSharpParser(); formatter.ParseCode(File.ReadAllText(original)); ICodeRoot codeRoot = formatter.CreatedCodeRoot; codeRootMap.AddCodeRoot(codeRoot, Version.User); codeRootMap.AddCodeRoot(codeRoot, Version.NewGen); codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen); Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy)); }
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 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);"); }
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)]"); }
public void Returns_An_Empty_Collection() { CodeRootMap root = new CodeRootMap(); root.AddCodeRoot(controller.Root, Version.NewGen); ReadOnlyCollection<IBaseConstruct> children = root.ChildNodes[0].GetSiblingsOfSameType(Version.User); Assert.That(children.Count, Is.EqualTo(0)); }
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; }"); }
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"); }
public void Returns_An_Empty_Collection() { CodeRootMap root = new CodeRootMap(); root.AddCodeRoot(controller.Root, Version.NewGen); ReadOnlyCollection <IBaseConstruct> children = root.ChildNodes[0].GetSiblingsOfSameType(Version.User); Assert.That(children.Count, Is.EqualTo(0)); }
public void User_File_Doesnt_Exist_Diff_Result_Is_Exact_Copy() { string original = Path.Combine(ResourcePath, "Class1.cs"); CodeRootMap codeRootMap = new CodeRootMap(); ICodeRoot codeRoot = Diffing_Two_Different_Basic_CSharp_Files.GetCodeRoot(original); codeRootMap.AddCodeRoot(codeRoot, Version.NewGen); Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy)); }
public void 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;"); }
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); }
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; }"); }
public void Diff_Does_Not_Modify_Base_Constructs() { string original = Path.Combine(ResourcePath, "Class1.cs"); string changed = Path.Combine(ResourcePath, "Class1_WithConstructor.cs"); ICodeRoot userCR = GetCodeRoot(original); ICodeRoot newgenCR = GetCodeRoot(changed); ICodeRoot prevgenCR = GetCodeRoot(changed); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(userCR, Version.User); map.AddCodeRoot(newgenCR, Version.NewGen); map.AddCodeRoot(prevgenCR, Version.PrevGen); map.Diff(); ICodeRoot withoutDiff = GetCodeRoot(changed); Assert.That(map.PrevGenCodeRoot.ToString(), Is.EqualTo(withoutDiff.ToString())); Assert.That(map.NewGenCodeRoot.ToString(), Is.EqualTo(withoutDiff.ToString())); }
public void Returns_Three_Siblings() { CodeRootMap root = new CodeRootMap(); root.AddCodeRoot(controller.Root, Version.NewGen); ReadOnlyCollection<IBaseConstruct> children = root.ChildNodes[0].ChildNodes[0].GetSiblingsOfSameType(Version.NewGen); Assert.That(children.Count, Is.EqualTo(3)); Assert.That(children.Contains(func2), "Contains second function"); Assert.That(children.Contains(func3), "Contains third function"); Assert.That(children.Contains(func4), "Contains fourth function"); }
internal static void AssertFilesAreSame(string original, string changed) { CodeRootMap codeRootMap = new CodeRootMap(); CSharpParser formatter = new CSharpParser(); formatter.FormatSettings.ReorderBaseConstructs = true; formatter.ParseCode(File.ReadAllText(original)); ICodeRoot codeRoot = formatter.CreatedCodeRoot; codeRootMap.AddCodeRoot(codeRoot, Version.NewGen); codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen); formatter = new CSharpParser(); formatter.FormatSettings.ReorderBaseConstructs = true; formatter.ParseCode(File.ReadAllText(changed)); codeRoot = formatter.CreatedCodeRoot; codeRootMap.AddCodeRoot(codeRoot, Version.User); Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy)); }
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 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"); }
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; }"); }
public void PrevGen_Is_Missing_Others_Are_Different_BodyText() { CodeRootMap map = new CodeRootMap(); Function inter = new Function(controller); inter.Name = "GetVal"; inter.Modifiers.Add("public"); inter.ReturnType = new DataType(controller,"int"); inter.BodyText = "{ return 5; }"; Parameter param = new Parameter(controller); param.Name = "i"; param.DataType = "int"; inter.Parameters.Add(param); CodeRoot root = ConstructRootWithClass(inter); map.AddCodeRoot(root, Version.User); inter = new Function(controller); inter.Name = "GetVal"; inter.Modifiers.Add("public"); inter.ReturnType = new DataType(controller,"int"); inter.BodyText = "{ return 6; }"; // Modified Body Text param = new Parameter(controller); param.Name = "i"; param.DataType = "int"; inter.Parameters.Add(param); root = ConstructRootWithClass(inter); map.AddCodeRoot(root, Version.NewGen); Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.Conflict)); }
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"); }
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 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); }
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;"); }
private CodeRootMap CreateBasicMap(out Class cl2) { CodeRootMap map = new CodeRootMap(); Class cl = new Class(controller, "Class1"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.PrevGen); cl = new Class(controller, "Class1"); ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); cl2 = new Class(controller, "Class2"); ns.AddChild(cl2); root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.NewGen); return map; }
public void 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"))); }
public void Matching_Successful() { controller.Reorder = true; Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); Class c2 = new Class(controller, "Class2"); // Extra class in user AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c2); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.PrevGen); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.NewGen); bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3"); Assert.That(matchResult, Is.True); string result = map.GetMergedCodeRoot().ToString(); Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly)); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "Class2"); Assertions.StringContains(result, "Class3", 0); int count = 0; foreach (CodeRootMapNode node in map.AllNodes) { if (node.IsTheSameReference(c2)) count++; } Assert.That(count, Is.EqualTo(1)); }
public void 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);"); }
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"); }
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)); }