From addd8dd5d2d461fdfa6d4da314ae95bec18fbc61 Mon Sep 17 00:00:00 2001 From: Mugdha Kulkarni Date: Wed, 21 Jan 2015 22:55:54 -0800 Subject: [PATCH] Changing produces and format filter interaction --- .../Controllers/FormatFilterController.cs | 1 - samples/MvcSample.Web/Startup.cs | 9 +-- .../Filters/FormatFilterAttribute.cs | 74 ++++++++----------- .../Filters/IFormatFilter.cs | 11 ++- .../Filters/ProducesAttribute.cs | 7 +- .../FormatterMappings.cs | 31 ++++---- src/Microsoft.AspNet.Mvc.Core/MvcOptions.cs | 2 +- .../Properties/Resources.Designer.cs | 5 ++ src/Microsoft.AspNet.Mvc.Core/Resources.resx | 3 + .../Filters/FormatFilterTest.cs | 66 +++++++++-------- .../Filters/ProducesAttributeTests.cs | 33 +++++++-- .../FormatterMappingsTest.cs | 28 +++---- .../FormatFilterTest.cs | 5 +- ...Microsoft.AspNet.Mvc.FunctionalTests.kproj | 5 ++ .../project.json | 4 +- .../ProducesContentBaseController.cs | 2 +- .../ProducesContentOnClassController.cs | 2 +- test/WebSites/ConnegWebSite/Startup.cs | 2 +- .../FiltersWebSite/FiltersWebSite.kproj | 5 -- test/WebSites/FiltersWebSite/Startup.cs | 1 - .../Controllers/ProducesBaseClass.cs | 17 ----- .../Controllers/ProducesOverrideClass.cs | 8 +- 22 files changed, 163 insertions(+), 158 deletions(-) delete mode 100644 test/WebSites/FormatFilterWebSite/Controllers/ProducesBaseClass.cs diff --git a/samples/MvcSample.Web/Controllers/FormatFilterController.cs b/samples/MvcSample.Web/Controllers/FormatFilterController.cs index 3f1e29216e..945331cd76 100644 --- a/samples/MvcSample.Web/Controllers/FormatFilterController.cs +++ b/samples/MvcSample.Web/Controllers/FormatFilterController.cs @@ -5,7 +5,6 @@ using Microsoft.AspNet.Mvc; namespace MvcSample.Web.Controllers { - [FormatFilter] public class FormatFilterController : Controller { public Product GetProduct(int id) diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs index ca21bbcf01..38763af5cd 100644 --- a/samples/MvcSample.Web/Startup.cs +++ b/samples/MvcSample.Web/Startup.cs @@ -63,9 +63,8 @@ namespace MvcSample.Web services.Configure(options => { options.Filters.Add(typeof(PassThroughAttribute), order: 17); - options.AddXmlDataContractSerializerFormatter(); - var formatFilter = new FormatFilterAttribute(); - options.Filters.Add(formatFilter); + options.AddXmlDataContractSerializerFormatter(); + options.Filters.Add(new FormatFilterAttribute()); }); services.Configure(options => { @@ -108,9 +107,7 @@ namespace MvcSample.Web { options.Filters.Add(typeof(PassThroughAttribute), order: 17); options.AddXmlDataContractSerializerFormatter(); - - var formatFilter = new FormatFilterAttribute(); - options.Filters.Add(formatFilter); + options.Filters.Add(new FormatFilterAttribute()); }); }); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/FormatFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/FormatFilterAttribute.cs index 0fd28aa08e..bca50549e2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/FormatFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/FormatFilterAttribute.cs @@ -13,19 +13,18 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Mvc { /// - /// This will look at the format parameter if present in the route data or query data and sets the content type in - /// ObjectResult corresponding to the format value. + /// A filter which will use the format value in the route data or query string to set the content type on an + /// returned from an action. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class FormatFilterAttribute : Attribute, IFormatFilter, IResourceFilter, IResultFilter { /// - /// As a resourceFilter, this filter looks at the request and rejects it - /// before going ahead if + /// As a , this filter looks at the request and rejects it before going ahead if /// 1. The format in the request doesnt match any format in the map. /// 2. If there is a conflicting producesFilter. /// - /// + /// The . public void OnResourceExecuting([NotNull] ResourceExecutingContext context) { var format = GetFormat(context); @@ -40,21 +39,23 @@ namespace Microsoft.AspNet.Mvc } else { - var responseTypeFilters = context.Filters.OfType(); - if (responseTypeFilters.Count() != 0) + var responseTypeFilters = context.Filters.OfType(); + var contentTypes = new List(); + + foreach (var filter in responseTypeFilters) { - var contentTypes = new List(); + filter.SetContentTypes(contentTypes); + } - foreach (var filter in responseTypeFilters) - { - filter.SetContentTypes(contentTypes); - } - - if (!contentTypes.Any(c => c.IsSubsetOf(formatContentType))) + if (contentTypes.Count() != 0) + { + // If formatfilterContentType is not subset of any of the content types produced by + // IApiResponseMetadataProviders, return 404 + if (!contentTypes.Any(c => formatContentType.IsSubsetOf(c))) { context.Result = new HttpNotFoundResult(); } - } + } } } } @@ -66,19 +67,19 @@ namespace Microsoft.AspNet.Mvc } /// - /// This method looks at the format that request has and sets it in the context + /// Sets a Content Type on an using a format value from the request. /// + /// The . public void OnResultExecuting([NotNull] ResultExecutingContext context) { var format = GetFormat(context); - if (format != null) + if (!string.IsNullOrEmpty(format)) { - var contentType = GetContentType(format, context); - Debug.Assert(contentType != null); - var objectResult = context.Result as ObjectResult; if (objectResult != null) { + var contentType = GetContentType(format, context); + Debug.Assert(contentType != null); objectResult.ContentTypes.Clear(); objectResult.ContentTypes.Add(contentType); } @@ -92,20 +93,15 @@ namespace Microsoft.AspNet.Mvc } /// - /// Looks at the current request for the format parameter. If it contains format, it returns the content type - /// for it. + /// If the current request contains format value, returns true. It means the format filter is going to execute. /// - /// - /// - public MediaTypeHeaderValue GetContentTypeForCurrentRequest(FilterContext context) + /// The + /// If the filter is active and will execute. + public bool IsActive(FilterContext context) { var format = GetFormat(context); - if (format != null && !string.IsNullOrEmpty(format.ToString())) - { - return GetContentType(format, context); - } - return null; + return !string.IsNullOrEmpty(format); } private string GetFormat(FilterContext context) @@ -114,25 +110,17 @@ namespace Microsoft.AspNet.Mvc if (!context.RouteData.Values.TryGetValue("format", out format)) { - if (context.HttpContext.Request.Query.ContainsKey("format")) - { - format = context.HttpContext.Request.Query.Get("format"); - return format.ToString(); - } - } - else - { - return format.ToString(); + format = context.HttpContext.Request.Query["format"]; } - return null; + return (string)format; } - private MediaTypeHeaderValue GetContentType(object format, FilterContext context) + private MediaTypeHeaderValue GetContentType(string format, FilterContext context) { - Debug.Assert(format != null); var options = context.HttpContext.RequestServices.GetRequiredService>(); - var contentType = options.Options.FormatterMappings.GetMediaTypeForFormat(format.ToString()); + var contentType = options.Options.FormatterMappings.GetMediaTypeMappingForFormat(format); + return contentType; } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/IFormatFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/IFormatFilter.cs index f16c14893d..1107dd760f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/IFormatFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/IFormatFilter.cs @@ -7,14 +7,17 @@ using System; namespace Microsoft.AspNet.Mvc { /// - /// Implement this interface if you want to have your own implementation of FormatFilter. A FormatFilter decides - /// what content type to use if the format is present in the Url. + /// A filter which produces a desired content type for the current request. /// + /// A FormatFilter decides what content type to use if a format value is present in the URL. + /// public interface IFormatFilter : IFilter { /// - /// Get the registered fot the format in the request. + /// Returns true if the filter is going to be executed for the current request. /// - MediaTypeHeaderValue GetContentTypeForCurrentRequest(FilterContext context); + /// The + /// If the filter will execute + bool IsActive(FilterContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ProducesAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ProducesAttribute.cs index 53526cbc9d..a3e74c662d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ProducesAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ProducesAttribute.cs @@ -34,10 +34,9 @@ namespace Microsoft.AspNet.Mvc if (objectResult != null) { - // Check if FormatFilter has already set the content type - // If it has, dont override it - var formatFilter = context.Filters.OfType().LastOrDefault(); - if (formatFilter == null || formatFilter.GetContentTypeForCurrentRequest(context) == null) + // Check if there are any IFormatFilter in the pipeline, and if any of them is active. If there is one, + // do not override the content type value. + if (context.Filters.OfType().All(f => !f.IsActive(context))) { SetContentTypes(objectResult.ContentTypes); } diff --git a/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs b/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs index f4e2f05b00..09c1051253 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs @@ -11,7 +11,7 @@ using Microsoft.AspNet.Mvc.Core; namespace Microsoft.AspNet.Mvc { /// - /// Used to specify mapping between the Url Format and corresponding . + /// Used to specify mapping between the URL Format and corresponding . /// public class FormatterMappings { @@ -19,21 +19,14 @@ namespace Microsoft.AspNet.Mvc new Dictionary(StringComparer.OrdinalIgnoreCase); /// - /// This will set mapping for the format to specified . + /// Sets mapping for the format to specified . /// If the format already exists, the will be overwritten with the new value. /// + /// format value + /// The for the format value public void SetMediaTypeMappingForFormat([NotNull] string format, [NotNull] MediaTypeHeaderValue contentType) { - if (string.IsNullOrEmpty(format)) - { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "format"); - } - - if (contentType == null) - { - throw new ArgumentException((Resources.ArgumentCannotBeNullOrEmpty), "contentType"); - } - + ValidateContentType(contentType); format = RemovePeriodIfPresent(format); _map[format] = contentType; } @@ -41,14 +34,26 @@ namespace Microsoft.AspNet.Mvc /// /// Gets for the specified format. /// - public MediaTypeHeaderValue GetMediaTypeForFormat(string format) + /// format value. + /// The for input format + public MediaTypeHeaderValue GetMediaTypeMappingForFormat([NotNull] string format) { format = RemovePeriodIfPresent(format); + MediaTypeHeaderValue value = null; _map.TryGetValue(format, out value); + return value; } + private void ValidateContentType(MediaTypeHeaderValue contentType) + { + if(contentType.Type == "*" || contentType.SubType == "*") + { + throw new ArgumentException(string.Format(Resources.FormatterMappings_NotValidMediaType, contentType)); + } + } + private string RemovePeriodIfPresent(string format) { if (format.StartsWith(".")) diff --git a/src/Microsoft.AspNet.Mvc.Core/MvcOptions.cs b/src/Microsoft.AspNet.Mvc.Core/MvcOptions.cs index 9a61898512..6eda47c88e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/MvcOptions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/MvcOptions.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Mvc } /// - /// Used to specify mapping between the Url Format and corresponding . + /// Used to specify mapping between the URL Format and corresponding . /// public FormatterMappings FormatterMappings { get; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs index 5ad74f797a..96ae8d636e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs @@ -562,6 +562,11 @@ namespace Microsoft.AspNet.Mvc.Core get { return GetString("Common_ValueNotValidForProperty"); } } + internal static string FormatterMappings_NotValidMediaType + { + get { return GetString("FormatterMappings_NotValidMediaType"); } + } + /// /// The value '{0}' is invalid. /// diff --git a/src/Microsoft.AspNet.Mvc.Core/Resources.resx b/src/Microsoft.AspNet.Mvc.Core/Resources.resx index 0ce426a309..27c11d8224 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Resources.resx +++ b/src/Microsoft.AspNet.Mvc.Core/Resources.resx @@ -450,6 +450,9 @@ The action '{0}' has ApiExplorer enabled, but is using conventional routing. Only actions which use attribute routing support ApiExplorer. + + + The media type {0} is not valid. The media type containing "<mediatype>/*" are not supported. No URL for remote validation could be found. diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Filters/FormatFilterTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Filters/FormatFilterTest.cs index ba1698d88a..1ae32112b5 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Filters/FormatFilterTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Filters/FormatFilterTest.cs @@ -171,8 +171,8 @@ namespace Microsoft.AspNet.Mvc [InlineData("json", FormatSource.RouteData, "application/json")] [InlineData("json", FormatSource.QueryData, "application/json")] public void FormatFilter_ContextContainsFormat_ContainsProducesFilter_Matching( - string format, - FormatSource place, + string format, + FormatSource place, string contentType) { // Arrange @@ -188,23 +188,38 @@ namespace Microsoft.AspNet.Mvc } [Fact] - public void FormatFilter_ContextContainsFormat_ContainsProducesFilter_WildCardMatching() + public void FormatFilter_LessSpecificThan_Produces() { // Arrange - var produces = new ProducesAttribute( - "application/baz", - new string[] { "application/foo", "text/bar" }); - var context = CreateResourceExecutingContext(new IFilter[] { produces }, "star", FormatSource.RouteData); + var produces = new ProducesAttribute("application/xml;version=1", new string [] { }); + var context = CreateResourceExecutingContext(new IFilter[] { produces }, "xml", FormatSource.RouteData); var options = context.HttpContext.RequestServices.GetService>(); - options.Options.FormatterMappings.SetMediaTypeMappingForFormat("star", MediaTypeHeaderValue.Parse("application/*")); + options.Options.FormatterMappings.SetMediaTypeMappingForFormat("xml", MediaTypeHeaderValue.Parse("application/xml")); + var filter = new FormatFilterAttribute(); + // Act + filter.OnResourceExecuting(context); + + // Assert + Assert.Null(context.Result); + } + + [Fact] + public void FormatFilter_MoreSpecificThan_Produces() + { + // Arrange + var produces = new ProducesAttribute("application/xml", new string[] { }); + var context = CreateResourceExecutingContext(new IFilter[] { produces }, "xml", FormatSource.RouteData); + var options = context.HttpContext.RequestServices.GetService>(); + options.Options.FormatterMappings.SetMediaTypeMappingForFormat("xml", MediaTypeHeaderValue.Parse("application/xml;version=1")); var filter = new FormatFilterAttribute(); // Act filter.OnResourceExecuting(context); // Assert - Assert.Null(context.Result); + var actionResult = context.Result; + Assert.IsType(actionResult); } [Theory] @@ -241,7 +256,7 @@ namespace Microsoft.AspNet.Mvc var resourceExecutingContext = CreateResourceExecutingContext( new IFilter[] { }, format, - FormatSource.RouteData); + place); var filter = new FormatFilterAttribute(); // Act @@ -252,31 +267,24 @@ namespace Microsoft.AspNet.Mvc } [Theory] - [InlineData("json", FormatSource.RouteData, "application/json")] - [InlineData("json", FormatSource.QueryData, "application/json")] - [InlineData("", FormatSource.RouteAndQueryData, null)] - [InlineData(null, FormatSource.RouteAndQueryData, null)] - public void FormatFilter_GetContentTypeForRequest( + [InlineData("json", FormatSource.RouteData, true)] + [InlineData("json", FormatSource.QueryData, true )] + [InlineData("", FormatSource.RouteAndQueryData, false)] + [InlineData(null, FormatSource.RouteAndQueryData, false)] + public void FormatFilter_IsActive( string format, FormatSource place, - string contentType) + bool expected) { // Arrange - var resourceExecutingContext = CreateResourceExecutingContext( - new IFilter[] { }, - format, - FormatSource.RouteData); + var resultExecutingContext = CreateResultExecutingContext(format, place); var filter = new FormatFilterAttribute(); - var returnContentType = filter.GetContentTypeForCurrentRequest(resourceExecutingContext); + // Act + var isActive = filter.IsActive(resultExecutingContext); - MediaTypeHeaderValue mediaType = null; - if (returnContentType != null) - { - mediaType = MediaTypeHeaderValue.Parse("application/json"); - } - - Assert.Equal(mediaType, returnContentType); + // Assert + Assert.Equal(expected, isActive); } private static ResourceExecutingContext CreateResourceExecutingContext( @@ -332,7 +340,7 @@ namespace Microsoft.AspNet.Mvc if (place == FormatSource.QueryData || place == FormatSource.RouteAndQueryData) { httpContext.Setup(c => c.Request.Query.ContainsKey("format")).Returns(true); - httpContext.Setup(c => c.Request.Query.Get("format")).Returns(format); + httpContext.Setup(c => c.Request.Query["format"]).Returns(format); } else if (place == null && format == null) { diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Filters/ProducesAttributeTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Filters/ProducesAttributeTests.cs index 8f2b4db5c2..6b9147d16c 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Filters/ProducesAttributeTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Filters/ProducesAttributeTests.cs @@ -39,16 +39,38 @@ namespace Microsoft.AspNet.Mvc.Test } [Fact] - public async Task ProducesContentAttribute_FormatFilterAttribute() + public async Task ProducesContentAttribute_FormatFilterAttribute_NotActive() { // Arrange - var mediaType1 = MediaTypeHeaderValue.Parse("application/xml"); - var mediaType2 = MediaTypeHeaderValue.Parse("application/json"); var producesContentAttribute = new ProducesAttribute("application/xml"); var formatFilter = new Mock(); - formatFilter.Setup(f => f.GetContentTypeForCurrentRequest(It.IsAny())) - .Returns(mediaType2); + formatFilter.Setup(f => f.IsActive(It.IsAny())) + .Returns(false); + + var filters = new IFilter[] { producesContentAttribute, formatFilter.Object }; + var resultExecutingContext = CreateResultExecutingContext(filters); + + var next = new ResultExecutionDelegate( + () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext))); + + // Act + await producesContentAttribute.OnResultExecutionAsync(resultExecutingContext, next); + + // Assert + var objectResult = Assert.IsType(resultExecutingContext.Result); + Assert.Equal(1, objectResult.ContentTypes.Count); + } + + [Fact] + public async Task ProducesContentAttribute_FormatFilterAttribute_Active() + { + // Arrange + var producesContentAttribute = new ProducesAttribute("application/xml"); + + var formatFilter = new Mock(); + formatFilter.Setup(f => f.IsActive(It.IsAny())) + .Returns(true); var filters = new IFilter[] { producesContentAttribute, formatFilter.Object }; var resultExecutingContext = CreateResultExecutingContext(filters); @@ -64,7 +86,6 @@ namespace Microsoft.AspNet.Mvc.Test Assert.Equal(0, objectResult.ContentTypes.Count); } - [Theory] [InlineData("", "")] [InlineData("application/xml,, application/json", "")] diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/FormatterMappingsTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/FormatterMappingsTest.cs index 9b583257e5..080af73dd2 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/FormatterMappingsTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/FormatterMappingsTest.cs @@ -24,31 +24,25 @@ namespace Microsoft.AspNet.Mvc options.SetMediaTypeMappingForFormat(setFormat, mediaType); // Act - var returnMediaType = options.GetMediaTypeForFormat(getFormat); + var returnMediaType = options.GetMediaTypeMappingForFormat(getFormat); // Assert Assert.Equal(mediaType, returnMediaType); } - + [Theory] - [InlineData("xml", null)] - [InlineData(".json", null)] - [InlineData(null, "application/json")] - [InlineData("", "text/foo")] - public void FormatterMappings_SetFormatMapping_Invalid(string format, string contentType) + [InlineData("application/*")] + [InlineData("*/json")] + [InlineData("*/*")] + public void FormatterMappings_Wildcardformat(string format) { // Arrange - MediaTypeHeaderValue mediaType = null; - if (!string.IsNullOrEmpty(contentType)) - { - mediaType = MediaTypeHeaderValue.Parse(contentType); - } + var options = new FormatterMappings(); + var expected = string.Format(@"The media type {0} is not valid. The media type containing ""/*"" are not supported.", format); - var options = new FormatterMappings(); - var expectedError = "Value cannot be null or empty." + Environment.NewLine + "Parameter name: format"; - - // Act and Assert - Assert.Throws(() => options.SetMediaTypeMappingForFormat(format, mediaType)); + // Act and assert + var exception = Assert.Throws(() => options.SetMediaTypeMappingForFormat("star", MediaTypeHeaderValue.Parse(format))); + Assert.Equal(expected, exception.Message); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs index 7b198cd9b8..895d15ae72 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs @@ -141,10 +141,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var client = server.CreateClient(); // Act - var response = await client.GetAsync("http://localhost/ProducesDerived/ReturnClassName.json"); + var response = await client.GetAsync("http://localhost/ProducesOverride/ReturnClassName"); // Assert - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(@"ProducesOverrideController", await response.Content.ReadAsStringAsync()); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/Microsoft.AspNet.Mvc.FunctionalTests.kproj b/test/Microsoft.AspNet.Mvc.FunctionalTests/Microsoft.AspNet.Mvc.FunctionalTests.kproj index be9e29520d..99b86b5642 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/Microsoft.AspNet.Mvc.FunctionalTests.kproj +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/Microsoft.AspNet.Mvc.FunctionalTests.kproj @@ -20,4 +20,9 @@ 2.0 + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json index 9f5a1f2abc..0d419bf356 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json @@ -17,6 +17,7 @@ "ErrorPageMiddlewareWebSite": "1.0.0", "FilesWebSite": "1.0.0", "FiltersWebSite": "1.0.0", + "FormatFilterWebSite": "1.0.0-*", "FormatterWebSite": "1.0.0", "InlineConstraintsWebSite": "1.0.0", "LoggingWebSite": "1.0.0", @@ -44,8 +45,7 @@ "MvcTagHelpersWebSite": "1.0.0", "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*", "xunit.runner.kre": "1.0.0-*", - "Microsoft.AspNet.WebUtilities": "1.0.0-*", -"FormatFilterWebSite": "1.0.0-*" + "Microsoft.AspNet.WebUtilities": "1.0.0-*" }, "commands": { "test": "xunit.runner.kre" diff --git a/test/WebSites/ConnegWebSite/Controllers/ProducesContentBaseController.cs b/test/WebSites/ConnegWebSite/Controllers/ProducesContentBaseController.cs index 082d3c6630..2e35e28a32 100644 --- a/test/WebSites/ConnegWebSite/Controllers/ProducesContentBaseController.cs +++ b/test/WebSites/ConnegWebSite/Controllers/ProducesContentBaseController.cs @@ -37,6 +37,6 @@ namespace ConnegWebSite public virtual string ReturnClassNameContentTypeOnDerivedAction() { return "ProducesContentBaseController"; - } + } } } \ No newline at end of file diff --git a/test/WebSites/ConnegWebSite/Controllers/ProducesContentOnClassController.cs b/test/WebSites/ConnegWebSite/Controllers/ProducesContentOnClassController.cs index 92e6fb4717..9b0acbdd10 100644 --- a/test/WebSites/ConnegWebSite/Controllers/ProducesContentOnClassController.cs +++ b/test/WebSites/ConnegWebSite/Controllers/ProducesContentOnClassController.cs @@ -39,6 +39,6 @@ namespace ConnegWebSite { // should be written using the content defined at derived class's class. return "ProducesContentOnClassController"; - } + } } } \ No newline at end of file diff --git a/test/WebSites/ConnegWebSite/Startup.cs b/test/WebSites/ConnegWebSite/Startup.cs index 99f766494c..12821f00e5 100644 --- a/test/WebSites/ConnegWebSite/Startup.cs +++ b/test/WebSites/ConnegWebSite/Startup.cs @@ -31,7 +31,7 @@ namespace ConnegWebSite app.UseMvc(routes => { routes.MapRoute("ActionAsMethod", "{controller}/{action}", - defaults: new { controller = "Home", action = "Index" }); + defaults: new { controller = "Home", action = "Index" }); }); } } diff --git a/test/WebSites/FiltersWebSite/FiltersWebSite.kproj b/test/WebSites/FiltersWebSite/FiltersWebSite.kproj index b7fd6c388d..b979cc3d87 100644 --- a/test/WebSites/FiltersWebSite/FiltersWebSite.kproj +++ b/test/WebSites/FiltersWebSite/FiltersWebSite.kproj @@ -15,9 +15,4 @@ 49641 - - - - - \ No newline at end of file diff --git a/test/WebSites/FiltersWebSite/Startup.cs b/test/WebSites/FiltersWebSite/Startup.cs index 13cdf43215..848e9ed791 100644 --- a/test/WebSites/FiltersWebSite/Startup.cs +++ b/test/WebSites/FiltersWebSite/Startup.cs @@ -5,7 +5,6 @@ using System.Security.Claims; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Security; -using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; namespace FiltersWebSite diff --git a/test/WebSites/FormatFilterWebSite/Controllers/ProducesBaseClass.cs b/test/WebSites/FormatFilterWebSite/Controllers/ProducesBaseClass.cs deleted file mode 100644 index 1281a339bb..0000000000 --- a/test/WebSites/FormatFilterWebSite/Controllers/ProducesBaseClass.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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 Microsoft.AspNet.Mvc; - -namespace FormatFilterWebSite -{ - public class ProducesBaseController : Controller - { - [Produces("application/custom_ProducesBaseController_Action")] - public virtual string ReturnClassName() - { - // Should be written using the action's content type. Overriding the one at the class. - return "ProducesBaseController"; - } - } -} \ No newline at end of file diff --git a/test/WebSites/FormatFilterWebSite/Controllers/ProducesOverrideClass.cs b/test/WebSites/FormatFilterWebSite/Controllers/ProducesOverrideClass.cs index 3a47305329..23b736d22e 100644 --- a/test/WebSites/FormatFilterWebSite/Controllers/ProducesOverrideClass.cs +++ b/test/WebSites/FormatFilterWebSite/Controllers/ProducesOverrideClass.cs @@ -5,11 +5,11 @@ using Microsoft.AspNet.Mvc; namespace FormatFilterWebSite { - [Produces("application/custom_ProducesOverrideController")] - public class ProducesOverrideController : ProducesBaseController + [Produces("application/custom_ProducesController")] + public class ProducesOverrideController { - [FormatFilter] - public override string ReturnClassName() + [Produces("application/ProducesMethod")] + public string ReturnClassName() { // should be written using the content defined at base class's action. return "ProducesOverrideController";