public void DataMigration7000031Test() { var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000031Tests.xml"); IFwMetaDataCacheManaged mockMdc = DataMigrationTests7000020.SetupMdc(); IDomainObjectDTORepository repoDto = new DomainObjectDtoRepository(7000030, dtos, mockMdc, Path.GetTempPath(), FwDirectoryFinder.FdoDirectories); // Initial check that data was read properly. var cObjects = repoDto.AllInstances().Count(); Assert.AreEqual(378, cObjects, "Before migrating, should be 378 objects"); var cLangProject = repoDto.AllInstancesSansSubclasses("LangProject").Count(); Assert.AreEqual(1, cLangProject, "Before migrating, should be 1 LangProject object"); var cUserView = repoDto.AllInstancesSansSubclasses("UserView").Count(); Assert.AreEqual(17, cUserView, "Before migrating, should be 17 UserView objects"); var cUserViewRec = repoDto.AllInstancesSansSubclasses("UserViewRec").Count(); Assert.AreEqual(31, cUserViewRec, "Before migrating, should be 31 UserViewRec objects"); var cUserViewField = repoDto.AllInstancesSansSubclasses("UserViewField").Count(); Assert.AreEqual(329, cUserViewField, "Before migrating, should be 329 UserViewField objects"); // Do the migration. m_dataMigrationManager.PerformMigration(repoDto, 7000031, new DummyProgressDlg()); // Verification Phase Assert.AreEqual(7000031, repoDto.CurrentModelVersion, "Wrong updated version."); cObjects = repoDto.AllInstances().Count(); Assert.AreEqual(1, cObjects, "After migrating, should be 1 object"); cLangProject = repoDto.AllInstancesSansSubclasses("LangProject").Count(); Assert.AreEqual(1, cLangProject, "After migrating, should be 1 LangProject object"); cUserView = repoDto.AllInstancesSansSubclasses("UserView").Count(); Assert.AreEqual(0, cUserView, "After migrating, should be 12 UserView objects"); cUserViewRec = repoDto.AllInstancesSansSubclasses("UserViewRec").Count(); Assert.AreEqual(0, cUserViewRec, "After migrating, should be 3 UserViewRec objects"); cUserViewField = repoDto.AllInstancesSansSubclasses("UserViewField").Count(); Assert.AreEqual(0, cUserViewField, "After migrating, should be 15 UserViewField objects"); }
public void DataMigration7000032Test() { var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000033.xml"); IFwMetaDataCacheManaged mockMdc = DataMigrationTests7000020.SetupMdc(); IDomainObjectDTORepository repoDto = new DomainObjectDtoRepository(7000032, dtos, mockMdc, Path.GetTempPath()); var projectFolder = repoDto.ProjectFolder; var projectName = Path.GetFileNameWithoutExtension(projectFolder); // This is equivalent to DirectoryFinder.GetConfigSettingsDir(projectFolder) at the time of creating // the migration, but could conceivably change later. var targetDir = Path.Combine(projectFolder, "ConfigurationSettings"); Directory.CreateDirectory(targetDir); var testFilePath = Path.Combine(targetDir, "LexEntry_Layouts.xml"); using (var writer = new StreamWriter(testFilePath)) { writer.WriteLine(@"<LayoutInventory>" + "<layout class='LexEntry' type='jtview' name='publishStemPara' css='$fwstyle=Dictionary-Normal' version='9'>" + " <part ref='Headword' label='Headword' before='' sep=' ' after=' ' ws='vernacular' wsType='vernacular' style='Dictionary-Headword' css='headword' visibility='ifdata' comment='Headword is a smart field. It is the lexeme form unless there is a citation form. Includes Homograph number and affix marking.' />" + " <part ref='$child' label='testYYY' before='' after=' ' visibility='ifdata' ws='$ws=analysis' wsType='analysis vernacular' sep=' ' showLabels='false'>" + " <configureMlString field='custom' class='LexEntry' />" + " </part>" + "<part ref='$child' label='TestXXX' before='' after=' ' visibility='ifdata'>" + " <string field='custom1' class='LexEntry' />" + "</part>" + " <part ref='$child' label='messed up' before='' after=' ' visibility='ifdata' ws='$ws=analysis' wsType='analysis vernacular' sep=' ' showLabels='false' originalLabel='testBB'>" + " <configureMlString field='custom' class='LexEntry' />" + " </part>" + "<part ref='$child' label='modified' before='' after=' ' visibility='ifdata' originalLabel='TestZZZ'>" + " <string field='custom1' class='LexEntry' />" + "</part>" + " <part ref='$child' before='' after=' ' visibility='ifdata' ws='$ws=analysis' wsType='analysis vernacular' sep=' ' showLabels='false' originalLabel='testCC'>" + " <configureMlString field='custom' class='LexEntry' />" + " </part>" + "<part ref='$child' before='' after=' ' visibility='ifdata' originalLabel='TestD'>" + " <string field='custom1' class='LexEntry' />" + "</part>" + "</layout>" + "</LayoutInventory>"); writer.Close(); } // Do the migration. m_dataMigrationManager.PerformMigration(repoDto, 7000033, new DummyProgressDlg()); Assert.AreEqual(7000033, repoDto.CurrentModelVersion, "Wrong updated version."); var root = XElement.Load(testFilePath); // layout inventory node var layout = root.Elements().ToList()[0]; var children = layout.Elements().ToList(); VerifyChild(children[1], "testYYY"); VerifyChild(children[2], "TestXXX"); VerifyChild(children[3], "testBB"); VerifyChild(children[4], "TestZZZ"); VerifyChild(children[5], "testCC"); VerifyChild(children[6], "TestD"); }
public void DataMigration7000032Test() { var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000032.xml"); IFwMetaDataCacheManaged mockMdc = DataMigrationTests7000020.SetupMdc(); IDomainObjectDTORepository repoDto = new DomainObjectDtoRepository(7000030, dtos, mockMdc, Path.Combine(Path.GetTempPath(), "Wildly-testing_Away~Migration7000032")); var projectFolder = repoDto.ProjectFolder; var projectName = Path.GetFileNameWithoutExtension(projectFolder); // This is equivalent to DirectoryFinder.UserAppDataFolder("Language Explorer") at the time of creating // the migration, but could conceivably change later. var sourceDir = Path.Combine( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SIL"), "Language Explorer"); // This is equivalent to DirectoryFinder.GetConfigSettingsDir(projectFolder) at the time of creating // the migration, but could conceivably change later. var targetDir = Path.Combine(projectFolder, "ConfigurationSettings"); Directory.CreateDirectory(sourceDir); // Enhance JohnT: would be nice to check that the test does this. // But then we can't create a test file there to be sure it doesn't get overwritten. // Is it worth simulating two complete migrations? Directory.CreateDirectory(targetDir); var sample1Source = Path.Combine(sourceDir, "db$" + projectName + "$Settings.xml"); var sample1Target = Path.Combine(targetDir, "db$local$Settings.xml"); File.Delete(sample1Source); // Make sure we don't already have one from an earlier run File.Delete(sample1Target); // Make sure we don't already have one from an earlier run using (var writer = new StreamWriter(sample1Source)) { writer.WriteLine("This is a test"); writer.Close(); } // Create a second sample, make a file with the same name in the target, verify NOT overwritten. var sample2Source = Path.Combine(sourceDir, "db$" + projectName + "$DoNotCopy.xml"); var sample2Target = Path.Combine(targetDir, "DoNotCopy.xml"); var bad2Target = Path.Combine(targetDir, "db$local$DoNotCopy.xml"); File.Delete(sample2Source); // Make sure we don't already have one from an earlier run File.Delete(sample2Target); // Make sure we don't already have one from an earlier run File.Delete(bad2Target); using (var writer = new StreamWriter(sample2Source)) { writer.WriteLine("This should not be copied"); writer.Close(); } using (var writer = new StreamWriter(sample2Target)) { writer.WriteLine("This should not be overwritten"); writer.Close(); } var sample3Source = Path.Combine(sourceDir, "db$" + projectName + "$LexEntry_Layouts.xml"); var sample3Target = Path.Combine(targetDir, "LexEntry_Layouts.xml"); var bad3Target = Path.Combine(targetDir, "db$local$LexEntry_Layouts.xml"); File.Delete(sample3Source); // Make sure we don't already have one from an earlier run File.Delete(sample3Target); // Make sure we don't already have one from an earlier run File.Delete(bad3Target); using (var writer = new StreamWriter(sample3Source)) { writer.WriteLine("This is a test layout of sorts!"); writer.Close(); } // Do the migration. m_dataMigrationManager.PerformMigration(repoDto, 7000032, new DummyProgressDlg()); Assert.AreEqual(7000032, repoDto.CurrentModelVersion, "Wrong updated version."); Assert.IsTrue(File.Exists(sample1Target)); Assert.IsTrue(File.Exists(sample1Source)); using (var reader = new StreamReader(sample1Source)) Assert.AreEqual("This is a test", reader.ReadLine()); using (var reader = new StreamReader(sample1Target)) Assert.AreEqual("This is a test", reader.ReadLine()); Assert.IsTrue(File.Exists(sample2Target)); Assert.IsTrue(File.Exists(sample2Source)); Assert.IsFalse(File.Exists(bad2Target)); using (var reader = new StreamReader(sample2Source)) Assert.AreEqual("This should not be copied", reader.ReadLine()); using (var reader = new StreamReader(sample2Target)) Assert.AreEqual("This should not be overwritten", reader.ReadLine()); Assert.IsTrue(File.Exists(sample3Target)); Assert.IsTrue(File.Exists(sample3Source)); Assert.IsFalse(File.Exists(bad3Target)); using (var reader = new StreamReader(sample3Source)) Assert.AreEqual("This is a test layout of sorts!", reader.ReadLine()); using (var reader = new StreamReader(sample3Target)) Assert.AreEqual("This is a test layout of sorts!", reader.ReadLine()); }