예제 #1
0
        public void Action_WithPreviousMongoGrammarWithMatchingGuids_ShouldBeUpdatedFromLcmGrammar()
        {
            // Setup
            var      lfProject = _lfProj;
            LcmCache cache     = lfProject.FieldWorksProject.Cache;
            int      wsEn      = cache.WritingSystemFactory.GetWsFromStr("en");
            var      converter = new ConvertLcmToMongoOptionList(null, wsEn,
                                                                 MagicStrings.LfOptionListCodeForGrammaticalInfo, new LfMerge.Core.Logging.NullLogger(),
                                                                 _cache.WritingSystemFactory);
            LfOptionList     lfGrammar   = converter.PrepareOptionListUpdate(cache.LanguageProject.PartsOfSpeechOA);
            LfOptionListItem itemForTest = lfGrammar.Items.First();
            Guid             g           = itemForTest.Guid.Value;

            itemForTest.Abbreviation = "Different abbreviation";
            itemForTest.Value        = "Different name";
            itemForTest.Key          = "Different key";
            _conn.UpdateMockOptionList(lfGrammar);

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            lfGrammar = _conn.GetLfOptionLists()
                        .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo);
            Assert.That(lfGrammar, Is.Not.Null);
            Assert.That(lfGrammar.Items, Is.Not.Empty);
            Assert.That(lfGrammar.Items.Count, Is.EqualTo(lfProject.FieldWorksProject.Cache.LanguageProject.AllPartsOfSpeech.Count));
            itemForTest = lfGrammar.Items.FirstOrDefault(x => x.Guid == g);
            Assert.That(itemForTest, Is.Not.Null);
            Assert.That(itemForTest.Abbreviation, Is.Not.EqualTo("Different abbreviation"));
            Assert.That(itemForTest.Value, Is.Not.EqualTo("Different name"));
            Assert.That(itemForTest.Key, Is.EqualTo("Different key"));             // NOTE: Is.EqualTo, because keys shouldn't be updated
        }
예제 #2
0
        public void Action_NoDataChanged_ShouldUpdatePictures()
        {
            // Setup
            var lfProject = _lfProj;
            IEnumerable <LfLexEntry> receivedData = _conn.GetLfLexEntries();
            int originalNumPictures = receivedData.Count(e => ((e.Senses.Count > 0) && (e.Senses[0].Pictures.Count > 0)));

            Assert.That(originalNumPictures, Is.EqualTo(0));

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify LF project now contains the 4 LCM pictures (1 externally linked, 3 internal)
            receivedData = _conn.GetLfLexEntries();
            int newNumPictures = receivedData.Count(e => ((e.Senses.Count > 0) && (e.Senses[0].Pictures.Count > 0)));

            Assert.That(newNumPictures, Is.EqualTo(4));
            LfLexEntry subEntry = receivedData.FirstOrDefault(e => e.Guid.ToString() == TestSubEntryGuidStr);

            Assert.That(subEntry, Is.Not.Null);
            Assert.That(subEntry.Senses[0].Pictures[0].FileName, Is.EqualTo("TestImage.tif"));
            LfLexEntry kenEntry = receivedData.FirstOrDefault(e => e.Guid.ToString() == KenEntryGuidStr);

            Assert.That(kenEntry, Is.Not.Null);
            Assert.That(kenEntry.Senses[0].Pictures[0].FileName, Is.EqualTo(string.Format(
                                                                                "F:{0}src{0}xForge{0}web-languageforge{0}test{0}php{0}common{0}TestImage.jpg",
                                                                                Path.DirectorySeparatorChar)));
        }
