-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/custom-primitive-types
- Loading branch information
Showing
51 changed files
with
1,137 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Adapters/Tests/WebForms/DotVVM.Adapters.WebForms.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net472</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
|
||
<!-- Required for CheckTestOutput to function correctly in a CI environment. --> | ||
<DeterministicSourcePaths>false</DeterministicSourcePaths> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="CheckTestOutput" Version="0.6.0" /> | ||
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.0" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Web" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Framework\Testing\DotVVM.Framework.Testing.csproj" /> | ||
<ProjectReference Include="..\..\WebForms\DotVVM.Adapters.WebForms.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using CheckTestOutput; | ||
using DotVVM.Framework.Configuration; | ||
using DotVVM.Framework.Testing; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DotVVM.Adapters.WebForms.Tests | ||
{ | ||
[TestClass] | ||
public class HybridRouteLinkTests | ||
{ | ||
private static readonly ControlTestHelper cth = new ControlTestHelper(config: config => config.AddWebFormsAdapters()); | ||
OutputChecker check = new OutputChecker("testoutputs"); | ||
|
||
[ClassInitialize] | ||
public static void Init(TestContext testContext) | ||
{ | ||
WebFormsRouteTableInit.EnsureInitialized(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task HybridRouteLink_NoBindings() | ||
{ | ||
HttpContext.Current = new HttpContext( | ||
new HttpRequest("", "http://tempuri.org", ""), | ||
new HttpResponse(new StringWriter()) | ||
); | ||
|
||
var r = await cth.RunPage(typeof(ControlTestViewModel), @" | ||
<webforms:HybridRouteLink RouteName=NoParams Text='hello 1' /> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index=3 Text='hello 2' /> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={resource: 15} Text='hello 3' /> | ||
<webforms:HybridRouteLink RouteName=MultipleOptionalParams Text='hello 4' /> | ||
<webforms:HybridRouteLink RouteName=MultipleOptionalParams Param-Tag=aaa Text='hello 5' /> | ||
<webforms:HybridRouteLink RouteName=MultipleOptionalParams Param-SubTag=bbb Text='hello 6' /> | ||
<webforms:HybridRouteLink RouteName=MultipleOptionalParams Param-Tag=aaa Param-SubTag=bbb Text='hello 6' />"); | ||
|
||
check.CheckString(r.FormattedHtml, fileExtension: "html"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task HybridRouteLink_ValueBinding() | ||
{ | ||
HttpContext.Current = new HttpContext( | ||
new HttpRequest("", "http://tempuri.org", ""), | ||
new HttpResponse(new StringWriter()) | ||
); | ||
|
||
var r = await cth.RunPage(typeof(ControlTestViewModel), @" | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Value} Text='hello 3' /> | ||
<dot:Repeater DataSource={value: Items}> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Id} Text={value: Name} /> | ||
</dot:Repeater>"); | ||
|
||
check.CheckString(r.FormattedHtml, fileExtension: "html"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task HybridRouteLink_SuffixAndQueryString() | ||
{ | ||
HttpContext.Current = new HttpContext( | ||
new HttpRequest("", "http://tempuri.org", ""), | ||
new HttpResponse(new StringWriter()) | ||
); | ||
|
||
var r = await cth.RunPage(typeof(ControlTestViewModel), @" | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Value} UrlSuffix='?hello=1' Text='hello 1' /> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Value} UrlSuffix={value: '?hello=' + Value} Text='hello 2' /> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Value} UrlSuffix={value: '?hello=' + Value} Query-Test=1 Text='hello 3' /> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Value} UrlSuffix={value: '?hello=' + Value} Query-Test={value: Value * 2} Text='hello 4' /> | ||
<webforms:HybridRouteLink RouteName=SingleParam Param-Index={value: Value} Query-Test1={value: Value + Items.Count} Query-Id=abc Text='hello 5' />"); | ||
|
||
check.CheckString(r.FormattedHtml, fileExtension: "html"); | ||
} | ||
} | ||
|
||
class ControlTestViewModel | ||
{ | ||
public int Value { get; set; } = 15; | ||
|
||
public List<ControlTestChildViewModel> Items { get; set; } = new() | ||
{ | ||
new ControlTestChildViewModel() { Id = 1, Name = "one" }, | ||
new ControlTestChildViewModel() { Id = 2, Name = "two" }, | ||
new ControlTestChildViewModel() { Id = 3, Name = "three" } | ||
}; | ||
} | ||
|
||
class ControlTestChildViewModel | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using System.Web.Routing; | ||
|
||
namespace DotVVM.Adapters.WebForms.Tests | ||
{ | ||
public static class WebFormsRouteTableInit | ||
{ | ||
|
||
static WebFormsRouteTableInit() | ||
{ | ||
RouteTable.Routes.Add("NoParams", new Route("", new EmptyHandler())); | ||
RouteTable.Routes.Add("SingleParam", new Route("page/{Index}", new EmptyHandler())); | ||
RouteTable.Routes.Add("MultipleOptionalParams", new Route("catalog/{Tag}/{SubTag}", new EmptyHandler()) { Defaults = new RouteValueDictionary(new { Tag = "xx", SubTag = "yy" })}); | ||
} | ||
|
||
public static void EnsureInitialized() | ||
{ | ||
} | ||
|
||
} | ||
|
||
public class EmptyHandler : IRouteHandler | ||
{ | ||
public IHttpHandler GetHttpHandler(RequestContext requestContext) => throw new NotImplementedException(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Adapters/Tests/WebForms/testoutputs/HybridRouteLinkTests.HybridRouteLink_NoBindings.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<a href="/">hello 1</a> | ||
<a href="/page/3">hello 2</a> | ||
<a href="/page/15">hello 3</a> | ||
<a href="/catalog">hello 4</a> | ||
<a href="/catalog/aaa">hello 5</a> | ||
<a href="/catalog/xx/bbb">hello 6</a> | ||
<a href="/catalog/aaa/bbb">hello 6</a> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
...Tests/WebForms/testoutputs/HybridRouteLinkTests.HybridRouteLink_SuffixAndQueryString.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Value})+"?hello=1"}" href="/page/15?hello=1">hello 1</a> | ||
<a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Value})+"?hello=" + Value()}" href="/page/15?hello=15">hello 2</a> | ||
<a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Value})+dotvvm.buildUrlSuffix("?hello=" + Value(), {"Test": "1"})}" href="/page/15?hello=15&Test=1">hello 3</a> | ||
<a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Value})+dotvvm.buildUrlSuffix("?hello=" + Value(), {"Test": Value() * 2})}" href="/page/15?hello=15&Test=30">hello 4</a> | ||
<a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Value})+dotvvm.buildUrlSuffix("", {"Id": "abc","Test1": Value() + Items()?.length})}" href="/page/15?Id=abc&Test1=18">hello 5</a> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
...dapters/Tests/WebForms/testoutputs/HybridRouteLinkTests.HybridRouteLink_ValueBinding.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Value})}" href="/page/15">hello 3</a> | ||
<div data-bind="template: { foreach: Items, name: "uEOag7AJw3xoMobIL1lXF5WbK01ZnznA1P04nkjfgBs=" }"></div> | ||
|
||
<!-- Resource uEOag7AJw3xoMobIL1lXF5WbK01ZnznA1P04nkjfgBs= of type TemplateResource. --> | ||
<template id="uEOag7AJw3xoMobIL1lXF5WbK01ZnznA1P04nkjfgBs="><a data-bind="attr: { 'href': "/"+dotvvm.buildRouteUrl("page/{Index}", {"Index": Id})}, text: Name"></a></template> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using DotVVM.Framework.Controls; | ||
using DotVVM.Framework.Hosting; | ||
|
||
#if NETFRAMEWORK | ||
using System.Web.Routing; | ||
#endif | ||
|
||
namespace DotVVM.Adapters.WebForms.Controls | ||
{ | ||
/// <summary> | ||
/// Renders a hyperlink pointing to the specified DotVVM route if such route exists; otherwise it falls back to a Web Forms route with the specified name. | ||
/// </summary> | ||
#if !NETFRAMEWORK | ||
[Obsolete("This control is used only during the Web Forms migration and is not needed in .NET Core. Use the standard RouteLink control.")] | ||
#endif | ||
public class HybridRouteLink : CompositeControl | ||
{ | ||
private readonly IDotvvmRequestContext context; | ||
|
||
public HybridRouteLink(IDotvvmRequestContext context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
public DotvvmControl GetContents( | ||
HtmlCapability htmlCapability, | ||
TextOrContentCapability textOrContent, | ||
RouteLinkCapability routeLinkCapability | ||
) | ||
{ | ||
if (context.Configuration.RouteTable.Contains(routeLinkCapability.RouteName)) | ||
{ | ||
return GenerateDotvvmRouteLink(htmlCapability, textOrContent, routeLinkCapability); | ||
} | ||
#if NETFRAMEWORK | ||
else if (RouteTable.Routes[routeLinkCapability.RouteName] is Route webFormsRoute) | ||
{ | ||
return WebFormsLinkUtils.BuildWebFormsRouteLink(this, context, htmlCapability, textOrContent, routeLinkCapability, webFormsRoute); | ||
} | ||
#endif | ||
else | ||
{ | ||
throw new DotvvmControlException($"Route '{routeLinkCapability.RouteName}' does not exist."); | ||
} | ||
} | ||
|
||
private static DotvvmControl GenerateDotvvmRouteLink(HtmlCapability htmlCapability, TextOrContentCapability textOrContent, RouteLinkCapability routeLinkCapability) | ||
{ | ||
return new RouteLink() | ||
.SetCapability(htmlCapability) | ||
.SetCapability(textOrContent) | ||
.SetCapability(routeLinkCapability); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.