diff --git a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs index f3b344cf7a..e0a137f926 100644 --- a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs @@ -12,7 +12,9 @@ using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.OptionsModel; +using Microsoft.Framework.DependencyInjection; using Moq; using Xunit; @@ -65,28 +67,19 @@ namespace System.Web.Http } } - private IServiceProvider CreateServices() + private static IServiceProvider CreateServices() { - var services = new Mock(MockBehavior.Strict); + var options = new OptionsManager(new IConfigureOptions[] { }); + options.Value.OutputFormatters.Add(new StringOutputFormatter()); + options.Value.OutputFormatters.Add(new JsonOutputFormatter()); - var options = new MvcOptions(); - options.OutputFormatters.Add(new JsonOutputFormatter()); + var services = new ServiceCollection(); + services.AddInstance(new ObjectResultExecutor( + options, + new ActionBindingContextAccessor(), + NullLoggerFactory.Instance)); - var optionsAccessor = new Mock>(); - 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))) - .Returns(optionsAccessor.Object); - - services.Setup(s => s.GetService(typeof(ILogger))) - .Returns(new Mock>().Object); - - return services.Object; + return services.BuildServiceProvider(); } } } diff --git a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs index bbec2ef5d0..af8d749d41 100644 --- a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs @@ -12,7 +12,9 @@ using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.OptionsModel; +using Microsoft.Framework.DependencyInjection; using Moq; using Xunit; @@ -65,28 +67,19 @@ namespace System.Web.Http } } - private IServiceProvider CreateServices() + private static IServiceProvider CreateServices() { - var services = new Mock(MockBehavior.Strict); + var options = new OptionsManager(new IConfigureOptions[] { }); + options.Value.OutputFormatters.Add(new StringOutputFormatter()); + options.Value.OutputFormatters.Add(new JsonOutputFormatter()); - var options = new MvcOptions(); - options.OutputFormatters.Add(new JsonOutputFormatter()); + var services = new ServiceCollection(); + services.AddInstance(new ObjectResultExecutor( + options, + new ActionBindingContextAccessor(), + NullLoggerFactory.Instance)); - var optionsAccessor = new Mock>(); - 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))) - .Returns(optionsAccessor.Object); - - services.Setup(s => s.GetService(typeof(ILogger))) - .Returns(new Mock>().Object); - - return services.Object; + return services.BuildServiceProvider(); } } } diff --git a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs index da586aff1a..f1c3614cd8 100644 --- a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs @@ -13,7 +13,9 @@ using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.OptionsModel; +using Microsoft.Framework.DependencyInjection; using Moq; using Xunit; @@ -78,28 +80,19 @@ namespace System.Web.Http } } - private IServiceProvider CreateServices() + private static IServiceProvider CreateServices() { - var services = new Mock(MockBehavior.Strict); + var options = new OptionsManager(new IConfigureOptions[] { }); + options.Value.OutputFormatters.Add(new StringOutputFormatter()); + options.Value.OutputFormatters.Add(new JsonOutputFormatter()); - var options = new MvcOptions(); - options.OutputFormatters.Add(new JsonOutputFormatter()); + var services = new ServiceCollection(); + services.AddInstance(new ObjectResultExecutor( + options, + new ActionBindingContextAccessor(), + NullLoggerFactory.Instance)); - var optionsAccessor = new Mock>(); - 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))) - .Returns(optionsAccessor.Object); - - services.Setup(s => s.GetService(typeof(ILogger))) - .Returns(new Mock>().Object); - - return services.Object; + return services.BuildServiceProvider(); } } } diff --git a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs index 7ded575482..dd7f6eafe8 100644 --- a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs @@ -12,7 +12,9 @@ using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.OptionsModel; +using Microsoft.Framework.DependencyInjection; using Moq; using Xunit; @@ -65,29 +67,19 @@ namespace System.Web.Http } } - - private IServiceProvider CreateServices() + private static IServiceProvider CreateServices() { - var services = new Mock(MockBehavior.Strict); + var options = new OptionsManager(new IConfigureOptions[] { }); + options.Value.OutputFormatters.Add(new StringOutputFormatter()); + options.Value.OutputFormatters.Add(new JsonOutputFormatter()); - var options = new MvcOptions(); - options.OutputFormatters.Add(new JsonOutputFormatter()); + var services = new ServiceCollection(); + services.AddInstance(new ObjectResultExecutor( + options, + new ActionBindingContextAccessor(), + NullLoggerFactory.Instance)); - var optionsAccessor = new Mock>(); - 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))) - .Returns(optionsAccessor.Object); - - services.Setup(s => s.GetService(typeof(ILogger))) - .Returns(new Mock>().Object); - - return services.Object; + return services.BuildServiceProvider(); } private class Product diff --git a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/project.json b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/project.json index 0567091f12..f6be08e0a8 100644 --- a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/project.json +++ b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/project.json @@ -7,6 +7,7 @@ "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Extensions.Logging.Testing": "1.0.0-*", + "Microsoft.Framework.DependencyInjection": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": {