35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNetCore.Rewrite.Tests.PatternSegments
|
|
{
|
|
public class UrlSegmentTests
|
|
{
|
|
[Theory]
|
|
[InlineData("http", "localhost", 80, "/foo/bar", "/foo/bar")]
|
|
[InlineData("http", "localhost", 80, "/foo:bar", "/foo:bar")]
|
|
[InlineData("http", "localhost", 80, "/foo bar", "/foo%20bar")]
|
|
public void AssertSegmentIsCorrect(string scheme, string host, int port, string path, string expectedResult)
|
|
{
|
|
// Arrange
|
|
var httpContext = new DefaultHttpContext();
|
|
httpContext.Request.Scheme = scheme;
|
|
httpContext.Request.Host = new HostString(host, port);
|
|
httpContext.Request.Path = new PathString(path);
|
|
|
|
var context = new RewriteContext { HttpContext = httpContext };
|
|
context.HttpContext = httpContext;
|
|
|
|
// Act
|
|
var segment = new UrlSegment();
|
|
var results = segment.Evaluate(context, null, null);
|
|
|
|
// Assert
|
|
Assert.Equal(expectedResult, results);
|
|
}
|
|
}
|
|
} |