コード例 #1
0
        public Endpoint Build()
        {
            var endpointBuilder = new RouteEndpointBuilder(_requestDelegate, _routePattern, _order)
            {
                DisplayName = _displayName,
            };

            foreach (var oldMetadata in _metadata)
            {
                endpointBuilder.Metadata.Add(oldMetadata);
            }

            foreach (var convention in _conventions)
            {
                convention(endpointBuilder);
            }

            return(endpointBuilder.Build());
        }
コード例 #2
0
        public void RequireHost_HostNames()
        {
            // Arrange
            var builder = new TestEndpointConventionBuilder();

            // Act
            builder.RequireHost("contoso.com:8080");

            // Assert
            var convention = Assert.Single(builder.Conventions);

            var endpointModel = new RouteEndpointBuilder((context) => Task.CompletedTask, RoutePatternFactory.Parse("/"), 0);

            convention(endpointModel);

            var hostMetadata = Assert.IsType <HostAttribute>(Assert.Single(endpointModel.Metadata));

            Assert.Equal("contoso.com:8080", hostMetadata.Hosts.Single());
        }
コード例 #3
0
        public void Build_AllValuesSet_EndpointCreated()
        {
            const int       defaultOrder    = 0;
            var             metadata        = new object();
            RequestDelegate requestDelegate = (d) => null;

            var builder = new RouteEndpointBuilder(requestDelegate, RoutePatternFactory.Parse("/"), defaultOrder)
            {
                DisplayName = "Display name!",
                Metadata    = { metadata }
            };

            var endpoint = Assert.IsType <RouteEndpoint>(builder.Build());

            Assert.Equal("Display name!", endpoint.DisplayName);
            Assert.Equal(defaultOrder, endpoint.Order);
            Assert.Equal(requestDelegate, endpoint.RequestDelegate);
            Assert.Equal("/", endpoint.RoutePattern.RawText);
            Assert.Equal(metadata, Assert.Single(endpoint.Metadata));
        }