Ejemplo n.º 1
0
        public void CreateContainingObjectValue()
        {
            var dataObject = new CloneableClassWithThreeProperties {Name = "b"};
            var data = new DataItem(dataObject, "a");

            Assert.AreEqual(dataObject, data.Value);
            Assert.AreEqual("a", data.Name);
            Assert.AreEqual(typeof(CloneableClassWithThreeProperties), data.ValueType);
            Assert.AreEqual(DataItem.DefaultRole, data.Role);
            Assert.AreEqual(null, data.Owner);
            Assert.AreEqual(0, data.Id);

            Assert.AreEqual(0, data.LinkedBy.Count);
            Assert.AreEqual(null, data.LinkedTo);
        }
Ejemplo n.º 2
0
        public void LinkAndUnlinkTwoDataItems()
        {
            var dataObject1 = new CloneableClassWithThreeProperties();
            var dataObject2 = new CloneableClassWithThreeProperties();

            var dataItem1 = new DataItem(dataObject1, "a1");
            var dataItem2 = new DataItem(dataObject2, "a2");

            dataItem2.LinkTo(dataItem1);
            

            Assert.IsTrue(dataItem2.IsLinked);
            Assert.AreSame(dataItem1, dataItem2.LinkedTo);
            Assert.AreSame(dataItem2, dataItem1.LinkedBy[0]);

            dataItem2.Unlink();

            Assert.AreEqual(null, dataItem2.LinkedTo);
            Assert.AreEqual(0, dataItem1.LinkedBy.Count);
        }
Ejemplo n.º 3
0
        public void PropertyChangedWorkOnLinkedItems()
        {
            var propertyChangedClass = new CloneableClassWithThreeProperties();
            var sourceDataItem = new DataItem(propertyChangedClass);
            var linkedDataItem = new DataItem(new CloneableClassWithThreeProperties());

            linkedDataItem.LinkTo(sourceDataItem);

            int callCount = 0;
            ((INotifyPropertyChanged) linkedDataItem).PropertyChanged += (s, e) =>
                                                                             {
                                                                                 callCount++;
                                                                                 Assert.AreEqual(propertyChangedClass, s);
                                                                                 Assert.AreEqual("StringProperty", e.PropertyName);
                                                                             };

            propertyChangedClass.StringProperty = "newName";
            Assert.AreEqual(1,callCount);
               
        }
Ejemplo n.º 4
0
        public void NameShouldChangeWhenLinkedNamedValueNameChanges()
        {
            var dataObject1 = new CloneableClassWithThreeProperties();
            var dataObject2 = new CloneableClassWithThreeProperties();

            var dataItem1 = new DataItem(dataObject1, "name1");
            var dataItem2 = new DataItem(dataObject2, "name2");

            dataItem2.LinkTo(dataItem1);

            Assert.AreEqual("name1", dataItem1.Name);
            Assert.AreEqual("name2", dataItem2.Name);
            Assert.AreEqual("name1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("name1", ((INameable)dataItem2.Value).Name);

            dataObject2.Name = "newName2";
            Assert.AreEqual("name1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("name1", ((INameable)dataItem2.Value).Name);

            dataObject1.Name = "newName1";
            Assert.AreEqual("newName1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("newName1", ((INameable)dataItem2.Value).Name);

            dataItem2.Unlink();

            // unlinking results in a new object of the original type as Value in the 
            // item with an uninitialized name. 
            // The original dataObject2 is now an orphan.
            Assert.AreEqual("newName1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual(null, ((INameable)dataItem2.Value).Name);

            ((INameable)dataItem2.Value).Name = "newerName2";
            Assert.AreEqual("newerName2", dataItem2.Name);

            dataItem2.Name = "weereensietsanders";
            Assert.AreEqual("weereensietsanders", ((INameable)dataItem2.Value).Name);
        }
Ejemplo n.º 5
0
        public void NameShouldBeKeptWhenCreatingNameableDataItem()
        {
            var dataObject = new CloneableClassWithThreeProperties { Name = "OldName" };
            var dataItem = new DataItem(dataObject);

            Assert.AreEqual("OldName", dataItem.Name);
        }
Ejemplo n.º 6
0
 public void NameValueNameShouldChangeWhenDataItemNameChanges()
 {
     IDataItem dataItem = new DataItem { Name = "Hoi" };
     //assign a nameble value.
     CloneableClassWithThreeProperties cloneableClassWithThreeProperties = new CloneableClassWithThreeProperties { Name = "Dag" };
     dataItem.Value = cloneableClassWithThreeProperties;
     dataItem.Name = "huh";
     //cloneableClassWithThreeProperties.Name = "huh";
     Assert.AreEqual("huh", cloneableClassWithThreeProperties.Name);
 }
Ejemplo n.º 7
0
 public void NameShouldChangeWhenSettingValueWithANamedValue()
 {
     IDataItem dataItem = new DataItem {Name = "Hoi"};
     //assign a nameble value.
     CloneableClassWithThreeProperties cloneableClassWithThreeProperties = new CloneableClassWithThreeProperties { Name = "Dag" };
     Assert.IsNotNull(cloneableClassWithThreeProperties as INameable);
     dataItem.Value = cloneableClassWithThreeProperties;
     Assert.AreEqual("Dag", dataItem.Name);
 }
Ejemplo n.º 8
0
        public void CloneShouldNotCausePropertyChangeOnSourceValue()
        {
            //set a nameable property changing class in the dataItem
            var propertyChangingClass = new CloneableClassWithThreeProperties();
            var dataItem = new DataItem(propertyChangingClass);

            propertyChangingClass.PropertyChanged += delegate
            {
                Assert.Fail("Clone should not cause a change in the source!");
            };

            //action clone the dataitem.
            dataItem.DeepClone();
        }