Esempio n. 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);
        }
Esempio n. 2
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);
        }