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() { 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 MatchesLoadedSuccessfully() { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); CodeRootMap map = mocks.StrictMock <CodeRootMap>(); using (mocks.Record()) { Expect.Call(map.MatchConstructs("Namespace|Class|Function1(string, int)", "Namespace|Class|Function2(string, int)", "Namespace|Class|Function3(string, int)")).Repeat.Once().Return(true); Expect.Call(map.MatchConstructs("Namespace|Class|Field1", "Namespace|Class|Field2", "Namespace|Class|Field3")).Repeat.Once().Return(true); } using (mocks.Playback()) { CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor(); processor.LoadCustomMappings(doc, map, "Test.cs"); } }
/// <summary> /// Loads custom mappings from the XmlDocument and applies them to the CodeRootMap. /// Returns a list of mappings that could not be applied. /// </summary> /// <param name="doc">The XmlDocument to load from.</param> /// <param name="map">The CodeRootMap to apply the mappings to.</param> /// <param name="filenameForMap">The filename to use when looking for mappings for this CodeRootMap</param> public void LoadCustomMappings(XmlDocument doc, CodeRootMap map, string filenameForMap) { string xpathQuery = string.Format("{0}/{1}/{2}/{3}[@filename='{4}']", Con.ManifestElement, Con.MappingsElement, Con.CodeRootMappingsElement, Con.CodeRootMappingElement, filenameForMap); XmlNodeList nodes = doc.SelectNodes(xpathQuery); if (nodes == null) return; foreach(XmlNode node in nodes) { XmlNode userNode = node.SelectSingleNode(Con.UserObjectElement); XmlNode newgNode = node.SelectSingleNode(Con.NewGenObjectElement); XmlNode prevNode = node.SelectSingleNode(Con.PrevGenObjectElement); map.MatchConstructs(string.IsNullOrEmpty(userNode.InnerText) ? null : userNode.InnerText, string.IsNullOrEmpty(newgNode.InnerText) ? null : newgNode.InnerText, string.IsNullOrEmpty(prevNode.InnerText) ? null : prevNode.InnerText); } }
/// <summary> /// Loads custom mappings from the XmlDocument and applies them to the CodeRootMap. /// Returns a list of mappings that could not be applied. /// </summary> /// <param name="doc">The XmlDocument to load from.</param> /// <param name="map">The CodeRootMap to apply the mappings to.</param> /// <param name="filenameForMap">The filename to use when looking for mappings for this CodeRootMap</param> public void LoadCustomMappings(XmlDocument doc, CodeRootMap map, string filenameForMap) { string xpathQuery = string.Format("{0}/{1}/{2}/{3}[@filename='{4}']", Con.ManifestElement, Con.MappingsElement, Con.CodeRootMappingsElement, Con.CodeRootMappingElement, filenameForMap); XmlNodeList nodes = doc.SelectNodes(xpathQuery); if (nodes == null) { return; } foreach (XmlNode node in nodes) { XmlNode userNode = node.SelectSingleNode(Con.UserObjectElement); XmlNode newgNode = node.SelectSingleNode(Con.NewGenObjectElement); XmlNode prevNode = node.SelectSingleNode(Con.PrevGenObjectElement); map.MatchConstructs(string.IsNullOrEmpty(userNode.InnerText) ? null : userNode.InnerText, string.IsNullOrEmpty(newgNode.InnerText) ? null : newgNode.InnerText, string.IsNullOrEmpty(prevNode.InnerText) ? null : prevNode.InnerText); } }
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 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 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)); }