Exemple #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);
    }
Exemple #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);
    }
Exemple #3
0
    public void DetachedChildTest()
    {
        var x      = new EventExchange(new BasicLogExchange());
        var parent = new BasicComponent();
        var child  = new BasicComponent();

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

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

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

        parent.IsActive = false;
        x.Raise(new BasicEvent(), this);
        Assert.Equal(1, parent.Handled);
        Assert.Equal(0, child.Handled);

        parent.IsActive = true;
        x.Raise(new BasicEvent(), this);
        Assert.Equal(2, parent.Handled);
        Assert.Equal(0, child.Handled);
    }