示例#1
0
        public void CreateNewLangProject_AnthropologyCategoriesExist()
        {
            const string dbName = "AnthropologicalTest";

            SureRemoveDb(dbName);
            var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory));

            try
            {
                // create project
                string dbFileName = LcmCache.CreateNewLangProj(new DummyProgressDlg(), dbName, m_lcmDirectories,
                                                               new SingleThreadedSynchronizeInvoke());

                var projectId = new TestProjectId(BackendProviderType.kXMLWithMemoryOnlyWsMgr, dbFileName);
                using (var cache = LcmCache.CreateCacheFromExistingData(projectId, "en", m_ui, m_lcmDirectories, new LcmSettings(),
                                                                        new DummyProgressDlg()))
                {
                    Assert.AreEqual(Strings.ksAnthropologyCategories, cache.LangProject.AnthroListOA.Name.UiString,
                                    "Anthropology Categories list was not properly initialized.");
                    Assert.AreEqual(Strings.ksAnth, cache.LangProject.AnthroListOA.Abbreviation.UiString,
                                    "Anthropology Categories list abrv was not properly initialized.");
                    Assert.AreNotEqual(0, cache.LangProject.AnthroListOA.ItemClsid,
                                       "Anthropology Categories list class ID was not properly initialized.");
                    Assert.AreNotEqual(0, cache.LangProject.AnthroListOA.Depth,
                                       "Anthropology Categories list depth was not properly initialized.");
                }
            }
            finally
            {
                RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory));
            }
        }
示例#2
0
        public void TestThatSharedSettingOpensXmlDataTypeAsSharedXml()
        {
            const string dbName = "ProjectSharingTest";

            SureRemoveDb(dbName);
            var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory));

            try
            {
                // create project
                string dbFileName = LcmCache.CreateNewLangProj(new DummyProgressDlg(), dbName, m_lcmDirectories,
                                                               new SingleThreadedSynchronizeInvoke());
                // Set up test file for project sharing setting
                var testFileStore = new FileSettingsStore(LexiconSettingsFileHelper.GetProjectLexiconSettingsPath(Path.GetDirectoryName(dbFileName)));
                var dataMapper    = new ProjectLexiconSettingsDataMapper(testFileStore);
                dataMapper.Write(new ProjectLexiconSettings {
                    ProjectSharing = true
                });
                // SUT
                // Request XML backend with project settings that have ProjectSharing set to true
                var projectId = new TestProjectId(BackendProviderType.kXML, dbFileName);
                using (var cache = LcmCache.CreateCacheFromExistingData(projectId, "en", m_ui, m_lcmDirectories, new LcmSettings(),
                                                                        new DummyProgressDlg()))
                {
                    var dataSetup = cache.ServiceLocator.GetInstance <IDataSetup>();
                    Assert.IsTrue(dataSetup is SharedXMLBackendProvider, "The project should have been opened as shared xml.");
                }
            }
            finally
            {
                RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory));
            }
        }
示例#3
0
        public void UpdateWritingSystemsFromGlobalStore_CopiesNewerWsOnly(
            string globalEn, string globalFr,
            string localEn, string localFr,
            string localEnResult, string localFrResult)
        {
            const string dbName = "UpdateWsFromGsTest";

            SureRemoveDb(dbName);
            var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory));

            try
            {
                // create project
                var dbFileName = LcmCache.CreateNewLangProj(new DummyProgressDlg(), dbName, m_lcmDirectories,
                                                            new SingleThreadedSynchronizeInvoke());
                // SUT
                // Request XML backend with project settings that have ProjectSharing set to true
                var projectId = new TestProjectId(BackendProviderType.kXML, dbFileName);
                using (var cache = LcmCache.CreateCacheFromExistingData(projectId, "en", m_ui, m_lcmDirectories, new LcmSettings(),
                                                                        new DummyProgressDlg()))
                {
                    var globalPath = Path.Combine(m_projectsDirectory,
                                                  $"{Path.GetFileNameWithoutExtension(dbFileName)}_GlobalWss");
                    var globalPathWithVersion = CoreGlobalWritingSystemRepository.CurrentVersionPath(globalPath);
                    Directory.CreateDirectory(globalPathWithVersion);
                    var storePath = Path.Combine(cache.ProjectId.ProjectFolder, LcmFileHelper.ksWritingSystemsDir);
                    File.Copy(Path.Combine(storePath, "en.ldml"), Path.Combine(globalPathWithVersion, "en.ldml"));
                    File.Copy(Path.Combine(storePath, "fr.ldml"), Path.Combine(globalPathWithVersion, "fr.ldml"));
                    var wsManager = cache.ServiceLocator.WritingSystemManager;

                    // Add new Ws for French and English in global repo
                    var globalRepoForTest = new CoreGlobalWritingSystemRepository(globalPath);

                    // Set up WritingSystemStore for test
                    wsManager.WritingSystemStore = new CoreLdmlInFolderWritingSystemRepository(storePath,
                                                                                               cache.ServiceLocator.DataSetup.ProjectSettingsStore,
                                                                                               cache.ServiceLocator.DataSetup.UserSettingsStore,
                                                                                               globalRepoForTest);

                    var enWs = globalRepoForTest.Get("en");
                    var frWs = globalRepoForTest.Get("fr");
                    Assert.That(string.IsNullOrEmpty(enWs.SpellCheckingId), Is.True);
                    Assert.That(string.IsNullOrEmpty(cache.WritingSystemFactory.get_Engine("en").SpellCheckingId), Is.True);
                    Assert.That(string.IsNullOrEmpty(frWs.SpellCheckingId), Is.True);
                    Assert.That(string.IsNullOrEmpty(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId), Is.True);

                    // Update the spellCheckIds in the global repository
                    if (globalEn != null)
                    {
                        enWs.SpellCheckingId = globalEn;
                    }

                    if (globalFr != null)
                    {
                        frWs.SpellCheckingId = globalFr;
                    }
                    globalRepoForTest.Set(enWs);
                    globalRepoForTest.Set(frWs);
                    globalRepoForTest.Save();
                    // Update the cache version of the repository
                    var enWsFromCache = cache.ServiceLocator.WritingSystemManager.Get("en");
                    var frWsFromCache = cache.ServiceLocator.WritingSystemManager.Get("fr");
                    enWsFromCache.SpellCheckingId = localEn;
                    frWsFromCache.SpellCheckingId = localFr;
                    cache.ServiceLocator.WritingSystemManager.Set(enWsFromCache);
                    cache.ServiceLocator.WritingSystemManager.Set(frWsFromCache);
                    cache.ServiceLocator.WritingSystemManager.Save();
                    enWs = globalRepoForTest.Get("en");
                    frWs = globalRepoForTest.Get("fr");

                    // Verify preconditions
                    Assert.That(enWs.SpellCheckingId, Is.StringMatching(globalEn));
                    Assert.That(frWs.SpellCheckingId, Is.StringMatching(globalFr));
                    Assert.That(cache.WritingSystemFactory.get_Engine("en").SpellCheckingId, Is.StringMatching(localEn));
                    Assert.That(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId, Is.StringMatching(localFr));

                    // SUT
                    cache.UpdateWritingSystemsFromGlobalStore("en");
                    Assert.That(cache.WritingSystemFactory.get_Engine("en").SpellCheckingId, Is.StringMatching(localEnResult));
                    Assert.That(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId, Is.StringMatching(localFr));

                    cache.UpdateWritingSystemsFromGlobalStore("fr");
                    Assert.That(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId, Is.StringMatching(localFrResult));
                }
            }
            finally
            {
                RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory));
            }
        }