// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if DNX451 using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Routing; using Microsoft.AspNet.WebUtilities; using Microsoft.Framework.OptionsModel; using Moq; using Xunit; namespace System.Web.Http { public class OkNegotiatedContentResultTest { [Fact] public async Task OkNegotiatedContentResult_SetsStatusCode() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = CreateServices(); var stream = new MemoryStream(); httpContext.Response.Body = stream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new OkNegotiatedContentResult(new Product()); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(StatusCodes.Status200OK, context.HttpContext.Response.StatusCode); } private IServiceProvider CreateServices() { var services = new Mock(MockBehavior.Strict); var options = new MvcOptions(); options.OutputFormatters.Add(new JsonOutputFormatter()); var optionsAccessor = new Mock>(); optionsAccessor.SetupGet(o => o.Options) .Returns(options); services.Setup(s => s.GetService(typeof(IOptions))) .Returns(optionsAccessor.Object); return services.Object; } private class Product { public int Id { get; set; } public string Name { get; set; } }; } } #endif