Example #1
0
        public void RemoveAllTest()
        {
            var x      = new EventExchange(new BasicLogExchange());
            var parent = new BasicComponent();
            var child1 = new BasicComponent();
            var child2 = new BasicComponent();

            parent.AddHandler <BasicEvent>(_ => { });
            child1.AddHandler <BasicEvent>(_ => { });
            child2.AddHandler <BasicEvent>(_ => { });

            parent.AddChild(child1);
            x.Attach(parent);
            parent.AddChild(child2);

            x.Raise(new BasicEvent(), this);
            Assert.Equal(1, parent.Handled);
            Assert.Equal(1, child1.Handled);
            Assert.Equal(1, child2.Handled);

            parent.RemoveAll();

            x.Raise(new BasicEvent(), this);
            Assert.Equal(2, parent.Handled);
            Assert.Equal(1, child1.Handled);
            Assert.Equal(1, child2.Handled);

            var nonChild = new BasicComponent();

            parent.RemoveChild(nonChild);
        }
Example #2
0
        public void ChildTest()
        {
            var x      = new EventExchange(new BasicLogExchange());
            var parent = new BasicComponent();
            var child1 = new BasicComponent();
            var child2 = new BasicComponent();

            parent.AddHandler <BasicEvent>(_ => { });
            child1.AddHandler <BasicEvent>(_ => { });
            child2.AddHandler <BasicEvent>(_ => { });

            parent.AddChild(child1);
            x.Attach(parent);

            x.Raise(new BasicEvent(), this);
            Assert.Equal(1, parent.Handled);
            Assert.Equal(1, child1.Handled);
            Assert.Equal(0, child2.Handled);

            parent.RemoveChild(child1);
            parent.AddChild(child2);
            x.Raise(new BasicEvent(), this);

            Assert.Equal(2, parent.Handled);
            Assert.Equal(1, child1.Handled);
            Assert.Equal(1, child2.Handled);

            parent.RemoveAll();
            x.Raise(new BasicEvent(), this);
            Assert.Equal(3, parent.Handled);
            Assert.Equal(1, child1.Handled);
            Assert.Equal(1, child2.Handled);

            parent.AddChild(child1);
            parent.AddChild(child2);
            child2.IsActive = false;
            x.Raise(new BasicEvent(), this);
            Assert.Equal(4, parent.Handled);
            Assert.Equal(2, child1.Handled);
            Assert.Equal(1, child2.Handled);

            parent.IsActive = false;
            x.Raise(new BasicEvent(), this);
            Assert.Equal(4, parent.Handled);
            Assert.Equal(2, child1.Handled);
            Assert.Equal(1, child2.Handled);

            parent.IsActive = true;
            x.Raise(new BasicEvent(), this);
            Assert.Equal(5, parent.Handled);
            Assert.Equal(3, child1.Handled);
            Assert.Equal(1, child2.Handled);

            parent.IsActive = true;
            child2.IsActive = true;
            x.Raise(new BasicEvent(), this);
            Assert.Equal(6, parent.Handled);
            Assert.Equal(4, child1.Handled);
            Assert.Equal(2, child2.Handled);
        }