示例#1
0
        public async Task ArraysTest()
        {
            using var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            var cancellationToken = tokenSource.Token;

            await BaseTests.BaseTestAsync(
                async client =>
            {
                client.On <BaseTests.ChatMessage[]>("messages", data =>
                {
                    Console.WriteLine(@"Messages:");
                    foreach (var value in data)
                    {
                        Console.WriteLine(value.Message);
                    }
                });

                await client.ConnectAsync(new Uri(LocalCharServerUrl), cancellationToken);
                await client.Emit("message", "message", cancellationToken: cancellationToken);

                await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken);

                await client.DisconnectAsync(cancellationToken);
            },
                cancellationToken,
                nameof(SocketIoClient.EventReceived));
        }
示例#2
0
        public async Task ConnectToLocalChatServerDebugTest()
        {
            using var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            var cancellationToken = tokenSource.Token;

            await BaseTests.BaseTestAsync(
                async client =>
            {
                BaseTests.EnableDebug(client);

                await client.ConnectAsync(new Uri(LocalCharServerUrl), cancellationToken);

                await Task.Delay(TimeSpan.FromMilliseconds(200), cancellationToken);
                await client.Emit("add user", "C# H.Socket.IO Test User", cancellationToken: cancellationToken);
                await Task.Delay(TimeSpan.FromMilliseconds(200), cancellationToken);
                await client.Emit("typing", cancellationToken: cancellationToken);
                await Task.Delay(TimeSpan.FromMilliseconds(200), cancellationToken);
                await client.Emit("new message", "hello", cancellationToken: cancellationToken);
                await Task.Delay(TimeSpan.FromMilliseconds(200), cancellationToken);
                await client.Emit("stop typing", cancellationToken: cancellationToken);
                await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken);

                await client.DisconnectAsync(cancellationToken);
            },
                cancellationToken);
        }
示例#3
0
        public async Task RoomsTest()
        {
            using var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            var cancellationToken = tokenSource.Token;

            await BaseTests.BaseTestAsync(
                async client =>
            {
                await client.ConnectAsync(new Uri(LocalCharServerUrl), cancellationToken);
                await client.Emit("message", cancellationToken: cancellationToken);

                await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken);

                await client.DisconnectAsync(cancellationToken);
            },
                cancellationToken,
                nameof(SocketIoClient.EventReceived),
                nameof(SocketIoClient.UnhandledEventReceived));
        }
示例#4
0
        public async Task ConnectToLocalChatServerNamespaceTest2()
        {
            using var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            var cancellationToken = tokenSource.Token;

            await BaseTests.BaseTestAsync(
                async client =>
            {
                BaseTests.EnableDebug(client);

                await client.ConnectAsync(new Uri(LocalCharServerUrl), cancellationToken, "my");

                await Task.Delay(TimeSpan.FromMilliseconds(200), cancellationToken);
                await client.Emit("message", "hello", "my", cancellationToken);
                await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken);

                await client.DisconnectAsync(cancellationToken);
            },
                cancellationToken,
                nameof(SocketIoClient.EventReceived),
                nameof(SocketIoClient.UnhandledEventReceived));
        }