예제 #3
0
        public void Run_CustomMultiListRefTest(int whichSense, params string[] desiredKeys)
        {
            // Setup
            var lfProj = _lfProj;

            SutLcmToMongo.Run(lfProj);

            Guid       entryGuid = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry     = _conn.GetLfLexEntryByGuid(entryGuid);
            LfSense    sense     = entry.Senses[whichSense];

            SetCustomMultiOptionList(sense, "customField_senses_Cust_Multi_ListRef", desiredKeys);
            entry.AuthorInfo = new LfAuthorInfo();
            entry.AuthorInfo.ModifiedDate = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            SutMongoToLcm.Run(lfProj);

            // Verify
            LcmCache cache = _cache;

            var lcmEntry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;

            Assert.IsNotNull(lcmEntry);
            Assert.That(cache.ServiceLocator.MetaDataCache.FieldExists(LexSenseTags.kClassName, "Cust Multi ListRef", false), "LexSense should have the Cust Multi ListRef field in our test data.");
            int                  fieldId    = cache.ServiceLocator.MetaDataCache.GetFieldId(LexSenseTags.kClassName, "Cust Multi ListRef", false);
            ILexSense            lcmSense   = lcmEntry.SensesOS[whichSense];
            IEnumerable <string> lcmAbbrevs = GetLcmAbbrevsForField(lcmSense, fieldId);

            Assert.That(lcmAbbrevs, Is.EquivalentTo(desiredKeys));
        }
예제 #4
0
        public void Action_WithOneDeletedEntry_ShouldNotCountThatDeletedEntryOnSecondRun()
        {
            // Setup
            var lfProj = _lfProj;

            SutLcmToMongo.Run(lfProj);

            Guid       entryGuid = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry     = _conn.GetLfLexEntryByGuid(entryGuid);

            entry.IsDeleted = true;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            SutMongoToLcm.Run(lfProj);

            // Verify
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(0));
            Assert.That(_counts.Deleted, Is.EqualTo(1));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge: 1 entry deleted"));

            // Exercise again
            SutMongoToLcm.Run(lfProj);

            // Verify zero on second run
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(0));
            Assert.That(_counts.Deleted, Is.EqualTo(0));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge S/R"));
        }
예제 #5
0
        public void Action_WithTwoDeletedEntries_ShouldCountTwoDeleted()
        {
            // Setup
            var lfProj = _lfProj;

            SutLcmToMongo.Run(lfProj);

            Guid       entryGuid = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry     = _conn.GetLfLexEntryByGuid(entryGuid);

            entry.IsDeleted = true;
            _conn.UpdateMockLfLexEntry(entry);
            Guid kenGuid = Guid.Parse(KenEntryGuidStr);

            entry           = _conn.GetLfLexEntryByGuid(kenGuid);
            entry.IsDeleted = true;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            SutMongoToLcm.Run(lfProj);

            // Verify
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(0));
            Assert.That(_counts.Deleted, Is.EqualTo(2));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge: 2 entries deleted"));
        }
예제 #6
0
        public void Action_WithOneModifiedEntry_ShouldCountOneModified()
        {
            // Setup
            var lfProj = _lfProj;

            SutLcmToMongo.Run(lfProj);

            Guid       entryGuid     = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry         = _conn.GetLfLexEntryByGuid(entryGuid);
            LcmCache   cache         = lfProj.FieldWorksProject.Cache;
            string     vernacularWS  = cache.LanguageProject.DefaultVernacularWritingSystem.Id;
            string     changedLexeme = "modified lexeme for this test";

            entry.Lexeme     = LfMultiText.FromSingleStringMapping(vernacularWS, changedLexeme);
            entry.AuthorInfo = new LfAuthorInfo();
            entry.AuthorInfo.ModifiedDate = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            SutMongoToLcm.Run(lfProj);

            // Verify
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(1));
            Assert.That(_counts.Deleted, Is.EqualTo(0));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge: 1 entry modified"));
        }
