public void GetWsForInputLanguage_GetsMatchingWsByCulture()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbdEn = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-US"
            };

            wsEn.LocalKeyboard = kbdEn;
            var kbdFr = new DefaultKeyboardDefinition()
            {
                Layout = "French", Locale = "fr-FR"
            };

            wsFr.LocalKeyboard = kbdFr;

            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsEn, new[] { wsEn, wsFr }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsFr, new[] { wsEn, wsFr }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsEn, new[] { wsFr, wsEn }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsFr, new[] { wsFr, wsEn }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("fr-FR"), wsEn, new[] { wsFr, wsEn }), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("fr-FR"), wsEn, new[] { wsEn, wsFr }), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("fr-FR"), null, new[] { wsEn, wsFr }), Is.EqualTo(wsFr));
        }
        public void GetWsForInputLanguage_PrefersCurrentLayoutIfTwoMatch()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbdEn = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-US"
            };

            wsEn.LocalKeyboard = kbdEn;
            var kbdFr = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "fr-US"
            };

            wsFr.LocalKeyboard = kbdFr;

            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsEn, new[] { wsEn, wsFr }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsFr, new[] { wsEn, wsFr }), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsEn, new[] { wsFr, wsEn }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsFr, new[] { wsFr, wsEn }), Is.EqualTo(wsFr));
        }
        public void SettingLocalKeyboardSettings_CausesLocalKeyboardToBeSetOnWritingSystemCreatedLater()
        {
            RepositoryUnderTest.LocalKeyboardSettings =
                @"<keyboards>
	<keyboard ws='en' layout='English' locale='en-AU'/>
	<keyboard ws='fr' layout='French-IPA' locale='fr-FR'/>
	<keyboard ws='de' layout='German-IPA' locale='de-DE'/>
</keyboards>";
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var wsDe = new WritingSystemDefinition("de");

            wsDe.LocalKeyboard = new DefaultKeyboardDefinition()
            {
                Layout = "German", Locale = "de-SW"
            };
            RepositoryUnderTest.Set(wsDe);

            Assert.That(wsEn.LocalKeyboard.Locale, Is.EqualTo("en-AU"));
            Assert.That(wsFr.LocalKeyboard.Layout, Is.EqualTo("French-IPA"));
            Assert.That(wsEn.LocalKeyboard.OperatingSystem, Is.EqualTo(Environment.OSVersion.Platform));
            Assert.That(wsDe.LocalKeyboard.Layout, Is.EqualTo("German"), "should not apply local keyboard settings if new WS already has them");
        }
        public void LocalKeyboardSettings_RetrievesLocalKeyboardData()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbd1 = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-GB", OperatingSystem = PlatformID.Win32NT
            };

            wsEn.LocalKeyboard = kbd1;

            var result = RepositoryUnderTest.LocalKeyboardSettings;
            var root   = XElement.Parse(result);

            Assert.That(root.Elements("keyboard").Count(), Is.EqualTo(1), "should have local keyboard for en but not fr");
            var keyboardElt = root.Elements("keyboard").First();

            Assert.That(keyboardElt.Attribute("layout").Value, Is.EqualTo("English"));
            Assert.That(keyboardElt.Attribute("locale").Value, Is.EqualTo("en-GB"));
            Assert.That(keyboardElt.Attribute("ws").Value, Is.EqualTo("en"));
        }
Ejemplo n.º 5
0
        public void WritingSystemIdHasChangedTo_IdExistsAndHasNeverChanged_ReturnsId()
        {
            //Add a writing system to the repo
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChangedTo("en"), Is.EqualTo("en"));
        }
Ejemplo n.º 6
0
        public void Remove_WritingsystemIdExists_FiresEventAndEventArgIsSetToIdOfDeletedWritingSystem()
        {
            RepositoryUnderTest.WritingSystemDeleted += OnWritingsystemDeleted;
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Remove(ws.LanguageTag);
            Assert.That(_writingSystemDeletedEventArgs.Id, Is.EqualTo(ws.LanguageTag));
        }
