Add functional test of MVC tag helper sample
- ensure future changes don't break this sample
This commit is contained in:
parent
27beca7738
commit
f94bd53464
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace TagHelperSample.Web
|
||||
|
|
@ -10,7 +11,14 @@ namespace TagHelperSample.Web
|
|||
{
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseServices(services => services.AddMvc());
|
||||
app.UseServices(services =>
|
||||
{
|
||||
services.AddMvc();
|
||||
|
||||
// Setup services with a test AssemblyProvider so that only the sample's assemblies are loaded. This
|
||||
// prevents loading controllers from other assemblies when the sample is used in functional tests.
|
||||
services.AddTransient<IAssemblyProvider, TestAssemblyProvider<Startup>>();
|
||||
});
|
||||
app.UseMvc();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace TagHelperSample.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// Limits MVC to use a single Assembly for controller discovery. This is used by the functional test to limit the
|
||||
/// Controller discovery to TagHelperSample.Web Assembly alone. The sample should work in the absence of this file
|
||||
/// when not run from a functional test.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a generic type because it needs to instantiated by a service provider to replace a built-in MVC
|
||||
/// service.
|
||||
/// </remarks>
|
||||
public class TestAssemblyProvider<T> : IAssemblyProvider
|
||||
{
|
||||
public TestAssemblyProvider()
|
||||
{
|
||||
CandidateAssemblies = new Assembly[] { typeof(T).GetTypeInfo().Assembly };
|
||||
}
|
||||
|
||||
public IEnumerable<Assembly> CandidateAssemblies { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +93,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
routePrefixedAttributes.Any())
|
||||
{
|
||||
// User specified an href and one of the bound attributes; can't determine the href attribute.
|
||||
// Reviewers: Should this instead ignore the helper-specific attributes?
|
||||
throw new InvalidOperationException(
|
||||
Resources.FormatAnchorTagHelper_CannotOverrideHref(
|
||||
"<a>",
|
||||
|
|
|
|||
|
|
@ -55,7 +55,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
public bool? AntiForgery { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>At most adds an anti-forgery token if user provides an <c>action</c> attribute.</remarks>
|
||||
/// <remarks>
|
||||
/// Does nothing if user provides an <c>action</c> attribute and <see cref="AntiForgery"/> is <c>null</c> or
|
||||
/// <c>false</c>.
|
||||
/// </remarks>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if <c>action</c> attribute is provided and <see cref="Action"/> or <see cref="Controller"/> are
|
||||
/// non-<c>null</c> or if the user provided <c>asp-route-*</c> attributes.
|
||||
|
|
@ -71,8 +74,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
if (Action != null || Controller != null || routePrefixedAttributes.Any())
|
||||
{
|
||||
// User also specified bound attributes we cannot use.
|
||||
// Reviewers: Should this instead ignore the helper-specific attributes -- only change
|
||||
// antiForgeryDefault?
|
||||
throw new InvalidOperationException(
|
||||
Resources.FormatFormTagHelper_CannotOverrideAction(
|
||||
"<form>",
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
if (For == null)
|
||||
{
|
||||
// Regular HTML <input/> element. Just make sure Format wasn't specified.
|
||||
// Reviewers: Should this instead ignore the unused helper-specific attribute?
|
||||
if (Format != null)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.FormatInputTagHelper_UnableToFormat(
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
if (For == null)
|
||||
{
|
||||
// Regular HTML <select/> element. Just make sure Items wasn't specified.
|
||||
// Reviewers: Should this instead ignore the unused helper-specific attribute?
|
||||
if (Items != null)
|
||||
{
|
||||
var message = Resources.FormatSelectTagHelper_CannotDetermineContentWhenOnlyItemsSpecified(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||
{
|
||||
public class TagHelperSampleTest
|
||||
{
|
||||
private static readonly List<string> Paths = new List<string>
|
||||
{
|
||||
string.Empty,
|
||||
"/",
|
||||
"/Home/Create",
|
||||
"/Home/Create?Name=Billy&Blurb=hello&DateOfBirth=2000-11-30&YearsEmployeed=0",
|
||||
"/Home/Create",
|
||||
"/Home/Create?Name=Joe&Blurb=goodbye&DateOfBirth=1980-10-20&YearsEmployeed=1",
|
||||
"/Home/Edit/0",
|
||||
"/Home/Edit/0?Name=Bobby&Blurb=howdy&DateOfBirth=1999-11-30&YearsEmployeed=1",
|
||||
"/Home/Edit/1",
|
||||
"/Home/Edit/1?Name=Jack&Blurb=goodbye&DateOfBirth=1979-10-20&YearsEmployeed=4",
|
||||
"/Home/Edit/0",
|
||||
"/Home/Edit/0?Name=Bobby&Blurb=howdy&DateOfBirth=1999-11-30&YearsEmployeed=2",
|
||||
"/Home/Index",
|
||||
};
|
||||
|
||||
// Path relative to Mvc\\test\Microsoft.AspNet.Mvc.FunctionalTests
|
||||
private readonly IServiceProvider _services =
|
||||
TestHelper.CreateServices("TagHelperSample.Web", Path.Combine("..", "..", "samples"));
|
||||
private readonly Action<IApplicationBuilder> _app = new TagHelperSample.Web.Startup().Configure;
|
||||
|
||||
[Fact]
|
||||
public async Task Home_Pages_ReturnSuccess()
|
||||
{
|
||||
using (TestHelper.ReplaceCallContextServiceLocationService(_services))
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.CreateClient();
|
||||
|
||||
for (var index = 0; index < Paths.Count; index++)
|
||||
{
|
||||
// Act
|
||||
var path = Paths[index];
|
||||
var response = await client.GetAsync("http://localhost" + path);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
"RazorWebSite": "1.0.0",
|
||||
"RazorInstrumentationWebsite": "1.0.0",
|
||||
"RequestServicesWebSite": "1.0.0",
|
||||
"TagHelperSample.Web": "1.0.0",
|
||||
"TagHelpersWebSite": "1.0.0",
|
||||
"UrlHelperWebSite": "1.0.0",
|
||||
"ValueProvidersSite": "1.0.0",
|
||||
|
|
|
|||
Loading…
Reference in New Issue