public void AddingValueToSortedArrayKeepsOldSubscribtion()
        {
            var array = new MultiDimensionalArray<TestNotifyPropertyChangedObject> { IsAutoSorted = true };

            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject {Value = 10};
            array.Add(testNotifyPropertyChangedObject);
            array.Add(new TestNotifyPropertyChangedObject { Value = 5 });//this will cause sorting

            int callCount = 0;
            ((INotifyPropertyChanged) array).PropertyChanged += (s, e) => { callCount++; };
            testNotifyPropertyChangedObject.FireChanged();

            Assert.AreEqual(1,callCount);
        }
Example #2
0
        public void PropertyChangedShouldBeBubbledToArgument()
        {
            var function = new Function();
            function.Arguments.Add(new Variable<TestNotifyPropertyChangedObject>());
            function.Components.Add(new Variable<double>());

            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();
            function[testNotifyPropertyChangedObject] = 1.0d;

            var callCount = 0;
            ((INotifyPropertyChanged) function.Arguments[0]).PropertyChanged += delegate { callCount++; };

            testNotifyPropertyChangedObject.FireChanged();

            Assert.AreEqual(1, callCount);
        }
        public void UnsubscribePropertyChanged()
        {
            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();

            IMultiDimensionalArray<TestNotifyPropertyChangedObject> array =
                new MultiDimensionalArray<TestNotifyPropertyChangedObject>();
            
            //remove the item from the array
            array.Insert(0, testNotifyPropertyChangedObject);
            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 1, testNotifyPropertyChangedObject.FireChanged);

            array.Remove(testNotifyPropertyChangedObject);
            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 0, testNotifyPropertyChangedObject.FireChanged);

            //reinsert & replace
            array.Insert(0,testNotifyPropertyChangedObject);
            array[0] = new TestNotifyPropertyChangedObject {Name = "new"};
            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 0, testNotifyPropertyChangedObject.FireChanged);

            //removeat 
            array.Insert(0, testNotifyPropertyChangedObject);
            array.RemoveAt(0);
            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 0, testNotifyPropertyChangedObject.FireChanged);

        }
        public void BubblePropertyChangedOfInsertObject2()
        {
            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();

            var array = new MultiDimensionalArray<TestNotifyPropertyChangedObject>
            {
                IsAutoSorted = false
            };
            array.Insert(0, testNotifyPropertyChangedObject);

            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 1, testNotifyPropertyChangedObject.FireChanged);
        }
        public void BubblePropertyChangesOfInsertedObjectViaSetValues()
        {
            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();
            var array = new MultiDimensionalArray<TestNotifyPropertyChangedObject> { IsAutoSorted = false };

            array.SetValues(new[] { testNotifyPropertyChangedObject });

            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 1, testNotifyPropertyChangedObject.FireChanged);
        }
        public void UnsubscribePropertyChangesAfterResize()
        {
            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();

            IMultiDimensionalArray<TestNotifyPropertyChangedObject> array = new MultiDimensionalArray<TestNotifyPropertyChangedObject>
            {
                IsAutoSorted = false
            };

            array.Add(testNotifyPropertyChangedObject);
            
            array.Resize(new[] {2, 2});

            Assert.AreEqual(1, testNotifyPropertyChangedObject.GetNumPropertyChangedSubscriptions(), "num property subscriptions");
        }
        public void BubblePropertyChangesOfInsertedObject()
        {
            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();

            IMultiDimensionalArray<TestNotifyPropertyChangedObject> array = new MultiDimensionalArray<TestNotifyPropertyChangedObject>
                                                                                {
                                                                                    IsAutoSorted = false
                                                                                };
            array.Add(new TestNotifyPropertyChangedObject());

            array.InsertAt(0, 0, 1, new[] { testNotifyPropertyChangedObject });

            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 1, testNotifyPropertyChangedObject.FireChanged);
        }