示例#1
0
    public async Task GenericEventWithoutEventArgsBaseTypeRaisedOnClient()
    {
        var tcs = new TaskCompletionSource <CustomNonDerivingEventArgs>();
        EventHandler <CustomNonDerivingEventArgs> handler = (sender, args) => tcs.SetResult(args);

        this.clientRpc.AppleGrown += handler;
        var expectedArgs = new CustomNonDerivingEventArgs {
            Color = "Red"
        };

        this.server.OnAppleGrown(expectedArgs);
        var actualArgs = await tcs.Task.WithCancellation(this.TimeoutToken);

        Assert.Equal(expectedArgs.Color, actualArgs.Color);

        // Now unregister and confirm we don't get notified.
        this.clientRpc.AppleGrown -= handler;
        tcs = new TaskCompletionSource <CustomNonDerivingEventArgs>();
        this.server.OnAppleGrown(expectedArgs);
        await Assert.ThrowsAsync <TimeoutException>(() => tcs.Task.WithTimeout(ExpectedTimeout));

        Assert.False(tcs.Task.IsCompleted);
    }
示例#2
0
 internal void OnAppleGrown(CustomNonDerivingEventArgs args) => this.AppleGrown?.Invoke(this, args);