예제 #7
0
        public void Action_RunTwiceWithTheSameEntryModifiedEachTime_ShouldCountTwoModifiedInTotal()
        {
            // Setup
            var lfProj = _lfProj;

            SutLcmToMongo.Run(lfProj);

            Guid       entryGuid     = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry         = _conn.GetLfLexEntryByGuid(entryGuid);
            LcmCache   cache         = lfProj.FieldWorksProject.Cache;
            string     vernacularWS  = cache.LanguageProject.DefaultVernacularWritingSystem.Id;
            string     changedLexeme = "modified lexeme for this test";

            entry.Lexeme     = LfMultiText.FromSingleStringMapping(vernacularWS, changedLexeme);
            entry.AuthorInfo = new LfAuthorInfo();
            entry.AuthorInfo.ModifiedDate = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            SutMongoToLcm.Run(lfProj);

            // Verify
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(1));
            Assert.That(_counts.Deleted, Is.EqualTo(0));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge: 1 entry modified"));

            // Setup second run
            string changedLexeme2 = "second modified lexeme for this test";

            entry.Lexeme     = LfMultiText.FromSingleStringMapping(vernacularWS, changedLexeme2);
            entry.AuthorInfo = new LfAuthorInfo();
            entry.AuthorInfo.ModifiedDate = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise second run
            SutMongoToLcm.Run(lfProj);

            // Verify second run
            Assert.That(_counts.Modified, Is.EqualTo(1));
            // Added and Deleted shouldn't have changed, but check Modified first
            // since that's the main point of this test
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Deleted, Is.EqualTo(0));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge: 1 entry modified"));
        }
예제 #8
0
        public void Action_NoDataChanged_ShouldUpdateCustomFieldConfig()
        {
            // Setup
            var lfProject = _lfProj;

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            var customFieldConfig = _conn.GetCustomFieldConfig(lfProject);

            Assert.That(customFieldConfig.Count, Is.EqualTo(6));
            Assert.That(customFieldConfig.ContainsKey("customField_entry_Cust_MultiPara"));
            Assert.That(customFieldConfig["customField_entry_Cust_MultiPara"].HideIfEmpty, Is.False);
            LfConfigMultiParagraph entryMultiPara = (LfConfigMultiParagraph)customFieldConfig["customField_entry_Cust_MultiPara"];

            Assert.That(entryMultiPara.Label, Is.EqualTo("Cust MultiPara"));
        }
예제 #9
0
        public void Action_WithPreviousMongoGrammarWithGuids_ShouldReplaceItemsFromLfGrammarWithItemsFromLcmGrammar()
        {
            // Setup
            var          lfProject = _lfProj;
            int          initialGrammarItemCount = 10;
            LfOptionList lfGrammar = CreateLfGrammarWith(DefaultGrammarItems(initialGrammarItemCount));

            _conn.UpdateMockOptionList(lfGrammar);

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            lfGrammar = _conn.GetLfOptionLists()
                        .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo);
            Assert.That(lfGrammar, Is.Not.Null);
            Assert.That(lfGrammar.Items, Is.Not.Empty);
            Assert.That(lfGrammar.Items.Count, Is.EqualTo(lfProject.FieldWorksProject.Cache.LanguageProject.AllPartsOfSpeech.Count));
        }
예제 #10
0
        public void Action_WithEmptyMongoGrammar_ShouldPopulateMongoGrammarFromLcmGrammar()
        {
            // Setup
            var          lfProject = _lfProj;
            LfOptionList lfGrammar = _conn.GetLfOptionLists()
                                     .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo);

            Assert.That(lfGrammar, Is.Null);

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            lfGrammar = _conn.GetLfOptionLists()
                        .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo);
            Assert.That(lfGrammar, Is.Not.Null);
            Assert.That(lfGrammar.Items, Is.Not.Empty);
            Assert.That(lfGrammar.Items.Count, Is.EqualTo(lfProject.FieldWorksProject.Cache.LanguageProject.AllPartsOfSpeech.Count));
        }
예제 #11
0
        public void Action_NoDataChanged_ShouldUpdateLexemes()
        {
            // Setup
            var lfProject = _lfProj;

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            string[] searchOrder    = new string[] { "en", "fr" };
            string   expectedLexeme = "zitʰɛstmen";
            IEnumerable <LfLexEntry> receivedData = _conn.GetLfLexEntries();

            Assert.That(receivedData, Is.Not.Null);
            Assert.That(receivedData, Is.Not.Empty);
            LfLexEntry entry = receivedData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);

            Assert.That(entry, Is.Not.Null);
            Assert.That(entry.Lexeme.BestString(searchOrder), Is.EqualTo(expectedLexeme));
        }
