Remove TestOptionsManager

This commit is contained in:
Pranav K 2017-10-30 16:17:37 -07:00
parent de2aef61ba
commit 41efa409a4
64 changed files with 264 additions and 262 deletions

View File

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
@ -271,7 +272,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices(Mock<IOutputFormatter> formatter)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(formatter.Object);
var services = new ServiceCollection();
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(

View File

@ -2,21 +2,18 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
namespace Microsoft.AspNetCore.Mvc
@ -180,7 +177,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices(Mock<IOutputFormatter> formatter)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(formatter.Object);
var services = new ServiceCollection();
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(

View File

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
@ -136,7 +137,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
private static IServiceProvider CreateServices(Mock<IOutputFormatter> formatter)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(formatter.Object);
var services = new ServiceCollection();
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(

View File

@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Mvc.TestCommon;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
@ -2837,7 +2838,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
{
new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null),
};

View File

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
@ -89,7 +90,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
@ -104,7 +105,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
@ -90,7 +91,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
var resultExecutingContext = mockObjects.CreateResultExecutingContext();
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { });
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
format,
MediaTypeHeaderValue.Parse(contentType));
@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
var mockObjects = new MockObjects("xml", FormatSource.RouteData);
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { produces });
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
"xml",
MediaTypeHeaderValue.Parse("application/xml"));
@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
var mockObjects = new MockObjects("xml", FormatSource.RouteData);
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { produces });
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
"xml",
MediaTypeHeaderValue.Parse("application/xml;version=1"));
@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
var mockObjects = new MockObjects(format, place);
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { produces });
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
"xml",
MediaTypeHeaderValue.Parse("application/xml"));
@ -374,10 +374,9 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
Assert.Empty(result.ContentTypes);
}
private class MockObjects
{
public MvcOptions Options { get; private set; }
public MvcOptions MvcOptions { get; private set; }
public HttpContext MockHttpContext { get; private set; }
public ActionContext MockActionContext { get; private set; }
@ -442,20 +441,20 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
string format = null,
FormatSource? place = null)
{
OptionsManager = new TestOptionsManager<MvcOptions>();
OptionsManager = Options.Create(new MvcOptions());
// Setup options on mock service provider
Options = OptionsManager.Value;
MvcOptions = OptionsManager.Value;
// Set up default output formatters.
Options.OutputFormatters.Add(new HttpNoContentOutputFormatter());
Options.OutputFormatters.Add(new StringOutputFormatter());
Options.OutputFormatters.Add(new JsonOutputFormatter(
MvcOptions.OutputFormatters.Add(new HttpNoContentOutputFormatter());
MvcOptions.OutputFormatters.Add(new StringOutputFormatter());
MvcOptions.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),
ArrayPool<char>.Shared));
// Set up default mapping for json extensions to content type
Options.FormatterMappings.SetMediaTypeMappingForFormat(
MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
"json",
MediaTypeHeaderValue.Parse("application/json"));

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Xunit;
@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Xunit;
@ -70,7 +71,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -314,7 +314,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
public void SelectFormatter_WithAcceptHeaderAndReturnHttpNotAcceptable_DoesNotUseFallback()
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ReturnHttpNotAcceptable = true;
var executor = CreateExecutor(options);
@ -467,7 +467,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
public async Task ExecuteAsync_FallsBackOnFormattersInOptions()
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new TestJsonOutputFormatter());
var executor = CreateExecutor(options: options);
@ -558,7 +558,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
string expectedContentType)
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.RespectBrowserAcceptHeader = false;
var executor = CreateExecutor(options: options);
@ -595,7 +595,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
string expectedContentType)
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.RespectBrowserAcceptHeader = true;
var executor = CreateExecutor(options: options);
@ -640,7 +640,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
private static TestObjectResultExecutor CreateExecutor(IOptions<MvcOptions> options = null)
{
return new TestObjectResultExecutor(
options ?? new TestOptionsManager<MvcOptions>(),
options ?? Options.Create(new MvcOptions()),
new TestHttpResponseStreamWriterFactory(),
NullLoggerFactory.Instance);
}
@ -648,7 +648,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
private static CustomObjectResultExecutor CreateCustomObjectResultExecutor()
{
return new CustomObjectResultExecutor(
new TestOptionsManager<MvcOptions>(),
Options.Create(new MvcOptions()),
new TestHttpResponseStreamWriterFactory(),
NullLoggerFactory.Instance);
}

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -785,7 +786,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
.Select(t => t.GetTypeInfo())
.ToList();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var manager = GetApplicationManager(controllerTypes);

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
// Arrange
var context = GetContext(typeof(TestApiController));
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
var options = Options.Create(new ApiBehaviorOptions
{
SuppressModelStateInvalidFilter = true,
});
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
// Arrange
var context = GetContext(typeof(SimpleController));
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
var options = Options.Create(new ApiBehaviorOptions
{
SuppressModelStateInvalidFilter = true,
});
@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
// Arrange
var context = GetContext(typeof(TestApiController));
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
var options = Options.Create(new ApiBehaviorOptions
{
SuppressModelStateInvalidFilter = true,
});
@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Arrange
var context = GetContext(typeof(TestApiController));
context.Result.Controllers[0].ApiExplorer.IsVisible = false;
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
var options = Options.Create(new ApiBehaviorOptions
{
SuppressModelStateInvalidFilter = true,
});
@ -401,7 +401,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
IOptions<ApiBehaviorOptions> options = null,
IModelMetadataProvider modelMetadataProvider = null)
{
options = options ?? new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
options = options ?? Options.Create(new ApiBehaviorOptions
{
InvalidModelStateResponseFactory = _ => null,
});
@ -414,7 +414,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
private static ApplicationModelProviderContext GetContext(Type type)
{
var context = new ApplicationModelProviderContext(new[] { type.GetTypeInfo() });
new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>()).OnProvidersExecuting(context);
new DefaultApplicationModelProvider(Options.Create(new MvcOptions())).OnProvidersExecuting(context);
return context;
}

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -20,8 +21,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
public void CreateControllerModel_AuthorizeAttributeAddsAuthorizeFilter()
{
// Arrange
var provider = new AuthorizationApplicationModelProvider(new DefaultAuthorizationPolicyProvider(new TestOptionsManager<AuthorizationOptions>()));
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var provider = new AuthorizationApplicationModelProvider(new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions())));
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(AccountController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -38,12 +39,12 @@ namespace Microsoft.AspNetCore.Mvc.Internal
public void BuildActionModels_BaseAuthorizeFiltersAreStillValidWhenOverriden()
{
// Arrange
var options = new TestOptionsManager<AuthorizationOptions>();
var options = Options.Create(new AuthorizationOptions());
options.Value.AddPolicy("Base", policy => policy.RequireClaim("Basic").RequireClaim("Basic2"));
options.Value.AddPolicy("Derived", policy => policy.RequireClaim("Derived"));
var provider = new AuthorizationApplicationModelProvider(new DefaultAuthorizationPolicyProvider(options));
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(DerivedController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -69,8 +70,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
public void CreateControllerModelAndActionModel_AllowAnonymousAttributeAddsAllowAnonymousFilter()
{
// Arrange
var provider = new AuthorizationApplicationModelProvider(new DefaultAuthorizationPolicyProvider(new TestOptionsManager<AuthorizationOptions>()));
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var provider = new AuthorizationApplicationModelProvider(new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions())));
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(AnonymousController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -94,12 +95,12 @@ namespace Microsoft.AspNetCore.Mvc.Internal
new AssertionRequirement((con) => { return true; })
};
var authorizationPolicy = new AuthorizationPolicy(requirements, new string[] { "dingos" });
var authOptions = new TestOptionsManager<AuthorizationOptions>();
var authOptions = Options.Create(new AuthorizationOptions());
authOptions.Value.AddPolicy("Base", authorizationPolicy);
var policyProvider = new DefaultAuthorizationPolicyProvider(authOptions);
var provider = new AuthorizationApplicationModelProvider(policyProvider);
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
// Act
var action = GetBaseControllerActionModel(provider, defaultProvider);
@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
.Verifiable();
var provider = new AuthorizationApplicationModelProvider(authorizationPolicyProviderMock.Object);
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
// Act
var action = GetBaseControllerActionModel(provider, defaultProvider);
@ -145,9 +146,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Arrange
var provider = new AuthorizationApplicationModelProvider(
new DefaultAuthorizationPolicyProvider(
new TestOptionsManager<AuthorizationOptions>()
Options.Create(new AuthorizationOptions())
));
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(NoAuthController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);

View File

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -706,7 +707,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Arrange
var controllerTypeInfo = typeof(UserController).GetTypeInfo();
var manager = GetApplicationManager(new[] { controllerTypeInfo });
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.Conventions.Add(new TestRoutingConvention());
var modelProvider = new DefaultApplicationModelProvider(options);
var provider = new ControllerActionDescriptorProvider(
@ -1175,7 +1176,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
.Setup(c => c.Apply(It.IsAny<ParameterModel>()))
.Callback(() => { Assert.Equal(3, sequence++); });
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.Conventions.Add(applicationConvention.Object);
var applicationModel = new ApplicationModel();
@ -1385,7 +1386,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
TypeInfo controllerTypeInfo,
IEnumerable<IFilterMetadata> filters = null)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
if (filters != null)
{
foreach (var filter in filters)
@ -1409,7 +1410,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
private ControllerActionDescriptorProvider GetProvider(
params TypeInfo[] controllerTypeInfos)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var manager = GetApplicationManager(controllerTypeInfos);
var modelProvider = new DefaultApplicationModelProvider(options);
@ -1426,7 +1427,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
TypeInfo controllerTypeInfo,
IApplicationModelConvention convention)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.Conventions.Add(convention);
var manager = GetApplicationManager(new[] { controllerTypeInfo });

View File

@ -1597,7 +1597,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var httpContext = new DefaultHttpContext();
var options = new MvcOptions();
var mvcOptionsAccessor = new TestOptionsManager<MvcOptions>(options);
var mvcOptionsAccessor = Options.Create(options);
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);

View File

@ -1250,13 +1250,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
_methods = methods;
}
public IEnumerable<string> HttpMethods
{
get
{
return _methods;
}
}
public IEnumerable<string> HttpMethods => _methods;
}
[Route("A")]
@ -1344,7 +1338,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
private class TestApplicationModelProvider : DefaultApplicationModelProvider
{
public TestApplicationModelProvider()
: this(new TestOptionsManager<MvcOptions>())
: this(Options.Create(new MvcOptions()))
{
}
@ -1352,11 +1346,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
IOptions<MvcOptions> options)
: base(options)
{
Options = options.Value;
}
public MvcOptions Options { get; }
public new ControllerModel CreateControllerModel(TypeInfo typeInfo)
{
return base.CreateControllerModel(typeInfo);

View File

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -595,8 +596,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
Assert.Single(modelStateDictionary);
// Check Age error.
ModelStateEntry entry;
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out entry));
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out var entry));
var modelError = Assert.Single(entry.Errors);
Assert.Null(modelError.Exception);
Assert.NotNull(modelError.ErrorMessage);
@ -630,8 +630,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
Assert.Single(modelStateDictionary);
// Check Age error.
ModelStateEntry entry;
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out entry));
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out var entry));
var modelError = Assert.Single(entry.Errors);
Assert.Null(modelError.Exception);
Assert.NotNull(modelError.ErrorMessage);
@ -667,8 +666,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
Assert.Single(modelStateDictionary);
// Check Age error.
ModelStateEntry entry;
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out entry));
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out var entry));
Assert.Equal(ModelValidationState.Invalid, entry.ValidationState);
var modelError = Assert.Single(entry.Errors);
@ -1032,7 +1030,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
private static TestableComplexTypeModelBinder CreateBinder(ModelMetadata metadata)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var setup = new MvcCoreMvcOptionsSetup(new TestHttpRequestStreamReaderFactory());
setup.Configure(options.Value);
@ -1368,8 +1366,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
return base.BindModelAsync(bindingContext);
}
ModelBindingResult result;
if (Results.TryGetValue(bindingContext.ModelMetadata, out result))
if (Results.TryGetValue(bindingContext.ModelMetadata, out var result))
{
bindingContext.Result = result;
}

