public void LaunchServerAndHandleRequestResponseAsync()
        {
            using var server = FunicularConnectionFactory.New(_serviceProvider).CreateServer("0-test-pipe");
            var client = FunicularClientFactory.New()
                         .CreateClient("0-test-pipe", (pipe, error) => _testOutputHelper.WriteLine($"{pipe}: {error.Message}"));

            var request = new TestRequest
            {
                StringField = "requestedFiled"
            };

            var cancellationTokenSource = new CancellationTokenSource();

            server.StartListening(
                (error, pipe) => _testOutputHelper.WriteLine($"{pipe}: {error.Message}"),
                cancellationTokenSource.Token);

            var stopwatch = Stopwatch.StartNew();
            var response  = client.Send <TestRequest, TestResponse>("test/receive-and-return-async", request);

            stopwatch.Stop();

            // delay in controller
            stopwatch.Elapsed.ShouldBeGreaterThan(TimeSpan.FromMilliseconds(1000));

            response.StringField.ShouldBe($"Received: {request.StringField} from pipe 0-test-pipe");
            cancellationTokenSource.Cancel();
        }
예제 #2
0
            public ConnectionsFixture()
            {
                var connectionFactory      = FunicularConnectionFactory.New(ConfigureServices());
                var funicularClientFactory = FunicularClientFactory.New();

                Clients = new Dictionary <string, IFunicularClient>();
                foreach (var pipeName in Enumerable.Range(0, 10).Select(x => $"test-pipe-{x}"))
                {
                    var server = connectionFactory.CreateServer(pipeName);
                    server.StartListening(CancellationToken.None);
                    Clients.Add(pipeName, funicularClientFactory.CreateClient(pipeName));
                }
            }
        public void LaunchServerAndHandleRequestResponseSync()
        {
            using var server = FunicularConnectionFactory.New(_serviceProvider).CreateServer("test-pipe");
            var client = FunicularClientFactory.New()
                         .CreateClient("test-pipe", (pipe, error) => _testOutputHelper.WriteLine($"{pipe}: {error.Message}"));

            var request = new TestRequest
            {
                StringField = "requestedFiled"
            };

            var cancellationTokenSource = new CancellationTokenSource();

            server.StartListening(
                (error, pipe) => _testOutputHelper.WriteLine($"{pipe}: {error.Message}"),
                cancellationTokenSource.Token);
            var response = client.Send <TestRequest, TestResponse>("test/receive-and-return", request);

            response.StringField.ShouldBe($"Received: {request.StringField} from pipe test-pipe");
            cancellationTokenSource.Cancel();
        }