예제 #12
0
        public void Action_RunTwiceWithTheSameEntryDeletedEachTime_ShouldCountJustOneDeletedInTotal()
        {
            // Setup
            var lfProj = _lfProj;

            SutLcmToMongo.Run(lfProj);

            Guid       entryGuid = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry     = _conn.GetLfLexEntryByGuid(entryGuid);

            entry.IsDeleted = true;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            SutMongoToLcm.Run(lfProj);

            // Verify
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(0));
            Assert.That(_counts.Deleted, Is.EqualTo(1));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge: 1 entry deleted"));

            entry           = _conn.GetLfLexEntryByGuid(entryGuid);
            entry.IsDeleted = true;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise second run
            SutMongoToLcm.Run(lfProj);

            // Verify second run
            Assert.That(_counts.Deleted, Is.EqualTo(0));
            // Added and Modified shouldn't have changed either, but check Deleted first
            // since that's the main point of this test
            Assert.That(_counts.Added, Is.EqualTo(0));
            Assert.That(_counts.Modified, Is.EqualTo(0));

            Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted),
                        Is.EqualTo("Language Forge S/R"));
        }
예제 #13
0
        public void Action_IsInitialClone_ShouldPopulateMongoInputSystems()
        {
            // Setup
            var lfProject = _lfProj;

            lfProject.IsInitialClone = true;
            Dictionary <string, LfInputSystemRecord> lfWsList = _conn.GetInputSystems(lfProject);

            Assert.That(lfWsList.Count, Is.EqualTo(0));

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            const int expectedNumVernacularWS = 3;
            const int expectedNumAnalysisWS   = 2;
            // TODO: Investigate why qaa-Zxxx-x-kal-audio is in CurrentVernacularWritingSystems, but somehow in
            // UpdateMongoDbFromLcm.LcmWsToLfWs() is not contained in _cache.LangProject.CurrentVernacularWritingSystems
            const string notVernacularWs = "qaa-Zxxx-x-kal-audio";

            lfWsList = _conn.GetInputSystems(lfProject);
            var languageProj = lfProject.FieldWorksProject.Cache.LangProject;

            foreach (var lcmVernacularWs in languageProj.CurrentVernacularWritingSystems)
            {
                if (lcmVernacularWs.Id != notVernacularWs)
                {
                    Assert.That(lfWsList[lcmVernacularWs.Id].VernacularWS);
                }
            }
            Assert.That(languageProj.CurrentVernacularWritingSystems.Count, Is.EqualTo(expectedNumVernacularWS));

            foreach (var lcmAnalysisWs in languageProj.CurrentAnalysisWritingSystems)
            {
                Assert.That(lfWsList[lcmAnalysisWs.Id].AnalysisWS);
            }
            Assert.That(languageProj.CurrentAnalysisWritingSystems.Count, Is.EqualTo(expectedNumAnalysisWS));
        }
예제 #14
0
        public void Action_IsInitialClone_ShouldUpdateDates()
        {
            // Setup
            var lfProject = _lfProj;

            lfProject.IsInitialClone = true;

            // Exercise
            SutLcmToMongo.Run(lfProject);

            // Verify
            IEnumerable <LfLexEntry> receivedData = _conn.GetLfLexEntries();

            Assert.That(receivedData, Is.Not.Null);
            Assert.That(receivedData, Is.Not.Empty);

            LfLexEntry entry = receivedData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);

            Assert.That(entry, Is.Not.Null);
            Assert.That(entry.DateCreated, Is.EqualTo(DateTime.UtcNow).Within(5).Seconds);
            Assert.That(entry.DateModified, Is.EqualTo(DateTime.UtcNow).Within(5).Seconds);
            Assert.That(entry.AuthorInfo.CreatedDate, Is.EqualTo(DateTime.Parse("2004-10-19 02:42:02.903")));
            Assert.That(entry.AuthorInfo.ModifiedDate, Is.EqualTo(DateTime.Parse("2016-02-25 03:51:29.404")));
        }