Ejemplo n.º 1
0
        public void ReconcileCollectionChanges()
        {
            int         entryCount = Cache.LangProject.LexDbOA.Entries.Count();
            var         destroy    = MakeEntry("destroy", "wipe out");
            var         destroyId  = destroy.Id;
            var         remove     = MakeEntry("remove", "get rid of");
            var         removeId   = remove.Id;
            ILexEntry   right      = null;
            ICmObjectId rightId    = null;
            ILexEntry   kick       = null;
            List <ICmObjectSurrogate> newbiesClockwise;
            List <ICmObjectSurrogate> dirtballsClockwise;
            List <ICmObjectId>        gonersClockwise;

            GetEffectsOfChange(() =>
            {
                right = MakeEntry("right", "correct");
                destroy.Delete();
            },
                               () => rightId = right.Id,
                               out newbiesClockwise, out dirtballsClockwise, out gonersClockwise);
            UndoableUnitOfWorkHelper.Do("undo", "redo", m_actionHandler,
                                        () =>
            {
                kick = MakeEntry("kick", "strike with foot");
                remove.Delete();
            });
            var uowService = Cache.ServiceLocator.GetInstance <IUnitOfWorkService>();
            var reconciler = ((UnitOfWorkService)uowService).Reconciler(newbiesClockwise, dirtballsClockwise, gonersClockwise);
            var notifiee   = new Notifiee();

            Cache.DomainDataByFlid.AddNotification(notifiee);
            Assert.That(reconciler.OkToReconcileChanges(), Is.True);
            reconciler.ReconcileForeignChanges();             // In effect the other client added 'right' and deleted 'destroy'.

            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(kick));
            right = (ILexEntry)Cache.ServiceLocator.GetObject(rightId);             // will throw if it doesn't exist.
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right));
            Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(remove));
            Assert.IsFalse(Cache.ServiceLocator.ObjectRepository.IsValidObjectId(destroyId.Guid));
            // One way to be sure 'destroy' really got destroyed.
            Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2));

            // See if we got PropChanged notifications on 'Entries'
            int flidEntries = Cache.MetaDataCache.GetFieldId2(LexDbTags.kClassId, "Entries", false);

            notifiee.CheckChangesWeaker(
                new[] { new ChangeInformationTest(Cache.LangProject.LexDbOA.Hvo, flidEntries, 0, entryCount + 2, entryCount + 2) },
                "missing Entries propcount");

            // adding kick; right should still be there. Remove should come back, Destroy still be gone.
            m_actionHandler.Undo();
            Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(kick));
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right));
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(remove));
            Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2));

            m_actionHandler.Redo();             // restore kick, re-delete Remove.
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(kick));
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right));
            Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(remove));
            Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2));
        }
