Skip to content

Commit

Permalink
Merge branch '1.1.0' of github.com:riganti/dotvvm into 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
djanosik committed Oct 27, 2017
2 parents e07af2f + de0f394 commit 493e9ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
33 changes: 28 additions & 5 deletions src/DotVVM.Framework.Tests.Common/Routing/DotvvmRouteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void DotvvmRoute_IsMatch_RouteMustNotEndWithSlash()
public void DotvvmRoute_IsMatch_EmptyRouteMatchesEmptyUrl()
{
var route = new DotvvmRoute("", null, null, null, configuration);

IDictionary<string, object> parameters;
var result = route.IsMatch("", out parameters);

Expand Down Expand Up @@ -77,7 +77,7 @@ public void DotvvmRoute_IsMatch_UrlTwoParametersBothSpecified()
Assert.AreEqual("15", parameters["Id"]);
Assert.AreEqual("Test-title", parameters["Title"]);
}

[TestMethod]
public void DotvvmRoute_IsMatch_UrlTwoParametersOneSpecifiedOneDefault()
{
Expand All @@ -91,7 +91,7 @@ public void DotvvmRoute_IsMatch_UrlTwoParametersOneSpecifiedOneDefault()
Assert.AreEqual("15", parameters["Id"]);
Assert.AreEqual("test", parameters["Title"]);
}


[TestMethod]
public void DotvvmRoute_IsMatch_UrlTwoParametersBothRequired_NoMatchWhenOneSpecified()
Expand Down Expand Up @@ -246,7 +246,7 @@ public void DotvvmRoute_BuildUrl_Static_TwoParts_TwoParameters_FirstOptionalOpti
Assert.AreEqual("~/Article/Test/aaa/suffix", result);
}


[TestMethod]
public void DotvvmRoute_BuildUrl_CombineParameters_OneOptional()
{
Expand All @@ -268,6 +268,29 @@ public void DotvvmRoute_BuildUrl_ParameterOnly()
Assert.AreEqual("~/", result);
}

[TestMethod]
public void DotvvmRoute_BuildUrl_OptionlaParameter()
{
var route = new DotvvmRoute("myPage/{Id?}/edit", null, null, null, configuration);

var result = route.BuildUrl(new { });
var result2 = route.BuildUrl(new Dictionary<string, object>{ ["Id"] = null });

Assert.AreEqual("~/myPage/edit", result);
Assert.AreEqual("~/myPage/edit", result2);
}

[TestMethod]
public void DotvvmRoute_BuildUrl_NullInParameter()
{
var route = new DotvvmRoute("myPage/{Id}/edit", null, null, null, configuration);

var ex = Assert.ThrowsException<Exception>(() => {
route.BuildUrl(new Dictionary<string, object>{ ["Id"] = null });
});
Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException));
}

[TestMethod]
public void DotvvmRoute_BuildUrl_NoParameter()
{
Expand All @@ -293,7 +316,7 @@ public void DotvvmRoute_BuildUrl_Invalid_UnclosedParameter()


[TestMethod]

public void DotvvmRoute_BuildUrl_Invalid_UnclosedParameterConstraint()
{
Assert.ThrowsException<ArgumentException>(() =>
Expand Down
5 changes: 2 additions & 3 deletions src/DotVVM.Framework/Routing/DotvvmRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ private string ParseParameter(string prefix, ref int index, Dictionary<string, I
{
urlBuilders.Add(v =>
{
object r;
if (v.TryGetValue(name, out r))
if (v.TryGetValue(name, out var r) && r != null)
{
return prefix + r.ToString();
}
Expand All @@ -185,7 +184,7 @@ private string ParseParameter(string prefix, ref int index, Dictionary<string, I
}
else
{
urlBuilders.Add(v => prefix + v[name].ToString());
urlBuilders.Add(v => prefix + (v[name]?.ToString() ?? throw new ArgumentNullException($"Could not build route, parameter '{name}' is null")));
}

// add a parameter
Expand Down

0 comments on commit 493e9ac

Please sign in to comment.