public void MigrateOldConfigurationsIfNeeded_MatchesLabelsWhenUIIsLocalized() { // Localize a Part's label to German (sufficient to cause a mismatched nodes crash if one config's labels are localized) var localizedPartLabels = new Dictionary <string, string>(); localizedPartLabels["Main Entry"] = "Haupteintrag"; var pathsToL10nStrings = (Dictionary <string, Dictionary <string, string> >)ReflectionHelper.GetField(m_mediator.StringTbl, "m_pathsToStrings"); pathsToL10nStrings["group[@id = 'LocalizedAttributes']/"] = localizedPartLabels; var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Path.GetDirectoryName(Cache.ProjectId.Path)); var newConfigFilePath = Path.Combine(configSettingsDir, DictionaryConfigurationListener.DictionaryConfigurationDirectoryName, "Lexeme" + DictionaryConfigurationModel.FileExtension); Assert.False(File.Exists(newConfigFilePath), "should not yet be migrated"); Directory.CreateDirectory(configSettingsDir); File.WriteAllLines(Path.Combine(configSettingsDir, "Test.fwlayout"), new[] { @"<layoutType label='Lexeme-based (complex forms as main entries)' layout='publishStem'><configure class='LexEntry' label='Main Entry' layout='publishStemEntry' />", @"<configure class='LexEntry' label='Minor Entry' layout='publishStemMinorEntry' hideConfig='true' /></layoutType>'" }); var migrator = new DictionaryConfigurationMigrator(m_mediator); Assert.DoesNotThrow(() => migrator.MigrateOldConfigurationsIfNeeded(), "ArgumentException indicates localized labels."); // SUT var updatedConfigModel = new DictionaryConfigurationModel(newConfigFilePath, Cache); Assert.AreEqual(2, updatedConfigModel.Parts.Count, "Should have 2 top-level nodes"); Assert.AreEqual("Main Entry", updatedConfigModel.Parts[0].Label); DirectoryUtilities.DeleteDirectoryRobust(configSettingsDir); }
public void MigrateOldConfigurationsIfNeeded_BringsPreHistoricFileToCurrentVersion() { var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Path.GetDirectoryName(Cache.ProjectId.Path)); var newConfigFilePath = Path.Combine(configSettingsDir, DictionaryConfigurationListener.DictionaryConfigurationDirectoryName, "Lexeme" + DictionaryConfigurationModel.FileExtension); Assert.False(File.Exists(newConfigFilePath), "should not yet be migrated"); Directory.CreateDirectory(configSettingsDir); File.WriteAllLines(Path.Combine(configSettingsDir, "Test.fwlayout"), new[] { @"<layoutType label='Lexeme-based (complex forms as main entries)' layout='publishStem'><configure class='LexEntry' label='Main Entry' layout='publishStemEntry' />", @"<configure class='LexEntry' label='Minor Entry' layout='publishStemMinorEntry' hideConfig='true' /></layoutType>'" }); var migrator = new DictionaryConfigurationMigrator(m_mediator); migrator.MigrateOldConfigurationsIfNeeded(); // SUT var updatedConfigModel = new DictionaryConfigurationModel(newConfigFilePath, Cache); Assert.AreEqual(DictionaryConfigurationMigrator.VersionCurrent, updatedConfigModel.Version); DirectoryUtilities.DeleteDirectoryRobust(configSettingsDir); }
public void MigrateOldConfigurationsIfNeeded_PreservesOrderOfBibliographies() { var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Path.GetDirectoryName(Cache.ProjectId.Path)); var newConfigFilePath = Path.Combine(configSettingsDir, DictionaryConfigurationListener.ReversalIndexConfigurationDirectoryName, "AllReversalIndexes" + DictionaryConfigurationModel.FileExtension); Assert.False(File.Exists(newConfigFilePath), "should not yet be migrated"); Directory.CreateDirectory(configSettingsDir); File.WriteAllLines(Path.Combine(configSettingsDir, "Test.fwlayout"), new[] { @"<layoutType label='All Reversal Indexes' layout='publishReversal'>", @"<configure class='ReversalIndexEntry' label='Reversal Entry' layout='publishReversalEntry' /></layoutType>'" }); var migrator = new DictionaryConfigurationMigrator(m_mediator); migrator.MigrateOldConfigurationsIfNeeded(); // SUT var updatedConfigModel = new DictionaryConfigurationModel(newConfigFilePath, Cache); var refdSenseChildren = updatedConfigModel.Parts[0].Children.Find(n => n.Label == "Referenced Senses").Children; var bibCount = 0; for (var i = 0; i < refdSenseChildren.Count; i++) { var bibNode = refdSenseChildren[i]; if (!bibNode.Label.StartsWith("Bibliography")) { continue; } StringAssert.StartsWith("Bibliography (", bibNode.Label, "Should specify (entry|sense), lest we never know"); Assert.False(bibNode.IsCustomField, bibNode.Label + " should not be custom."); // Rough test to ensure Bibliography nodes aren't bumped to the end of the list. In the defaults, the later Bibliography // node is a little more than five nodes from the end Assert.LessOrEqual(i, refdSenseChildren.Count - 5, "Bibliography nodes should not have been bumped to the end of the list"); ++bibCount; } Assert.AreEqual(2, bibCount, "Should be exactly two Bibliography nodes (sense and entry)"); DirectoryUtilities.DeleteDirectoryRobust(configSettingsDir); }