Ejemplo n.º 1
0
        [Fact] // Endpoint name does not support multiple matches
        public void ParsePathByAddresss_HasMatches_ReturnsFirstSuccessfulParse()
        {
            // Arrange
            var endpoint = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new EndpointNameMetadata("Test"), });

            var parser = CreateLinkParser(endpoint);

            // Act
            var values = parser.ParsePathByEndpointName("Test", "/Home/Index/17");

            // Assert
            MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", id = "17" }, values);
        }
Ejemplo n.º 2
0
    public void ParsePathByAddresss_HasMatches_IncludesDefaults()
    {
        // Arrange
        var endpoint = EndpointFactory.CreateRouteEndpoint("{controller=Home}/{action=Index}/{id?}", metadata: new object[] { new IntMetadata(0), });

        var parser = CreateLinkParser(endpoint);

        // Act
        var values = parser.ParsePathByAddress(0, "/");

        // Assert
        MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", }, values);
    }
Ejemplo n.º 3
0
    public void ParsePathByAddresss_HasMatches_RunsConstraints()
    {
        // Arrange
        var endpoint0 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id:int}", metadata: new object[] { new IntMetadata(0), });
        var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id2:alpha}", metadata: new object[] { new IntMetadata(0), });

        var parser = CreateLinkParser(endpoint0, endpoint1);

        // Act
        var values = parser.ParsePathByAddress(0, "/Home/Index/abc");

        // Assert
        MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", id2 = "abc" }, values);
    }
Ejemplo n.º 4
0
    public void ParsePathByAddresss_HasMatches_ReturnsFirstSuccessfulParse()
    {
        // Arrange
        var endpoint0 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}", displayName: "Test1", metadata: new object[] { new IntMetadata(0), });
        var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", displayName: "Test2", metadata: new object[] { new IntMetadata(0), });
        var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id2}", displayName: "Test3", metadata: new object[] { new IntMetadata(0), });

        var sink          = new TestSink();
        var loggerFactory = new TestLoggerFactory(sink, enabled: true);
        var parser        = CreateLinkParser(services => { services.AddSingleton <ILoggerFactory>(loggerFactory); }, endpoint0, endpoint1, endpoint2);

        // Act
        var values = parser.ParsePathByAddress(0, "/Home/Index/17");

        // Assert
        MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", id = "17" }, values);

        Assert.Collection(
            sink.Writes,
            w => Assert.Equal("Found the endpoints Test1, Test2, Test3 for address 0", w.Message),
            w => Assert.Equal("Path parsing succeeded for endpoint Test2 and URI path /Home/Index/17", w.Message));
    }