Пример #1
0
        public void ExtendedObservableCollection_RemoveNullHandlerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();

                verify.ArgumentNullException("eventHandler", () => result.RemoveHandler((IListener <NotifyCollectionChangedEventArgs>)null));
                verify.ArgumentNullException("eventHandler", () => result.RemoveHandler((IListener <PropertyChangedEventArgs>)null));
                verify.ArgumentNullException("eventHandler", () => result.RemoveHandler((IListener <RelayedEventArgs <PropertyChangedEventArgs> >)null));
            }
        }
Пример #2
0
        public void ExtendedObservableCollection_ItemPropertyChangedListenerTest1()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var itemPropertyChangedEventQueue = new Queue <Tuple <object, RelayedEventArgs <PropertyChangedEventArgs> > >();
                var itemPropertyChangedListener   = new Listener <RelayedEventArgs <PropertyChangedEventArgs> >((s, e) => itemPropertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));

                var mutator = new Foo();
                result.Add(mutator);

                result.AddHandler(itemPropertyChangedListener);
                mutator.FooBar = "AAA";

                verify.AreEqual(1, itemPropertyChangedEventQueue.Count, "event didn't fire");
                var event1 = itemPropertyChangedEventQueue.Dequeue();
                verify.AreSame(result, event1.Item1, "event has the wrong item");
                verify.AreEqual <object>(mutator, event1.Item2.OriginalSender, "event has the wrong original sender");
                verify.AreEqual("FooBar", event1.Item2.EventArgs.PropertyName, "event as the wrong parameter name");

                result.RemoveHandler(itemPropertyChangedListener);

                mutator.FooBar = "BBB";

                verify.AreEqual(0, itemPropertyChangedEventQueue.Count, "event handler wasn't removed");
            }
        }
Пример #3
0
        public void ExtendedObservableCollection_RemoveHandlerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var collectionChangedEventQueue = new Queue <Tuple <object, NotifyCollectionChangedEventArgs> >();
                var collectionChangedListener   = new Listener <NotifyCollectionChangedEventArgs>((s, e) => collectionChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.RemoveHandler(collectionChangedListener);

                var propertyChangedEventQueue = new Queue <Tuple <object, PropertyChangedEventArgs> >();
                var propertyChangedListener   = new Listener <PropertyChangedEventArgs>((s, e) => propertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.RemoveHandler(propertyChangedListener);

                var itemPropertyChangedEventQueue = new Queue <Tuple <object, RelayedEventArgs <PropertyChangedEventArgs> > >();
                var itemPropertyChangedListener   = new Listener <RelayedEventArgs <PropertyChangedEventArgs> >((s, e) => itemPropertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.RemoveHandler(itemPropertyChangedListener);
            }
        }
Пример #4
0
        public void ExtendedObservableCollection_CollectionChangedListenerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var collectionChangedEventQueue = new Queue <Tuple <object, NotifyCollectionChangedEventArgs> >();
                var collectionChangedListener   = new Listener <NotifyCollectionChangedEventArgs>((s, e) => collectionChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(collectionChangedListener);

                result.Add(new Foo());
                verify.AreEqual(1, collectionChangedEventQueue.Count, "event didn't fire");
                var event1 = collectionChangedEventQueue.Dequeue();
                verify.AreSame(result, event1.Item1, "event has the wrong item");
                verify.AreEqual(NotifyCollectionChangedAction.Add, event1.Item2.Action, "event as the wrong action");

                result.RemoveHandler(collectionChangedListener);
                result.Add(new Foo());
                verify.AreEqual(0, collectionChangedEventQueue.Count, "event handler wasn't removed");
            }
        }
