public void GetValidConfigurationForPublication_AllEntriesReturnsAlreadySelectedConfig() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = Cache.TsStrFactory.MakeString("TestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); var configWithTestPub = ConfigurationTemplate.Replace("</Publications>", "<Publication>TestPub</Publication></Publications>"); var subDir = Path.Combine(Path.GetTempPath(), "Dictionary"); Directory.CreateDirectory(subDir); // required by DictionaryConfigurationListener.GetCurrentConfiguration() using (var docView = new TestXhtmlDocView()) using (var tempConfigFile = TempFile.WithFilename( Path.Combine(subDir, "baz" + DictionaryConfigurationModel.FileExtension))) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); m_mediator.PropertyTable.SetProperty("DictionaryPublicationLayout", tempConfigFile.Path); // DictionaryConfigurationListener.GetCurrentConfiguration() needs to know the currentContentControl. m_mediator.PropertyTable.SetProperty("currentContentControl", "lexiconDictionary"); File.WriteAllText(tempConfigFile.Path, configWithTestPub); // SUT Assert.That(docView.GetValidConfigurationForPublication(xWorksStrings.AllEntriesPublication), Is.StringContaining(tempConfigFile.Path)); } } }
public void SplitPublicationsByConfiguration_UnmatchedPublicationIsOut() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = Cache.TsStrFactory.MakeString("TestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); var notTestPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); var notTestPubName = Cache.TsStrFactory.MakeString("NotTestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(notTestPubItem); notTestPubItem.Name.set_String(enId, notTestPubName); var configWithoutTestPub = ConfigurationTemplate.Replace("</Publications>", "<Publication>NotTestPub</Publication></Publications>"); using (var docView = new TestXhtmlDocView()) using (var tempConfigFile = TempFile.WithFilename(Path.Combine(Path.GetTempPath(), "AllPubsConf" + DictionaryConfigurationModel.FileExtension))) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); File.WriteAllText(tempConfigFile.Path, configWithoutTestPub); List <string> pubsInConfig; List <string> pubsNotInConfig; // SUT docView.SplitPublicationsByConfiguration( Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS, tempConfigFile.Path, out pubsInConfig, out pubsNotInConfig); CollectionAssert.DoesNotContain(pubsInConfig, testPubName.Text); CollectionAssert.Contains(pubsNotInConfig, testPubName.Text); } } }
public void SplitConfigurationsByPublication_MatchedPublicationIsIn() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = Cache.TsStrFactory.MakeString("TestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); var configWithTestPub = ConfigurationTemplate.Replace("</Publications>", "<Publication>TestPub</Publication></Publications>"); using (var docView = new TestXhtmlDocView()) using (var tempConfigFile = TempFile.WithFilename(Path.Combine(Path.GetTempPath(), "baz" + DictionaryConfigurationModel.FileExtension))) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); File.WriteAllText(tempConfigFile.Path, configWithTestPub); IDictionary <string, string> configsWithPub; IDictionary <string, string> configsWithoutPub; var configurations = new Dictionary <string, string>(); configurations["AConfigPubtest"] = tempConfigFile.Path; // SUT docView.SplitConfigurationsByPublication(configurations, "TestPub", out configsWithPub, out configsWithoutPub); CollectionAssert.Contains(configsWithPub.Values, tempConfigFile.Path); CollectionAssert.DoesNotContain(configsWithoutPub.Values, tempConfigFile.Path); } } }
public void GetValidConfigurationForPublication_ReturnsAlreadySelectedConfigIfValid() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = TsStringUtils.MakeString("TestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); // Change the project path to temp for this test Cache.ProjectId.Path = Path.GetTempPath(); var configWithTestPub = ConfigurationTemplate.Replace("</Publications>", "<Publication>TestPub</Publication></Publications>"); using (var docView = new TestXhtmlDocView()) { var configPathForTest = Path.Combine(Path.GetTempPath(), "ConfigurationSettings", "Dictionary"); Directory.CreateDirectory(configPathForTest); using (var tempConfigFile = TempFile.WithFilename(Path.Combine(configPathForTest, "Squirrel" + DictionaryConfigurationModel.FileExtension))) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); docView.SetPropertyTable(m_propertyTable); m_propertyTable.SetProperty("currentContentControl", "lexiconDictionary", false); m_propertyTable.SetProperty("DictionaryPublicationLayout", tempConfigFile.Path, true); File.WriteAllText(tempConfigFile.Path, configWithTestPub); // SUT Assert.That(docView.GetValidConfigurationForPublication("TestPub"), Is.StringContaining(tempConfigFile.Path)); } } } }
public void SplitConfigurationsByPublication_ConfigWithAllPublicationIsIn() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var allPubsConfig = ConfigurationTemplateWithAllPublications; using (var docView = new TestXhtmlDocView()) using (var tempConfigFile = TempFile.WithFilename(Path.Combine(Path.GetTempPath(), "AllPubsConf" + DictionaryConfigurationModel.FileExtension))) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); docView.SetPropertyTable(m_propertyTable); File.WriteAllText(tempConfigFile.Path, allPubsConfig); IDictionary <string, string> configsWithPub; IDictionary <string, string> configsWithoutPub; var configurations = new Dictionary <string, string>(); configurations["AConfigPubtest"] = tempConfigFile.Path; // SUT docView.SplitConfigurationsByPublication(configurations, "TestPub", out configsWithPub, out configsWithoutPub); CollectionAssert.Contains(configsWithPub.Values, tempConfigFile.Path); CollectionAssert.DoesNotContain(configsWithoutPub.Values, tempConfigFile.Path); } } }
public void GetValidConfigurationForPublication_PublicationThatMatchesNoConfigReturnsNull() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = TsStringUtils.MakeString("NotTheTestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); var configSansTestPub = ConfigurationTemplate.Replace("</Publications>", "<Publication>NotTheTestPub</Publication></Publications>"); var overrideFiles = new List <TempFile>(); using (var docView = new TestXhtmlDocView()) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); docView.SetPropertyTable(m_propertyTable); var projConfigs = Path.Combine(LcmFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder), "Dictionary"); Directory.CreateDirectory(projConfigs); // override every shipped config with a config that does not have the TestPub publication var shippedFileList = Directory.EnumerateFiles(Path.Combine(FwDirectoryFinder.DefaultConfigurations, "Dictionary"), "*" + DictionaryConfigurationModel.FileExtension); var overrideCount = 0; foreach (var shippedFile in shippedFileList) { ++overrideCount; var tempFileName = Path.Combine(projConfigs, overrideCount + DictionaryConfigurationModel.FileExtension); var tempConfigFile = TempFile.WithFilename(tempFileName); overrideFiles.Add(tempConfigFile); using (var stream = new FileStream(shippedFile, FileMode.Open)) { var doc = new XmlDocument(); doc.Load(stream); var node = doc.SelectSingleNode("DictionaryConfiguration"); var shippedName = node.Attributes["name"].Value; File.WriteAllText(tempConfigFile.Path, configSansTestPub.Replace("name='AConfigPubtest'", "name='" + shippedName + "'")); } } // SUT var result = docView.GetValidConfigurationForPublication("TestPub"); // Delete all our temp files before asserting so they are sure to go away foreach (var tempFile in overrideFiles) { tempFile.Dispose(); } Assert.IsNull(result, "When no configurations have the publication null should be returned."); } } }
public void GetValidConfigurationForPublication_ConfigurationContainingPubIsPicked() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = TsStringUtils.MakeString("TestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); var notTestPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); var notTestPubName = TsStringUtils.MakeString("NotTestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(notTestPubItem); notTestPubItem.Name.set_String(enId, notTestPubName); var nonMatchingConfig = ConfigurationTemplate.Replace("</Publications>", "<Publication>NotTestPub</Publication></Publications>"); //Change the name for the matching config so that our two user configs don't conflict with each other var matchingConfig = ConfigurationTemplate.Replace("</Publications>", "<Publication>TestPub</Publication></Publications>").Replace("AConfigPub", "AAConfigPub"); var dictionaryConfigPath = Path.Combine(LcmFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder), "Dictionary"); using (var docView = new TestXhtmlDocView()) using (var nonMatchedConfigFile = TempFile.WithFilename(Path.Combine(dictionaryConfigPath, "NoMatch" + DictionaryConfigurationModel.FileExtension))) using (var matchedConfigFile = TempFile.WithFilename(Path.Combine(dictionaryConfigPath, "Match" + DictionaryConfigurationModel.FileExtension))) { File.WriteAllText(nonMatchedConfigFile.Path, nonMatchingConfig); File.WriteAllText(matchedConfigFile.Path, matchingConfig); docView.SetConfigObjectName("Dictionary"); m_propertyTable.SetProperty("currentContentControl", "lexiconDictionary", false); m_propertyTable.SetProperty("DictionaryPublicationLayout", nonMatchedConfigFile.Path, true); docView.SetMediator(m_mediator); docView.SetPropertyTable(m_propertyTable); // SUT var validConfig = docView.GetValidConfigurationForPublication("TestPub"); Assert.That(validConfig, Is.Not.StringContaining(nonMatchedConfigFile.Path)); Assert.That(validConfig, Is.StringContaining(matchedConfigFile.Path)); } } }