public void TestNSMappingSQLConnectorGetAllNamespaces() { AssertAditional.SetEquals(new HashSet <string> { }, instance.GetAllNamespaces(id), "initial value"); var mapA = instance.GetOrCreateOldNSMap(id, "space"); var mapB = instance.GetOrCreateOldNSMap(id, "space"); AssertAditional.SetEquals(new HashSet <string> { "space" }, instance.GetAllNamespaces(id), "added entry"); var mapC = instance.GetOrCreateOldNSMap(id, "space2"); AssertAditional.SetEquals(new HashSet <string> { "space", "space2" }, instance.GetAllNamespaces(id), "added second entry"); var targetSdkMap = new sdk_map2(); instance.UpdateOrCreateNSMapping(mapA, targetSdkMap, "spaceNew"); instance.UpdateOrCreateNSMapping(mapA, targetSdkMap, "spaceNew2"); AssertAditional.SetEquals(new HashSet <string> { "space", "space2" }, instance.GetAllNamespaces(id), "split first entry"); }
private void ReplaceQualifiedNames() { IEnumerable <QualifiedNameSyntax> qualifiedNames = tree.GetRoot().DescendantNodes().OfType <QualifiedNameSyntax>(); foreach (QualifiedNameSyntax oldQualifiedNameNode in qualifiedNames) // iterate over all qualified names in the file { if (!(oldQualifiedNameNode.Parent is QualifiedNameSyntax)) { var qualifiedSymbolInfo = semanticModel.GetSymbolInfo(oldQualifiedNameNode); string nsString = oldQualifiedNameNode.Left.WithoutTrivia().GetText().ToString(); if (qualifiedSymbolInfo.Symbol != null) { string className = qualifiedSymbolInfo.Symbol.Name.ToString(); sdk_map2 sdkMap = SDKMappingSQLConnector.GetInstance().GetSDKMapFromClassAndNamespace(TransformProject.sdkId, nsString, className); if (sdkMap != null) { string newNamespace = sdkMap.namespace_map.new_namespace; string newClassName = sdkMap.new_classname; QualifiedNameSyntax newQualifiedNameNode = QualifiedName(IdentifierName(newNamespace), IdentifierName(newClassName)).WithTriviaFrom(oldQualifiedNameNode); documentEditor.ReplaceNode(oldQualifiedNameNode, newQualifiedNameNode); } } } } }
public void TestSDKMappingSQLConnectorUpdateSDKMapping() { var nsMapA = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space"); var asMapA = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path"); var nsMapB = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space2"); var asMapB = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path2"); var expectedA = new sdk_map2 { namespace_map_id = nsMapA.id, assembly_map_id = asMapA.id, model_identifier = "modelA", old_classname = "clazz", sdk_id = id, new_classname = "clazzNew" }; var expectedB = new sdk_map2 { namespace_map_id = nsMapB.id, assembly_map_id = asMapB.id, model_identifier = "modelB", old_classname = "clazz2", sdk_id = id, new_classname = "clazzNew2", }; instance.SaveOldSDKMapping(id, "modelA", "clazz", nsMapA, asMapA); instance.UpdateSDKMapping(instance.GetSDKMappingByIdentifiers(id, "modelA"), "clazzNew"); AssertAditional.SDKMapEquals(expectedA, instance.GetSDKMappingByIdentifiers(id, "modelA"), ""); instance.SaveOldSDKMapping(id, "modelB", "clazz2", nsMapB, asMapB); instance.UpdateSDKMapping(instance.GetSDKMappingByIdentifiers(id, "modelB"), "clazzNew2"); AssertAditional.SDKMapEquals(expectedA, instance.GetSDKMappingByIdentifiers(id, "modelA"), ""); AssertAditional.SDKMapEquals(expectedB, instance.GetSDKMappingByIdentifiers(id, "modelB"), ""); }
private void SaveEntry(sdk_map2 map) { var id = SDKSQLConnector.GetInstance().GetByName(sdkNameId).id; var ns = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, map.namespace_map.old_namespace); var assem = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, map.assembly_map.old_path); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, map.model_identifier, map.old_classname, ns, assem); var entry = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, map.model_identifier); NSMappingSQLConnector.GetInstance().UpdateOrCreateNSMapping(ns, entry, map.namespace_map.new_namespace); AssemblyMappingSQLConnector.GetInstance().UpdateAssemblyMapping(assem, entry, map.assembly_map.new_path, map.assembly_map.name); SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(entry, map.new_classname); }
public static void SDKMapEquals(sdk_map2 expected, sdk_map2 actual, string message) { Assert.IsNotNull(actual, message); var expectedText = ""; var actualText = ""; if (expected.assembly_map_id != 0) { expectedText += ", [assembly_map_id]" + expected.assembly_map_id; actualText += ", [assembly_map_id]" + actual.assembly_map_id; } if (expected.id != 0) { expectedText += ", [id]" + expected.id; actualText += ", [id]" + actual.id; } if (expected.model_identifier != null) { expectedText += ", [model_identifier]" + ToSafeString(expected.model_identifier); actualText += ", [model_identifier]" + ToSafeString(actual.model_identifier); } if (expected.namespace_map_id != 0) { expectedText += ", [namespace_map_id]" + expected.namespace_map_id; actualText += ", [namespace_map_id]" + actual.namespace_map_id; } if (expected.new_classname != null) { expectedText += ", [new_classname]" + ToSafeString(expected.new_classname); actualText += ", [new_classname]" + ToSafeString(actual.new_classname); } if (expected.old_classname != null) { expectedText += ", [old_classname]" + ToSafeString(expected.old_classname); actualText += ", [old_classname]" + ToSafeString(actual.old_classname); } if (expected.sdk_id != 0) { expectedText += ", [sdk_id]" + expected.sdk_id; actualText += ", [sdk_id]" + actual.sdk_id; } expectedText = expectedText.Substring(2); actualText = actualText.Substring(2); Assert.AreEqual(expectedText, actualText, message); }
private void ReplaceIdentifierNames() { // https://duckduckgo.com/?q=nested+selection+linq&ia=qa IEnumerable <IdentifierNameSyntax> identifierNames = tree.GetRoot().DescendantNodes().OfType <IdentifierNameSyntax>(); foreach (IdentifierNameSyntax oldNameNode in identifierNames) // iterate over all identifier names in the file { if (!(oldNameNode.Parent is QualifiedNameSyntax)) { var semanticObjCreation = semanticModel.GetSymbolInfo(oldNameNode); var nodeTypeInfo = semanticModel.GetTypeInfo(oldNameNode); if ((nodeTypeInfo.Type != null || oldNameNode.Parent is ObjectCreationExpressionSyntax) && semanticObjCreation.Symbol != null) { var oldNamespace = ""; for (var curNamespaceSymbol = semanticObjCreation.Symbol.ContainingNamespace; curNamespaceSymbol != null && curNamespaceSymbol.Name != ""; curNamespaceSymbol = curNamespaceSymbol.ContainingNamespace) { oldNamespace = "." + curNamespaceSymbol.Name + oldNamespace; } if (oldNamespace != "") { oldNamespace = oldNamespace.Substring(1); } String oldClassname = semanticObjCreation.Symbol.Name.ToString(); sdk_map2 sdkMap = SDKMappingSQLConnector.GetInstance().GetSDKMapFromClassAndNamespace(TransformProject.sdkId, oldNamespace, oldClassname); if (sdkMap != null) { String newClassname = sdkMap.new_classname; if (newClassname != null) { SyntaxToken oldNameToken = oldNameNode.DescendantTokens().First(); SyntaxToken name = Identifier(newClassname).WithTriviaFrom(oldNameToken); IdentifierNameSyntax newNameNode = oldNameNode.WithIdentifier(name); documentEditor.ReplaceNode(oldNameNode, newNameNode); } else { Console.WriteLine("Missing new class name for old class " + oldNamespace + "." + oldClassname); } } } } } }
public void TestSDKMappingSQLConnectorGetSDKMappingByIdentifiers() { Assert.IsNull(instance.GetSDKMappingByIdentifiers(-1, "a"), "shouldn't have gotten something from invalid id -1"); var nsMapA = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space"); var asMapA = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path"); var nsMapB = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space2"); var asMapB = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path2"); var expectedA = new sdk_map2 { namespace_map_id = nsMapA.id, assembly_map_id = asMapA.id, model_identifier = "modelA", old_classname = "clazz", sdk_id = id, }; var expectedB = new sdk_map2 { namespace_map_id = nsMapB.id, assembly_map_id = asMapB.id, model_identifier = "modelB", old_classname = "clazz2", sdk_id = id, }; Assert.IsNull(instance.GetSDKMappingByIdentifiers(id, "modelA"), "value should be initially null"); Assert.IsNull(instance.GetSDKMappingByIdentifiers(id, "modelB"), "value should be initially null"); instance.SaveOldSDKMapping(id, "modelA", "clazz", nsMapA, asMapA); AssertAditional.SDKMapEquals(expectedA, instance.GetSDKMappingByIdentifiers(id, "modelA"), ""); Assert.IsNull(instance.GetSDKMappingByIdentifiers(id, "ab"), "value shouldn't exist yet"); instance.SaveOldSDKMapping(id, "modelB", "clazz2", nsMapB, asMapB); AssertAditional.SDKMapEquals(expectedA, instance.GetSDKMappingByIdentifiers(id, "modelA"), ""); AssertAditional.SDKMapEquals(expectedB, instance.GetSDKMappingByIdentifiers(id, "modelB"), ""); }
public void DoStuff(string dllPath, bool isOld, int sdkId) { var assem = Assembly.LoadFrom(dllPath); string assemFullName = assem.FullName; Console.WriteLine("Read from " + dllPath); var types = assem.GetTypes(); // the types will tell you if there are custom data attributes foreach (var type in types) // itereate over old dll to find custom attributes { foreach (var attr in type.CustomAttributes) { if (attr.AttributeType.Name.Equals(ReadProject.CustomAttributeName)) { string modelIdentifier = (string)attr.ConstructorArguments.First().Value; if (isOld) { namespace_map nsMap = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(sdkId, type.Namespace); assembly_map asMap = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(sdkId, dllPath); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(sdkId, modelIdentifier, type.Name, nsMap, asMap); } else { sdk_map2 sdkMap = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(sdkId, modelIdentifier); if (sdkMap != null) { NSMappingSQLConnector.GetInstance().UpdateOrCreateNSMapping(sdkMap.namespace_map, sdkMap, type.Namespace); AssemblyMappingSQLConnector.GetInstance().UpdateAssemblyMapping(sdkMap.assembly_map, sdkMap, dllPath, assemFullName); SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(sdkMap, type.Name); } } } } } }
public virtual void LoadExpectedMappings() { int model_identifier_id = -1; int old_namespace_id = -1; int old_classname_id = -1; int new_namespace_id = -1; int new_classname_id = -1; int old_assembly_path_id = -1; int new_assembly_path_id = -1; int assembly_name_id = -1; if (!File.Exists(Path.Combine(TestFolder, "expectedSql.txt"))) { Assert.Fail("expectedSql.txt does not exist"); } var lines = File.ReadAllLines(Path.Combine(TestFolder, "expectedSql.txt")); if (lines.Length <= 0) { Assert.Fail("expectedSql.txt is empty"); } var lineOne = lines[0].Split('\t'); Assert.AreEqual(8, lineOne.Length, "Impropper number of headers"); for (var i = 0; i < lineOne.Length; i++) { switch (lineOne[i]) { case "model_identifier": model_identifier_id = i; break; case "old_namespace": old_namespace_id = i; break; case "old_classname": old_classname_id = i; break; case "new_namespace": new_namespace_id = i; break; case "new_classname": new_classname_id = i; break; case "old_assembly_path": old_assembly_path_id = i; break; case "new_assembly_path": new_assembly_path_id = i; break; case "assembly_name": assembly_name_id = i; break; default: Assert.Fail("invalid header " + lineOne[i]); break; } } expectedMappings = new List <sdk_map2>(); for (var i = 1; i < lines.Length; i++) { var curLine = lines[i].Split('\t'); Assert.AreEqual(lineOne.Length, curLine.Length, "wrong number of entries on line " + i); var namespaceMap = new namespace_map(); namespaceMap.new_namespace = GetValueFromExpected(curLine[new_namespace_id]); namespaceMap.old_namespace = GetValueFromExpected(curLine[old_namespace_id]); var assemblyMap = new assembly_map(); assemblyMap.name = GetValueFromExpected(curLine[assembly_name_id]); assemblyMap.new_path = GetValueFromExpected(curLine[new_assembly_path_id]); if (assemblyMap.new_path != null && assemblyMap.new_path != "'?'") { assemblyMap.new_path = Path.GetFullPath(Path.Combine(TestFolder, curLine[new_assembly_path_id])); } assemblyMap.old_path = GetValueFromExpected(curLine[old_assembly_path_id]); if (assemblyMap.old_path != null && assemblyMap.old_path != "'?'") { assemblyMap.old_path = Path.GetFullPath(Path.Combine(TestFolder, curLine[old_assembly_path_id])); } var sdkMap = new sdk_map2(); sdkMap.namespace_map = namespaceMap; sdkMap.assembly_map = assemblyMap; sdkMap.new_classname = GetValueFromExpected(curLine[new_classname_id]); sdkMap.old_classname = GetValueFromExpected(curLine[old_classname_id]); sdkMap.model_identifier = GetValueFromExpected(curLine[model_identifier_id]); expectedMappings.Add(sdkMap); } }
public void TestSDKMappingSQLConnectorSaveOldSDKMapping() { var nsMapA = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space"); var asMapA = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path"); var nsMapB = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space2"); var asMapB = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path2"); var mapA = new sdk_map2 { namespace_map_id = nsMapA.id, assembly_map_id = asMapA.id, model_identifier = "A", old_classname = "oldA", sdk_id = id }; var mapB = new sdk_map2 { namespace_map_id = nsMapA.id, assembly_map_id = asMapB.id, model_identifier = "B", old_classname = "oldB", sdk_id = id }; var mapC = new sdk_map2 { namespace_map_id = nsMapB.id, assembly_map_id = asMapA.id, model_identifier = "C", old_classname = "oldC", sdk_id = id }; var mapD = new sdk_map2 { namespace_map_id = nsMapB.id, assembly_map_id = asMapB.id, model_identifier = "D", old_classname = "oldD", sdk_id = id }; var expected = new List <sdk_map2>(); AssertDatabaseState(expected, "initial value"); instance.SaveOldSDKMapping(id, "A", "oldA", nsMapA, asMapA); expected.Add(mapA); AssertDatabaseState(expected, "first value"); instance.SaveOldSDKMapping(id, "B", "oldB", nsMapA, asMapB); expected.Add(mapB); AssertDatabaseState(expected, "second value"); instance.SaveOldSDKMapping(id, "C", "oldC", nsMapB, asMapA); expected.Add(mapC); AssertDatabaseState(expected, "third value"); instance.SaveOldSDKMapping(id, "D", "oldD", nsMapB, asMapB); expected.Add(mapD); AssertDatabaseState(expected, "fourth value"); }
public void TestSDKMappingSQLConnectorGetSDKMapFromClassAndNamespace() { var nsMapA = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space"); var asMapA = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path"); var nsMapB = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "space2"); var asMapB = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path2"); var mapA = new sdk_map2 { namespace_map_id = nsMapA.id, assembly_map_id = asMapA.id, model_identifier = "A", old_classname = "oldA", sdk_id = id }; var mapB = new sdk_map2 { namespace_map_id = nsMapA.id, assembly_map_id = asMapB.id, model_identifier = "B", old_classname = "oldB", sdk_id = id }; var mapC = new sdk_map2 { namespace_map_id = nsMapB.id, assembly_map_id = asMapA.id, model_identifier = "C", old_classname = "oldC", sdk_id = id }; var mapD = new sdk_map2 { namespace_map_id = nsMapB.id, assembly_map_id = asMapB.id, model_identifier = "D", old_classname = "oldD", sdk_id = id }; instance.SaveOldSDKMapping(id, "A", "oldA", nsMapA, asMapA); AssertAditional.SDKMapEquals(mapA, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldA"), "first value"); instance.SaveOldSDKMapping(id, "B", "oldB", nsMapA, asMapB); AssertAditional.SDKMapEquals(mapA, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldA"), "invalid change"); AssertAditional.SDKMapEquals(mapB, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldB"), "second value"); instance.SaveOldSDKMapping(id, "C", "oldC", nsMapB, asMapA); AssertAditional.SDKMapEquals(mapA, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldA"), "invalid change"); AssertAditional.SDKMapEquals(mapB, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldB"), "invalid change"); AssertAditional.SDKMapEquals(mapC, instance.GetSDKMapFromClassAndNamespace(id, "space2", "oldC"), "third value"); instance.SaveOldSDKMapping(id, "D", "oldD", nsMapB, asMapB); AssertAditional.SDKMapEquals(mapA, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldA"), "invalid change"); AssertAditional.SDKMapEquals(mapB, instance.GetSDKMapFromClassAndNamespace(id, "space", "oldB"), "invalid change"); AssertAditional.SDKMapEquals(mapC, instance.GetSDKMapFromClassAndNamespace(id, "space2", "oldC"), "invalid change"); AssertAditional.SDKMapEquals(mapD, instance.GetSDKMapFromClassAndNamespace(id, "space2", "oldD"), "fourth value"); }