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

Commit 41efa40

Browse files
committed
Remove TestOptionsManager
1 parent de2aef6 commit 41efa40

File tree

64 files changed

+264
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+264
-262
lines changed

test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtActionResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.AspNetCore.Testing;
1616
using Microsoft.Extensions.DependencyInjection;
1717
using Microsoft.Extensions.Logging.Abstractions;
18+
using Microsoft.Extensions.Options;
1819
using Moq;
1920
using Newtonsoft.Json;
2021
using Xunit;
@@ -271,7 +272,7 @@ private static Mock<IOutputFormatter> CreateMockFormatter()
271272

272273
private static IServiceProvider CreateServices(Mock<IOutputFormatter> formatter)
273274
{
274-
var options = new TestOptionsManager<MvcOptions>();
275+
var options = Options.Create(new MvcOptions());
275276
options.Value.OutputFormatters.Add(formatter.Object);
276277
var services = new ServiceCollection();
277278
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(

test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtRouteResultTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Buffers;
65
using System.Collections.Generic;
7-
using System.IO;
86
using System.Threading.Tasks;
97
using Microsoft.AspNetCore.Http;
108
using Microsoft.AspNetCore.Mvc.Abstractions;
119
using Microsoft.AspNetCore.Mvc.Formatters;
1210
using Microsoft.AspNetCore.Mvc.Infrastructure;
13-
using Microsoft.AspNetCore.Mvc.Internal;
1411
using Microsoft.AspNetCore.Routing;
1512
using Microsoft.AspNetCore.Testing;
1613
using Microsoft.Extensions.DependencyInjection;
1714
using Microsoft.Extensions.Logging.Abstractions;
15+
using Microsoft.Extensions.Options;
1816
using Moq;
19-
using Newtonsoft.Json;
2017
using Xunit;
2118

2219
namespace Microsoft.AspNetCore.Mvc
@@ -180,7 +177,7 @@ private static Mock<IOutputFormatter> CreateMockFormatter()
180177

181178
private static IServiceProvider CreateServices(Mock<IOutputFormatter> formatter)
182179
{
183-
var options = new TestOptionsManager<MvcOptions>();
180+
var options = Options.Create(new MvcOptions());
184181
options.Value.OutputFormatters.Add(formatter.Object);
185182
var services = new ServiceCollection();
186183
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(

test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.AspNetCore.Routing;
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.Extensions.Logging.Abstractions;
16+
using Microsoft.Extensions.Options;
1617
using Moq;
1718
using Newtonsoft.Json;
1819
using Xunit;
@@ -136,7 +137,7 @@ private static Mock<IOutputFormatter> CreateMockFormatter()
136137

137138
private static IServiceProvider CreateServices(Mock<IOutputFormatter> formatter)
138139
{
139-
var options = new TestOptionsManager<MvcOptions>();
140+
var options = Options.Create(new MvcOptions());
140141
options.Value.OutputFormatters.Add(formatter.Object);
141142
var services = new ServiceCollection();
142143
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(

test/Microsoft.AspNetCore.Mvc.Core.Test/ControllerBaseTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.AspNetCore.Mvc.TestCommon;
1919
using Microsoft.AspNetCore.Routing;
2020
using Microsoft.AspNetCore.Testing;
21+
using Microsoft.Extensions.Options;
2122
using Microsoft.Net.Http.Headers;
2223
using Moq;
2324
using Xunit;
@@ -2837,7 +2838,7 @@ private static ControllerBase GetController(IModelBinder binder, IValueProvider
28372838
{
28382839
new DataAnnotationsModelValidatorProvider(
28392840
new ValidationAttributeAdapterProvider(),
2840-
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(),
2841+
Options.Create(new MvcDataAnnotationsLocalizationOptions()),
28412842
stringLocalizerFactory: null),
28422843
};
28432844

test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtActionResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.AspNetCore.Testing;
1616
using Microsoft.Extensions.DependencyInjection;
1717
using Microsoft.Extensions.Logging.Abstractions;
18+
using Microsoft.Extensions.Options;
1819
using Moq;
1920
using Newtonsoft.Json;
2021
using Xunit;
@@ -89,7 +90,7 @@ private static HttpContext GetHttpContext()
8990

9091
private static IServiceProvider CreateServices()
9192
{
92-
var options = new TestOptionsManager<MvcOptions>();
93+
var options = Options.Create(new MvcOptions());
9394
options.Value.OutputFormatters.Add(new StringOutputFormatter());
9495
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
9596
new JsonSerializerSettings(),

test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtRouteResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.AspNetCore.Testing;
1616
using Microsoft.Extensions.DependencyInjection;
1717
using Microsoft.Extensions.Logging.Abstractions;
18+
using Microsoft.Extensions.Options;
1819
using Moq;
1920
using Newtonsoft.Json;
2021
using Xunit;
@@ -104,7 +105,7 @@ private static HttpContext GetHttpContext()
104105

105106
private static IServiceProvider CreateServices()
106107
{
107-
var options = new TestOptionsManager<MvcOptions>();
108+
var options = Options.Create(new MvcOptions());
108109
options.Value.OutputFormatters.Add(new StringOutputFormatter());
109110
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
110111
new JsonSerializerSettings(),

test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.AspNetCore.Routing;
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.Extensions.Logging.Abstractions;
16+
using Microsoft.Extensions.Options;
1617
using Moq;
1718
using Newtonsoft.Json;
1819
using Xunit;
@@ -90,7 +91,7 @@ private static HttpContext GetHttpContext()
9091

9192
private static IServiceProvider CreateServices()
9293
{
93-
var options = new TestOptionsManager<MvcOptions>();
94+
var options = Options.Create(new MvcOptions());
9495
options.Value.OutputFormatters.Add(new StringOutputFormatter());
9596
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
9697
new JsonSerializerSettings(),

test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatFilterTest.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void FormatFilter_ContextContainsFormat_Custom(
120120
var resultExecutingContext = mockObjects.CreateResultExecutingContext();
121121
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { });
122122

123-
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
123+
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
124124
format,
125125
MediaTypeHeaderValue.Parse(contentType));
126126

@@ -203,7 +203,7 @@ public void FormatFilter_LessSpecificThan_Produces()
203203
var mockObjects = new MockObjects("xml", FormatSource.RouteData);
204204
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { produces });
205205

206-
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
206+
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
207207
"xml",
208208
MediaTypeHeaderValue.Parse("application/xml"));
209209

@@ -224,7 +224,7 @@ public void FormatFilter_MoreSpecificThan_Produces()
224224
var mockObjects = new MockObjects("xml", FormatSource.RouteData);
225225
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { produces });
226226

227-
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
227+
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
228228
"xml",
229229
MediaTypeHeaderValue.Parse("application/xml;version=1"));
230230

@@ -250,7 +250,7 @@ public void FormatFilter_ContextContainsFormat_ContainsProducesFilter_Conflictin
250250
var mockObjects = new MockObjects(format, place);
251251
var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { produces });
252252

253-
mockObjects.Options.FormatterMappings.SetMediaTypeMappingForFormat(
253+
mockObjects.MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
254254
"xml",
255255
MediaTypeHeaderValue.Parse("application/xml"));
256256

@@ -374,10 +374,9 @@ public void FormatFilter_ExplicitContentType_SetOnResponse_TakesPrecedence()
374374
Assert.Empty(result.ContentTypes);
375375
}
376376

377-
378377
private class MockObjects
379378
{
380-
public MvcOptions Options { get; private set; }
379+
public MvcOptions MvcOptions { get; private set; }
381380
public HttpContext MockHttpContext { get; private set; }
382381
public ActionContext MockActionContext { get; private set; }
383382

@@ -442,20 +441,20 @@ private void Initialize(
442441
string format = null,
443442
FormatSource? place = null)
444443
{
445-
OptionsManager = new TestOptionsManager<MvcOptions>();
444+
OptionsManager = Options.Create(new MvcOptions());
446445

447446
// Setup options on mock service provider
448-
Options = OptionsManager.Value;
447+
MvcOptions = OptionsManager.Value;
449448

450449
// Set up default output formatters.
451-
Options.OutputFormatters.Add(new HttpNoContentOutputFormatter());
452-
Options.OutputFormatters.Add(new StringOutputFormatter());
453-
Options.OutputFormatters.Add(new JsonOutputFormatter(
450+
MvcOptions.OutputFormatters.Add(new HttpNoContentOutputFormatter());
451+
MvcOptions.OutputFormatters.Add(new StringOutputFormatter());
452+
MvcOptions.OutputFormatters.Add(new JsonOutputFormatter(
454453
new JsonSerializerSettings(),
455454
ArrayPool<char>.Shared));
456455

457456
// Set up default mapping for json extensions to content type
458-
Options.FormatterMappings.SetMediaTypeMappingForFormat(
457+
MvcOptions.FormatterMappings.SetMediaTypeMappingForFormat(
459458
"json",
460459
MediaTypeHeaderValue.Parse("application/json"));
461460

test/Microsoft.AspNetCore.Mvc.Core.Test/HttpNotFoundObjectResultTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.AspNetCore.Mvc.Internal;
1212
using Microsoft.Extensions.DependencyInjection;
1313
using Microsoft.Extensions.Logging.Abstractions;
14+
using Microsoft.Extensions.Options;
1415
using Newtonsoft.Json;
1516
using Xunit;
1617

@@ -69,7 +70,7 @@ private static HttpContext GetHttpContext()
6970

7071
private static IServiceProvider CreateServices()
7172
{
72-
var options = new TestOptionsManager<MvcOptions>();
73+
var options = Options.Create(new MvcOptions());
7374
options.Value.OutputFormatters.Add(new StringOutputFormatter());
7475
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
7576
new JsonSerializerSettings(),

test/Microsoft.AspNetCore.Mvc.Core.Test/HttpOkObjectResultTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.AspNetCore.Routing;
1313
using Microsoft.Extensions.DependencyInjection;
1414
using Microsoft.Extensions.Logging.Abstractions;
15+
using Microsoft.Extensions.Options;
1516
using Newtonsoft.Json;
1617
using Xunit;
1718

@@ -70,7 +71,7 @@ public async Task HttpOkObjectResult_SetsStatusCode(object value)
7071

7172
private static IServiceProvider CreateServices()
7273
{
73-
var options = new TestOptionsManager<MvcOptions>();
74+
var options = Options.Create(new MvcOptions());
7475
options.Value.OutputFormatters.Add(new StringOutputFormatter());
7576
options.Value.OutputFormatters.Add(new JsonOutputFormatter(
7677
new JsonSerializerSettings(),

test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/ObjectResultExecutorTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public void SelectFormatter_WithAcceptHeader_UsesFallback()
314314
public void SelectFormatter_WithAcceptHeaderAndReturnHttpNotAcceptable_DoesNotUseFallback()
315315
{
316316
// Arrange
317-
var options = new TestOptionsManager<MvcOptions>();
317+
var options = Options.Create(new MvcOptions());
318318
options.Value.ReturnHttpNotAcceptable = true;
319319

320320
var executor = CreateExecutor(options);
@@ -467,7 +467,7 @@ public async Task ExecuteAsync_NoFormatterFound_Returns406()
467467
public async Task ExecuteAsync_FallsBackOnFormattersInOptions()
468468
{
469469
// Arrange
470-
var options = new TestOptionsManager<MvcOptions>();
470+
var options = Options.Create(new MvcOptions());
471471
options.Value.OutputFormatters.Add(new TestJsonOutputFormatter());
472472

473473
var executor = CreateExecutor(options: options);
@@ -558,7 +558,7 @@ public async Task ExecuteAsync_SelectDefaultFormatter_OnAllMediaRangeAcceptHeade
558558
string expectedContentType)
559559
{
560560
// Arrange
561-
var options = new TestOptionsManager<MvcOptions>();
561+
var options = Options.Create(new MvcOptions());
562562
options.Value.RespectBrowserAcceptHeader = false;
563563

564564
var executor = CreateExecutor(options: options);
@@ -595,7 +595,7 @@ public async Task ObjectResult_PerformsContentNegotiation_OnAllMediaRangeAcceptH
595595
string expectedContentType)
596596
{
597597
// Arrange
598-
var options = new TestOptionsManager<MvcOptions>();
598+
var options = Options.Create(new MvcOptions());
599599
options.Value.RespectBrowserAcceptHeader = true;
600600

601601
var executor = CreateExecutor(options: options);
@@ -640,15 +640,15 @@ private static HttpContext GetHttpContext()
640640
private static TestObjectResultExecutor CreateExecutor(IOptions<MvcOptions> options = null)
641641
{
642642
return new TestObjectResultExecutor(
643-
options ?? new TestOptionsManager<MvcOptions>(),
643+
options ?? Options.Create(new MvcOptions()),
644644
new TestHttpResponseStreamWriterFactory(),
645645
NullLoggerFactory.Instance);
646646
}
647647

648648
private static CustomObjectResultExecutor CreateCustomObjectResultExecutor()
649649
{
650650
return new CustomObjectResultExecutor(
651-
new TestOptionsManager<MvcOptions>(),
651+
Options.Create(new MvcOptions()),
652652
new TestHttpResponseStreamWriterFactory(),
653653
NullLoggerFactory.Instance);
654654
}

test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ActionSelectorTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Extensions.Logging;
1818
using Microsoft.Extensions.Logging.Abstractions;
1919
using Microsoft.Extensions.Logging.Testing;
20+
using Microsoft.Extensions.Options;
2021
using Moq;
2122
using Xunit;
2223

@@ -785,7 +786,7 @@ private ControllerActionDescriptorProvider GetActionDescriptorProvider()
785786
.Select(t => t.GetTypeInfo())
786787
.ToList();
787788

788-
var options = new TestOptionsManager<MvcOptions>();
789+
var options = Options.Create(new MvcOptions());
789790

790791
var manager = GetApplicationManager(controllerTypes);
791792

test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ApiBehaviorApplicationModelProviderTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void OnProvidersExecuting_DoesNotAddModelStateInvalidFilterToController_I
3636
{
3737
// Arrange
3838
var context = GetContext(typeof(TestApiController));
39-
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
39+
var options = Options.Create(new ApiBehaviorOptions
4040
{
4141
SuppressModelStateInvalidFilter = true,
4242
});
@@ -79,7 +79,7 @@ public void OnProvidersExecuting_SkipsAddingFilterToActionIfFeatureIsDisabledUsi
7979
{
8080
// Arrange
8181
var context = GetContext(typeof(SimpleController));
82-
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
82+
var options = Options.Create(new ApiBehaviorOptions
8383
{
8484
SuppressModelStateInvalidFilter = true,
8585
});
@@ -107,7 +107,7 @@ public void OnProvidersExecuting_MakesControllerVisibleInApiExplorer_IfItIsAnnot
107107
{
108108
// Arrange
109109
var context = GetContext(typeof(TestApiController));
110-
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
110+
var options = Options.Create(new ApiBehaviorOptions
111111
{
112112
SuppressModelStateInvalidFilter = true,
113113
});
@@ -128,7 +128,7 @@ public void OnProvidersExecuting_DoesNotModifyVisibilityInApiExplorer_IfValueIsA
128128
// Arrange
129129
var context = GetContext(typeof(TestApiController));
130130
context.Result.Controllers[0].ApiExplorer.IsVisible = false;
131-
var options = new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
131+
var options = Options.Create(new ApiBehaviorOptions
132132
{
133133
SuppressModelStateInvalidFilter = true,
134134
});
@@ -401,7 +401,7 @@ private static ApiBehaviorApplicationModelProvider GetProvider(
401401
IOptions<ApiBehaviorOptions> options = null,
402402
IModelMetadataProvider modelMetadataProvider = null)
403403
{
404-
options = options ?? new TestOptionsManager<ApiBehaviorOptions>(new ApiBehaviorOptions
404+
options = options ?? Options.Create(new ApiBehaviorOptions
405405
{
406406
InvalidModelStateResponseFactory = _ => null,
407407
});
@@ -414,7 +414,7 @@ private static ApiBehaviorApplicationModelProvider GetProvider(
414414
private static ApplicationModelProviderContext GetContext(Type type)
415415
{
416416
var context = new ApplicationModelProviderContext(new[] { type.GetTypeInfo() });
417-
new DefaultApplicationModelProvider(new TestOptionsManager<MvcOptions>()).OnProvidersExecuting(context);
417+
new DefaultApplicationModelProvider(Options.Create(new MvcOptions())).OnProvidersExecuting(context);
418418
return context;
419419
}
420420

0 commit comments

Comments
 (0)