Fix test breaks in WebAPI shim

This hasn't hit universe yet, but these needed to change with the
ObjectResult refactor
This commit is contained in:
Ryan Nowak 2015-10-19 18:00:02 -07:00
parent 82cba7c0b2
commit 6985015e2d
5 changed files with 49 additions and 77 deletions

View File

@ -12,7 +12,9 @@ using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.OptionsModel;
using Microsoft.Framework.DependencyInjection;
using Moq; using Moq;
using Xunit; using Xunit;
@ -65,28 +67,19 @@ namespace System.Web.Http
} }
} }
private IServiceProvider CreateServices() private static IServiceProvider CreateServices()
{ {
var services = new Mock<IServiceProvider>(MockBehavior.Strict); var options = new OptionsManager<MvcOptions>(new IConfigureOptions<MvcOptions>[] { });
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var options = new MvcOptions(); var services = new ServiceCollection();
options.OutputFormatters.Add(new JsonOutputFormatter()); services.AddInstance(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
NullLoggerFactory.Instance));
var optionsAccessor = new Mock<IOptions<MvcOptions>>(); return services.BuildServiceProvider();
optionsAccessor.SetupGet(o => o.Value)
.Returns(options);
var actionBindingContext = new ActionBindingContext { OutputFormatters = options.OutputFormatters };
services.Setup(o => o.GetService(typeof(IActionBindingContextAccessor)))
.Returns(new ActionBindingContextAccessor() { ActionBindingContext = actionBindingContext });
services.Setup(s => s.GetService(typeof(IOptions<MvcOptions>)))
.Returns(optionsAccessor.Object);
services.Setup(s => s.GetService(typeof(ILogger<ObjectResult>)))
.Returns(new Mock<ILogger<ObjectResult>>().Object);
return services.Object;
} }
} }
} }

View File

@ -12,7 +12,9 @@ using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.OptionsModel;
using Microsoft.Framework.DependencyInjection;
using Moq; using Moq;
using Xunit; using Xunit;
@ -65,28 +67,19 @@ namespace System.Web.Http
} }
} }
private IServiceProvider CreateServices() private static IServiceProvider CreateServices()
{ {
var services = new Mock<IServiceProvider>(MockBehavior.Strict); var options = new OptionsManager<MvcOptions>(new IConfigureOptions<MvcOptions>[] { });
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var options = new MvcOptions(); var services = new ServiceCollection();
options.OutputFormatters.Add(new JsonOutputFormatter()); services.AddInstance(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
NullLoggerFactory.Instance));
var optionsAccessor = new Mock<IOptions<MvcOptions>>(); return services.BuildServiceProvider();
optionsAccessor.SetupGet(o => o.Value)
.Returns(options);
var actionBindingContext = new ActionBindingContext { OutputFormatters = options.OutputFormatters };
services.Setup(o => o.GetService(typeof(IActionBindingContextAccessor)))
.Returns(new ActionBindingContextAccessor() { ActionBindingContext = actionBindingContext });
services.Setup(s => s.GetService(typeof(IOptions<MvcOptions>)))
.Returns(optionsAccessor.Object);
services.Setup(s => s.GetService(typeof(ILogger<ObjectResult>)))
.Returns(new Mock<ILogger<ObjectResult>>().Object);
return services.Object;
} }
} }
} }

View File

@ -13,7 +13,9 @@ using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.OptionsModel;
using Microsoft.Framework.DependencyInjection;
using Moq; using Moq;
using Xunit; using Xunit;
@ -78,28 +80,19 @@ namespace System.Web.Http
} }
} }
private IServiceProvider CreateServices() private static IServiceProvider CreateServices()
{ {
var services = new Mock<IServiceProvider>(MockBehavior.Strict); var options = new OptionsManager<MvcOptions>(new IConfigureOptions<MvcOptions>[] { });
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var options = new MvcOptions(); var services = new ServiceCollection();
options.OutputFormatters.Add(new JsonOutputFormatter()); services.AddInstance(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
NullLoggerFactory.Instance));
var optionsAccessor = new Mock<IOptions<MvcOptions>>(); return services.BuildServiceProvider();
optionsAccessor.SetupGet(o => o.Value)
.Returns(options);
var actionBindingContext = new ActionBindingContext { OutputFormatters = options.OutputFormatters };
services.Setup(o => o.GetService(typeof(IActionBindingContextAccessor)))
.Returns(new ActionBindingContextAccessor() { ActionBindingContext = actionBindingContext });
services.Setup(s => s.GetService(typeof(IOptions<MvcOptions>)))
.Returns(optionsAccessor.Object);
services.Setup(s => s.GetService(typeof(ILogger<ObjectResult>)))
.Returns(new Mock<ILogger<ObjectResult>>().Object);
return services.Object;
} }
} }
} }

View File

@ -12,7 +12,9 @@ using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.OptionsModel;
using Microsoft.Framework.DependencyInjection;
using Moq; using Moq;
using Xunit; using Xunit;
@ -65,29 +67,19 @@ namespace System.Web.Http
} }
} }
private static IServiceProvider CreateServices()
private IServiceProvider CreateServices()
{ {
var services = new Mock<IServiceProvider>(MockBehavior.Strict); var options = new OptionsManager<MvcOptions>(new IConfigureOptions<MvcOptions>[] { });
options.Value.OutputFormatters.Add(new StringOutputFormatter());
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var options = new MvcOptions(); var services = new ServiceCollection();
options.OutputFormatters.Add(new JsonOutputFormatter()); services.AddInstance(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
NullLoggerFactory.Instance));
var optionsAccessor = new Mock<IOptions<MvcOptions>>(); return services.BuildServiceProvider();
optionsAccessor.SetupGet(o => o.Value)
.Returns(options);
var actionBindingContext = new ActionBindingContext { OutputFormatters = options.OutputFormatters };
services.Setup(o => o.GetService(typeof(IActionBindingContextAccessor)))
.Returns(new ActionBindingContextAccessor() { ActionBindingContext = actionBindingContext });
services.Setup(s => s.GetService(typeof(IOptions<MvcOptions>)))
.Returns(optionsAccessor.Object);
services.Setup(s => s.GetService(typeof(ILogger<ObjectResult>)))
.Returns(new Mock<ILogger<ObjectResult>>().Object);
return services.Object;
} }
private class Product private class Product

View File

@ -7,6 +7,7 @@
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-*", "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"Microsoft.Extensions.Logging.Testing": "1.0.0-*", "Microsoft.Extensions.Logging.Testing": "1.0.0-*",
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*" "xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"commands": { "commands": {