Example #1
0
        public async Task SocketRequest_AgainstListeningRoute_ExceptionOnClientCreation_ResultsInBadRequest()
        {
            bool nextCalled = false;

            Task CallNext(HttpContext context)
            {
                nextCalled = true;
                return(Task.CompletedTask);
            }

            var next   = new RequestDelegate(CallNext);
            var server = new Mock <ISubscriptionServer <GraphSchema> >();

            server.Setup(x => x.RegisterNewClient(It.IsAny <IClientConnection>())).Throws(new InvalidOperationException("failed"));

            var options    = new SubscriptionServerOptions <GraphSchema>();
            var middleware = new DefaultGraphQLHttpSubscriptionMiddleware <GraphSchema>(
                next,
                server.Object,
                options);

            var context = new FakeWebSocketHttpContext();

            context.RequestServices = new Mock <IServiceProvider>().Object;
            context.Request.Path    = options.Route;

            // not a socket request aginst the route
            // next middleware component should not be invoked
            await middleware.InvokeAsync(context);

            Assert.IsFalse(nextCalled);

            Assert.AreEqual((int)HttpStatusCode.InternalServerError, context.Response.StatusCode);
        }
Example #2
0
        public async Task NonSocketRequest_AgainstDifferentRoute_IsSkipped()
        {
            bool nextCalled = false;

            Task CallNext(HttpContext context)
            {
                nextCalled = true;
                return(Task.CompletedTask);
            }

            var next = new RequestDelegate(CallNext);

            var options    = new SubscriptionServerOptions <GraphSchema>();
            var server     = new Mock <ISubscriptionServer <GraphSchema> >();
            var middleware = new DefaultGraphQLHttpSubscriptionMiddleware <GraphSchema>(
                next,
                server.Object,
                options);

            var context = new DefaultHttpContext();

            context.RequestServices = new Mock <IServiceProvider>().Object;
            context.Request.Path    = "/stuff/data";

            // not a socket request aginst the route
            // should be skipped
            await middleware.InvokeAsync(context);

            Assert.IsTrue(nextCalled);
        }
Example #3
0
        public async Task SocketRequest_AgainstListeningRoute_SocketIsInvoked()
        {
            bool nextCalled = false;

            Task CallNext(HttpContext context)
            {
                nextCalled = true;
                return(Task.CompletedTask);
            }

            var next = new RequestDelegate(CallNext);

            var connection = new Mock <ISubscriptionClientProxy>();

            connection.Setup(x => x.StartConnection()).Returns(Task.CompletedTask);

            var server = new Mock <ISubscriptionServer <GraphSchema> >();

            server.Setup(x => x.RegisterNewClient(It.IsAny <IClientConnection>())).ReturnsAsync(connection.Object);

            var options    = new SubscriptionServerOptions <GraphSchema>();
            var middleware = new DefaultGraphQLHttpSubscriptionMiddleware <GraphSchema>(
                next,
                server.Object,
                options);

            var context = new FakeWebSocketHttpContext();

            context.RequestServices = new Mock <IServiceProvider>().Object;
            context.Request.Path    = options.Route;

            // not a socket request aginst the route
            // next middleware component should not be invoked
            await middleware.InvokeAsync(context);

            Assert.IsFalse(nextCalled);
        }