예제 #1
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));
            }
        }
예제 #2
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));
            }
        }
예제 #3
0
        public void CreateNewLangProject_DbFilesExist()
        {
            var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory));

            try
            {
                // Setup: Create "pre-existing" DB filenames
                using (new DummyFileMaker(Path.Combine(m_projectsDirectory, "Gumby", LcmFileHelper.GetXmlDataFileName("Gumby"))))
                {
                    LcmCache.CreateNewLangProj(new DummyProgressDlg(), "Gumby", m_lcmDirectories,
                                               new SingleThreadedSynchronizeInvoke(), null, null, null, null, null, null, true);
                }
            }
            finally
            {
                RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory));
            }
        }
예제 #4
0
        public void CreateNewLangProject_NameWithSingleQuote()
        {
            const string dbName = "!!t'st";
            string       dbDir  = Path.Combine(m_projectsDirectory, dbName);

            SureRemoveDb(dbName);

            var expectedDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory))
            {
                dbDir
            };
            var writingSystemsCommonDir = Path.Combine(m_projectsDirectory, LcmFileHelper.ksWritingSystemsDir);

            List <string> currentDirs = null;

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

                currentDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory));
                if (currentDirs.Contains(writingSystemsCommonDir) && !expectedDirs.Contains(writingSystemsCommonDir))
                {
                    expectedDirs.Add(writingSystemsCommonDir);
                }
                CollectionAssert.AreEquivalent(expectedDirs, currentDirs);
                string dbFileBase = Path.GetFileNameWithoutExtension(dbFileName);
                Assert.AreEqual(dbName, dbFileBase);
            }
            finally
            {
                if (currentDirs != null)
                {
                    RemoveTestDirs(expectedDirs, currentDirs);
                }
            }
        }
예제 #5
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));
            }
        }