View File

@ -3,6 +3,7 @@
using System;
using System.Linq;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
@ -256,7 +257,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
{
return new DefaultModelMetadataProvider(
new EmptyCompositeMetadataDetailsProvider(),
new TestOptionsManager<MvcOptions>());
Options.Create(new MvcOptions()));
}
[Model("OnType")]
@ -292,7 +293,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
private class ModelTypeWithIndexer
{
public PropertyType this[string key] { get { return null; } }
public PropertyType this[string key] => null;
public PropertyType Property1 { get; set; }
}

View File

@ -5,6 +5,7 @@ using System;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -19,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var expected = $"'{typeof(MvcOptions).FullName}.{nameof(MvcOptions.ModelBinderProviders)}' must not be " +
$"empty. At least one '{typeof(IModelBinderProvider).FullName}' is required to model bind.";
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var factory = new ModelBinderFactory(metadataProvider, options);
var context = new ModelBinderFactoryContext()
{
@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(_ => null));
var factory = new ModelBinderFactory(metadataProvider, options);
@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var metadataProvider = new TestModelMetadataProvider();
// There isn't a provider that can handle WidgetId.
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(c =>
{
if (c.Metadata.ModelType == typeof(Widget))
@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var modelBinder = new ByteArrayModelBinder();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(c =>
{
if (c.Metadata.ModelType == typeof(WidgetId))
@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(c =>
{
if (c.Metadata.ModelType == typeof(Widget))
@ -166,7 +167,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var callCount = 0;
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(c =>
{
var currentCallCount = ++callCount;
@ -201,7 +202,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(c =>
{
Assert.Equal(typeof(Employee), c.Metadata.ModelType);
@ -229,7 +230,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Add(new TestModelBinderProvider(c =>
{
Assert.Equal(typeof(Employee), c.Metadata.ModelType);
@ -341,7 +342,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
return modelBinder;
});
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.ModelBinderProviders.Insert(0, modelBinderProvider);
var factory = new ModelBinderFactory(metadataProvider, options);
@ -364,7 +365,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
IModelBinder inner = null;
@ -422,7 +423,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
IModelBinder inner = null;
@ -483,7 +484,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
IModelBinder inner = null;
@ -542,7 +543,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
// Arrange
var metadataProvider = new TestModelMetadataProvider();
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
IModelBinder inner = null;
IModelBinder innerInner = null;

View File

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Microsoft.AspNetCore.Mvc.ModelBinding.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -58,7 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel();
@ -100,7 +101,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel { MyProperty = "Old-Value" };
@ -166,7 +167,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel
{
@ -246,7 +247,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel
{
@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel
{
@ -494,7 +495,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel
{
@ -574,7 +575,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
var validator = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var model = new MyModel { MyProperty = "Old-Value" };

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc
{
var services = new ServiceCollection();
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
new TestOptionsManager<MvcOptions>(),
Options.Create(new MvcOptions()),
new TestHttpResponseStreamWriterFactory(),
NullLoggerFactory.Instance));
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);

View File

@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Mvc
string expectedUrl)
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var uri = new Uri(url);
var requestContext = new DefaultHttpContext();
@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Mvc
private static IServiceProvider CreateServices(int? sslPort = null, bool requireHttpsPermanent = false)
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.SslPort = sslPort;
options.Value.RequireHttpsPermanent = requireHttpsPermanent;

View File

@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Mvc
private IServiceProvider GetServiceProvider(Dictionary<string, CacheProfile> cacheProfiles)
{
var serviceProvider = new Mock<IServiceProvider>();
var optionsAccessor = new TestOptionsManager<MvcOptions>();
var optionsAccessor = Options.Create(new MvcOptions());
if (cacheProfiles != null)
{
foreach (var p in cacheProfiles)

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new [] { typeof(CorsController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(CustomCorsFilterController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(EnableCorsController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsActionController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(CustomCorsFilterOnActionController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() });
context.Result.Filters.Add(new CorsAuthorizationFilter(Mock.Of<ICorsService>(), Mock.Of<ICorsPolicyProvider>()));
@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() });
context.Result.Filters.Add(new DisableCorsAuthorizationFilter());
@ -198,7 +198,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() });
context.Result.Filters.Add(new CustomCorsFilterAttribute());
@ -220,7 +220,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{
// Arrange
var corsProvider = new CorsApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);

View File

@ -6,6 +6,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsClientModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForProperty(
@ -43,7 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsClientModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForProperty(
@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsClientModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForProperty(
@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsClientModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForProperty(
@ -120,7 +121,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsClientModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForType(typeof(DummyClassWithDummyValidationAttribute));

View File

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -65,7 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var key = ModelMetadataIdentity.ForType(typeof(string));
@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var dataType = new DataTypeAttribute(DataType.Currency);
@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var dataType = new DataTypeAttribute(DataType.Time); // Has a non-null DisplayFormat.
@ -131,7 +132,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var editable = new EditableAttribute(allowEdit: false);
@ -152,7 +153,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var editable = new EditableAttribute(allowEdit: true);
@ -172,7 +173,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
public void CreateDisplayMetadata_DisplayAttribute_OverridesDisplayNameAttribute()
{
// Arrange
var localizationOptions = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var localizationOptions = Options.Create(new MvcDataAnnotationsLocalizationOptions());
var provider = new DataAnnotationsMetadataProvider(
localizationOptions,
@ -199,7 +200,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
public void CreateDisplayMetadata_DisplayAttribute_OverridesDisplayNameAttribute_IfNameEmpty()
{
// Arrange
var localizationOptions = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var localizationOptions = Options.Create(new MvcDataAnnotationsLocalizationOptions());
var provider = new DataAnnotationsMetadataProvider(
localizationOptions,
@ -226,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
public void CreateDisplayMetadata_DisplayAttribute_DoesNotOverrideDisplayNameAttribute_IfNameNull()
{
// Arrange
var localizationOptions = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var localizationOptions = Options.Create(new MvcDataAnnotationsLocalizationOptions());
var provider = new DataAnnotationsMetadataProvider(
localizationOptions,
@ -263,7 +264,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Setup(s => s.Create(typeof(EmptyClass)))
.Returns(() => sharedLocalizer.Object);
var localizationOptions = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var localizationOptions = Options.Create(new MvcDataAnnotationsLocalizationOptions());
localizationOptions.Value.DataAnnotationLocalizerProvider = (type, stringLocalizerFactory) =>
{
return stringLocalizerFactory.Create(typeof(EmptyClass));
@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Setup(s => s.Create(typeof(EmptyClass)))
.Returns(() => sharedLocalizer.Object);
var options = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var options = Options.Create(new MvcDataAnnotationsLocalizationOptions());
bool dataAnnotationLocalizerProviderWasUsed = false;
options.Value.DataAnnotationLocalizerProvider = (type, stringLocalizerFactory) =>
{
@ -330,7 +331,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var display = new DisplayAttribute()
@ -367,7 +368,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Setup(s => s.Create(It.IsAny<Type>()))
.Returns(() => stringLocalizer.Object);
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory.Object);
var display = new DisplayAttribute()
@ -404,7 +405,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Setup(s => s.Create(It.IsAny<Type>()))
.Returns(() => stringLocalizer.Object);
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory.Object);
var display = new DisplayAttribute()
@ -435,7 +436,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var display = new DisplayAttribute()
@ -472,7 +473,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Setup(s => s.Create(It.IsAny<Type>()))
.Returns(() => stringLocalizer.Object);
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory.Object);
var display = new DisplayAttribute()
@ -503,7 +504,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var display = new DisplayAttribute()
@ -548,7 +549,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Setup(f => f.Create(It.IsAny<Type>()))
.Returns(stringLocalizer.Object);
var options = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var options = Options.Create(new MvcDataAnnotationsLocalizationOptions());
options.Value.DataAnnotationLocalizerProvider = (type, stringLocalizerFactory) =>
{
return stringLocalizerFactory.Create(type);
@ -609,7 +610,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var key = ModelMetadataIdentity.ForType(type);
@ -645,7 +646,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var key = ModelMetadataIdentity.ForType(type);
@ -779,7 +780,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var key = ModelMetadataIdentity.ForType(type);
@ -825,7 +826,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Returns(stringLocalizer.Object);
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory.Object);
// Act
@ -959,7 +960,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var key = ModelMetadataIdentity.ForType(type);
@ -989,7 +990,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
};
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var key = ModelMetadataIdentity.ForType(typeof(EnumWithDisplayOrder));
@ -1091,7 +1092,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var required = new RequiredAttribute();
@ -1115,7 +1116,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var attributes = new Attribute[] { };
@ -1138,7 +1139,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var attributes = new Attribute[] { new RequiredAttribute() };
@ -1161,7 +1162,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var attributes = new Attribute[] { };
@ -1181,7 +1182,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var attribute = new TestValidationAttribute();
@ -1202,7 +1203,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
// Arrange
var provider = new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var attribute = new TestValidationAttribute();
@ -1249,7 +1250,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
.Returns(stringLocalizer.Object);
return new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
useStringLocalizer ? stringLocalizerFactory.Object : null);
}

View File

@ -6,6 +6,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -21,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var mockValidatable = Mock.Of<IValidatableObject>();
var metadata = _metadataProvider.GetMetadataForType(mockValidatable.GetType());
@ -41,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
var provider = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForProperty(
typeof(ClassWithProperty),
@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var metadata = _metadataProvider.GetMetadataForType(typeof(DummyClassWithDummyValidationAttribute));
@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
// Arrange
var provider = new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null);
var mockValidatable = new Mock<IValidatableObject>();
var metadata = _metadataProvider.GetMetadataForType(mockValidatable.Object.GetType());

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
@ -1051,10 +1052,10 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{
new DefaultBindingMetadataProvider(),
new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null),
}),
new TestOptionsManager<MvcOptions>())
Options.Create(new MvcOptions()))
{
_attributes = attributes;
}

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Test.Internal
services.AddSingleton<IHostingEnvironment>(Mock.Of<IHostingEnvironment>());
services.AddSingleton<IValidationAttributeAdapterProvider, ValidationAttributeAdapterProvider>();
services.AddSingleton<IOptions<MvcDataAnnotationsLocalizationOptions>>(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>());
Options.Create(new MvcDataAnnotationsLocalizationOptions()));
services.AddSingleton<IConfigureOptions<MvcOptions>, MvcDataAnnotationsMvcOptionsSetup>();
var serviceProvider = services.BuildServiceProvider();

View File

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json;
using Xunit;
@ -221,7 +222,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
return new JsonResultExecutor(
new TestHttpResponseStreamWriterFactory(),
logger ?? NullLogger<JsonResultExecutor>.Instance,
new TestOptionsManager<MvcJsonOptions>(),
Options.Create(new MvcJsonOptions()),
ArrayPool<char>.Shared);
}

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Xunit;
@ -46,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc
var executor = new JsonResultExecutor(
new TestHttpResponseStreamWriterFactory(),
NullLogger<JsonResultExecutor>.Instance,
new TestOptionsManager<MvcJsonOptions>(),
Options.Create(new MvcJsonOptions()),
ArrayPool<char>.Shared);
var services = new ServiceCollection();

View File

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.IntegrationTests
@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
new[] { typeof(AuthorizeController).GetTypeInfo() });
var policyProvider = new TestAuthorizationPolicyProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
defaultProvider.OnProvidersExecuting(applicationModelProviderContext);

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
optionsSetup.Configure(Value);
var validationAttributeAdapterProvider = new ValidationAttributeAdapterProvider();
var dataAnnotationLocalizationOptions = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
var dataAnnotationLocalizationOptions = Options.Create(new MvcDataAnnotationsLocalizationOptions());
var stringLocalizer = new Mock<IStringLocalizer>();
var stringLocalizerFactory = new Mock<IStringLocalizerFactory>();
stringLocalizerFactory
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
dataAnnotationOptionsSetup.Configure(Value);
var loggerFactory = new LoggerFactory();
var jsonOptions = new TestOptionsManager<MvcJsonOptions>();
var jsonOptions = Options.Create(new MvcJsonOptions());
var charPool = ArrayPool<char>.Shared;
var objectPoolProvider = new DefaultObjectPoolProvider();

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.Razor.Test.Internal
@ -31,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Test.Internal
.Select(r => r.Display);
var referenceManager = new DefaultRazorReferenceManager(
applicationPartManager,
new TestOptionsManager<RazorViewEngineOptions>(options));
Options.Create(options));
// Act
var references = referenceManager.CompilationReferences;

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);
var partManager = new ApplicationPartManager();
var options = new TestOptionsManager<RazorViewEngineOptions>();
var options = Options.Create(new RazorViewEngineOptions());
var referenceManager = new DefaultRazorReferenceManager(partManager, options);

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -507,7 +508,7 @@ this should fail";
var applicationPartManager = new ApplicationPartManager();
var referenceManager = new DefaultRazorReferenceManager(
applicationPartManager,
new TestOptionsManager<RazorViewEngineOptions>());
Options.Create(new RazorViewEngineOptions()));
var compiler = GetViewCompiler(
compilationCallback: compilationCallback,
referenceManager: referenceManager);
@ -531,7 +532,7 @@ this should fail";
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);
compilationCallback = compilationCallback ?? (_ => { });
var options = new TestOptionsManager<RazorViewEngineOptions>();
var options = Options.Create(new RazorViewEngineOptions());
if (referenceManager == null)
{
var applicationPartManager = new ApplicationPartManager();

View File

@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
private static IOptions<RazorPagesOptions> GetRazorPagesOptions()
{
return new TestOptionsManager<RazorPagesOptions>();
return Options.Create(new RazorPagesOptions());
}
private static RazorProjectItem GetProjectItem(string basePath, string path, string content)

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_IgnoresAttributesOnHandlerMethods()
{
// Arrange
var policyProvider = new DefaultAuthorizationPolicyProvider(new TestOptionsManager<AuthorizationOptions>());
var policyProvider = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);
var typeInfo = typeof(PageWithAuthorizeHandlers).GetTypeInfo();
var context = GetApplicationProviderContext(typeInfo);
@ -50,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_AddsAuthorizeFilter_IfModelHasAuthorizationAttributes()
{
// Arrange
var policyProvider = new DefaultAuthorizationPolicyProvider(new TestOptionsManager<AuthorizationOptions>());
var policyProvider = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);
var context = GetApplicationProviderContext(typeof(TestPage).GetTypeInfo());
@ -83,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_CollatesAttributesFromInheritedTypes()
{
// Arrange
var options = new TestOptionsManager<AuthorizationOptions>();
var options = Options.Create(new AuthorizationOptions());
options.Value.AddPolicy("Base", policy => policy.RequireClaim("Basic").RequireClaim("Basic2"));
options.Value.AddPolicy("Derived", policy => policy.RequireClaim("Derived"));
@ -130,7 +131,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_AddsAllowAnonymousFilter()
{
// Arrange
var policyProvider = new DefaultAuthorizationPolicyProvider(new TestOptionsManager<AuthorizationOptions>());
var policyProvider = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);
var context = GetApplicationProviderContext(typeof(PageWithAnonymousModel).GetTypeInfo());

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
private readonly IEnumerable<CompiledViewDescriptor> _descriptors;
public TestCompiledPageRouteModelProvider(IEnumerable<CompiledViewDescriptor> descriptors, RazorPagesOptions options)
: base(new ApplicationPartManager(), new TestOptionsManager<RazorPagesOptions>(options))
: base(new ApplicationPartManager(), Options.Create(options))
{
_descriptors = descriptors;
}

View File

@ -2,10 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var compilerProvider = GetCompilerProvider();
var razorPagesOptions = new TestOptionsManager<RazorPagesOptions>();
var mvcOptions = new TestOptionsManager<MvcOptions>();
var razorPagesOptions = Options.Create(new RazorPagesOptions());
var mvcOptions = Options.Create(new MvcOptions());
var provider1 = new Mock<IPageApplicationModelProvider>();
var provider2 = new Mock<IPageApplicationModelProvider>();
@ -90,8 +90,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
// Arrange
var descriptor = new PageActionDescriptor();
var compilerProvider = GetCompilerProvider();
var razorPagesOptions = new TestOptionsManager<RazorPagesOptions>();
var mvcOptions = new TestOptionsManager<MvcOptions>();
var razorPagesOptions = Options.Create(new RazorPagesOptions());
var mvcOptions = Options.Create(new MvcOptions());
var provider1 = new Mock<IPageApplicationModelProvider>();
provider1.SetupGet(p => p.Order).Returns(10);
@ -164,8 +164,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
});
var providers = new[] { provider.Object };
var razorPagesOptions = new TestOptionsManager<RazorPagesOptions>();
var mvcOptions = new TestOptionsManager<MvcOptions>();
var razorPagesOptions = Options.Create(new RazorPagesOptions());
var mvcOptions = Options.Create(new MvcOptions());
var convention = new Mock<IPageApplicationModelConvention>();
convention.Setup(c => c.Apply(It.IsAny<PageApplicationModel>()))
.Callback((PageApplicationModel m) =>

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Moq;
using Xunit;
@ -23,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var templateEngine = new RazorTemplateEngine(
RazorEngine.Create(),
new FileProviderRazorProject(accessor));
var options = new TestOptionsManager<RazorPagesOptions>();
var options = Options.Create(new RazorPagesOptions());
var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);
// Act
@ -45,7 +46,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var templateEngine = new RazorTemplateEngine(
RazorEngine.Create(),
new FileProviderRazorProject(accessor));
var options = new TestOptionsManager<RazorPagesOptions>();
var options = Options.Create(new RazorPagesOptions());
options.Value.RootDirectory = rootDirectory;
var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);
@ -68,7 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
RazorEngine.Create(),
new FileProviderRazorProject(accessor));
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
var options = new TestOptionsManager<RazorPagesOptions>();
var options = Options.Create(new RazorPagesOptions());
options.Value.RootDirectory = "/dir1/dir2";
var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

View File

@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -487,8 +488,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
parameterBinder,
modelMetadataProvider,
tempDataFactory.Object,
new TestOptionsManager<MvcOptions>(),
new TestOptionsManager<HtmlHelperOptions>(),
Options.Create(new MvcOptions()),
Options.Create(new HtmlHelperOptions()),
Mock.Of<IPageHandlerMethodSelector>(),
razorProject,
new DiagnosticListener("Microsoft.AspNetCore"),

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
};
var viewEngineOptions = GetViewEngineOptions();
var setup = new RazorPagesRazorViewEngineOptionsSetup(
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions));
Options.Create(razorPagesOptions));
// Act
setup.Configure(viewEngineOptions);
@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var razorPagesOptions = new RazorPagesOptions();
var viewEngineOptions = GetViewEngineOptions();
var setup = new RazorPagesRazorViewEngineOptionsSetup(
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions));
Options.Create(razorPagesOptions));
// Act
setup.Configure(viewEngineOptions);
@ -78,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
};
var viewEngineOptions = GetViewEngineOptions();
var setup = new RazorPagesRazorViewEngineOptionsSetup(
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions));
Options.Create(razorPagesOptions));
// Act
setup.Configure(viewEngineOptions);
@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
};
var viewEngineOptions = GetViewEngineOptions();
var setup = new RazorPagesRazorViewEngineOptionsSetup(
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions));
Options.Create(razorPagesOptions));
// Act
setup.Configure(viewEngineOptions);
@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
{
// Arrange
var viewEngineOptions = GetViewEngineOptions();
var setup = new RazorPagesRazorViewEngineOptionsSetup(new TestOptionsManager<RazorPagesOptions>());
var setup = new RazorPagesRazorViewEngineOptionsSetup(Options.Create(new RazorPagesOptions()));
// Act
setup.Configure(viewEngineOptions);

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var project = new TestRazorProject(fileProvider);
var optionsManager = new TestOptionsManager<RazorPagesOptions>();
var optionsManager = Options.Create(new RazorPagesOptions());
optionsManager.Value.RootDirectory = "/";
var provider = new RazorProjectPageRouteModelProvider(project, optionsManager, NullLoggerFactory.Instance);
var context = new PageRouteModelProviderContext();
@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var project = new TestRazorProject(fileProvider);
var optionsManager = new TestOptionsManager<RazorPagesOptions>();
var optionsManager = Options.Create(new RazorPagesOptions());
optionsManager.Value.RootDirectory = "/";
var provider = new RazorProjectPageRouteModelProvider(project, optionsManager, NullLoggerFactory.Instance);
var context = new PageRouteModelProviderContext();
@ -97,7 +98,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var project = new TestRazorProject(fileProvider);
var optionsManager = new TestOptionsManager<RazorPagesOptions>();
var optionsManager = Options.Create(new RazorPagesOptions());
optionsManager.Value.RootDirectory = "/";
var provider = new RazorProjectPageRouteModelProvider(project, optionsManager, NullLoggerFactory.Instance);
var context = new PageRouteModelProviderContext();
@ -123,7 +124,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var project = new TestRazorProject(fileProvider);
var optionsManager = new TestOptionsManager<RazorPagesOptions>();
var optionsManager = Options.Create(new RazorPagesOptions());
optionsManager.Value.RootDirectory = "/";
var provider = new RazorProjectPageRouteModelProvider(project, optionsManager, NullLoggerFactory.Instance);
var context = new PageRouteModelProviderContext();
@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var project = new TestRazorProject(fileProvider);
var optionsManager = new TestOptionsManager<RazorPagesOptions>();
var optionsManager = Options.Create(new RazorPagesOptions());
optionsManager.Value.RootDirectory = "/Pages";
var provider = new RazorProjectPageRouteModelProvider(project, optionsManager, NullLoggerFactory.Instance);
var context = new PageRouteModelProviderContext();
@ -190,7 +191,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
var project = new TestRazorProject(fileProvider);
var optionsManager = new TestOptionsManager<RazorPagesOptions>();
var optionsManager = Options.Create(new RazorPagesOptions());
optionsManager.Value.RootDirectory = "/";
var provider = new RazorProjectPageRouteModelProvider(project, optionsManager, NullLoggerFactory.Instance);
var context = new PageRouteModelProviderContext();

View File

@ -6,6 +6,7 @@ using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_DoesNothingIfHandlerHasNoResponseCacheAttributes()
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var provider = new ResponseCacheFilterApplicationModelProvider(options);
var typeInfo = typeof(PageWithoutResponseCache).GetTypeInfo();
var context = GetApplicationProviderContext(typeInfo);
@ -49,7 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_AddsResponseCacheFilters()
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
var provider = new ResponseCacheFilterApplicationModelProvider(options);
var typeInfo = typeof(PageWithResponseCache).GetTypeInfo();
var context = GetApplicationProviderContext(typeInfo);
@ -90,7 +91,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
public void OnProvidersExecuting_ReadsCacheProfileFromOptions()
{
// Arrange
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.CacheProfiles.Add("TestCacheProfile", new CacheProfile
{
Duration = 14,

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
{
@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
new DefaultClientModelValidatorProvider(),
new DataAnnotationsClientModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null),
};

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
metadataProvider = TestModelMetadataProvider.CreateDefaultProvider();
}
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
foreach (var provider in providers)
{
options.Value.ModelBinderProviders.Add(provider);
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
metadataProvider = TestModelMetadataProvider.CreateDefaultProvider();
}
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
foreach (var provider in providers)
{
options.Value.ModelBinderProviders.Add(provider);

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
@ -23,13 +24,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
new DefaultBindingMetadataProvider(),
new DefaultValidationMetadataProvider(),
new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory),
new DataMemberRequiredBindingMetadataProvider(),
};
var compositeDetailsProvider = new DefaultCompositeMetadataDetailsProvider(detailsProviders);
return new DefaultModelMetadataProvider(compositeDetailsProvider, new TestOptionsManager<MvcOptions>());
return new DefaultModelMetadataProvider(compositeDetailsProvider, Options.Create(new MvcOptions()));
}
public static IModelMetadataProvider CreateDefaultProvider(IList<IMetadataDetailsProvider> providers)
@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
new DefaultBindingMetadataProvider(),
new DefaultValidationMetadataProvider(),
new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null),
new DataMemberRequiredBindingMetadataProvider(),
};
@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
detailsProviders.AddRange(providers);
var compositeDetailsProvider = new DefaultCompositeMetadataDetailsProvider(detailsProviders);
return new DefaultModelMetadataProvider(compositeDetailsProvider, new TestOptionsManager<MvcOptions>());
return new DefaultModelMetadataProvider(compositeDetailsProvider, Options.Create(new MvcOptions()));
}
public static IModelMetadataProvider CreateProvider(IList<IMetadataDetailsProvider> providers)
@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
var compositeDetailsProvider = new DefaultCompositeMetadataDetailsProvider(detailsProviders);
return new DefaultModelMetadataProvider(compositeDetailsProvider, new TestOptionsManager<MvcOptions>());
return new DefaultModelMetadataProvider(compositeDetailsProvider, Options.Create(new MvcOptions()));
}
private readonly TestModelMetadataDetailsProvider _detailsProvider;
@ -76,11 +77,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
new DefaultBindingMetadataProvider(),
new DefaultValidationMetadataProvider(),
new DataAnnotationsMetadataProvider(
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null),
detailsProvider
}),
new TestOptionsManager<MvcOptions>())
Options.Create(new MvcOptions()))
{
_detailsProvider = detailsProvider;
}

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
{
@ -18,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
new DefaultModelValidatorProvider(),
new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null)
};

