Exemplo n.º 1
0
    public void Signal_RemoveListener_Success()
    {
        // Arrange
        var argsArray = new object[1];
        var actual    = 0;

        // Act
        var signal = new Signal();

        signal.AddListener(ActionRuntime);
        signal.AddListener(ActionRuntime);
        signal.AddListenerOnce(ActionRuntimeOne);
        signal.AddListenerOnce(ActionRuntimeOne);
        signal.RemoveListener(ActionRuntime);
        signal.RemoveListener(ActionRuntimeOne);
        signal.Dispatch(argsArray);

        void ActionRuntime(ISignal target, object[] args) => actual++;
        void ActionRuntimeOne(ISignal target, object[] args) => actual++;

        //Assert
        Assert.AreEqual(2, actual);
    }
Exemplo n.º 2
0
    public void Signal_AddListenerOnceAndDispatch_Success()
    {
        // Arrange
        var expectedArgs   = new object[1];
        var expectedSignal = new Signal();
        var actualTarget   = default(ISignal);
        var actualArgs     = default(object[]);

        // Act
        expectedSignal.AddListenerOnce(ActionRuntime);
        expectedSignal.Dispatch(expectedArgs);

        void ActionRuntime(ISignal target, object[] args)
        {
            actualTarget = target;
            actualArgs   = args;
        }

        //Assert
        Assert.AreEqual(expectedArgs, actualArgs);
        Assert.AreEqual(expectedSignal, actualTarget);
    }