Ejemplo n.º 1
0
        internal async Task SendToConnectionTest(ServiceTransportType serviceTransportType, string appName)
        {
            var testServer = _testServerFactory.Create(TestOutputHelper);
            await testServer.StartAsync(new Dictionary <string, string> {
                [TestStartup.ApplicationName] = appName
            });

            var task = testServer.HubConnectionManager.WaitForConnectionCountAsync(1);

            var receivedMessageDict = new ConcurrentDictionary <int, int>();

            var(clientEndpoint, clientAccessTokens, serviceHubContext) = await InitAsync(serviceTransportType, appName);

            try
            {
                await RunTestCore(clientEndpoint, clientAccessTokens,
                                  async() =>
                {
                    var connectionId = await task.OrTimeout();
                    await serviceHubContext.Clients.Client(connectionId).SendAsync(MethodName, Message);
                },
                                  1, receivedMessageDict);
            }
            finally
            {
                await serviceHubContext.DisposeAsync();
            }
        }
Ejemplo n.º 2
0
        protected async Task RunE2ETestsBase(string methodName, int expectedMessageCount, Func <string, ITestClientSet, Task> coreTask)
        {
            ITestServer server = null;

            try
            {
                server = _testServerFactory.Create(_output);
                var serverUrl = await server.StartAsync();

                var count   = 0;
                var clients = _testClientSetFactory.Create(serverUrl, DefaultClientCount, _output);
                clients.AddListener(methodName, message => Interlocked.Increment(ref count));
                await clients.StartAsync();
                await coreTask(methodName, clients);

                await Task.Delay(DefaultDelayMilliseconds);

                await clients.StopAsync();

                await Task.Delay(DefaultDelayMilliseconds);

                Assert.Equal(expectedMessageCount, count);
            }
            finally
            {
                await server?.StopAsync();
            }
        }