public void ReferencesToDeletedWordformsShouldSwitch()
        {
            var wf1  = MakeWordform("wordXX");
            var wf2  = MakeWordform("wordXX");
            var wf3  = MakeWordform("wordXX");
            var text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create();
            //Cache.LangProject.TextsOC.Add(text);
            var stText = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            text.ContentsOA = stText;
            var para = Cache.ServiceLocator.GetInstance <IStTxtParaFactory>().Create();

            stText.ParagraphsOS.Add(para);
            var seg = Cache.ServiceLocator.GetInstance <ISegmentFactory>().Create();

            para.SegmentsOS.Add(seg);
            seg.AnalysesRS.Add(wf1);
            seg.AnalysesRS.Add(wf2);
            seg.AnalysesRS.Add(wf3);
            seg.AnalysesRS.Add(wf2);
            seg.AnalysesRS.Add(wf3);

            var wordset = Cache.ServiceLocator.GetInstance <IWfiWordSetFactory>().Create();

            Cache.LangProject.MorphologicalDataOA.TestSetsOC.Add(wordset);
            wordset.CasesRC.Add(wf2);

            ICmPossibilityList list = Cache.LangProject.KeyTermsList;
            var term = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create();

            list.PossibilitiesOS.Add(term);
            var rendering = Cache.ServiceLocator.GetInstance <IChkRenderingFactory>().Create();

            term.RenderingsOC.Add(rendering);
            rendering.SurfaceFormRA = wf2;
            var chkRef = Cache.ServiceLocator.GetInstance <IChkRefFactory>().Create();

            term.OccurrencesOS.Add(chkRef);
            chkRef.RenderingRA = wf2;

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            // One but only one should survive.
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(seg.AnalysesRS.Count, Is.EqualTo(5));
            Assert.That(seg.AnalysesRS[0], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[1], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[2], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[3], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[4], Is.EqualTo(wf));

            // for several tests to prove anything, the wordform that survives must NOT be the
            // one that was there already.
            Assert.That(wf, Is.Not.EqualTo(wf2));

            Assert.That(wordset.CasesRC, Has.Member(wf));
            Assert.That(rendering.SurfaceFormRA, Is.EqualTo(wf));
            Assert.That(chkRef.RenderingRA, Is.EqualTo(wf));
        }
        public void WordformsWithNothingSpecialMerged()
        {
            var wf1 = MakeWordform("wordXX");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            // One but only one should survive.
            Survivor(wf1, wf2, wf3);
        }
        public void CopesWithNullVernacular()
        {
            var wf1 = MakeWordform("");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            Survivor(wf2, wf3);
            Assert.That(wf1.IsValidObject, Is.True);
        }
        public void ExtraWritingSystemsAreCopied()
        {
            var wf1   = MakeWordform("wordXX");
            var wf2   = MakeWordform("wordXX");
            var wf3   = MakeWordform("wordXX");
            int wsSpn = Cache.WritingSystemFactory.GetWsFromStr("es");

            wf2.Form.set_String(wsSpn, TsStringUtils.MakeString("Spanish", wsSpn));
            WfiWordformServices.FixDuplicates(Cache, m_progress);
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wf, Is.Not.EqualTo(wf2));             // otherwise it doesn't prove much
            Assert.That(wf.Form.get_String(wsSpn).Text, Is.EqualTo("Spanish"));
        }
        public void SpellingInCorrectBeatsUnknown()
        {
            var wf1 = MakeWordform("wordXX");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            wf2.SpellingStatus = (int)SpellingStatusStates.incorrect;
            WfiWordformServices.FixDuplicates(Cache, m_progress);
            // One but only one should survive.
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wf, Is.Not.EqualTo(wf2));             // otherwise it doesn't prove much
            Assert.That(wf.SpellingStatus, Is.EqualTo((int)SpellingStatusStates.incorrect));
        }
        public void ChecksumIsReset()
        {
            var wf1 = MakeWordform("wordXX");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            wf1.Checksum = 5;
            wf2.Checksum = 6;
            wf3.Checksum = 7;
            WfiWordformServices.FixDuplicates(Cache, m_progress);
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wf, Is.Not.EqualTo(wf2));             // otherwise it doesn't prove much
            Assert.That(wf.Checksum, Is.EqualTo(0));
        }
        public void AnalysesPreserved()
        {
            var wf1 = MakeWordform("wordXX");
            var wa1 = MakeAnalysis(wf1);
            var wf2 = MakeWordform("wordXX");
            var wa2 = MakeAnalysis(wf2);
            var wf3 = MakeWordform("wordXX");
            var wa3 = MakeAnalysis(wf3);

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wa1.Owner, Is.EqualTo(wf));
            Assert.That(wa2.Owner, Is.EqualTo(wf));
            Assert.That(wa3.Owner, Is.EqualTo(wf));
        }
        public void InconsistentAlternativesPreventMergeAndAreReported()
        {
            var wf1   = MakeWordform("wordXX");
            var wf2   = MakeWordform("wordXX");
            var wf3   = MakeWordform("wordZZ");
            var wf4   = MakeWordform("wordZZ");
            var wf5   = MakeWordform("wordZZ");
            int wsSpn = Cache.WritingSystemFactory.GetWsFromStr("es");

            wf1.Form.set_String(wsSpn, TsStringUtils.MakeString("Spanish", wsSpn));
            wf2.Form.set_String(wsSpn, TsStringUtils.MakeString("SpanishOther", wsSpn));
            wf3.Form.set_String(wsSpn, TsStringUtils.MakeString("Spanish", wsSpn));
            wf4.Form.set_String(wsSpn, TsStringUtils.MakeString("SpanishOther", wsSpn));
            wf5.Form.set_String(wsSpn, TsStringUtils.MakeString("SpanishYetAnother", wsSpn));
            var failureList = WfiWordformServices.FixDuplicates(Cache, m_progress);

            // None should be deleted.
            Assert.That(wf1.IsValidObject && wf2.IsValidObject && wf3.IsValidObject && wf4.IsValidObject && wf5.IsValidObject);
            Assert.That(failureList, Is.EqualTo("wordXX wordZZ"));
        }