public void Initialize_SkipsBadFile_DataProblemInLDMLFont() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var versionPath = Path.Combine(e.Path, LdmlDataMapper.CurrentLdmlLibraryVersion.ToString()); Directory.CreateDirectory(versionPath); var badFile = Path.Combine(versionPath, "en.ldml"); const string ldmlData = @"<?xml version='1.0' encoding='utf-8'?> <ldml> <identity> <version number=''/> <generation date='2020-02-28T18:43:36Z'/> <language type='en'/> <special xmlns:sil='urn://www.sil.org/ldml/0.1'> <sil:identity windowsLCID='1033'/> </special> </identity> <special xmlns:sil='urn://www.sil.org/ldml/0.1'> <sil:external-resources> <sil:font name='Amdo Classic 1' types='kaboom' /> </sil:external-resources> </special> </ldml>" ; File.WriteAllText(badFile, ldmlData); var repo = GlobalWritingSystemRepository.InitializeWithBasePath(e.Path, null); // main part of test is that we don't get any exception. Assert.That(repo.Count, Is.EqualTo(0)); // original .ldml file should have been renamed Assert.That(File.Exists(badFile), Is.False); Assert.That(File.Exists(badFile + ".bad"), Is.True); Assert.That(File.Exists(Path.Combine(versionPath, "badldml.log")), Is.True); } }
public void Constructor_CreatesFolders() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); Assert.That(Directory.Exists(repo.PathToWritingSystems), Is.True); } }
public void Constructor_CreatesFolders() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var repo = new GlobalWritingSystemRepository(e.Path); Assert.That(Directory.Exists(repo.PathToWritingSystems), Is.True); } }
public void PathConstructor_HasCorrectPath() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); Assert.That(repo.PathToWritingSystems, Is.StringMatching(".*GlobalWritingSystemRepositoryTests.2")); } }
private void CopyLdmlFromFolder(string sourcePath) { if (!Directory.Exists(SourcePath)) { GlobalWritingSystemRepository.CreateGlobalWritingSystemRepositoryDirectory(SourcePath); } DirectoryUtilities.CopyDirectoryWithException(sourcePath, SourcePath); }
private void CopyLdmlFromFolder(string sourcePath) { if (!Directory.Exists(SourcePath)) { GlobalWritingSystemRepository.CreateGlobalWritingSystemRepositoryDirectory(SourcePath); } DirectoryHelper.Copy(sourcePath, SourcePath); }
public WritingSystemTest() { InitializeComponent(); _repository = GlobalWritingSystemRepository.Initialize(MigrationHandler); _wsModel = new WritingSystemSetupModel(_repository); wsPropertiesPanel1.BindToModel(_wsModel); }
public void DefaultInitializer_HasCorrectPath() { GlobalWritingSystemRepository repo = GlobalWritingSystemRepository.Initialize(); string expectedPath = string.Format(".*SIL.WritingSystemRepository.{0}", LdmlDataMapper.CurrentLdmlLibraryVersion); Assert.That(repo.PathToWritingSystems, Is.StringMatching(expectedPath)); }
public void Constructor_WithExistingFolders_NoThrow() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); Assert.That(Directory.Exists(repo2.PathToWritingSystems), Is.True); } }
public void PathConstructor_HasCorrectPath() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var repo = new GlobalWritingSystemRepository(e.Path); Assert.That(repo.PathToWritingSystems, Is.StringMatching($".*PathConstructor_HasCorrectPath.*{LdmlDataMapper.CurrentLdmlLibraryVersion}")); } }
public void PathConstructor_HasCorrectPath() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); string expectedPath = string.Format(".*GlobalWritingSystemRepositoryTests.{0}", LdmlDataMapper.CurrentLdmlVersion); Assert.That(repo.PathToWritingSystems, Is.StringMatching(expectedPath)); } }
public void PathConstructor_HasCorrectPath() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); string expectedPath = string.Format(".*GlobalWritingSystemRepositoryTests.{0}", LdmlDataMapper.CurrentLdmlLibraryVersion); Assert.That(repo.PathToWritingSystems, Is.StringMatching(expectedPath)); } }
public WritingSystemPickerTestForm() { InitializeComponent(); _repository = GlobalWritingSystemRepository.Initialize(null); _wsModel = new WritingSystemSetupModel(_repository); _wsModel.SelectionChanged += _wsModel_SelectionChanged; wsPickerUsingListView1.BindToModel(_wsModel); pickerUsingComboBox1.BindToModel(_wsModel); }
private void _openGlobal_Click(object sender, EventArgs e) { var dlg = new WritingSystemSetupDialog(GlobalWritingSystemRepository.Initialize()); dlg.WritingSystemSuggestor.SuggestVoice = true; dlg.WritingSystemSuggestor.OtherKnownWritingSystems = null; dlg.DisposeRepository = true; dlg.Text = String.Format("Writing Systems for all users of this computer"); dlg.Show(); }
public void Set_NewWritingSystem_SetsId() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); Assert.That(ws.Id, Is.Null); repo.Set(ws); Assert.That(ws.Id, Is.EqualTo("en-US")); } }
public void Save_NewWritingSystem_CreatesLdmlFile() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo.Set(ws); repo.Save(); Assert.That(File.Exists(repo.GetFilePathFromLanguageTag("en-US")), Is.True); } }
public void Set_NewWritingSystem_SetsId() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var repo = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); Assert.That(ws.Id, Is.Null); repo.Set(ws); Assert.That(ws.Id, Is.EqualTo("en-US")); } }
public void Count_LdmlRemovedByAnotherRepo_ReturnsZero() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.Count, Is.EqualTo(1)); repo2.Remove("en-US"); Assert.That(repo1.Count, Is.EqualTo(0)); } }
public void Count_LdmlAddedByAnotherRepo_ReturnsOne() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); Assert.That(repo2.Count, Is.EqualTo(0)); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(File.Exists(repo1.GetFilePathFromLanguageTag("en-US")), Is.True); Assert.That(repo2.Count, Is.EqualTo(1)); } }
public void AllWritingSystems_LdmlAddedByAnotherRepo_ReturnsDefinition() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); Assert.That(repo2.AllWritingSystems, Is.Empty); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(File.Exists(repo1.GetFilePathFromLanguageTag("en-US")), Is.True); Assert.That(repo2.AllWritingSystems.First().LanguageTag, Is.EqualTo("en-US")); } }
public void Get_LdmlAddedByAnotherRepo_ReturnsDefinition() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); Assert.That(() => repo2.Get("en-US"), Throws.TypeOf <ArgumentOutOfRangeException>()); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(File.Exists(repo1.GetFilePathFromLanguageTag("en-US")), Is.True); Assert.That(repo2.Get("en-US").LanguageTag, Is.EqualTo("en-US")); } }
public void Get_LdmlRemovedByAnotherRepo_Throws() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US")); repo2.Remove("en-US"); Assert.That(() => repo1.Get("en-US"), Throws.TypeOf <ArgumentOutOfRangeException>()); } }
public void AllWritingSystems_LdmlRemovedByAnotherRepo_ReturnsEmpty() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.AllWritingSystems, Is.Not.Empty); repo2.Remove("en-US"); Assert.That(repo1.AllWritingSystems, Is.Empty); } }
public void Save_DeletedWritingSystem_RemovesLdmlFile() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo.Set(ws); repo.Save(); Assert.That(File.Exists(repo.GetFilePathFromLanguageTag("en-US")), Is.True); ws.MarkedForDeletion = true; repo.Save(); Assert.That(File.Exists(repo.GetFilePathFromLanguageTag("en-US")), Is.False); } }
public void Get_UpdatedLdmlRemovedByAnotherRepo_ReturnUpdatedDefinition() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US")); repo2.Remove("en-US"); ws.WindowsLcid = "test"; Assert.That(repo1.Get("en-US").WindowsLcid, Is.EqualTo("test")); } }
public void Initialize_SkipsBadFile() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { string versionPath = Path.Combine(e.Path, LdmlDataMapper.CurrentLdmlLibraryVersion.ToString()); Directory.CreateDirectory(versionPath); string badFile = Path.Combine(versionPath, "en.ldml"); File.WriteAllBytes(badFile, new byte[100]); // 100 nulls var repo = GlobalWritingSystemRepository.InitializeWithBasePath(e.Path, null); // main part of test is that we don't get any exception. Assert.That(repo.Count, Is.EqualTo(0)); // original .ldml file should have been renamed Assert.That(File.Exists(badFile), Is.False); Assert.That(File.Exists(badFile + ".bad"), Is.True); } }
public void Save_UpdatedWritingSystem_UpdatesLdmlFile() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo.Set(ws); repo.Save(); DateTime modified = File.GetLastWriteTime(repo.GetFilePathFromLanguageTag("en-US")); // ensure that last modified timestamp changes Thread.Sleep(1000); ws.WindowsLcid = "test"; repo.Save(); Assert.That(File.GetLastWriteTime(repo.GetFilePathFromLanguageTag("en-US")), Is.Not.EqualTo(modified)); } }
public void AllWritingSystems_LdmlUpdatedByAnotherRepo_ReturnsUpdatedDefinition() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(ws.WindowsLcid, Is.Empty); ws = repo2.Get("en-US"); ws.WindowsLcid = "test"; repo2.Save(); Assert.That(repo2.AllWritingSystems.First().WindowsLcid, Is.EqualTo("test")); } }
public void Get_CaseDifferingWritingSystems_DoesNotThrow(string id) { using (var temporaryFolder = CreateTemporaryFolder("Get_CaseDifferingWritingSystems_DoesNotThrow")) { // Setup var repo = new GlobalWritingSystemRepository(temporaryFolder.Path); var ws = new WritingSystemDefinition("en-US"); repo.Set(ws); repo.Save(); // Now we simulate that the user did a S/R which added a WS that differs by case File.Copy(Path.Combine(temporaryFolder.Path, "3", ws.Id + ".ldml"), Path.Combine(temporaryFolder.Path, "3", ws.Id.ToLower() + ".ldml")); // SUT/Verify Assert.That(() => repo.Get(id), Throws.Nothing); } }
public void Get_UpdatedLdmlUpdatedByAnotherRepo_ReturnLastUpdatedDefinition() { using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name)) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US")); WritingSystemDefinition ws2 = repo2.Get("en-US"); ws2.WindowsLcid = "test2"; repo2.Save(); ws.WindowsLcid = "test1"; Assert.That(repo1.Get("en-US").WindowsLcid, Is.EqualTo("test1")); } }
public void Get_LdmlUpdatedByAnotherRepo_ReturnsUpdatedDefinition() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(ws.WindowsLcid, Is.Empty); // ensure that last modified timestamp changes Thread.Sleep(1000); ws = repo2.Get("en-US"); ws.WindowsLcid = "test"; repo2.Save(); Assert.That(repo1.Get("en-US").WindowsLcid, Is.EqualTo("test")); } }
public TestLdmlInFolderWritingSystemRepository(string basePath, IEnumerable<ICustomDataMapper<WritingSystemDefinition>> customDataMappers, GlobalWritingSystemRepository globalRepository = null) : base(basePath, customDataMappers, globalRepository) { }
public void Get_LdmlRemovedByAnotherRepo_Throws() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US")); repo2.Remove("en-US"); Assert.That(() => repo1.Get("en-US"), Throws.TypeOf<ArgumentOutOfRangeException>()); } }
public void Get_UpdatedLdmlUpdatedByAnotherRepo_ReturnLastUpdatedDefinition() { using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests")) { var repo1 = new GlobalWritingSystemRepository(e.Path); var repo2 = new GlobalWritingSystemRepository(e.Path); var ws = new WritingSystemDefinition("en-US"); repo1.Set(ws); repo1.Save(); Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US")); WritingSystemDefinition ws2 = repo2.Get("en-US"); ws2.WindowsLcid = "test2"; repo2.Save(); ws.WindowsLcid = "test1"; Assert.That(repo1.Get("en-US").WindowsLcid, Is.EqualTo("test1")); } }
public TestLdmlInFolderWritingSystemRepository(string basePath, GlobalWritingSystemRepository globalRepository = null) : base(basePath, globalRepository) { }