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 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 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 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 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)); }
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 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 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 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())); }
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 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)); }
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 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 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)); }
public void Exception_Raised() { CodeRootMap map = new CodeRootMap(); map.Diff(); }
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)); }
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 Exception_Raised() { CodeRootMap map = new CodeRootMap(); map.Diff(); }
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 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 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)); }