Ejemplo n.º 2
0
        public void TestLexSenseSideEffects()
        {
            var       senseFactory = Cache.ServiceLocator.GetInstance <ILexSenseFactory>();
            ILexEntry entry = null;
            ILexSense sense, sense2 = null, sense3 = null, sense2_1 = null, sense2_2 = null, sense2_1_1 = null, sense2_2_1 = null;

            UndoableUnitOfWorkHelper.Do("Undo add senses", "Redo add senses", m_actionHandler, () =>
            {
                entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
                sense = senseFactory.Create();
                entry.SensesOS.Add(sense);
                Assert.AreEqual("1", sense.LexSenseOutline.Text);
                sense2 = senseFactory.Create();
                entry.SensesOS.Add(sense2);
                Assert.AreEqual("2", sense2.LexSenseOutline.Text);
                sense3 = senseFactory.Create();
                entry.SensesOS.Add(sense3);
                Assert.AreEqual("3", sense3.LexSenseOutline.Text);

                sense2_1 = senseFactory.Create();
                sense2.SensesOS.Add(sense2_1);
                Assert.AreEqual("2.1", sense2_1.LexSenseOutline.Text);

                sense2_2 = senseFactory.Create();
                sense2.SensesOS.Add(sense2_2);
                Assert.AreEqual("2.2", sense2_2.LexSenseOutline.Text);

                sense2_1_1 = senseFactory.Create();
                sense2_1.SensesOS.Add(sense2_1_1);
                Assert.AreEqual("2.1.1", sense2_1_1.LexSenseOutline.Text);

                sense2_2_1 = senseFactory.Create();
                sense2_2.SensesOS.Add(sense2_2_1);
                Assert.AreEqual("2.2.1", sense2_2_1.LexSenseOutline.Text);
            });

            m_notifiee = new Notifiee();
            var mdc = m_sda.MetaDataCache;
            var lsoFlid = mdc.GetFieldId("LexSense", "LexSenseOutline", false);

            m_sda.AddNotification(m_notifiee);
            ILexSense senseInserted = null;

            UndoableUnitOfWorkHelper.Do("Undo add another sense", "Redo add another sense", m_actionHandler, () =>
            {
                senseInserted = senseFactory.Create();
                entry.SensesOS.Insert(1, senseInserted);
                Assert.AreEqual("2", senseInserted.LexSenseOutline.Text);
            });
            int nosFlid = mdc.GetFieldId("LexEntry", "NumberOfSensesForEntry", false);

            m_notifiee.CheckChangesWeaker(new[]
            {
                new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0),
                new ChangeInformationTest(entry.Hvo, LexEntryTags.kflidSenses, 1, 1, 0),
                new ChangeInformationTest(sense2.Hvo, lsoFlid, 0, "2".Length, "3".Length),
                new ChangeInformationTest(sense3.Hvo, lsoFlid, 0, "3".Length, "4".Length),
                new ChangeInformationTest(sense2_1.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length),
                new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length),
                new ChangeInformationTest(sense2_1_1.Hvo, lsoFlid, 0, "2.1.1".Length, "3.1.1".Length),
                new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "3.2.1".Length),
            }, "insert second sense in entry");
            m_sda.RemoveNotification(m_notifiee);
            Assert.AreEqual("3.1.1", sense2_1_1.LexSenseOutline.Text);

            m_notifiee = new Notifiee();
            m_sda.AddNotification(m_notifiee);
            UndoableUnitOfWorkHelper.Do("Undo remove sense", "Redo remove sense", m_actionHandler, () =>
                                        entry.SensesOS.Remove(senseInserted));
            m_notifiee.CheckChangesWeaker(new[]
            {
                new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0),
                new ChangeInformationTest(entry.Hvo, LexEntryTags.kflidSenses, 1, 0, 1),
                new ChangeInformationTest(sense2.Hvo, lsoFlid, 0, "2".Length, "3".Length),
                new ChangeInformationTest(sense3.Hvo, lsoFlid, 0, "3".Length, "4".Length),
                new ChangeInformationTest(sense2_1.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length),
                new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length),
                new ChangeInformationTest(sense2_1_1.Hvo, lsoFlid, 0, "2.1.1".Length, "3.1.1".Length),
                new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "3.2.1".Length),
            }, "delete second sense in entry");
            m_sda.RemoveNotification(m_notifiee);
            Assert.AreEqual("2.1.1", sense2_1_1.LexSenseOutline.Text);

            m_notifiee = new Notifiee();
            m_sda.AddNotification(m_notifiee);
            UndoableUnitOfWorkHelper.Do("Undo add another sense", "Redo add another sense", m_actionHandler, () =>
            {
                senseInserted = senseFactory.Create();
                sense2.SensesOS.Insert(1, senseInserted);
                Assert.AreEqual("2.2", senseInserted.LexSenseOutline.Text);
            });
            m_notifiee.CheckChangesWeaker(new[]
            {
                new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0),
                new ChangeInformationTest(sense2.Hvo, LexSenseTags.kflidSenses, 1, 1, 0),
                new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.2".Length, "2.3".Length),
                new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "2.3.1".Length),
            }, "insert subsense in sense");
            m_sda.RemoveNotification(m_notifiee);
            Assert.AreEqual("2.3.1", sense2_2_1.LexSenseOutline.Text);

            m_notifiee = new Notifiee();
            m_sda.AddNotification(m_notifiee);
            UndoableUnitOfWorkHelper.Do("Undo get rid of sense", "Redo get rid of sense", m_actionHandler, () =>
                                        sense2.SensesOS.Remove(senseInserted));
            m_notifiee.CheckChangesWeaker(new[]
            {
                new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0),
                new ChangeInformationTest(sense2.Hvo, LexSenseTags.kflidSenses, 1, 0, 1),
                new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.2".Length, "2.3".Length),
                new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "2.3.1".Length),
            }, "remove subsense from sense");
            m_sda.RemoveNotification(m_notifiee);
            Assert.AreEqual("2.2.1", sense2_2_1.LexSenseOutline.Text);
        }