Exemplo n.º 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));
            }
Exemplo n.º 2
0
            public async Task ShouldRaiseCollectionChangedEventForRemoveRange()
            {
                // Arrange
                List <TestObservableObject> objectsToRemove = TestObservableObjectFaker.Create().Generate(10);

                var collection = new ObservableItemCollection <TestObservableObject>();

                var tcs = new TaskCompletionSource <NotifyCollectionChangedEventArgs>();

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

                // Act
                collection.RemoveRange(objectsToRemove);

                // Assert
                NotifyCollectionChangedEventArgs collectionChanged = await tcs.Task;

                collectionChanged.ShouldNotBeNull();
                collectionChanged.OldItems.Count.ShouldBe(objectsToRemove.Count);
                foreach (object item in collectionChanged.OldItems)
                {
                    objectsToRemove.ShouldContain(item);
                }
            }
Exemplo n.º 3
0
            public void ShouldContainItemsIfInitializedAsList()
            {
                // Arrange
                List <TestObservableObject> objects = TestObservableObjectFaker.Create().Generate(10);

                // Act
                var collection = new ObservableItemCollection <TestObservableObject>(objects);

                // Assert
                collection.Count.ShouldBe(objects.Count());
                collection.ShouldBeEquivalentTo(objects);
            }
Exemplo n.º 4
0
            public void ShouldAddSingleItem()
            {
                // Arrange
                TestObservableObject objectToAdd = TestObservableObjectFaker.Create().Generate();

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

                // Assert
                collection.ShouldContain(objectToAdd);
            }
Exemplo n.º 5
0
            public void ShouldRemoveSingleItem()
            {
                // Arrange
                TestObservableObject objectToRemove = TestObservableObjectFaker.Create().Generate();
                var collection = new ObservableItemCollection <TestObservableObject> {
                    objectToRemove
                };

                // Act
                collection.Remove(objectToRemove);

                // Assert
                collection.ShouldNotContain(objectToRemove);
            }
Exemplo n.º 6
0
            public void ShouldAddRangeOfItems()
            {
                // Arrange
                List <TestObservableObject> objectsToAdd = TestObservableObjectFaker.Create().Generate(10);

                var collection = new ObservableItemCollection <TestObservableObject>();

                // Act
                collection.AddRange(objectsToAdd);

                // Assert
                foreach (TestObservableObject item in objectsToAdd)
                {
                    collection.ShouldContain(item);
                }
            }
Exemplo n.º 7
0
            public void ShouldRemoveRangeOfItems()
            {
                // Arrange
                List <TestObservableObject> items = TestObservableObjectFaker.Create().Generate(10);
                var itemsToRemove = items.Take(5).ToList();

                var collection = new ObservableItemCollection <TestObservableObject>(items);

                // Act
                collection.RemoveRange(itemsToRemove);

                // Assert
                foreach (TestObservableObject item in itemsToRemove)
                {
                    collection.ShouldNotContain(item);
                }
            }
Exemplo n.º 8
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();
            }