Example #1
0
        public async Task RunServer(string identifier)
        {
            Console.WriteLine("Starting server..");
            var server = new MediatorServerPool(sender, poolName: identifier, poolSize: 4);

            await server.Run();
        }
Example #2
0
        public void Setup()
        {
            cts    = new CancellationTokenSource();
            Sender = new Mock <ISender>();

            this.SetupRequest <VoidRequest, Unit>(Unit.Value);
            this.SetupRequest <RequestWithResponse, Response>((a, _) => new Response {
                A = a.A, B = a.B, C = a.C
            });
            this.SetupRequest <SlowRequest, Response>(async() =>
            {
                await Task.Delay(500);
                return(new Response());
            });
            this.SetupRequest <HugeRequest, byte[]>((req, _) => (byte[])req.Data.Clone());

            Sender.Setup(s => s.Send(It.IsAny <IRequest>(), It.Is <CancellationToken>(t => t.IsCancellationRequested)))
            .ThrowsAsync(new TaskCanceledException());

            clientPool = new MediatorClientPool("testpool", poolSize);
            serverPool = new MediatorServerPool(Sender.Object, "testpool", poolSize);
            serverTask = serverPool.Run();
        }