Esempio n. 1
0
        public void BuildDoesNotCallMatchedEndpointWhenTerminated()
        {
            var builder = new ApplicationBuilder(null);

            builder.Use((context, next) =>
            {
                // Do not call next
                return(Task.CompletedTask);
            });
            var app = builder.Build();

            var endpointCalled = false;
            var endpoint       = new Endpoint(
                context =>
            {
                endpointCalled = true;
                return(Task.CompletedTask);
            },
                EndpointMetadataCollection.Empty,
                "Test endpoint");

            var httpContext = new DefaultProtoContext();

            httpContext.SetEndpoint(endpoint);

            app.Invoke(httpContext);

            Assert.False(endpointCalled);
        }
Esempio n. 2
0
        public async Task BuildImplicitlyThrowsForMatchedEndpointAsLastStep()
        {
            var builder = new ApplicationBuilder(null);
            var app     = builder.Build();

            var endpointCalled = false;
            var endpoint       = new Endpoint(
                context =>
            {
                endpointCalled = true;
                return(Task.CompletedTask);
            },
                EndpointMetadataCollection.Empty,
                "Test endpoint");

            var httpContext = new DefaultProtoContext();

            httpContext.SetEndpoint(endpoint);

            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => app.Invoke(httpContext));

            var expected =
                "The request reached the end of the pipeline without executing the endpoint: 'Test endpoint'. " +
                "Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if " +
                "using routing, or 'IApplicationBuilder.UseEndpointExecutor()' if not using routing.";

            Assert.Equal(expected, ex.Message);
            Assert.False(endpointCalled);
        }
Esempio n. 3
0
        public void SetEndpoint_NullOnContextWithoutFeature_NoFeatureSet()
        {
            // Arrange
            var context = new DefaultProtoContext();

            // Act
            context.SetEndpoint(null);

            // Assert
            Assert.Null(context.Features.Get <IEndpointFeature>());
        }
Esempio n. 4
0
        public void SetAndGetEndpoint_Roundtrip_EndpointIsRoundtrip()
        {
            // Arrange
            var context         = new DefaultProtoContext();
            var initialEndpoint = new Endpoint(c => Task.CompletedTask, EndpointMetadataCollection.Empty, "Test endpoint");

            // Act
            context.SetEndpoint(initialEndpoint);
            var endpoint = context.GetEndpoint();

            // Assert
            Assert.Equal(initialEndpoint, endpoint);
        }
Esempio n. 5
0
        public void SetEndpoint_EndpointOnContextWithoutFeature_FeatureWithEndpointSet()
        {
            // Arrange
            var context = new DefaultProtoContext();

            // Act
            var endpoint = new Endpoint(c => Task.CompletedTask, EndpointMetadataCollection.Empty, "Test endpoint");

            context.SetEndpoint(endpoint);

            // Assert
            var feature = context.Features.Get <IEndpointFeature>();

            Assert.NotNull(feature);
            Assert.Equal(endpoint, feature.Endpoint);
        }
Esempio n. 6
0
        public void SetEndpoint_NullOnContextWithFeature_NullSetOnExistingFeature()
        {
            // Arrange
            var context         = new DefaultProtoContext();
            var initialEndpoint = new Endpoint(c => Task.CompletedTask, EndpointMetadataCollection.Empty, "Test endpoint");
            var initialFeature  = new EndpointFeature
            {
                Endpoint = initialEndpoint
            };

            context.Features.Set <IEndpointFeature>(initialFeature);

            // Act
            context.SetEndpoint(null);

            // Assert
            var feature = context.Features.Get <IEndpointFeature>();

            Assert.Equal(initialFeature, feature);
            Assert.Null(feature.Endpoint);
        }