public void TestAssemblyMappingSQLConnectorGetOrCreateOldAssemblyMapTest() { var mapA = instance.GetOrCreateOldAssemblyMap(id, "path"); var expectA = new assembly_map { old_path = "path", sdk_id = id }; AssertAditional.AssemblyMapEquals(expectA, mapA, "issue on first create"); var mapB = instance.GetOrCreateOldAssemblyMap(id, "path2"); var expectB = new assembly_map { old_path = "path2", sdk_id = id }; AssertAditional.AssemblyMapEquals(expectB, mapB, "issue on second create"); AssertAditional.AssemblyMapEquals(expectA, mapA, "impropper modification of A"); var mapC = instance.GetOrCreateOldAssemblyMap(id, "path"); var expectC = new assembly_map { old_path = "path", sdk_id = id, id = mapA.id }; AssertAditional.AssemblyMapEquals(expectC, mapC, "issue on first get"); AssertAditional.AssemblyMapEquals(expectB, mapB, "impropper modification of B"); AssertAditional.AssemblyMapEquals(expectA, mapA, "impropper modification of A"); }
public static void AssemblyMapEquals(assembly_map expected, assembly_map actual, string message) { Assert.IsNotNull(actual, message); var expectedText = ""; var actualText = ""; if (expected.id != 0) { expectedText += ", [id]:" + expected.id; actualText += ", [id]:" + actual.id; } if (expected.name != null) { expectedText += ", [name]:" + ToSafeString(expected.name); actualText += ", [name]:" + ToSafeString(actual.name); } if (expected.new_path != null) { expectedText += ", [new_path]:" + ToSafeString(expected.new_path); actualText += ", [new_path]:" + ToSafeString(actual.new_path); } if (expected.old_path != null) { expectedText += ", [old_path]:" + ToSafeString(expected.old_path); actualText += ", [old_path]:" + ToSafeString(actual.old_path); } 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); }
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); } }