View File

@ -1,23 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Mvc
{
public class TestOptionsManager<TOptions> : IOptions<TOptions>
where TOptions : class, new()
{
public TestOptionsManager()
: this(new TOptions())
{
}
public TestOptionsManager(TOptions value)
{
Value = value;
}
public TOptions Value { get; }
}
}

View File

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using Moq;
using Newtonsoft.Json;
using Xunit;
@ -442,7 +443,7 @@ namespace Microsoft.AspNetCore.Mvc.Test
{
new DataAnnotationsModelValidatorProvider(
new ValidationAttributeAdapterProvider(),
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
stringLocalizerFactory: null),
};

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
// Arrange
var provider = new TempDataApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { type.GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -38,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
// Arrange
var provider = new TempDataApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(TestController_OneTempDataProperty).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -61,7 +62,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
// Arrange
var provider = new TempDataApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(TestController_OneValid_OneInvalidProperty).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -78,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
// Arrange
var provider = new TempDataApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(TestController_PrivateSet).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);
@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
// Arrange
var provider = new TempDataApplicationModelProvider();
var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>());
var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions()));
var context = new ApplicationModelProviderContext(new[] { typeof(TestController_NonPrimitiveType).GetTypeInfo() });
defaultProvider.OnProvidersExecuting(context);

