Example #1
0
    public async Task WebHost_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent()
    {
        // Arrange
        var requestIdentifierFeature = new StubHttpRequestIdentifierFeature();
        var requestDelegate          = new RequestDelegate(httpContext =>
        {
            // Assert
            Assert.NotNull(httpContext);
            Assert.Same(requestIdentifierFeature, httpContext.Features.Get <IHttpRequestIdentifierFeature>());

            return(Task.CompletedTask);
        });

        using (var host = CreateHost(requestDelegate))
        {
            var server = (FakeServer)host.Services.GetRequiredService <IServer>();
            server.CreateRequestFeatures = () =>
            {
                var features = FakeServer.NewFeatureCollection();
                features.Set <IHttpRequestIdentifierFeature>(requestIdentifierFeature);
                return(features);
            };
            // Act
            await host.StartAsync();
        }
    }