public void Action_WithOneWellKnownTopLevelItemButNoGuidInMongoGrammar_ShouldAddOnlyOneNewGrammarEntry()
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            int grammarCountBeforeTest = cache.LangProject.AllPartsOfSpeech.Count;
            var data = new SampleData();
            BsonDocument grammarEntry = new BsonDocument();
            grammarEntry.Add("key", "adp"); // Standard abbreviation for "adposition", a top-level entry
            grammarEntry.Add("value", "NotTheRightName");
            grammarEntry.Add("abbreviation", "NotTheRightAbbrev");
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            int grammarCountAfterTest = cache.LangProject.AllPartsOfSpeech.Count;
            Assert.That(grammarCountAfterTest, Is.EqualTo(grammarCountBeforeTest + 1));
        }
        public void Action_WithOneWellKnownItemThatHasOneParentButNoGuidInMongoGrammar_ShouldAddTwoGrammarEntriesWithCorrectNamesAndParents()
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            var data = new SampleData();
            BsonDocument grammarEntry = new BsonDocument();
            grammarEntry.Add("key", "subordconn"); // Standard abbreviation for "subordinating connector", whose parent is "connector"
            grammarEntry.Add("value", "NotTheRightName");
            grammarEntry.Add("abbreviation", "NotTheRightAbbrev");
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            char ORC = '\ufffc';
            string expectedGuid = PartOfSpeechMasterList.FlatPosGuidsFromAbbrevs["subordconn"];
            string[] expectedNames = PartOfSpeechMasterList.HierarchicalPosNames[expectedGuid].Split(ORC);
            string[] expectedAbbrevs = PartOfSpeechMasterList.HierarchicalPosAbbrevs[expectedGuid].Split(ORC);
            string expectedName = expectedNames[1];
            string expectedAbbrev = expectedAbbrevs[1];
            string expectedParentName = expectedNames[0];
            string expectedParentAbbrev = expectedAbbrevs[0];
            string expectedParentGuid = PartOfSpeechMasterList.FlatPosGuidsFromAbbrevs[expectedParentAbbrev];

            IPartOfSpeech newlyCreatedPos = cache.LangProject.AllPartsOfSpeech.FirstOrDefault(pos =>
                pos.Name.BestAnalysisVernacularAlternative.Text == expectedName
            );
            Assert.That(newlyCreatedPos, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid.ToString(), Is.EqualTo(expectedGuid));
            Assert.That(newlyCreatedPos.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedName));
            Assert.That(newlyCreatedPos.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedAbbrev));
            Assert.That(newlyCreatedPos.OwningPossibility, Is.Not.Null);
            Assert.That(newlyCreatedPos.OwningPossibility, Is.InstanceOf<IPartOfSpeech>());
            Assert.That(newlyCreatedPos.OwningPossibility.Guid, Is.Not.Null);
            Assert.That(newlyCreatedPos.OwningPossibility.Guid.ToString(), Is.EqualTo(expectedParentGuid));
            Assert.That(newlyCreatedPos.OwningPossibility.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedParentName));
            Assert.That(newlyCreatedPos.OwningPossibility.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedParentAbbrev));
        }
        public void Action_ChangedWithSampleData_ShouldUpdatePictures()
        {
            // Setup initial Mongo project has 1 picture and 2 captions
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var data = new SampleData();
            _conn.UpdateMockLfLexEntry(data.bsonTestData);
            string expectedInternalFileName = Path.Combine("Pictures", data.bsonTestData["senses"][0]["pictures"][0]["fileName"].ToString());
            string expectedExternalFileName = data.bsonTestData["senses"][0]["pictures"][1]["fileName"].ToString();
            int newMongoPictureCount = data.bsonTestData["senses"][0]["pictures"].AsBsonArray.Count;
            int newMongoCaptionCount = data.bsonTestData["senses"][0]["pictures"][0]["caption"].AsBsonDocument.Count();
            Assert.That(newMongoPictureCount, Is.EqualTo(2));
            Assert.That(newMongoCaptionCount, Is.EqualTo(2));

            // Initial FDO project has 63 entries, 3 internal pictures, and 1 externally linked picture
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            ILexEntryRepository entryRepo = cache.ServiceLocator.GetInstance<ILexEntryRepository>();
            int originalNumOfFdoPictures = entryRepo.AllInstances().
                Count(e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0));
            Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(originalNumOfFdoPictures, Is.EqualTo(3+1));
            string expectedGuidStr = data.bsonTestData["guid"].AsString;
            Guid expectedGuid = Guid.Parse(expectedGuidStr);
            var entryBefore = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry;
            Assert.That(entryBefore.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entryBefore.SensesOS.First().PicturesOS.Count, Is.EqualTo(1));

            // Exercise adding 1 picture with 2 captions. Note that the picture that was previously attached
            // to this FDO entry will end up being deleted, because it does not have a corresponding picture in LF.
            sutMongoToFdo.Run(lfProj);

            // Verify "Added" picture is now the only picture on the sense (because the "old" picture was deleted),
            // and that it has 2 captions with the expected values.
            entryRepo = cache.ServiceLocator.GetInstance<ILexEntryRepository>();
            int numOfFdoPictures = entryRepo.AllInstances().
                Count(e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0));
            Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(numOfFdoPictures, Is.EqualTo(originalNumOfFdoPictures));

            var entry = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry;
            Assert.IsNotNull(entry);
            Assert.That(entry.Guid, Is.EqualTo(expectedGuid));
            Assert.That(entry.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entry.SensesOS.First().PicturesOS.Count, Is.EqualTo(2));
            Assert.That(entry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(),
                Is.EqualTo(expectedInternalFileName));
            Assert.That(entry.SensesOS[0].PicturesOS[1].PictureFileRA.InternalPath.ToString(),
                Is.EqualTo(expectedExternalFileName));

            LfMultiText expectedNewCaption = ConvertFdoToMongoLexicon.
                ToMultiText(entry.SensesOS[0].PicturesOS[0].Caption, cache.ServiceLocator.WritingSystemManager);
            int expectedNumOfNewCaptions = expectedNewCaption.Count();
            Assert.That(expectedNumOfNewCaptions, Is.EqualTo(2));
            string expectedNewVernacularCaption = expectedNewCaption["qaa-x-kal"].Value;
            string expectedNewAnalysisCaption = expectedNewCaption["en"].Value;
            Assert.That(expectedNewVernacularCaption.Equals("First Vernacular caption"));
            Assert.That(expectedNewAnalysisCaption.Equals("Internal path reference"));

            var testSubEntry = cache.ServiceLocator.GetObject(Guid.Parse(TestSubEntryGuidStr)) as ILexEntry;
            Assert.That(testSubEntry, Is.Not.Null);
            Assert.That(testSubEntry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(),
                Is.EqualTo("Pictures\\TestImage.tif"));
            var kenEntry = cache.ServiceLocator.GetObject(Guid.Parse(KenEntryGuidStr)) as ILexEntry;
            Assert.That(kenEntry, Is.Not.Null);
            Assert.That(kenEntry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(),
                Is.EqualTo("F:\\src\\xForge\\web-languageforge\\test\\php\\common\\TestImage.jpg"));
        }
        public void Action_WithOneItemInMongoGrammar_ShouldUpdateThatOneItemInFdoGrammar()
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            int grammarCountBeforeTest = cache.LangProject.AllPartsOfSpeech.Count;
            IPartOfSpeech secondPosBeforeTest = cache.LangProject.AllPartsOfSpeech.Skip(1).FirstOrDefault();
            var data = new SampleData();
            BsonDocument grammarEntry = new BsonDocument();
            grammarEntry.Add("key", "k");
            grammarEntry.Add("value", "v");
            grammarEntry.Add("abbreviation", "a");
            grammarEntry.Add("guid", secondPosBeforeTest.Guid.ToString());
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            int grammarCountAfterTest = cache.LangProject.AllPartsOfSpeech.Count;
            IPartOfSpeech secondPosAfterTest = cache.LangProject.AllPartsOfSpeech.Skip(1).FirstOrDefault();
            Assert.That(grammarCountAfterTest, Is.EqualTo(grammarCountBeforeTest));
            Assert.That(secondPosAfterTest, Is.Not.Null);
            Assert.That(secondPosAfterTest.Guid, Is.EqualTo(secondPosBeforeTest.Guid));
            Assert.That(secondPosAfterTest, Is.SameAs(secondPosBeforeTest));
            Assert.That(secondPosAfterTest.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo("v"));
            Assert.That(secondPosAfterTest.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo("a"));
            // LF key shouldn't be copied to FDO, so don't test that one
        }
        public void Action_WithOneWellKnownItemButNoGuidInMongoGrammar_ShouldGetCorrectWellKnownGuidInFdo()
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            var data = new SampleData();
            BsonDocument grammarEntry = new BsonDocument();
            grammarEntry.Add("key", "subordconn"); // Standard abbreviation for "subordinating connector"
            grammarEntry.Add("value", "NotTheRightName");
            grammarEntry.Add("abbreviation", "NotTheRightAbbrev");
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            string expectedGuid = PartOfSpeechMasterList.FlatPosGuidsFromAbbrevs["subordconn"];
            string expectedName = PartOfSpeechMasterList.FlatPosNames[expectedGuid];
            string expectedAbbrev = PartOfSpeechMasterList.FlatPosAbbrevs[expectedGuid];
            IPartOfSpeech newlyCreatedPos = cache.LangProject.AllPartsOfSpeech.FirstOrDefault(pos =>
                pos.Name.BestAnalysisVernacularAlternative.Text == expectedName
            );
            Assert.That(newlyCreatedPos, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid.ToString(), Is.EqualTo(expectedGuid));
            Assert.That(newlyCreatedPos.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedName));
            Assert.That(newlyCreatedPos.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedAbbrev));
        }
        public void Action_Should_UpdateDefinitions()
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var data = new SampleData();
            string newDefinition = "New definition for this unit test";
            data.bsonTestData["senses"][0]["definition"]["en"]["value"] = newDefinition;

            _conn.UpdateMockLfLexEntry(data.bsonTestData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            string expectedGuidStr = data.bsonTestData["guid"].AsString;
            string expectedShortName = data.bsonTestData["citationForm"].AsBsonDocument.GetElement(0).Value["value"].AsString;
            Guid expectedGuid = Guid.Parse(expectedGuidStr);

            var entry = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry;
            Assert.IsNotNull(entry);
            Assert.That(entry.Guid, Is.EqualTo(expectedGuid));
            Assert.That(entry.ShortName, Is.EqualTo(expectedShortName));
            Assert.That(entry.SensesOS[0].Definition.BestAnalysisAlternative.Text, Is.EqualTo(newDefinition));
        }
        public void Action_WithOneItemInMongoGrammarThatHasNoGuidAndIsNotWellKnown_ShouldAddOneNewItemInFdoGrammar()
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            int grammarCountBeforeTest = cache.LangProject.AllPartsOfSpeech.Count;
            IPartOfSpeech secondPosBeforeTest = cache.LangProject.AllPartsOfSpeech.Skip(1).FirstOrDefault();
            var data = new SampleData();
            BsonDocument grammarEntry = new BsonDocument();
            grammarEntry.Add("key", "k2");
            grammarEntry.Add("value", "v2");
            grammarEntry.Add("abbreviation", "a2");
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            int grammarCountAfterTest = cache.LangProject.AllPartsOfSpeech.Count;
            IPartOfSpeech secondPosAfterTest = cache.LangProject.AllPartsOfSpeech.Skip(1).FirstOrDefault();
            IPartOfSpeech newlyCreatedPos = cache.LangProject.AllPartsOfSpeech.FirstOrDefault(pos =>
                pos.Abbreviation.BestAnalysisVernacularAlternative.Text == "k2" && // NOTE: k2 not a2
                pos.Name.BestAnalysisVernacularAlternative.Text == "v2"
            );
            Assert.That(grammarCountAfterTest, Is.EqualTo(grammarCountBeforeTest + 1));
            Assert.That(secondPosAfterTest, Is.Not.Null);
            Assert.That(secondPosAfterTest.Guid, Is.EqualTo(secondPosBeforeTest.Guid));
            Assert.That(secondPosAfterTest, Is.SameAs(secondPosBeforeTest));
            Assert.That(secondPosAfterTest.Name.BestAnalysisVernacularAlternative.Text, Is.Not.EqualTo("v2"));
            Assert.That(secondPosAfterTest.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.Not.EqualTo("a2"));
            Assert.That(secondPosAfterTest.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.Not.EqualTo("k2"));
            Assert.That(newlyCreatedPos, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid, Is.Not.Null);
            Assert.That(newlyCreatedPos.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo("v2"));
            Assert.That(newlyCreatedPos.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo("k2"));
            // The newly-created part of speech will get its abbreviation from the LF key, not the LF abbrev.
            // TODO: Consider whether or not that's a bug, and whether it should use the (user-supplied) abbrev.
            // OTOH, they should be the same... unless LF has a non-English UI language. In which case we *need*
            // the English abbrev (the "key") and we *want* the non-English abbrev.
        }
        public void Action_RunTwice_ShouldNotDuplicatePictures()
        {
            // Setup initial Mongo project has 1 picture and 2 captions
            var lfProj = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var data = new SampleData();
            int newMongoPictureCount = data.bsonTestData["senses"][0]["pictures"].AsBsonArray.Count;
            int newMongoCaptionCount = data.bsonTestData["senses"][0]["pictures"][0]["caption"].AsBsonDocument.Count();
            Assert.That(newMongoPictureCount, Is.EqualTo(2));
            Assert.That(newMongoCaptionCount, Is.EqualTo(2));

            // Initial FDO project has 63 entries, 3 internal pictures, and 1 externally linked picture
            FdoCache cache = lfProj.FieldWorksProject.Cache;
            ILexEntryRepository entryRepo = cache.ServiceLocator.GetInstance<ILexEntryRepository>();
            int originalNumOfFdoPictures = entryRepo.AllInstances().Count(
                e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0));
            Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(originalNumOfFdoPictures, Is.EqualTo(3+1));
            string expectedGuidStrBefore = data.bsonTestData["guid"].AsString;
            Guid expectedGuidBefore = Guid.Parse(expectedGuidStrBefore);
            var entryBefore = cache.ServiceLocator.GetObject(expectedGuidBefore) as ILexEntry;
            Assert.That(entryBefore.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entryBefore.SensesOS.First().PicturesOS.Count, Is.EqualTo(1));

            // Exercise running Action twice
            _conn.UpdateMockLfLexEntry(data.bsonTestData);
            sutMongoToFdo.Run(lfProj);
            sutMongoToFdo.Run(lfProj);

            string expectedGuidStr = data.bsonTestData["guid"].AsString;
            Guid expectedGuid = Guid.Parse(expectedGuidStr);
            var entry = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry;
            Assert.IsNotNull(entry);
            Assert.That(entry.Guid, Is.EqualTo(expectedGuid));

            Assert.That(entry.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entry.SensesOS.First().PicturesOS.Count, Is.EqualTo(2));
        }