Пример #5
0
        public void ExtendedObservableCollection_PropertyChangedListenerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var propertyChangedEventQueue = new Queue <Tuple <object, PropertyChangedEventArgs> >();
                var propertyChangedListener   = new Listener <PropertyChangedEventArgs>((s, e) => propertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(propertyChangedListener);

                result.Boom += 1;
                verify.AreEqual(1, propertyChangedEventQueue.Count, "event didn't fire");
                var event1 = propertyChangedEventQueue.Dequeue();
                verify.AreSame(result, event1.Item1, "event has the wrong item");
                verify.AreEqual("Boom", event1.Item2.PropertyName, "event as the wrong parameter name");

                result.RemoveHandler(propertyChangedListener);
                result.Boom += 1;
                verify.AreEqual(0, propertyChangedEventQueue.Count, "event handler wasn't removed");
            }
        }
        public void ExtendedObservableCollection_CollectionChangedListenerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var collectionChangedEventQueue = new Queue<Tuple<object, NotifyCollectionChangedEventArgs>>();
                var collectionChangedListener = new Listener<NotifyCollectionChangedEventArgs>((s, e) => collectionChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(collectionChangedListener);

                result.Add(new Foo());
                verify.AreEqual(1, collectionChangedEventQueue.Count, "event didn't fire");
                var event1 = collectionChangedEventQueue.Dequeue();
                verify.AreSame(result, event1.Item1, "event has the wrong item");
                verify.AreEqual(NotifyCollectionChangedAction.Add, event1.Item2.Action, "event as the wrong action");

                result.RemoveHandler(collectionChangedListener);
                result.Add(new Foo());
                verify.AreEqual(0, collectionChangedEventQueue.Count, "event handler wasn't removed");
            }
        }
        public void ExtendedObservableDictionary_RemoveHandlerTest2()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var collectionChangedEventQueue = new Queue<Tuple<object, NotifyCollectionChangedEventArgs>>();
                var collectionChangedListener = new Listener<NotifyCollectionChangedEventArgs>((s, e) => collectionChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(collectionChangedListener);
                result.RemoveHandler(collectionChangedListener);
                result.RemoveHandler(collectionChangedListener);

                var propertyChangedEventQueue = new Queue<Tuple<object, PropertyChangedEventArgs>>();
                var propertyChangedListener = new Listener<PropertyChangedEventArgs>((s, e) => propertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(propertyChangedListener);
                result.RemoveHandler(propertyChangedListener);
                result.RemoveHandler(propertyChangedListener);

                var itemPropertyChangedEventQueue = new Queue<Tuple<object, RelayedEventArgs<PropertyChangedEventArgs>>>();
                var itemPropertyChangedListener = new Listener<RelayedEventArgs<PropertyChangedEventArgs>>((s, e) => itemPropertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(itemPropertyChangedListener);
                result.RemoveHandler(itemPropertyChangedListener);
                result.RemoveHandler(itemPropertyChangedListener);
            }
        }
        public void ExtendedObservableCollection_RemoveNullHandlerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();

                verify.ArgumentNullException("eventHandler", () => result.RemoveHandler((IListener<NotifyCollectionChangedEventArgs>)null));
                verify.ArgumentNullException("eventHandler", () => result.RemoveHandler((IListener<PropertyChangedEventArgs>)null));
                verify.ArgumentNullException("eventHandler", () => result.RemoveHandler((IListener<RelayedEventArgs<PropertyChangedEventArgs>>)null));
            }
        }
        public void ExtendedObservableCollection_PropertyChangedListenerTest()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var propertyChangedEventQueue = new Queue<Tuple<object, PropertyChangedEventArgs>>();
                var propertyChangedListener = new Listener<PropertyChangedEventArgs>((s, e) => propertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));
                result.AddHandler(propertyChangedListener);

                result.Boom += 1;
                verify.AreEqual(1, propertyChangedEventQueue.Count, "event didn't fire");
                var event1 = propertyChangedEventQueue.Dequeue();
                verify.AreSame(result, event1.Item1, "event has the wrong item");
                verify.AreEqual("Boom", event1.Item2.PropertyName, "event as the wrong parameter name");

                result.RemoveHandler(propertyChangedListener);
                result.Boom += 1;
                verify.AreEqual(0, propertyChangedEventQueue.Count, "event handler wasn't removed");
            }
        }
        public void ExtendedObservableCollection_ItemPropertyChangedListenerTest1()
        {
            using (var verify = new Verify())
            {
                var result = new FooCollection();
                var itemPropertyChangedEventQueue = new Queue<Tuple<object, RelayedEventArgs<PropertyChangedEventArgs>>>();
                var itemPropertyChangedListener = new Listener<RelayedEventArgs<PropertyChangedEventArgs>>((s, e) => itemPropertyChangedEventQueue.Enqueue(Tuple.Create(s, e)));

                var mutator = new Foo();
                result.Add(mutator);

                result.AddHandler(itemPropertyChangedListener);
                mutator.FooBar = "AAA";

                verify.AreEqual(1, itemPropertyChangedEventQueue.Count, "event didn't fire");
                var event1 = itemPropertyChangedEventQueue.Dequeue();
                verify.AreSame(result, event1.Item1, "event has the wrong item");
                verify.AreEqual<object>(mutator, event1.Item2.OriginalSender, "event has the wrong original sender");
                verify.AreEqual("FooBar", event1.Item2.EventArgs.PropertyName, "event as the wrong parameter name");

                result.RemoveHandler(itemPropertyChangedListener);

                mutator.FooBar = "BBB";

                verify.AreEqual(0, itemPropertyChangedEventQueue.Count, "event handler wasn't removed");
            }
        }