Esempio n. 1
0
        public void CloneModel()
        {
            var compositeModel = new CompositeModel();
            var containedModel = mocks.StrictMock <IModel>();
            var modelClone     = mocks.StrictMock <IModel>();

            using (mocks.Record())
            {
                Expect.Call(containedModel.Owner = compositeModel);
                Expect.Call(containedModel.DataItems).Return(new EventedList <IDataItem>()).Repeat.Any();
                Expect.Call(containedModel.GetDirectChildren()).Return(new EventedList <object>()).Repeat.Any();
                Expect.Call(containedModel.DeepClone()).Return(modelClone);

                containedModel.StatusChanged += null;
                LastCall.IgnoreArguments();
                //containedModel.StatusChanged -= null;
                //LastCall.IgnoreArguments();
                Expect.Call(modelClone.Owner = null).IgnoreArguments();
                modelClone.StatusChanged    += null;
                LastCall.IgnoreArguments();
                Expect.Call(modelClone.DataItems).Return(new EventedList <IDataItem>()).Repeat.Any();
                Expect.Call(modelClone.GetDirectChildren()).Return(new EventedList <object>()).Repeat.Any();
            }


            CompositeModel clonedModel;

            using (mocks.Playback())
            {
                compositeModel.Models.Add(containedModel);
                clonedModel = (CompositeModel)compositeModel.DeepClone();
            }

            Assert.AreEqual(compositeModel.Models.Count, clonedModel.Models.Count);
        }
Esempio n. 2
0
        public void CloneModel()
        {
            var compositeModel = new CompositeModel();
            var containedModel = mocks.StrictMock <IModel>();
            var modelClone     = mocks.StrictMock <IModel>();

            using (mocks.Record())
            {
                Expect.Call(containedModel.Owner = compositeModel);
                Expect.Call(containedModel.DataItems).Return(new EventedList <IDataItem>()).Repeat.Any();
                Expect.Call(containedModel.GetAllItemsRecursive()).Return(new EventedList <object>()).Repeat.Any();
                Expect.Call(containedModel.DeepClone()).Return(modelClone);

                Expect.Call(modelClone.Owner = null).IgnoreArguments();
                Expect.Call(modelClone.DataItems).Return(new EventedList <IDataItem>()).Repeat.Any();
                Expect.Call(modelClone.GetAllItemsRecursive()).Return(new EventedList <object>()).Repeat.Any();
            }

            compositeModel.Models.Add(containedModel);

            CompositeModel clonedModel;

            using (mocks.Playback())
            {
                clonedModel = (CompositeModel)compositeModel.DeepClone();
            }

            Assert.AreEqual(compositeModel.Models.Count, clonedModel.Models.Count);
        }
Esempio n. 3
0
        public void CloneShouldUpdateLinksWithinModel()
        {
            //Situation
            // CompositeModel
            //   |-SourceModel
            //   |-LinkedModel (->SourceModel)

            //Clone this composite model and expect the c-linkedmodel to be connected to the cloned-sourcemodel.

            var compositeModel = new CompositeModel();

            IModel    sourceModel    = new TestModel("source");
            IDataItem sourceDataItem = new DataItem(new Url(), "sourceItem");

            sourceModel.DataItems.Add(sourceDataItem);

            compositeModel.Models.Add(sourceModel);

            IModel    linkedModel    = new TestModel("linked");
            IDataItem linkedDataItem = new DataItem {
                Name = "linkedItem"
            };

            linkedModel.DataItems.Add(linkedDataItem);

            compositeModel.Models.Add(linkedModel);

            linkedDataItem.LinkTo(sourceDataItem);

            var clonedModel = (CompositeModel)compositeModel.DeepClone();

            IModel clonedSourceModel = clonedModel.Models.Where(m => m.Name == "source").First();
            IModel clonedLinkedModel = clonedModel.Models.Where(m => m.Name == "linked").First();

            IDataItem clonedLinkedItem = clonedLinkedModel.DataItems.Where(d => d.Name == "linkedItem").First();
            IDataItem clonedSourceItem = clonedSourceModel.DataItems.Where(d => d.Name == "sourceItem").First();

            //the cloned sourceitem should not be the the sourcedataitem.
            Assert.AreNotEqual(clonedSourceItem.Value, sourceDataItem.Value);


            Assert.IsTrue(clonedLinkedItem.IsLinked);
            Assert.AreEqual(clonedSourceItem, clonedLinkedItem.LinkedTo);
        }
Esempio n. 4
0
        public void CloneShouldUpdateLinksWithinModel()
        {
            //Situation
            // CompositeModel
            //   |-SourceModel
            //   |-LinkedModel (->SourceModel)

            //Clone this composite model and expect the c-linkedmodel to be connected to the cloned-sourcemodel.

            var compositeModel = new CompositeModel();
            IModel sourceModel = new TestModel("source");
            
            IDataItem sourceDataItem = new DataItem(new Url(), "sourceItem");
            sourceModel.DataItems.Add(sourceDataItem);
            compositeModel.Models.Add(sourceModel);

            IModel linkedModel = new TestModel("linked");
            IDataItem linkedDataItem = new DataItem {Name = "linkedItem"};
            
            linkedModel.DataItems.Add(linkedDataItem);
            compositeModel.Models.Add(linkedModel);

            linkedDataItem.LinkTo(sourceDataItem);

            var clonedModel = (CompositeModel) compositeModel.DeepClone();

            IModel clonedSourceModel = clonedModel.Models.Where(m => m.Name == "source").First();
            IModel clonedLinkedModel = clonedModel.Models.Where(m => m.Name == "linked").First();

            IDataItem clonedLinkedItem = clonedLinkedModel.DataItems.Where(d => d.Name == "linkedItem").First();
            IDataItem clonedSourceItem = clonedSourceModel.DataItems.Where(d => d.Name == "sourceItem").First();

            //the cloned sourceitem should not be the the sourcedataitem.
            Assert.AreNotEqual(clonedSourceItem.Value, sourceDataItem.Value);


            Assert.IsTrue(clonedLinkedItem.IsLinked);
            Assert.AreEqual(clonedSourceItem, clonedLinkedItem.LinkedTo);
        }
Esempio n. 5
0
        public void CloneModel()
        {
            var compositeModel = new CompositeModel();
            var containedModel = mocks.StrictMock<IModel>();
            var modelClone = mocks.StrictMock<IModel>();
            using (mocks.Record())
            {
                Expect.Call(containedModel.Owner = compositeModel);
                Expect.Call(containedModel.DataItems).Return(new EventedList<IDataItem>()).Repeat.Any();
                Expect.Call(containedModel.GetAllItemsRecursive()).Return(new EventedList<object>()).Repeat.Any();
                Expect.Call(containedModel.DeepClone()).Return(modelClone);

                Expect.Call(modelClone.Owner = null).IgnoreArguments();
                Expect.Call(modelClone.DataItems).Return(new EventedList<IDataItem>()).Repeat.Any();
                Expect.Call(modelClone.GetAllItemsRecursive()).Return(new EventedList<object>()).Repeat.Any();
            }

            compositeModel.Models.Add(containedModel);

            CompositeModel clonedModel;
            using (mocks.Playback())
            {
                clonedModel = (CompositeModel) compositeModel.DeepClone();
            }

            Assert.AreEqual(compositeModel.Models.Count, clonedModel.Models.Count);
        }