Esempio n. 9
0
        public void RoundTrip_FdoToMongoToFdo_ShouldKeepOriginalValuesInSenses()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);
            ILexSense[] senses = entry.SensesOS.ToArray();
            Assert.That(senses.Length, Is.EqualTo(2));

            BsonDocument[] customFieldValues = senses.Select(sense => GetCustomFieldValues(cache, sense, "senses")).ToArray();
            IDictionary<int, object>[] fieldValues = senses.Select(sense => GetFieldValues(cache, sense)).ToArray();

            // We no longer populate the semantic domain optionlist in Fdo->Mongo, so we need to populate it here
            var data = new SampleData();
            _conn.UpdateMockOptionList(data.bsonSemDomData);

            // Exercise
            sutFdoToMongo.Run(lfProject);
            sutMongoToFdo.Run(lfProject);

            // Verify
            BsonDocument[] customFieldValuesAfterTest = senses.Select(sense => GetCustomFieldValues(cache, sense, "senses")).ToArray();
            IDictionary<int, object>[] fieldValuesAfterTest = senses.Select(sense => GetFieldValues(cache, sense)).ToArray();

            var differencesByName1 = GetFdoDifferences(cache, fieldValues[0], fieldValuesAfterTest[0]);
            var differencesByName2 = GetFdoDifferences(cache, fieldValues[1], fieldValuesAfterTest[1]);

            PrintDifferences(differencesByName1);
            Assert.That(differencesByName1, Is.Empty);
            Assert.That(customFieldValues[0], Is.EqualTo(customFieldValuesAfterTest[0]));
            PrintDifferences(differencesByName2);
            Assert.That(differencesByName2, Is.Empty);
            Assert.That(customFieldValues[1], Is.EqualTo(customFieldValuesAfterTest[1]));
        }
