|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using Microsoft.AspNet.Http.Internal; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace Microsoft.AspNet.Http.Extensions |
| 8 | +{ |
| 9 | + public class UriHelperTests |
| 10 | + { |
| 11 | + [Fact] |
| 12 | + public void EncodeEmptyPartialUrl() |
| 13 | + { |
| 14 | + var result = UriHelper.Encode(); |
| 15 | + |
| 16 | + Assert.Equal("/", result); |
| 17 | + } |
| 18 | + |
| 19 | + [Fact] |
| 20 | + public void EncodePartialUrl() |
| 21 | + { |
| 22 | + var result = UriHelper.Encode(new PathString("/un?escaped/base"), new PathString("/un?escaped"), |
| 23 | + new QueryString("?name=val%23ue"), new FragmentString("#my%20value")); |
| 24 | + |
| 25 | + Assert.Equal("/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result); |
| 26 | + } |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public void EncodeEmptyFullUrl() |
| 30 | + { |
| 31 | + var result = UriHelper.Encode("http", new HostString(string.Empty)); |
| 32 | + |
| 33 | + Assert.Equal("http:///", result); |
| 34 | + } |
| 35 | + |
| 36 | + [Fact] |
| 37 | + public void EncodeFullUrl() |
| 38 | + { |
| 39 | + var result = UriHelper.Encode("http", new HostString("my.HoΨst:80"), new PathString("/un?escaped/base"), new PathString("/un?escaped"), |
| 40 | + new QueryString("?name=val%23ue"), new FragmentString("#my%20value")); |
| 41 | + |
| 42 | + Assert.Equal("http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public void GetEncodedUrlFromRequest() |
| 47 | + { |
| 48 | + var request = new DefaultHttpContext().Request; |
| 49 | + request.Scheme = "http"; |
| 50 | + request.Host = new HostString("my.HoΨst:80"); |
| 51 | + request.PathBase = new PathString("/un?escaped/base"); |
| 52 | + request.Path = new PathString("/un?escaped"); |
| 53 | + request.QueryString = new QueryString("?name=val%23ue"); |
| 54 | + |
| 55 | + Assert.Equal("http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue", request.GetEncodedUrl()); |
| 56 | + } |
| 57 | + |
| 58 | + [Fact] |
| 59 | + public void GetDecodedUrlFromRequest() |
| 60 | + { |
| 61 | + var request = new DefaultHttpContext().Request; |
| 62 | + request.Scheme = "http"; |
| 63 | + request.Host = new HostString("my.HoΨst:80"); |
| 64 | + request.PathBase = new PathString("/un?escaped/base"); |
| 65 | + request.Path = new PathString("/un?escaped"); |
| 66 | + request.QueryString = new QueryString("?name=val%23ue"); |
| 67 | + |
| 68 | + Assert.Equal("http://my.hoψst:80/un?escaped/base/un?escaped?name=val%23ue", request.GetDecodedUrl()); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments