public void ReversalEntries()
        {
            // Verify that if we make three reversal index entries that point at the same sense,
            // that the sense shows them in alphabetical order: boy, child, girl.
            var childEntry = (LexEntry)MakeEntry("child", "niño");
            var childSense = childEntry.SensesOS.First();

            var lexDb = Cache.ServiceLocator.GetInstance <ILexDbRepository>().Singleton;
            var ri    = Cache.ServiceLocator.GetInstance <IReversalIndexFactory>().Create();

            lexDb.ReversalIndexesOC.Add(ri);
            var child = MakeReversalIndexReference(childSense, "el pequeño", ri);
            var boy   = MakeReversalIndexReference(childSense, "niño", ri);
            var girl  = MakeReversalIndexReference(childSense, "niña", ri);

            Assert.That(childSense.ReferringReversalIndexEntries.First(), Is.EqualTo(child));
            Assert.That(childSense.ReferringReversalIndexEntries.Skip(1).First(), Is.EqualTo(girl));
            Assert.That(childSense.ReferringReversalIndexEntries.Last(), Is.EqualTo(boy));

            // we now manually reorder the senses
            var flid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "ReferringReversalIndexEntries", false);

            VirtualOrderingServices.SetVO(childSense, flid, new ICmObject[] { boy, girl, child });

            Assert.That(childSense.ReferringReversalIndexEntries.First(), Is.EqualTo(boy));
            Assert.That(childSense.ReferringReversalIndexEntries.Skip(1).First(), Is.EqualTo(girl));
            Assert.That(childSense.ReferringReversalIndexEntries.Last(), Is.EqualTo(child));
        }
        public void GetOrderedValue_extraVoElements_sameSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            AppendTestItemToList("Third");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();
            var myvo       = CreateTestVO(initialSeq);

            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            Assert.AreEqual(3, myvo.ItemsRS.Count, "Wrong number of items in VO.");
            // Delete an element from the 'testing' sequence.
            var newList = m_testList.PossibilitiesOS.ToList();

            newList.RemoveAt(0);
            var newSeq = newList.Cast <ICmObject>();

            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            Assert.AreEqual(2, resultSeq.Count(), "Wrong number of items in result.");
            Assert.AreEqual(newSeq, resultSeq, "Hvo lists differ.");
        }
        public void VisibleComplexFormBackRefs()
        {
            // Verify that if we make lex entries blackboard and blackbird, blackboard correctly comes first.
            var black        = (LexEntry)MakeEntry("black", "nonreflecting");
            var blackbird    = (LexEntry)MakeEntry("blackbird", "dark avian");
            var blackboard   = (LexEntry)MakeEntry("blackboard", "something to write on");
            var lerBlackbird = MakeComplexEntryRef(blackbird);

            lerBlackbird.ComponentLexemesRS.Add(black);
            lerBlackbird.ShowComplexFormsInRS.Add(black);
            Assert.That(black.VisibleComplexFormBackRefs.First(), Is.EqualTo(lerBlackbird));

            var lerBlackboard = MakeComplexEntryRef(blackboard);

            lerBlackboard.ComponentLexemesRS.Add(black);
            lerBlackboard.ShowComplexFormsInRS.Add(black);
            Assert.That(black.VisibleComplexFormBackRefs.First(), Is.EqualTo(lerBlackbird), "although added later, blackbird is sorted first");
            Assert.That(black.VisibleComplexFormBackRefs.Skip(1).First(), Is.EqualTo(lerBlackboard));

            var flid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "VisibleComplexFormBackRefs", false);

            VirtualOrderingServices.SetVO(black, flid, new ICmObject[] { lerBlackboard, lerBlackbird });
            Assert.That(black.VisibleComplexFormBackRefs.First(), Is.EqualTo(lerBlackboard), "although added later, blackbird is sorted first");
            Assert.That(black.VisibleComplexFormBackRefs.Skip(1).First(), Is.EqualTo(lerBlackbird));
        }
        public void GetOrderedValue_extraNativeAndExtraVoElements()
        {
            // Setup
            AppendTestItemToList("Second");
            AppendTestItemToList("Third");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(initialSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            // Make a sequence in a different order
            AppendTestItemToList("Fourth");
            var newList = m_testList.PossibilitiesOS.Reverse().ToList();

            // remove 'First' (which is now at the end)
            newList.RemoveAt(newList.Count - 1);
            var newSeq = newList.Cast <ICmObject>();

            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            // result should be (Second, Third, Fourth) (or reverse of newSeq)
            var actualList = newSeq.Reverse().ToList();

            Assert.AreEqual(actualList, resultSeq, "Hvo lists differ.");
        }
        public void GetOrderedValue_extraVoElements_diffSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            AppendTestItemToList("Third");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(initialSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            // Make a sequence in a different order
            var newList = m_testList.PossibilitiesOS.Reverse().ToList();

            newList.RemoveAt(0);
            var newSeq = newList.Cast <ICmObject>();


            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            var resultList = new List <ICmObject>(resultSeq);            // makes it easier to verify results

            Assert.AreEqual(2, resultList.Count);
            Assert.AreEqual("First", ((ICmPossibility)resultList[0]).Name.AnalysisDefaultWritingSystem.Text,
                            "Wrong element at beginning of result sequence.");
            Assert.AreEqual("Second", ((ICmPossibility)resultList[1]).Name.AnalysisDefaultWritingSystem.Text,
                            "Wrong element at end of result sequence.");
        }
        public void SetExistingVO_diffSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            AppendTestItemToList("Third");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(initialSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            // Make a sequence in a different order
            var newSeq = m_testList.PossibilitiesOS.Reverse().Cast <ICmObject>();

            // SUT
            VirtualOrderingServices.SetVO(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            var myvo = m_voRepo.AllInstances().First();

            Assert.AreEqual(m_testList.Hvo, myvo.SourceRA.Hvo, "Got wrong Source object!");
            Assert.AreEqual(possName, myvo.Field, "VO is on the wrong field!");
            var voList = myvo.ItemsRS;

            Assert.AreEqual(newSeq, voList, "Hvo lists differ.");
        }
예제 #7
0
        public void ReferringSenses()
        {
            // Verify that if we make three lex entries whose senses all refer to niño,
            // that the reversal index shows them in alphabetical order: boy, child, girl.
            var girl       = (LexEntry)MakeEntry("girl", "niño");
            var senseGirl  = girl.SensesOS.First();
            var boy        = (LexEntry)MakeEntry("boy", "niño");
            var senseBoy   = boy.SensesOS.First();
            var child      = (LexEntry)MakeEntry("child", "niño");
            var senseChild = child.SensesOS.First();

            var lexDb = Cache.ServiceLocator.GetInstance <ILexDbRepository>().Singleton;
            var ri    = Cache.ServiceLocator.GetInstance <IReversalIndexFactory>().Create();

            lexDb.ReversalIndexesOC.Add(ri);
            var rie = MakeReversalIndexReference(senseGirl, "niño", ri);

            senseBoy.ReversalEntriesRC.Add(rie);
            senseChild.ReversalEntriesRC.Add(rie);

            Assert.That(rie.ReferringSenses.First(), Is.EqualTo(senseBoy));
            Assert.That(rie.ReferringSenses.Skip(1).First(), Is.EqualTo(senseChild));
            Assert.That(rie.ReferringSenses.Last(), Is.EqualTo(senseGirl));

            // we now manually reorder the senses
            var flid = Cache.MetaDataCacheAccessor.GetFieldId2(ReversalIndexEntryTags.kClassId, "ReferringSenses", false);

            VirtualOrderingServices.SetVO(rie, flid, new ICmObject[] { senseGirl, senseChild, senseBoy });
            Assert.That(rie.ReferringSenses.First(), Is.EqualTo(senseGirl));
            Assert.That(rie.ReferringSenses.Skip(1).First(), Is.EqualTo(senseChild));
            Assert.That(rie.ReferringSenses.Last(), Is.EqualTo(senseBoy));
        }
        private IVirtualOrdering CreateTestVO(IEnumerable <ICmObject> desiredSeq)
        {
            VirtualOrderingServices.SetVO(m_testList, possibilitiesFlid, desiredSeq);
            var result = m_voRepo.AllInstances().Where(vo => vo.SourceRA == m_testList &&
                                                       vo.Field == possName);

            return(result.FirstOrDefault());
        }
        public void GetOrderedValue_nonexistentVO()
        {
            // Setup
            AppendTestItemToList("Second");
            // Make sure test setup worked
            Assert.AreEqual(0, m_voRepo.Count, "There shouldn't be an existing VO object.");
            // Make a sequence in a different order
            var newSeq = m_testList.PossibilitiesOS.Reverse().Cast <ICmObject>();

            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(0, m_voRepo.Count, "There ought to still not be a VO object.");
            Assert.AreEqual(newSeq, resultSeq, "Hvo lists differ.");
        }
        public void SetVO_nullSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            // For this test, just keep the same order.
            var desiredSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(desiredSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");

            // SUT
            VirtualOrderingServices.SetVO(m_testList, possibilitiesFlid, null);

            // Verify
            Assert.AreEqual(0, m_voRepo.Count, "Test should have deleted the only VO object.");
        }
        public void VirtualPropTest()
        {
            // Setup
            CreateFakeGenreList();             // creates fake list of 4 genres on LangProj
            var testText   = CreateTestText(); // creates IText on LangProj with its IStText.
            var testStText = testText.ContentsOA;
            // Get LP Fake Genre list
            var entireGenreList = Cache.LangProject.GenreListOA.PossibilitiesOS.ToList();

            testText.GenresRC.Add(entireGenreList[1]);             // Second
            testText.GenresRC.Add(entireGenreList[2]);             // Third
            var initialSeq = testText.GenresRC.ToList();

            // Verify that setup affects our chosen virtual property
            Assert.AreEqual(2, testStText.GenreCategories.Count,
                            "Wrong number of items on virtual property.");
            var mdc      = Cache.MetaDataCacheAccessor;
            int virtFlid = mdc.GetFieldId2(testStText.ClassID, "GenreCategories", true);

            // SUT1
            VirtualOrderingServices.SetVO(testStText, virtFlid, initialSeq.Cast <ICmObject>());
            // Make sure SUT1 worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");

            // Setup for SUT2
            // Make a sequence in a different order and with an extra item, but missing an original.
            var newList = new List <ICmObject>(entireGenreList.Cast <ICmObject>());

            newList.Reverse();             // now has (Fourth, Third, Second, First)
            // remove 'Second' (which is now at index=2)
            newList.RemoveAt(2);           // now has (Fourth, Third, First)

            // SUT2
            var resultSeq = VirtualOrderingServices.GetOrderedValue(testStText, virtFlid, newList);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            // result should be (Third, Fourth, First)
            var actualList = new List <ICmPossibility> {
                entireGenreList[2], entireGenreList[3], entireGenreList[0]
            };
            var actualAsObj = actualList.Cast <ICmObject>();

            Assert.AreEqual(actualAsObj, resultSeq, "Hvo lists differ.");
        }
        public void GetOrderedValue_extraNativeElements_diffSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(initialSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            // Make a sequence in a different order with an extra element
            AppendTestItemToList("Third");
            var newSeq = m_testList.PossibilitiesOS.Reverse().Cast <ICmObject>().ToList();

            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            newSeq.Reverse();             // the resulting sequence should be the reverse of what was fed in.
            Assert.AreEqual(newSeq, resultSeq, "Hvo lists differ.");
        }
        public void GetOrderedValue_completeOverlap_diffSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            AppendTestItemToList("Third");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(initialSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            // Make a sequence in a different order
            var newSeq = m_testList.PossibilitiesOS.Reverse().Cast <ICmObject>();

            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            Assert.AreEqual(3, resultSeq.Count(), "Wrong number of items in result.");
            Assert.AreEqual(initialSeq, resultSeq, "Hvo lists differ.");
        }
        public void GetOrderedValue_extraNativeElements_sameSequence()
        {
            // Setup
            AppendTestItemToList("Second");
            var initialSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            CreateTestVO(initialSeq);
            // Make sure test setup worked
            Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object.");
            // Add to the 'testing' sequence
            AppendTestItemToList("Third");
            var newSeq = m_testList.PossibilitiesOS.Cast <ICmObject>();

            // SUT
            var resultSeq = VirtualOrderingServices.GetOrderedValue(m_testList, possibilitiesFlid, newSeq);

            // Verify
            Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object.");
            Assert.AreEqual(3, resultSeq.Count(), "Wrong number of items in result.");
            Assert.AreEqual(newSeq, resultSeq, "Hvo lists differ.");
            Assert.AreEqual("Third", ((ICmPossibility)resultSeq.Last()).Name.AnalysisDefaultWritingSystem.Text,
                            "Wrong element at end of result sequence.");
        }