Ejemplo n.º 7
0
        public void WritingSystemIdHasChangedTo_IdChanged_ReturnsNewId()
        {
            //Add a writing system to the repo
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            //Now change the Id
            ws.Variants.Add("bogus");
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChangedTo("en"), Is.EqualTo("en-x-bogus"));
        }
        public void WritingSystemIdHasBeenChanged_IdChanged_ReturnsTrue()
        {
            //Add a writing system to the repo
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            //Now change the Id
            ws.Variant = "x-bogus";
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChanged("en"), Is.True);
        }
        public void GetWsForInputLanguage_CorrectlyPrioritizesLayoutAndCulture()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsEnIpa = new WritingSystemDefinition("en-fonipa");

            RepositoryUnderTest.Set(wsEnIpa);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var wsDe = new WritingSystemDefinition("de");

            RepositoryUnderTest.Set(wsDe);
            var kbdEn = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-US"
            };

            wsEn.LocalKeyboard = kbdEn;
            var kbdEnIpa = new DefaultKeyboardDefinition()
            {
                Layout = "English-IPA", Locale = "en-US"
            };

            wsEnIpa.LocalKeyboard = kbdEnIpa;
            var kbdFr = new DefaultKeyboardDefinition()
            {
                Layout = "French", Locale = "fr-FR"
            };

            wsFr.LocalKeyboard = kbdFr;
            var kbdDe = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "de-DE"
            };

            wsDe.LocalKeyboard = kbdDe;

            var wss = new IWritingSystemDefinition[] { wsEn, wsFr, wsDe, wsEnIpa };

            // Exact match selects correct one, even though there are other matches for layout and/or culture
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsFr, wss), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English-IPA", new CultureInfo("en-US"), wsEn, wss), Is.EqualTo(wsEnIpa));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("French", new CultureInfo("fr-FR"), wsDe, wss), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsEn, wss), Is.EqualTo(wsDe));

            // If there is no exact match, but there are matches by both layout and culture, we prefer layout (even though there is a
            // culture match for the default WS)
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsFr, wss), Is.EqualTo(wsEn));             // first of two equally good matches
        }
Ejemplo n.º 10
0
        public void WritingSystemIdHasChangedTo_IdChangedToMultipleDifferentNewIds_ReturnsNull()
        {
            //Add a writing system to the repo
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            RepositoryUnderTest.Save();
            //Now change the Id and create a duplicate of the original Id
            wsEn.Variants.Add("bogus");
            RepositoryUnderTest.Set(wsEn);
            var wsEnDup = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEnDup);
            RepositoryUnderTest.Save();
            //Now change the duplicate's Id as well
            wsEnDup.Variants.Add("bogus2");
            RepositoryUnderTest.Set(wsEnDup);
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChangedTo("en"), Is.Null);
        }
        public void SettingLocalKeyboardSettings_UpdatesLocalKeyboardsForExistingWritingSystems()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbd1 = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-GB", OperatingSystem = PlatformID.Win32NT
            };

            wsEn.LocalKeyboard = kbd1;

            RepositoryUnderTest.LocalKeyboardSettings =
                @"<keyboards>
	<keyboard ws='en' layout='English' locale='en-AU'/>
	<keyboard ws='fr' layout='French-IPA' locale='fr-FR'/>
</keyboards>";
            Assert.That(wsEn.LocalKeyboard.Locale, Is.EqualTo("en-AU"));
            Assert.That(wsFr.LocalKeyboard.Layout, Is.EqualTo("French-IPA"));
            Assert.That(wsEn.LocalKeyboard.OperatingSystem, Is.EqualTo(Environment.OSVersion.Platform));
        }
        public void GetWsForInputLanguage_PrefersWsCurrentIfEqualMatches()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsEnUS = new WritingSystemDefinition("en-US");

            RepositoryUnderTest.Set(wsEnUS);
            var wsEnIpa = new WritingSystemDefinition("en-fonipa");

            RepositoryUnderTest.Set(wsEnIpa);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var wsDe = new WritingSystemDefinition("de");

            RepositoryUnderTest.Set(wsDe);
            var kbdEn = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-US"
            };

            wsEn.LocalKeyboard = kbdEn;
            var kbdEnIpa = new DefaultKeyboardDefinition()
            {
                Layout = "English-IPA", Locale = "en-US"
            };

            wsEnIpa.LocalKeyboard = kbdEnIpa;
            wsEnUS.LocalKeyboard  = kbdEn;            // exact same keyboard used!
            var kbdFr = new DefaultKeyboardDefinition()
            {
                Layout = "French", Locale = "fr-FR"
            };

            wsFr.LocalKeyboard = kbdFr;
            var kbdDe = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "de-DE"
            };

            wsDe.LocalKeyboard = kbdDe;

            var wss = new IWritingSystemDefinition[] { wsEn, wsFr, wsDe, wsEnIpa, wsEnUS };

            // Exact matches
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsFr, wss), Is.EqualTo(wsEn));             // first of 2
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsEn, wss), Is.EqualTo(wsEn));             // prefer default
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsEnUS, wss), Is.EqualTo(wsEnUS));         // prefer default

            // Match on Layout only
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsFr, wss), Is.EqualTo(wsEn));             // first of 3
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsEn, wss), Is.EqualTo(wsEn));             // prefer default
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsEnUS, wss), Is.EqualTo(wsEnUS));         // prefer default
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsDe, wss), Is.EqualTo(wsDe));             // prefer default

            // Match on culture only
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsDe, wss), Is.EqualTo(wsEn));             // first of 3
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsEn, wss), Is.EqualTo(wsEn));             // prefer default
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsEnUS, wss), Is.EqualTo(wsEnUS));         // prefer default
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsEnIpa, wss), Is.EqualTo(wsEnIpa));       // prefer default
        }