From 5f47546d40440b3b7e0ac7f4889c88884c4674cc Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 14 Oct 2014 12:48:29 -0700 Subject: [PATCH] Use DefaultOrder in MvcOptionsSetup --- src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs | 3 +- .../BasicTests.cs | 3 +- .../DefaultOrderTest.cs | 53 +++++++++++++++++++ .../Controllers/OrderController.cs | 36 +++++++++++++ 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs create mode 100644 test/WebSites/BasicWebSite/Controllers/OrderController.cs diff --git a/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs b/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs index 1b9c367aff..dde9bdafa1 100644 --- a/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs +++ b/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs @@ -12,10 +12,9 @@ namespace Microsoft.AspNet.Mvc /// public class MvcOptionsSetup : ConfigureOptions { - /// Sets the Order to -1 to allow MvcOptionsSetup to run before a user call to ConfigureOptions. public MvcOptionsSetup() : base(ConfigureMvc) { - Order = -1; + Order = DefaultOrder.DefaultFrameworkSortOrder; } /// diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs index 8b29e54eef..f2637e9b2c 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs @@ -27,11 +27,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // use it on all the rest of the tests. private readonly Assembly _resourcesAssembly = typeof(BasicTests).GetTypeInfo().Assembly; + [Theory] [InlineData("http://localhost/")] [InlineData("http://localhost/Home")] [InlineData("http://localhost/Home/Index")] - [InlineData("http://localhost/Users")] - [InlineData("http://localhost/Monitor/CountActionDescriptorInvocations")] public async Task CanRender_ViewsWithLayout(string url) { // Arrange diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs new file mode 100644 index 0000000000..2c7eec5bd7 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs @@ -0,0 +1,53 @@ +// 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.Net; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Mvc.Description; +using Microsoft.AspNet.Mvc.Razor; +using Microsoft.AspNet.TestHost; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.OptionsModel; +using Xunit; + +namespace Microsoft.AspNet.Mvc.FunctionalTests +{ + // Tests that various MVC services have the correct order. + public class DefaultOrderTest + { + private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(BasicWebSite)); + private readonly Action _app = new BasicWebSite.Startup().Configure; + + [Theory] + [InlineData(typeof(INestedProvider), typeof(ControllerActionDescriptorProvider), -1000)] + [InlineData(typeof(INestedProvider), (Type)null, -1000)] + [InlineData(typeof(INestedProvider), (Type)null, -1000)] + [InlineData(typeof(INestedProvider), (Type)null, -1000)] + [InlineData(typeof(INestedProvider), (Type)null, -1000)] + [InlineData(typeof(IConfigureOptions), (Type)null, -1000)] + [InlineData(typeof(IConfigureOptions), (Type)null, -1000)] + public async Task ServiceOrder_GetOrder(Type serviceType, Type actualType, int order) + { + // Arrange + var server = TestServer.Create(_provider, _app); + var client = server.CreateClient(); + + var url = "http://localhost/Order/GetServiceOrder?serviceType=" + serviceType.AssemblyQualifiedName; + + if (actualType != null) + { + url += "&actualType=" + actualType.AssemblyQualifiedName; + } + + // Act + var response = await client.GetAsync(url); + var content = await response.Content.ReadAsStringAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(order, int.Parse(content)); + } + } +} \ No newline at end of file diff --git a/test/WebSites/BasicWebSite/Controllers/OrderController.cs b/test/WebSites/BasicWebSite/Controllers/OrderController.cs new file mode 100644 index 0000000000..d61d02d82b --- /dev/null +++ b/test/WebSites/BasicWebSite/Controllers/OrderController.cs @@ -0,0 +1,36 @@ +// 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 Microsoft.AspNet.Mvc; + +namespace BasicWebSite +{ + public class OrderController : Controller + { + public int GetServiceOrder(string serviceType, string actualType) + { + var elementType = Type.GetType(serviceType); + + var queryType = typeof(IEnumerable<>).MakeGenericType(elementType); + + var services = (IEnumerable)Resolver.GetService(queryType); + foreach (var service in services) + { + if (actualType != null && service.GetType().AssemblyQualifiedName == actualType) + { + var orderProperty = elementType.GetProperty("Order"); + return (int)orderProperty.GetValue(service); + } + else if (actualType == null) + { + var orderProperty = elementType.GetProperty("Order"); + return (int)orderProperty.GetValue(service); + } + } + + throw new InvalidOperationException(); + } + } +} \ No newline at end of file