Esempio n. 10
0
        public void RoundTrip_FdoToMongoToFdoToMongo_ShouldKeepModifiedValuesInEntries()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);
            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("undo", "redo", cache.ActionHandlerAccessor, () =>
                {
                    entry.CitationForm.SetVernacularDefaultWritingSystem("New value for this test");
                });

            // Save field values before test, to compare with values after test
            BsonDocument customFieldValues = GetCustomFieldValues(cache, entry, "entry");
            IDictionary<int, object> fieldValues = GetFieldValues(cache, entry);

            // Exercise
            sutFdoToMongo.Run(lfProject);
            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("undo", "redo", cache.ActionHandlerAccessor, () =>
                {
                    entry.CitationForm.SetVernacularDefaultWritingSystem("This value should be overwritten by MongoToFdo");
                });

            // Save original mongo data
            IEnumerable<LfLexEntry> originalData = _conn.GetLfLexEntries();
            LfLexEntry originalLfEntry = originalData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);

            string vernacularWS = cache.ServiceLocator.WritingSystemManager.GetStrFromWs(cache.DefaultVernWs);
            string originalLexeme = originalLfEntry.Lexeme[vernacularWS].Value;
            string changedLexeme = "Changed lexeme for this test";
            originalLfEntry.Lexeme[vernacularWS].Value = changedLexeme;
            _conn.UpdateMockLfLexEntry(originalLfEntry);

            // We no longer populate the semantic domain optionlist in Fdo->Mongo, so we need to populate it here
            var data = new SampleData();
            _conn.UpdateMockOptionList(data.bsonSemDomData);

            // Exercise
            sutMongoToFdo.Run(lfProject);
            string changedLexemeDuringUpdate = "This value should be overwritten by FdoToMongo";
            originalLfEntry.Lexeme[vernacularWS].Value = changedLexemeDuringUpdate;
            _conn.UpdateMockLfLexEntry(originalLfEntry);
            sutFdoToMongo.Run(lfProject);

            // Verify
            Assert.That(entry.CitationForm.VernacularDefaultWritingSystem.Text, Is.Not.EqualTo("This value should be overwritten by MongoToFdo"));
            Assert.That(entry.CitationForm.VernacularDefaultWritingSystem.Text, Is.EqualTo("New value for this test"));

            BsonDocument customFieldValuesAfterTest = GetCustomFieldValues(cache, entry, "entry");
            IDictionary<int, object> fieldValuesAfterTest = GetFieldValues(cache, entry);
            IDictionary<string, Tuple<string, string>> differencesByName = GetFdoDifferences(cache, fieldValues, fieldValuesAfterTest);
            if (differencesByName.ContainsKey("DateModified"))
                differencesByName.Remove("DateModified");
            PrintDifferences(differencesByName);
            Assert.That(differencesByName, Is.Empty);
            Assert.That(customFieldValuesAfterTest, Is.EqualTo(customFieldValues));

            IEnumerable<LfLexEntry> receivedData = _conn.GetLfLexEntries();
            Assert.That(receivedData, Is.Not.Null);
            Assert.That(receivedData, Is.Not.Empty);
            Assert.That(receivedData.Count(), Is.EqualTo(OriginalNumOfFdoEntries));

            LfLexEntry lfEntry = receivedData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);
            Assert.That(lfEntry, Is.Not.Null);
            Assert.That(lfEntry.Lexeme[vernacularWS].Value, Is.Not.EqualTo(changedLexemeDuringUpdate));
            Assert.That(lfEntry.Lexeme[vernacularWS].Value, Is.EqualTo(changedLexeme));

            originalLfEntry.Lexeme[vernacularWS].Value = originalLexeme;
            differencesByName = GetMongoDifferences(originalLfEntry.ToBsonDocument(), lfEntry.ToBsonDocument());
            differencesByName.Remove("lexeme");
            PrintDifferences(differencesByName);
            Assert.That(differencesByName.Count(), Is.EqualTo(0));
        }
