|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved.
|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using Microsoft.AspNet.Testing;
|
5 | 6 | using Xunit;
|
6 | 7 |
|
@@ -70,5 +71,81 @@ public void ImplicitStringConverters_WorksWithAdd()
|
70 | 71 | result = path + "text";
|
71 | 72 | Assert.Equal("/pathtext", result);
|
72 | 73 | }
|
| 74 | + |
| 75 | + [Theory] |
| 76 | + [InlineData("/test/path", "/TEST", true)] |
| 77 | + [InlineData("/test/path", "/TEST/pa", false)] |
| 78 | + [InlineData("/TEST/PATH", "/test", true)] |
| 79 | + [InlineData("/TEST/path", "/test/pa", false)] |
| 80 | + [InlineData("/test/PATH/path/TEST", "/TEST/path/PATH", true)] |
| 81 | + public void StartsWithSegments_DoesACaseInsensitiveMatch(string sourcePath, string testPath, bool expectedResult) |
| 82 | + { |
| 83 | + var source = new PathString(sourcePath); |
| 84 | + var test = new PathString(testPath); |
| 85 | + |
| 86 | + var result = source.StartsWithSegments(test); |
| 87 | + |
| 88 | + Assert.Equal(expectedResult, result); |
| 89 | + } |
| 90 | + |
| 91 | + [Theory] |
| 92 | + [InlineData("/test/path", "/TEST", true)] |
| 93 | + [InlineData("/test/path", "/TEST/pa", false)] |
| 94 | + [InlineData("/TEST/PATH", "/test", true)] |
| 95 | + [InlineData("/TEST/path", "/test/pa", false)] |
| 96 | + [InlineData("/test/PATH/path/TEST", "/TEST/path/PATH", true)] |
| 97 | + public void StartsWithSegmentsWithRemainder_DoesACaseInsensitiveMatch(string sourcePath, string testPath, bool expectedResult) |
| 98 | + { |
| 99 | + var source = new PathString(sourcePath); |
| 100 | + var test = new PathString(testPath); |
| 101 | + |
| 102 | + PathString remaining; |
| 103 | + var result = source.StartsWithSegments(test, out remaining); |
| 104 | + |
| 105 | + Assert.Equal(expectedResult, result); |
| 106 | + } |
| 107 | + |
| 108 | + [Theory] |
| 109 | + [InlineData("/test/path", "/TEST", StringComparison.OrdinalIgnoreCase, true)] |
| 110 | + [InlineData("/test/path", "/TEST", StringComparison.Ordinal, false)] |
| 111 | + [InlineData("/test/path", "/TEST/pa", StringComparison.OrdinalIgnoreCase, false)] |
| 112 | + [InlineData("/test/path", "/TEST/pa", StringComparison.Ordinal, false)] |
| 113 | + [InlineData("/TEST/PATH", "/test", StringComparison.OrdinalIgnoreCase, true)] |
| 114 | + [InlineData("/TEST/PATH", "/test", StringComparison.Ordinal, false)] |
| 115 | + [InlineData("/TEST/path", "/test/pa", StringComparison.OrdinalIgnoreCase, false)] |
| 116 | + [InlineData("/TEST/path", "/test/pa", StringComparison.Ordinal, false)] |
| 117 | + [InlineData("/test/PATH/path/TEST", "/TEST/path/PATH", StringComparison.OrdinalIgnoreCase, true)] |
| 118 | + [InlineData("/test/PATH/path/TEST", "/TEST/path/PATH", StringComparison.Ordinal, false)] |
| 119 | + public void StartsWithSegments_DoesMatchUsingSpecifiedComparison(string sourcePath, string testPath, StringComparison comparison, bool expectedResult) |
| 120 | + { |
| 121 | + var source = new PathString(sourcePath); |
| 122 | + var test = new PathString(testPath); |
| 123 | + |
| 124 | + var result = source.StartsWithSegments(test, comparison); |
| 125 | + |
| 126 | + Assert.Equal(expectedResult, result); |
| 127 | + } |
| 128 | + |
| 129 | + [Theory] |
| 130 | + [InlineData("/test/path", "/TEST", StringComparison.OrdinalIgnoreCase, true)] |
| 131 | + [InlineData("/test/path", "/TEST", StringComparison.Ordinal, false)] |
| 132 | + [InlineData("/test/path", "/TEST/pa", StringComparison.OrdinalIgnoreCase, false)] |
| 133 | + [InlineData("/test/path", "/TEST/pa", StringComparison.Ordinal, false)] |
| 134 | + [InlineData("/TEST/PATH", "/test", StringComparison.OrdinalIgnoreCase, true)] |
| 135 | + [InlineData("/TEST/PATH", "/test", StringComparison.Ordinal, false)] |
| 136 | + [InlineData("/TEST/path", "/test/pa", StringComparison.OrdinalIgnoreCase, false)] |
| 137 | + [InlineData("/TEST/path", "/test/pa", StringComparison.Ordinal, false)] |
| 138 | + [InlineData("/test/PATH/path/TEST", "/TEST/path/PATH", StringComparison.OrdinalIgnoreCase, true)] |
| 139 | + [InlineData("/test/PATH/path/TEST", "/TEST/path/PATH", StringComparison.Ordinal, false)] |
| 140 | + public void StartsWithSegmentsWithRemainder_DoesMatchUsingSpecifiedComparison(string sourcePath, string testPath, StringComparison comparison, bool expectedResult) |
| 141 | + { |
| 142 | + var source = new PathString(sourcePath); |
| 143 | + var test = new PathString(testPath); |
| 144 | + |
| 145 | + PathString remaining; |
| 146 | + var result = source.StartsWithSegments(test, comparison, out remaining); |
| 147 | + |
| 148 | + Assert.Equal(expectedResult, result); |
| 149 | + } |
73 | 150 | }
|
74 | 151 | }
|
0 commit comments