public void NonMatchingFails() { string UriPattern = "Simple"; string MappedUriPattern = "Result/123?x=10"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri(UriPattern + "/123", UriKind.Relative); Uri result = alias.MapUri(testUri); ; Assert.IsNull(result); }
public void NoUriParametersIsPassthrough() { string UriPattern = "Simple"; string MappedUriPattern = "Result/123?x=10"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri(UriPattern, UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); Assert.AreEqual<string>(MappedUriPattern, result.OriginalString); }
public void SimpleMatch() { string UriPattern = "Simple/{id}"; string MappedUriPattern = "Result/{id}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123", UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); Assert.AreEqual<string>("Result/123", result.OriginalString); }
public void SimpleMatchOriginalUriQueryStringPreserved() { string UriPattern = "Simple/{id}"; string MappedUriPattern = "Result/{id}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123?x=10&id=456", UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */); string uriBase = UriParsingHelper.InternalUriGetBaseValue(result); Assert.AreEqual<string>("Result/123", uriBase); Assert.AreEqual(2, queryStringValues.Count); Assert.IsTrue(queryStringValues.ContainsKey("id") && queryStringValues["id"] == "456"); Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10"); }
public void MappedUriParameterNotInUriBecomesEmptyString() { string UriPattern = "Simple/{id}"; string MappedUriPattern = "Result/{foo}/{id}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123?x=10", UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */); string uriBase = UriParsingHelper.InternalUriGetBaseValue(result); Assert.AreEqual<string>("Result//123", uriBase); Assert.IsFalse(queryStringValues.ContainsKey("id")); Assert.IsFalse(queryStringValues.ContainsKey("foo")); Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10"); }
public void SimpleMatchOriginalUriQueryStringPreserved() { string UriPattern = "Simple/{id}"; string MappedUriPattern = "Result/{id}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123?x=10&id=456", UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); IDictionary <string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */); string uriBase = UriParsingHelper.InternalUriGetBaseValue(result); Assert.AreEqual <string>("Result/123", uriBase); Assert.AreEqual(2, queryStringValues.Count); Assert.IsTrue(queryStringValues.ContainsKey("id") && queryStringValues["id"] == "456"); Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10"); }
private static UriMapper CreateOldAppMapping() { var mapping = new UriMapping { Uri = new Uri(ExampleNavigationPattern, UriKind.RelativeOrAbsolute), MappedUri = new Uri(OldAppNavigationPattern, UriKind.RelativeOrAbsolute) }; var mapper = new UriMapper(); mapper.UriMappings.Add(mapping); var examples = Module.ChartingPages.Where(x => x.Value is ExampleAppPage).Select(x => x.Value); foreach (var example in examples) { mapper.UriMappings.Add(new UriMapping { Uri = mapping.MapUri(new Uri(example.MappedUri, UriKind.RelativeOrAbsolute)), MappedUri = new Uri(example.Uri, UriKind.RelativeOrAbsolute), }); } return(mapper); }
public void FragmentWithIdentifier() { string UriPattern = "Simple/{id}/{foo}"; string MappedUriPattern = "Result.xaml?{foo}2=6#fragment{id}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123/myVar?x=10", UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */); string uriBase = UriParsingHelper.InternalUriGetBaseValue(result); string fragment = UriParsingHelper.InternalUriGetFragment(result); Assert.AreEqual<string>("Result.xaml", uriBase); Assert.IsFalse(queryStringValues.ContainsKey("id")); Assert.IsFalse(queryStringValues.ContainsKey("foo")); Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10"); Assert.IsTrue(queryStringValues.ContainsKey("myVar2") && queryStringValues["myVar2"] == "6"); Assert.AreEqual("fragment123", fragment); }
public void NoMappedUriTemplateThrows() { string UriPattern = "Simple/var1={x}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/var1=10", UriKind.Relative); try { Uri result = alias.MapUri(testUri); Assert.Fail(); } catch (InvalidOperationException) { // This is expected } catch (Exception) { Assert.Fail("Exception other than InvalidOperationException thrown"); } }
public void QueryStringValueInMappedUriAndActualUriHasActualUriWin() { string UriPattern = "Simple/{id}"; string MappedUriPattern = "Result/{id}?ShowDetails=true"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123?ShowDetails=false", UriKind.Relative); Uri result = alias.MapUri(testUri); Assert.IsNotNull(result); IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */); string uriBase = UriParsingHelper.InternalUriGetBaseValue(result); Assert.AreEqual<string>("Result/123", uriBase); Assert.IsFalse(queryStringValues.ContainsKey("id")); Assert.IsTrue(queryStringValues.ContainsKey("ShowDetails") && queryStringValues["ShowDetails"] == "false"); }
private static void GlobalizedTestCore(Uri uri, Uri mappedUri, Uri inputUri, Uri expectedOutputUri) { UriMapping mapping = new UriMapping(); mapping.Uri = uri; mapping.MappedUri = mappedUri; Uri outputUri = mapping.MapUri(inputUri); Assert.AreEqual(expectedOutputUri, outputUri); }
public void OnlyQueryStringInMappedUriTemplateThrows() { string UriPattern = "Simple"; string MappedUriPattern = "?Result=1"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple", UriKind.Relative); try { Uri result = alias.MapUri(testUri); Assert.Fail(); } catch (InvalidOperationException) { // This is expected } catch (Exception) { Assert.Fail("Exception other than InvalidOperationException thrown"); } }
public void FragmentInUriTemplateThrows() { string UriPattern = "Simple/var1={x}#foo"; string MappedUriPattern = "Result"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/var1=10#foo", UriKind.Relative); try { Uri result = alias.MapUri(testUri); Assert.Fail(); } catch (InvalidOperationException) { // This is expected } catch (Exception) { Assert.Fail("Exception other than InvalidOperationException thrown"); } }
public void NoUriTemplateReturnsMappedUriExactlyWithNullInput() { string MappedUriPattern = "Result.aspx?id={x}"; UriMapping alias = new UriMapping(); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri1 = null; Uri testUri2 = new Uri(String.Empty, UriKind.Relative); Uri result1 = alias.MapUri(testUri1); Uri result2 = alias.MapUri(testUri2); Assert.AreEqual(MappedUriPattern, result1.OriginalString); Assert.AreEqual(MappedUriPattern, result2.OriginalString); }
public void NoUriTemplateDoesNotMatchNonNullInput() { string MappedUriPattern = "Result.xaml?id={x}"; UriMapping alias = new UriMapping(); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple?var1=10", UriKind.Relative); Assert.IsNull(alias.MapUri(testUri)); }
public void UriCannotContainQueryString() { string UriPattern = "Simple?var1={x}"; string MappedUriPattern = "Result.xaml?id={x}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple?var1=10", UriKind.Relative); try { Uri result = alias.MapUri(testUri); Assert.Fail(); } catch (InvalidOperationException) { // This is expected } catch (Exception) { Assert.Fail("Exception other than InvalidOperationException thrown"); } }
public void UriParameterUsedTwiceThrows() { string UriPattern = "Simple/{id}/{id}"; string MappedUriPattern = "Result/{id}"; UriMapping alias = new UriMapping(); alias.Uri = new Uri(UriPattern, UriKind.Relative); alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative); Uri testUri = new Uri("Simple/123/123", UriKind.Relative); try { Uri result = alias.MapUri(testUri); Assert.Fail(); } catch (InvalidOperationException) { // Expected } catch (Exception) { Assert.Fail("Exception other than InvalidOperationException thrown"); } }