Inheritance: IFwWritingSystemStore
        public void GetValidLangCodeForNewLang()
        {
            string storePath       = PrepareTempStore("Store");
            string globalStorePath = PrepareTempStore("GlobalStore");

            EnsureDirectoryIsEmpty(storePath);
            EnsureDirectoryIsEmpty(globalStorePath);

            var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
            var wsManager   = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath, globalStore), globalStore);

            Assert.AreEqual("qip", wsManager.GetValidLangTagForNewLang("Qipkey"));
            Assert.AreEqual("sn", wsManager.GetValidLangTagForNewLang("Sn"));
            Assert.AreEqual("eba", wsManager.GetValidLangTagForNewLang("\u00CBbashlish"));             // \u00CB == E with diacritic
            Assert.AreEqual("eee", wsManager.GetValidLangTagForNewLang("\u00CB\u00CB\u00CBlish"));
            // \u00CB == E with diacritic
            Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("U"));

            LanguageSubtag subtag = new LanguageSubtag("qip", "Qipkey", true, null);
            IWritingSystem newWs  = wsManager.Create(subtag, null, null, null);

            wsManager.Set(newWs);
            Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("Qipsing"), "code for 'qip' should already be taken");

            subtag = new LanguageSubtag("aaa", "Qipsing", true, null);
            newWs  = wsManager.Create(subtag, null, null, null);
            wsManager.Set(newWs);
            Assert.AreEqual("aab", wsManager.GetValidLangTagForNewLang("Qipwest"),
                            "code for 'qip' should already be taken twice");

            // ENHANCE: Ideally, we would want to test incrementing the middle and first character,
            // but that would require at least 677 (26^2 + 1) writing systems be created.
        }
        public void GlobalStore_WritingSystemsToIgnore()
        {
            string storePath1      = PrepareTempStore("Store1");
            string storePath2      = PrepareTempStore("Store2");
            string globalStorePath = PrepareTempStore("GlobalStore");

            var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
            var wsManager   = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            var ws = wsManager.Set("en-US");

            ws.SpellCheckingId = "id1";
            wsManager.Save();

            Thread.Sleep(1000);

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
            ws = wsManager.Set("en-US");
            ws.SpellCheckingId = "id2";
            wsManager.Save();

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            IEnumerable <IWritingSystem> sharedWss = wsManager.CheckForNewerGlobalWritingSystems();

            Assert.AreEqual(1, sharedWss.Count());
            Assert.AreEqual("en-US", sharedWss.First().Id);
            ws = wsManager.Get("en-US");
            Assert.AreEqual("id1", ws.SpellCheckingId);
            wsManager.Save();

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
            Assert.AreEqual(0, sharedWss.Count());
            wsManager.Save();

            Thread.Sleep(1000);

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
            ws = wsManager.Get("en-US");
            ws.LegacyMapping = "encoding converter";
            wsManager.Save();

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            ws = wsManager.Get("en-US");
            Assert.IsNullOrEmpty(ws.LegacyMapping);
            sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
            Assert.AreEqual(1, sharedWss.Count());
            IWritingSystem sharedWs = sharedWss.First();

            Assert.AreEqual("en-US", sharedWs.Id);
            wsManager.Replace(sharedWs);
            wsManager.Save();
            ws = wsManager.Get("en-US");
            Assert.AreEqual("encoding converter", ws.LegacyMapping);
        }
        public void GlobalStore()
        {
            string storePath1      = PrepareTempStore("Store1");
            string storePath2      = PrepareTempStore("Store2");
            string globalStorePath = PrepareTempStore("GlobalStore");

            var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
            var wsManager   = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            var ws = wsManager.Set("en-US");

            ws.SpellCheckingId = "id1";
            wsManager.Save();
            Assert.IsTrue(File.Exists(Path.Combine(storePath1, "en-US.ldml")));
            Assert.IsTrue(File.Exists(Path.Combine(globalStorePath, "en-US.ldml")));

            Thread.Sleep(1000);

            DateTime lastModified = File.GetLastWriteTime(Path.Combine(globalStorePath, "en-US.ldml"));

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
            ws = wsManager.Set("en-US");
            ws.SpellCheckingId = "id2";
            wsManager.Save();
            Assert.Less(lastModified, File.GetLastWriteTime(Path.Combine(globalStorePath, "en-US.ldml")));

            lastModified = File.GetLastWriteTime(Path.Combine(storePath1, "en-US.ldml"));
            wsManager    = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            ws = wsManager.Get("en-US");
            Assert.AreEqual("id1", ws.SpellCheckingId);
            IEnumerable <IWritingSystem> sharedWss = wsManager.CheckForNewerGlobalWritingSystems();

            Assert.AreEqual(1, sharedWss.Count());
            IWritingSystem sharedWs = sharedWss.First();

            Assert.AreEqual("en-US", sharedWs.Id);
            wsManager.Replace(sharedWs);
            wsManager.Save();

            ws = wsManager.Get("en-US");
            Assert.AreEqual("id2", ws.SpellCheckingId);
            Assert.Less(lastModified, File.GetLastWriteTime(Path.Combine(storePath1, "en-US.ldml")));
        }
        public void CreateAudioWritingSystemVariantFirst()
        {
            string storePath       = PrepareTempStore("Store");
            string globalStorePath = PrepareTempStore("GlobalStore");

            EnsureDirectoryIsEmpty(storePath);
            EnsureDirectoryIsEmpty(globalStorePath);

            var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
            var wsManager   = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath, globalStore), globalStore);

            IWritingSystem newWs = wsManager.Create(new LanguageSubtag("qaa", "Unknown", true, null), null, null, null);

            Assert.DoesNotThrow(() =>
            {
                newWs.VariantSubtag = new VariantSubtag("x-audio", "Audio", false, null);
                newWs.ScriptSubtag  = new ScriptSubtag("Zxxx", "Audio", false);
            });
        }
		public void CreateAudioWritingSystemVariantFirst()
		{

			string storePath = PrepareTempStore("Store");
			string globalStorePath = PrepareTempStore("GlobalStore");

			EnsureDirectoryIsEmpty(storePath);
			EnsureDirectoryIsEmpty(globalStorePath);

			var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
			var wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath, globalStore), globalStore);

			IWritingSystem newWs = wsManager.Create(new LanguageSubtag("qaa", "Unknown", true, null), null, null, null);

			Assert.DoesNotThrow(() =>
			{
				newWs.VariantSubtag = new VariantSubtag("x-audio", "Audio", false, null);
				newWs.ScriptSubtag = new ScriptSubtag("Zxxx", "Audio", false);
			});
		}
		public void GetValidLangCodeForNewLang()
		{
			string storePath = PrepareTempStore("Store");
			string globalStorePath = PrepareTempStore("GlobalStore");

			EnsureDirectoryIsEmpty(storePath);
			EnsureDirectoryIsEmpty(globalStorePath);

			var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
			var wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath, globalStore), globalStore);

			Assert.AreEqual("qip", wsManager.GetValidLangTagForNewLang("Qipkey"));
			Assert.AreEqual("sn", wsManager.GetValidLangTagForNewLang("Sn"));
			Assert.AreEqual("eba", wsManager.GetValidLangTagForNewLang("\u00CBbashlish")); // \u00CB == E with diacritic
			Assert.AreEqual("eee", wsManager.GetValidLangTagForNewLang("\u00CB\u00CB\u00CBlish"));
			// \u00CB == E with diacritic
			Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("U"));

			LanguageSubtag subtag = new LanguageSubtag("qip", "Qipkey", true, null);
			IWritingSystem newWs = wsManager.Create(subtag, null, null, null);
			wsManager.Set(newWs);
			Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("Qipsing"), "code for 'qip' should already be taken");

			subtag = new LanguageSubtag("aaa", "Qipsing", true, null);
			newWs = wsManager.Create(subtag, null, null, null);
			wsManager.Set(newWs);
			Assert.AreEqual("aab", wsManager.GetValidLangTagForNewLang("Qipwest"),
				"code for 'qip' should already be taken twice");

			// ENHANCE: Ideally, we would want to test incrementing the middle and first character,
			// but that would require at least 677 (26^2 + 1) writing systems be created.
		}
		public void GlobalStore_WritingSystemsToIgnore()
		{
			string storePath1 = PrepareTempStore("Store1");
			string storePath2 = PrepareTempStore("Store2");
			string globalStorePath = PrepareTempStore("GlobalStore");

			var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
			var wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
			var ws = wsManager.Set("en-US");
			ws.SpellCheckingId = "id1";
			wsManager.Save();

			Thread.Sleep(1000);

			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
			ws = wsManager.Set("en-US");
			ws.SpellCheckingId = "id2";
			wsManager.Save();

			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
			IEnumerable<IWritingSystem> sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
			Assert.AreEqual(1, sharedWss.Count());
			Assert.AreEqual("en-US", sharedWss.First().Id);
			ws = wsManager.Get("en-US");
			Assert.AreEqual("id1", ws.SpellCheckingId);
			wsManager.Save();

			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
			sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
			Assert.AreEqual(0, sharedWss.Count());
			wsManager.Save();

			Thread.Sleep(1000);

			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
			ws = wsManager.Get("en-US");
			ws.LegacyMapping = "encoding converter";
			wsManager.Save();

			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
			ws = wsManager.Get("en-US");
			Assert.IsNullOrEmpty(ws.LegacyMapping);
			sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
			Assert.AreEqual(1, sharedWss.Count());
			IWritingSystem sharedWs = sharedWss.First();
			Assert.AreEqual("en-US", sharedWs.Id);
			wsManager.Replace(sharedWs);
			wsManager.Save();
			ws = wsManager.Get("en-US");
			Assert.AreEqual("encoding converter", ws.LegacyMapping);
		}
		public void GlobalStore()
		{
			string storePath1 = PrepareTempStore("Store1");
			string storePath2 = PrepareTempStore("Store2");
			string globalStorePath = PrepareTempStore("GlobalStore");

			var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
			var wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
			var ws = wsManager.Set("en-US");
			ws.SpellCheckingId = "id1";
			wsManager.Save();
			Assert.IsTrue(File.Exists(Path.Combine(storePath1, "en-US.ldml")));
			Assert.IsTrue(File.Exists(Path.Combine(globalStorePath, "en-US.ldml")));

			Thread.Sleep(1000);

			DateTime lastModified = File.GetLastWriteTime(Path.Combine(globalStorePath, "en-US.ldml"));
			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
			ws = wsManager.Set("en-US");
			ws.SpellCheckingId = "id2";
			wsManager.Save();
			Assert.Less(lastModified, File.GetLastWriteTime(Path.Combine(globalStorePath, "en-US.ldml")));

			lastModified = File.GetLastWriteTime(Path.Combine(storePath1, "en-US.ldml"));
			wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
			ws = wsManager.Get("en-US");
			Assert.AreEqual("id1", ws.SpellCheckingId);
			IEnumerable<IWritingSystem> sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
			Assert.AreEqual(1, sharedWss.Count());
			IWritingSystem sharedWs = sharedWss.First();
			Assert.AreEqual("en-US", sharedWs.Id);
			wsManager.Replace(sharedWs);
			wsManager.Save();

			ws = wsManager.Get("en-US");
			Assert.AreEqual("id2", ws.SpellCheckingId);
			Assert.Less(lastModified, File.GetLastWriteTime(Path.Combine(storePath1, "en-US.ldml")));
		}