Beispiel #1
0
        public void UpdateWritingSystemTag_MarksObjectsAsDirty()
        {
            var entry0 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            CoreWritingSystemDefinition newWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out newWs);
            // A string property NOT using the WS we will change.
            entry0.ImportResidue = TsStringUtils.MakeString("hello", Cache.DefaultAnalWs);
            // A multilingual one using the WS.
            entry0.LiteralMeaning.set_String(Cache.DefaultAnalWs, TsStringUtils.MakeString("whatever", Cache.DefaultAnalWs));

            var entry1 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense1 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry1.SensesOS.Add(sense1);
            // Sense1 should be dirty: it has a gloss in the changing WS.
            sense1.Gloss.set_String(newWs.Handle, TsStringUtils.MakeString("whatever", newWs.Handle));

            // Entry2 should be dirty: it has a string property with a run in the changing WS.
            var entry2 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var bldr   = TsStringUtils.MakeString("abc ", Cache.DefaultAnalWs).GetBldr();

            bldr.ReplaceTsString(bldr.Length, bldr.Length, TsStringUtils.MakeString("def", newWs.Handle));
            var stringWithNewWs = bldr.GetString();

            entry2.ImportResidue = stringWithNewWs;

            // Sense3 should be dirty: it has a multistring string property with a run in the changing WS.
            var entry3 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense3 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry3.SensesOS.Add(sense3);
            sense3.Definition.set_String(Cache.DefaultAnalWs, stringWithNewWs);

            Cache.LangProject.AnalysisWss = "en en-SU";

            m_actionHandler.EndUndoTask();
            var undoManager = Cache.ServiceLocator.GetInstance <IUndoStackManager>();

            undoManager.Save();             // makes everything non-dirty.

            var newbies   = new HashSet <ICmObjectId>();
            var dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            var goners    = new HashSet <ICmObjectId>();

            Assert.That(dirtballs.Count, Is.EqualTo(0));             // After save nothing should be dirty.

            var uowServices = Cache.ServiceLocator.GetInstance <IUnitOfWorkService>();

            uowServices.GatherChanges(newbies, dirtballs, goners);

            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.UpdateWritingSystemId(Cache, newWs, "en-SU"));

            newbies   = new HashSet <ICmObjectId>();
            dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            goners    = new HashSet <ICmObjectId>();

            uowServices.GatherChanges(newbies, dirtballs, goners);

            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense1));
            Assert.That(!dirtballs.Contains((ICmObjectOrSurrogate)entry0));             // make sure the implementation doesn't just dirty everything.
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)entry2));
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense3));
            Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("en en-NO"), "should have updated WS lists");
        }
        public void UpdateWritingSystemTag_ChangesWsContent()
        {
            var entry0 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            CoreWritingSystemDefinition newWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SU", true, false, out newWs);
            // A string property NOT using the WS we will change.
            entry0.ImportResidue = TsStringUtils.MakeString("hello", Cache.DefaultAnalWs);
            // A multilingual one using the WS.
            entry0.LiteralMeaning.set_String(Cache.DefaultAnalWs, TsStringUtils.MakeString("whatever", Cache.DefaultAnalWs));

            var entry1 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense1 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry1.SensesOS.Add(sense1);
            // Sense1 should be dirty: it has a gloss in the changing WS.
            sense1.Gloss.set_String(newWs.Handle, TsStringUtils.MakeString("whatever", newWs.Handle));

            // Entry2 should be dirty: it has a string property with a run in the changing WS.
            var entry2 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var bldr   = TsStringUtils.MakeString("abc ", Cache.DefaultAnalWs).GetBldr();

            bldr.ReplaceTsString(bldr.Length, bldr.Length, TsStringUtils.MakeString("def", newWs.Handle));
            var stringWithNewWs = bldr.GetString();

            entry2.ImportResidue = stringWithNewWs;

            // Sense3 should be dirty: it has a multistring string property with a run in the changing WS.
            var entry3 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense3 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry3.SensesOS.Add(sense3);
            var styledAndNormalRunInChangingWs = TsStringUtils.MakeString("changing", newWs.Handle);

            styledAndNormalRunInChangingWs.Insert(0, TsStringUtils.MakeString("8", newWs.Handle, "Verse Number"));
            sense3.Definition.set_String(newWs.Handle, styledAndNormalRunInChangingWs);

            Cache.LangProject.AnalysisWss = "en en-SU";
            // Add Free Translation in the changing ws
            var paraBldr = Cache.ServiceLocator.GetInstance <StTxtParaBldr>();
            var stText   = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            Cache.ServiceLocator.GetInstance <ITextFactory>().Create().ContentsOA = stText;            // needed to put a Cache in stText
            var para = paraBldr.CreateParagraph(stText);

            para.Contents = TsStringUtils.MakeString("vernacular", Cache.DefaultVernWs);
            para.SegmentsOS[0].FreeTranslation.set_String(newWs.Handle, "Free Willy!");
            m_actionHandler.EndUndoTask();
            var undoManager = Cache.ServiceLocator.GetInstance <IUndoStackManager>();

            undoManager.Save();             // makes everything non-dirty.

            var newbies   = new HashSet <ICmObjectId>();
            var dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            var goners    = new HashSet <ICmObjectId>();

            var uowServices = Cache.ServiceLocator.GetInstance <IUnitOfWorkService>();

            Assert.That(dirtballs.Count, Is.EqualTo(0));             // After save nothing should be dirty.

            uowServices.GatherChanges(newbies, dirtballs, goners);
            int oldWsHandle = newWs.Handle;
            var tempWs      = new CoreWritingSystemDefinition("en-GB");

            newWs.Copy(tempWs);
            Cache.ServiceLocator.GetInstance <WritingSystemManager>().Set(newWs);

            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.UpdateWritingSystemId(Cache, newWs, oldWsHandle, "en-SU"));

            newbies   = new HashSet <ICmObjectId>();
            dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            goners    = new HashSet <ICmObjectId>();

            uowServices.GatherChanges(newbies, dirtballs, goners);

            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense1));
            Assert.That(!dirtballs.Contains((ICmObjectOrSurrogate)entry0));             // make sure the implementation doesn't just dirty everything.
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)entry2));
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense3));
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)para.SegmentsOS[0]));
            Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("en en-GB"), "should have updated WS lists");
        }