Пример #1
0
        public async Task ShouldRoute()
        {
            var handler = new FakeHandler();
            var route   = new Route <Ping, Pong>("/Ping");
            var request = new FakeRequest();

            request.Services.Add(typeof(IRouteRequestHandler <Ping, Pong>), handler);
            var media = new FakeMedia();

            await route.Send(media, request);

            Assert.IsTrue(media.HasRead);
            Assert.IsTrue(media.HasWritten);
            Assert.IsTrue(handler.HasHandled);
        }
Пример #2
0
        public async Task ShouldMatchRoute()
        {
            var handler = new FakeHandler();
            var route   = new FakeRoute()
            {
                Path = "/Ping"
            };
            var request = new FakeRequest()
            {
                Path = "/Ping"
            };
            var media = new FakeMedia();

            var router = new Router(new[] { route }, new[] { media });

            await router.RouteRequest(request);

            Assert.IsTrue(request.IsHandled);
            Assert.IsTrue(route.HasSent);
        }
Пример #3
0
        public async Task ShouldCancelRequest()
        {
            var handler = new FakeCancelMeHandler();
            var route   = new Route <Ping, Pong>("/Ping");
            var request = new FakeRequest();

            request.Services.Add(typeof(IRouteRequestHandler <Ping, Pong>), handler);
            var media  = new FakeMedia();
            var cancel = new CancellationTokenSource();

            request.CancellationToken = cancel.Token;

            cancel.Cancel();
            var routeTask = route.Send(media, request);

            //standard async pattern throws on cancellation
            await Assert.ThrowsExceptionAsync <OperationCanceledException>(() => routeTask);

            Assert.IsTrue(routeTask.IsCanceled);
            Assert.IsFalse(handler.HasHandled);
            Assert.IsFalse(media.HasWritten);
        }