Esempio n. 11
0
        public void RoundTrip_FdoToMongoToFdoToMongo_ShouldKeepOriginalValuesInEntries()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);

            // Save field values before test, to compare with values after test
            BsonDocument customFieldValues = GetCustomFieldValues(cache, entry, "entry");
            IDictionary<int, object> fieldValues = GetFieldValues(cache, entry);

            // We no longer populate the semantic domain optionlist in Fdo->Mongo, so we need to populate it here
            var data = new SampleData();
            _conn.UpdateMockOptionList(data.bsonSemDomData);

            // Exercise
            sutFdoToMongo.Run(lfProject);

            // Save original Mongo data
            IEnumerable<LfLexEntry> originalData = _conn.GetLfLexEntries();
            LfLexEntry originalLfEntry = originalData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);
            Assert.That(originalData, Is.Not.Null);
            Assert.That(originalData, Is.Not.Empty);
            Assert.That(originalData.Count(), Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(originalLfEntry, Is.Not.Null);

            // Exercise
            sutMongoToFdo.Run(lfProject);

            // Verify
            BsonDocument customFieldValuesAfterTest = GetCustomFieldValues(cache, entry, "entry");
            IDictionary<int, object> fieldValuesAfterTest = GetFieldValues(cache, entry);
            IDictionary<string, Tuple<string, string>> differencesByName = GetFdoDifferences(cache, fieldValues, fieldValuesAfterTest);
            PrintDifferences(differencesByName);
            Assert.That(differencesByName, Is.Empty);
            Assert.That(customFieldValues, Is.EqualTo(customFieldValuesAfterTest));

            // Exercise
            sutFdoToMongo.Run(lfProject);

            // Verify
            IEnumerable<LfLexEntry> receivedData = _conn.GetLfLexEntries();
            Assert.That(receivedData, Is.Not.Null);
            Assert.That(receivedData, Is.Not.Empty);
            Assert.That(receivedData.Count(), Is.EqualTo(OriginalNumOfFdoEntries));

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

            differencesByName = GetMongoDifferences(originalLfEntry.ToBsonDocument(), lfEntry.ToBsonDocument());
            PrintDifferences(differencesByName);
            Assert.That(differencesByName.Count(), Is.EqualTo(0));
        }
Esempio n. 12
0
        public void RoundTrip_FdoToMongoToFdoToMongo_ShouldKeepModifiedValuesInSenses()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);
            ILexSense[] senses = entry.SensesOS.ToArray();
            Assert.That(senses.Length, Is.EqualTo(2));
            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("undo", "redo", cache.ActionHandlerAccessor, () =>
                {
                    senses[0].AnthroNote.SetAnalysisDefaultWritingSystem("New value for this test");
                    senses[1].AnthroNote.SetAnalysisDefaultWritingSystem("Second value for this test");
                });

            BsonDocument[] customFieldValues = senses.Select(sense => GetCustomFieldValues(cache, sense, "senses")).ToArray();
            IDictionary<int, object>[] fieldValues = senses.Select(sense => GetFieldValues(cache, sense)).ToArray();

            // We no longer populate the semantic domain optionlist in Fdo->Mongo, so we need to populate it here
            var data = new SampleData();
            _conn.UpdateMockOptionList(data.bsonSemDomData);

            // Exercise
            sutFdoToMongo.Run(lfProject);
            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("undo", "redo", cache.ActionHandlerAccessor, () =>
                {
                    senses[0].AnthroNote.SetAnalysisDefaultWritingSystem("This value should be overwritten by MongoToFdo");
                    senses[1].AnthroNote.SetAnalysisDefaultWritingSystem("This value should be overwritten by MongoToFdo");
                });

            // Save original mongo data
            IEnumerable<LfLexEntry> originalData = _conn.GetLfLexEntries();
            LfLexEntry originalEntry = originalData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);
            Assert.That(originalEntry.Senses.Count, Is.EqualTo(2));

            string originalSense0Definition = originalEntry.Senses[0].Definition["en"].Value;
            string originalSense1Definition = originalEntry.Senses[1].Definition["en"].Value;
            string changedSense0Definition = "Changed sense0 definition for this test";
            string changedSense1Definition = "Changed sense1 definition for this test";
            originalEntry.Senses[0].Definition["en"].Value = changedSense0Definition;
            originalEntry.Senses[1].Definition["en"].Value = changedSense1Definition;
            _conn.UpdateMockLfLexEntry(originalEntry);

            // Exercise
            sutMongoToFdo.Run(lfProject);
            string changedDefinitionDuringUpdate = "This value should be overwritten by FdoToMongo";
            originalEntry.Senses[0].Definition["en"].Value = changedDefinitionDuringUpdate;
            originalEntry.Senses[1].Definition["en"].Value = changedDefinitionDuringUpdate;
            _conn.UpdateMockLfLexEntry(originalEntry);

            // Verify
            Assert.That(senses[0].AnthroNote.AnalysisDefaultWritingSystem.Text, Is.Not.EqualTo("This value should be overwritten by MongoToFdo"));
            Assert.That(senses[1].AnthroNote.AnalysisDefaultWritingSystem.Text, Is.Not.EqualTo("This value should be overwritten by MongoToFdo"));
            Assert.That(senses[0].AnthroNote.AnalysisDefaultWritingSystem.Text, Is.EqualTo("New value for this test"));
            Assert.That(senses[1].AnthroNote.AnalysisDefaultWritingSystem.Text, Is.EqualTo("Second value for this test"));

            BsonDocument[] customFieldValuesAfterTest = senses.Select(sense => GetCustomFieldValues(cache, sense, "senses")).ToArray();
            IDictionary<int, object>[] fieldValuesAfterTest = senses.Select(sense => GetFieldValues(cache, sense)).ToArray();
            var differencesByName1 = GetFdoDifferences(cache, fieldValues[0], fieldValuesAfterTest[0]);
            var differencesByName2 = GetFdoDifferences(cache, fieldValues[1], fieldValuesAfterTest[1]);

            PrintDifferences(differencesByName1);
            Assert.That(differencesByName1, Is.Empty);
            Assert.That(customFieldValues[0], Is.EqualTo(customFieldValuesAfterTest[0]));
            PrintDifferences(differencesByName2);
            Assert.That(differencesByName2, Is.Empty);
            Assert.That(customFieldValues[1], Is.EqualTo(customFieldValuesAfterTest[1]));

            // Exercise
            sutFdoToMongo.Run(lfProject);

            // Verify
            IEnumerable<LfLexEntry> receivedData = _conn.GetLfLexEntries();
            Assert.That(receivedData, Is.Not.Null);
            Assert.That(receivedData, Is.Not.Empty);
            Assert.That(receivedData.Count(), Is.EqualTo(OriginalNumOfFdoEntries));

            LfLexEntry lfEntry = receivedData.FirstOrDefault(e => e.Guid.ToString() == TestEntryGuidStr);
            Assert.That(lfEntry, Is.Not.Null);
            Assert.That(originalEntry.Senses.Count, Is.EqualTo(2));
            Assert.That(lfEntry.Senses[0].Definition["en"].Value, Is.Not.EqualTo(changedDefinitionDuringUpdate));
            Assert.That(lfEntry.Senses[1].Definition["en"].Value, Is.Not.EqualTo(changedDefinitionDuringUpdate));
            Assert.That(lfEntry.Senses[0].Definition["en"].Value, Is.EqualTo(changedSense0Definition));
            Assert.That(lfEntry.Senses[1].Definition["en"].Value, Is.EqualTo(changedSense1Definition));

            originalEntry.Senses[0].Definition["en"].Value = originalSense0Definition;
            originalEntry.Senses[1].Definition["en"].Value = originalSense1Definition;
            IDictionary<string, Tuple<string, string>> differencesByName =
                GetMongoDifferences(originalEntry.Senses[0].ToBsonDocument(), lfEntry.Senses[0].ToBsonDocument());
            differencesByName.Remove("definition");
            PrintDifferences(differencesByName);
            Assert.That(differencesByName.Count(), Is.EqualTo(0));
            differencesByName = GetMongoDifferences(originalEntry.Senses[1].ToBsonDocument(), lfEntry.Senses[1].ToBsonDocument());
            differencesByName.Remove("definition");
            PrintDifferences(differencesByName);
            Assert.That(differencesByName.Count(), Is.EqualTo(0));
            differencesByName = GetMongoDifferences(originalEntry.ToBsonDocument(), lfEntry.ToBsonDocument());
            differencesByName.Remove("senses");
            PrintDifferences(differencesByName);
            Assert.That(differencesByName.Count(), Is.EqualTo(0));
        }