예제 #1
0
            public async Task ShouldRaisePropertyChangedEvent()
            {
                // Arrange
                TestObservableObject obj = TestObservableObjectFaker.Create().Generate();

                var collection = new ObservableItemCollection <TestObservableObject> {
                    obj
                };

                var tcs = new TaskCompletionSource <ObservableItemCollectionPropertyChangedEventArgs>();

                collection.ItemPropertyChanged += (sender, args) =>
                {
                    tcs.SetResult(args);
                };

                // Act
                obj.Name = "Hello, World!";

                // Assert
                ObservableItemCollectionPropertyChangedEventArgs result = await tcs.Task;

                result.ShouldNotBeNull();
                result.Sender.ShouldBe(obj);
                result.EventArgs.ShouldNotBeNull();
                result.EventArgs.PropertyName.ShouldBe(nameof(TestObservableObject.Name));
            }
        public void VerifyPropertyName_ExistentPropertyName_ExecutesWithoutException()
        {
            var obj          = TestObservableObject.CreateWithValue(TestString);
            var propertyName = nameof(obj.TestProperty);

            obj.VerifyPropertyName(propertyName);
        }
        public void Set_PropertyByPropertyExpressionTwice_LastReturnsFalse()
        {
            var obj = TestObservableObject.CreateWithValue(TestString);

            var result = obj.SetTestPropertyByPropertyExpression(TestString);

            Assert.False(result);
        }
        public void Set_RegularProperty_RisesPropertyChanged()
        {
            var obj = TestObservableObject.CreateEmpty();

            Assert_PropertyChanged(obj, nameof(obj.TestProperty), () =>
            {
                obj.TestProperty = TestString;
            });
        }
        public void Set_PropertyByPropertyExpression_RisesPropertyChanged()
        {
            var obj = TestObservableObject.CreateEmpty();

            Assert_PropertyChanged(obj, nameof(obj.TestProperty), () =>
            {
                obj.SetTestPropertyByPropertyExpression(TestString);
            });
        }
        public void Set_RegularPropertySameValueTwice_NotRisesPropertyChangedSecondTime()
        {
            var obj = TestObservableObject.CreateWithValue(TestString);

            Assert.Throws <PropertyChangedException>(() =>
            {
                Assert_PropertyChanged(obj, nameof(obj.TestProperty), () =>
                {
                    obj.TestProperty = TestString;
                });
            });
        }
예제 #7
0
            public void ShouldAddSingleItem()
            {
                // Arrange
                TestObservableObject objectToAdd = TestObservableObjectFaker.Create().Generate();

                // Act
                var collection = new ObservableItemCollection <TestObservableObject> {
                    objectToAdd
                };

                // Assert
                collection.ShouldContain(objectToAdd);
            }
예제 #8
0
            public void ShouldRemoveSingleItem()
            {
                // Arrange
                TestObservableObject objectToRemove = TestObservableObjectFaker.Create().Generate();
                var collection = new ObservableItemCollection <TestObservableObject> {
                    objectToRemove
                };

                // Act
                collection.Remove(objectToRemove);

                // Assert
                collection.ShouldNotContain(objectToRemove);
            }
        public void ObservableItemContentRangeCollection_WhenCreatedWithItems_DoesNotNotifyForRemovedItems()
        {
            var item  = new TestObservableObject();
            var items = new List <TestObservableObject>()
            {
                item, new TestObservableObject(), new TestObservableObject()
            };
            var collection = new ObservableItemContentRangeCollection <TestObservableObject>(items);

            collection.Remove(item);

            CustomAsserts.Assert_NotRaises <NotifyCollectionChangedEventArgs>(
                handler => collection.CollectionChanged += (s, e) => handler.Invoke(s, e),
                handler => { },
                () => item.TestProperty = TestPropertyValue2);
        }
        public void ObservableItemContentRangeCollection_WhenCreatedWithoutItems_NotifiesForAddedItems()
        {
            var item       = new TestObservableObject();
            var collection = new ObservableItemContentRangeCollection <TestObservableObject>();

            collection.Add(item);
            var itemIndex = collection.IndexOf(item);

            var raisedEvent = Assert.Raises <NotifyCollectionChangedEventArgs>(
                handler => collection.CollectionChanged += (s, e) => handler.Invoke(s, e),
                handler => { },
                () => item.TestProperty = TestPropertyValue);

            Assert.NotNull(raisedEvent);
            Assert.Equal(NotifyCollectionChangedAction.Replace, raisedEvent.Arguments.Action);
            Assert.Equal(itemIndex, raisedEvent.Arguments.NewStartingIndex);
            Assert.Equal(itemIndex, raisedEvent.Arguments.OldStartingIndex);
        }
예제 #11
0
        public void RaisePropertyChanged_WithSetAndString_ShouldCallRaisePropertyChangedWithStringOnly()
        {
            var testObject = new TestObservableObject();

            var eventWasRaised = false;
            testObject.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "BoolPropertyWithSetAndString")
                {
                    eventWasRaised = true;
                }
            };

            Assert.IsFalse(testObject.BoolPropertyWithSetAndString);
            testObject.BoolPropertyWithSetAndString = true;
            Assert.IsTrue(testObject.BoolPropertyWithSetAndString);
            Assert.IsTrue(eventWasRaised);
            Assert.IsTrue(testObject.RaisePropertyChangedWithPropertyNameWasCalled);
            Assert.IsFalse(testObject.RaisePropertyChangedWithExpressionWasCalled);
        }
        public void RaisePropertyChanged_WithSetAndString_ShouldCallRaisePropertyChangedWithStringOnly()
        {
            var testObject = new TestObservableObject();

            var eventWasRaised = false;

            testObject.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "BoolPropertyWithSetAndString")
                {
                    eventWasRaised = true;
                }
            };

            Assert.IsFalse(testObject.BoolPropertyWithSetAndString);
            testObject.BoolPropertyWithSetAndString = true;
            Assert.IsTrue(testObject.BoolPropertyWithSetAndString);
            Assert.IsTrue(eventWasRaised);
            Assert.IsTrue(testObject.RaisePropertyChangedWithPropertyNameWasCalled);
            Assert.IsFalse(testObject.RaisePropertyChangedWithExpressionWasCalled);
        }
예제 #13
0
            public async Task ShouldRaiseCollectionChangedEventForAdd()
            {
                // Arrange
                TestObservableObject objectToAdd = TestObservableObjectFaker.Create().Generate();

                var collection = new ObservableItemCollection <TestObservableObject>();

                var tcs = new TaskCompletionSource <NotifyCollectionChangedEventArgs>();

                collection.CollectionChanged += (sender, args) =>
                {
                    tcs.SetResult(args);
                };

                // Act
                collection.Add(objectToAdd);

                // Assert
                NotifyCollectionChangedEventArgs collectionChanged = await tcs.Task;

                collectionChanged.ShouldNotBeNull();
                collectionChanged.NewItems.Contains(objectToAdd).ShouldBeTrue();
            }
예제 #14
0
        public void TestObservableObject_Ctor()
        {
            var actual = new TestObservableObject();

            Assert.NotNull(actual);
        }