Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit c87de5a

Browse files
author
N. Taylor Mullen
committed
Add TagHelper functional test.
- Added an end-to-end test that verifies all content behaviors, interactions and functionalities of tag helpers. - Added some common user scenarios to verify that the system works how we expect. #1116
1 parent b68fae9 commit c87de5a

22 files changed

+667
-0
lines changed

Mvc.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ EndProject
8383
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ApiExplorerWebSite", "test\WebSites\ApiExplorerWebSite\ApiExplorerWebSite.kproj", "{61061528-071E-424E-965A-07BCC2F02672}"
8484
EndProject
8585
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "VersioningWebSite", "test\WebSites\VersioningWebSite\VersioningWebSite.kproj", "{C6304029-78C8-4604-99BE-2078DCA1DD36}"
86+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ReflectedModelWebSite", "test\WebSites\ReflectedModelWebSite\ReflectedModelWebSite.kproj", "{C2EF54F8-8886-4260-A322-44F76245F95D}"
87+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TagHelpersWebSite", "test\WebSites\TagHelpersWebSite\TagHelpersWebSite.kproj", "{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}"
8688
EndProject
8789
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FilesWebSite", "test\WebSites\FilesWebSite\FilesWebSite.kproj", "{0EF9860B-10D7-452F-B0F4-A405B88BEBB3}"
8890
EndProject
@@ -470,6 +472,16 @@ Global
470472
{CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
471473
{CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}.Release|Mixed Platforms.Build.0 = Release|Any CPU
472474
{CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}.Release|x86.ActiveCfg = Release|Any CPU
475+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
476+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Debug|Any CPU.Build.0 = Debug|Any CPU
477+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
478+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
479+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Debug|x86.ActiveCfg = Debug|Any CPU
480+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Release|Any CPU.ActiveCfg = Release|Any CPU
481+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Release|Any CPU.Build.0 = Release|Any CPU
482+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
483+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Release|Mixed Platforms.Build.0 = Release|Any CPU
484+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47}.Release|x86.ActiveCfg = Release|Any CPU
473485
EndGlobalSection
474486
GlobalSection(SolutionProperties) = preSolution
475487
HideSolutionNode = FALSE
@@ -513,5 +525,6 @@ Global
513525
{0EF9860B-10D7-452F-B0F4-A405B88BEBB3} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
514526
{2B2B9876-903C-4065-8D62-2EE832BBA106} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
515527
{CAE52CB7-0FAC-4B5B-8251-B0FF837DB657} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
528+
{6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
516529
EndGlobalSection
517530
EndGlobal
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. 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 System;
5+
using System.Net;
6+
using System.Net.Http.Headers;
7+
using System.Reflection;
8+
using System.Threading.Tasks;
9+
using BasicWebSite;
10+
using Microsoft.AspNet.Builder;
11+
using Microsoft.AspNet.TestHost;
12+
using Xunit;
13+
14+
namespace Microsoft.AspNet.Mvc.FunctionalTests
15+
{
16+
public class TagHelpersTests
17+
{
18+
private readonly IServiceProvider _provider = TestHelper.CreateServices("TagHelpersWebSite");
19+
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
20+
21+
// Some tests require comparing the actual response body against an expected response baseline
22+
// so they require a reference to the assembly on which the resources are located, in order to
23+
// make the tests less verbose, we get a reference to the assembly with the resources and we
24+
// use it on all the rest of the tests.
25+
private readonly Assembly _resourcesAssembly = typeof(TagHelpersTests).GetTypeInfo().Assembly;
26+
27+
[Theory]
28+
[InlineData("Index")]
29+
[InlineData("About")]
30+
[InlineData("Help")]
31+
public async Task CanRenderViewsWithTagHelpers(string action)
32+
{
33+
// Arrange
34+
var server = TestServer.Create(_provider, _app);
35+
var client = server.CreateClient();
36+
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
37+
38+
// The K runtime compiles every file under compiler/resources as a resource at runtime with the same name
39+
// as the file name, in order to update a baseline you just need to change the file in that folder.
40+
var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync(
41+
"compiler/resources/TagHelpersWebSite.Home." + action + ".html");
42+
43+
// Act
44+
45+
// The host is not important as everything runs in memory and tests are isolated from each other.
46+
var response = await client.GetAsync("http://localhost/Home/" + action);
47+
var responseContent = await response.Content.ReadAsStringAsync();
48+
49+
// Assert
50+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
51+
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);
52+
Assert.Equal(expectedContent, responseContent);
53+
}
54+
}
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+

2+
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta charset="utf-8"></meta>
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
8+
<title>About - My ASP.NET Application</title>
9+
10+
11+
</head>
12+
<body>
13+
<h1 style="font-family: cursive;">ASP.NET vNext - About</h1>
14+
<p>| <a href="/" style="background-color: gray;
15+
color: white;
16+
border-radius: 3px;
17+
border: 1px solid black;
18+
padding: 3px;
19+
font-family: cursive;">My Home</a>
20+
| <a href="/home/about" style="background-color: gray;
21+
color: white;
22+
border-radius: 3px;
23+
border: 1px solid black;
24+
padding: 3px;
25+
font-family: cursive;">My About</a>
26+
| <a href="/home/help" style="background-color: gray;
27+
color: white;
28+
border-radius: 3px;
29+
border: 1px solid black;
30+
padding: 3px;
31+
font-family: cursive;">My Help</a> |</p>
32+
<div>
33+
34+
35+
36+
37+
<div>
38+
<p>Hello, you've reached the about page.</p>
39+
40+
<h3>Information about our website (outdated):</h3>
41+
<section><p><strong>Version:</strong> 1.1</p>
42+
<p><strong>Copyright Year:</strong> 1990</p>
43+
<p><strong>Approved:</strong> True</p>
44+
<p><strong>Number of tags to show:</strong> 30</p>
45+
</section>
46+
</div>
47+
<hr></hr>
48+
<footer>
49+
50+
</footer>
51+
</div>
52+
</body>
53+
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+

2+
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta charset="utf-8"></meta>
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
8+
<title>Help - My ASP.NET Application</title>
9+
10+
11+
</head>
12+
<body>
13+
<h1 style="font-family: cursive;">ASP.NET vNext - Help</h1>
14+
<p>| <a href="/" style="background-color: gray;
15+
color: white;
16+
border-radius: 3px;
17+
border: 1px solid black;
18+
padding: 3px;
19+
font-family: cursive;">My Home</a>
20+
| <a href="/home/about" style="background-color: gray;
21+
color: white;
22+
border-radius: 3px;
23+
border: 1px solid black;
24+
padding: 3px;
25+
font-family: cursive;">My About</a>
26+
| <a href="/home/help" style="background-color: gray;
27+
color: white;
28+
border-radius: 3px;
29+
border: 1px solid black;
30+
padding: 3px;
31+
font-family: cursive;">My Help</a> |</p>
32+
<div>
33+
34+
35+
36+
<div>
37+
<p>Hello, you've reached the help page. If you're having troubles try visiting our <a href="/?approved=true">My Approved Home Page</a></p>
38+
</div>
39+
<hr></hr>
40+
<footer>
41+
42+
</footer>
43+
</div>
44+
</body>
45+
</html>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+

2+
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta charset="utf-8"></meta>
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
8+
<title>Home Page - My ASP.NET Application</title>
9+
10+
11+
<style>
12+
h1 {
13+
color:red;
14+
font-size:2em;
15+
}
16+
</style>
17+
18+
</head>
19+
<body>
20+
<h1 style="font-family: cursive;">ASP.NET vNext - Home Page</h1>
21+
<p>| <a href="/" style="background-color: gray;
22+
color: white;
23+
border-radius: 3px;
24+
border: 1px solid black;
25+
padding: 3px;
26+
font-family: cursive;">My Home</a>
27+
| <a href="/home/about" style="background-color: gray;
28+
color: white;
29+
border-radius: 3px;
30+
border: 1px solid black;
31+
padding: 3px;
32+
font-family: cursive;">My About</a>
33+
| <a href="/home/help" style="background-color: gray;
34+
color: white;
35+
border-radius: 3px;
36+
border: 1px solid black;
37+
padding: 3px;
38+
font-family: cursive;">My Help</a> |</p>
39+
<div>
40+
41+
42+
43+
44+
<div>
45+
<p>This website has <strong style="font-size: 1.25em;
46+
text-decoration: underline;">not</strong> been approved yet. Visit <strong><a target="_blank" href="http://www.contoso.com">www.contoso.com</a></strong> for <strong>more</strong> information.</p>
47+
</div>
48+
49+
<div>
50+
<h3 style="font-family: cursive;">Current Tag Cloud from Tag Helper</h3>
51+
<section>["Lorem","ipsum","dolor","sit","amet","consectetur","adipisicing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore","et","dolore","magna","aliquaUt","enim"]</section>
52+
<h3 style="font-family: cursive;">Current Tag Cloud from ViewComponentHelper:</h3>
53+
<section>["Lorem","ipsum","dolor","sit","amet","consectetur","adipisicing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore"]</section>
54+
</div>
55+
56+
57+
<hr></hr>
58+
<footer>
59+
60+
61+
62+
</footer>
63+
</div>
64+
</body>
65+
</html>

test/Microsoft.AspNet.Mvc.FunctionalTests/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"Microsoft.Framework.Logging": "1.0.0-*",
3434
"Microsoft.Framework.Runtime.Interfaces": "1.0.0-*",
3535
"Microsoft.AspNet.PipelineCore": "1.0.0-*",
36+
"TagHelpersWebSite": "1.0.0",
3637
"Xunit.KRunner": "1.0.0-*"
3738
},
3839
"commands": {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. 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 System;
5+
using Microsoft.AspNet.Mvc;
6+
using TagHelpersWebSite.Models;
7+
8+
namespace TagHelpersWebSite.Controllers
9+
{
10+
public class HomeController : Controller
11+
{
12+
public IActionResult Index(bool approved = false)
13+
{
14+
return View(new WebsiteContext
15+
{
16+
Approved = approved,
17+
CopyrightYear = 2015,
18+
Version = new Version(1, 3, 3, 7),
19+
TagsToShow = 20
20+
});
21+
}
22+
23+
public IActionResult About()
24+
{
25+
return View();
26+
}
27+
28+
public IActionResult Help()
29+
{
30+
return View();
31+
}
32+
}
33+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. 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 System;
5+
6+
namespace TagHelpersWebSite.Models
7+
{
8+
public class WebsiteContext
9+
{
10+
public Version Version { get; set; }
11+
12+
public int CopyrightYear { get; set; }
13+
14+
public bool Approved { get; set; }
15+
16+
public int TagsToShow { get; set; }
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. 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.Builder;
5+
using Microsoft.Framework.DependencyInjection;
6+
7+
namespace TagHelpersWebSite
8+
{
9+
public class Startup
10+
{
11+
public void Configure(IApplicationBuilder app)
12+
{
13+
var configuration = app.GetTestConfiguration();
14+
15+
app.UseServices(services =>
16+
{
17+
services.AddMvc(configuration);
18+
});
19+
20+
app.UseMvc();
21+
}
22+
}
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. 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 System;
5+
using System.Linq;
6+
using Microsoft.AspNet.Mvc;
7+
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
8+
using Microsoft.AspNet.Razor.TagHelpers;
9+
10+
namespace TagHelpersWebSite.TagHelpers
11+
{
12+
[ContentBehavior(ContentBehavior.Prepend)]
13+
public class ATagHelper : TagHelper
14+
{
15+
[Activate]
16+
public IUrlHelper UrlHelper { get; set; }
17+
18+
public string Controller { get; set; }
19+
20+
public string Action { get; set; }
21+
22+
public override void Process(TagHelperContext context, TagHelperOutput output)
23+
{
24+
if (Controller != null && Action != null)
25+
{
26+
var methodParameters = output.Attributes.ToDictionary(attribute => attribute.Key,
27+
attribute => (object)attribute.Value);
28+
29+
// We remove all attributes from the resulting HTML element because they're supposed to
30+
// be parameters to our final href value.
31+
output.Attributes.Clear();
32+
33+
output.Attributes["href"] = UrlHelper.Action(Action, Controller, methodParameters);
34+
35+
output.Content = "My ";
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)