View File

@ -12,10 +12,10 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Mvc
private HttpContext GetHttpContext()
{
var options = new TestOptionsManager<MvcViewOptions>();
var options = Options.Create(new MvcViewOptions());
var viewExecutor = new PartialViewResultExecutor(
options,

View File

@ -565,7 +565,7 @@ namespace Microsoft.AspNetCore.Mvc
services.AddSingleton<DiagnosticSource>(diagnosticSource);
services.AddSingleton<ViewComponentInvokerCache>();
services.AddSingleton<ExpressionTextCache>();
services.AddSingleton<IOptions<MvcViewOptions>, TestOptionsManager<MvcViewOptions>>();
services.AddSingleton(Options.Create(new MvcViewOptions()));
services.AddTransient<IViewComponentHelper, DefaultViewComponentHelper>();
services.AddSingleton<IViewComponentSelector, DefaultViewComponentSelector>();
services.AddSingleton<IViewComponentDescriptorCollectionProvider, DefaultViewComponentDescriptorCollectionProvider>();

View File

@ -6,6 +6,7 @@ using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -19,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
// Arrange
var viewEngine1 = Mock.Of<IViewEngine>();
var viewEngine2 = Mock.Of<IViewEngine>();
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(viewEngine1);
optionsAccessor.Value.ViewEngines.Add(viewEngine2);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
$"empty. At least one '{typeof(IViewEngine).FullName}' is required to locate a view for rendering.";
var viewName = "test-view";
var actionContext = GetActionContext();
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
// Act & Assert
@ -58,7 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "controller/test-view" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine.Object);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -80,7 +81,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.Found(viewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine.Object);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -112,7 +113,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.Found(viewName, view3));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine1.Object);
optionsAccessor.Value.ViewEngines.Add(engine2.Object);
optionsAccessor.Value.ViewEngines.Add(engine3.Object);
@ -145,7 +146,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine1.Object);
optionsAccessor.Value.ViewEngines.Add(engine2.Object);
optionsAccessor.Value.ViewEngines.Add(engine3.Object);
@ -168,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
var expected = $"'{typeof(MvcViewOptions).FullName}.{nameof(MvcViewOptions.ViewEngines)}' must not be " +
$"empty. At least one '{typeof(IViewEngine).FullName}' is required to locate a view for rendering.";
var viewName = "test-view.cshtml";
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
// Act & Assert
@ -191,7 +192,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
engine
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.NotFound(expectedViewName, new[] { expectedViewName }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine.Object);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -216,7 +217,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
engine
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.Found(expectedViewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine.Object);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -251,7 +252,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.Found(expectedViewName, view3));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine1.Object);
optionsAccessor.Value.ViewEngines.Add(engine2.Object);
optionsAccessor.Value.ViewEngines.Add(engine3.Object);
@ -287,7 +288,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "4", "5" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine1.Object);
optionsAccessor.Value.ViewEngines.Add(engine2.Object);
optionsAccessor.Value.ViewEngines.Add(engine3.Object);
@ -308,7 +309,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
var expected = $"'{typeof(MvcViewOptions).FullName}.{nameof(MvcViewOptions.ViewEngines)}' must not be " +
$"empty. At least one '{typeof(IViewEngine).FullName}' is required to locate a view for rendering.";
var viewName = "my-partial-view";
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
// Act & AssertS
@ -326,7 +327,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "Shared/partial-view" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine.Object);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -348,7 +349,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(viewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine.Object);
var compositeViewEngine = new CompositeViewEngine(optionsAccessor);
@ -380,7 +381,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(viewName, view3));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine1.Object);
optionsAccessor.Value.ViewEngines.Add(engine2.Object);
optionsAccessor.Value.ViewEngines.Add(engine3.Object);
@ -413,7 +414,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
var optionsAccessor = Options.Create(new MvcViewOptions());
optionsAccessor.Value.ViewEngines.Add(engine1.Object);
optionsAccessor.Value.ViewEngines.Add(engine2.Object);
optionsAccessor.Value.ViewEngines.Add(engine3.Object);

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
@ -332,7 +333,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
.Returns<ActionContext, string, bool>(
(context, name, isMainPage) => ViewEngineResult.Found(name, Mock.Of<IView>()));
var options = new TestOptionsManager<MvcViewOptions>();
var options = Options.Create(new MvcViewOptions());
options.Value.ViewEngines.Add(viewEngine.Object);
var viewExecutor = new PartialViewResultExecutor(

View File

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
@ -360,7 +361,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
}
return new ViewExecutor(
new TestOptionsManager<MvcViewOptions>(),
Options.Create(new MvcViewOptions()),
new TestHttpResponseStreamWriterFactory(),
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
@ -322,7 +323,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
.Returns<ActionContext, string, bool>(
(context, name, partial) => ViewEngineResult.Found(name, Mock.Of<IView>()));
var options = new TestOptionsManager<MvcViewOptions>();
var options = Options.Create(new MvcViewOptions());
options.Value.ViewEngines.Add(viewEngine.Object);
var viewExecutor = new ViewResultExecutor(

View File

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
@ -227,7 +228,7 @@ namespace Microsoft.AspNetCore.Mvc
private HttpContext GetHttpContext()
{
var options = new TestOptionsManager<MvcViewOptions>();
var options = Options.Create(new MvcViewOptions());
var viewExecutor = new ViewResultExecutor(
options,

View File

@ -68,7 +68,7 @@ namespace System.Web.Http
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -68,7 +68,7 @@ namespace System.Web.Http
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -81,7 +81,7 @@ namespace System.Web.Http
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),

View File

@ -69,7 +69,7 @@ namespace System.Web.Http
private static IServiceProvider CreateServices()
{
var options = new TestOptionsManager<MvcOptions>();
var options = Options.Create(new MvcOptions());
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
new JsonSerializerSettings(),