[Fixes #1156] EmptyResult should not set status code (or do anything for that matter)
This commit is contained in:
parent
96318dcbc2
commit
f2dab5eaa7
|
|
@ -1,10 +1,12 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an <see cref="ActionResult"/> that when executed will
|
||||||
|
/// do nothing.
|
||||||
|
/// </summary>
|
||||||
public class EmptyResult : ActionResult
|
public class EmptyResult : ActionResult
|
||||||
{
|
{
|
||||||
private static readonly EmptyResult _singleton = new EmptyResult();
|
private static readonly EmptyResult _singleton = new EmptyResult();
|
||||||
|
|
@ -14,9 +16,9 @@ namespace Microsoft.AspNet.Mvc
|
||||||
get { return _singleton; }
|
get { return _singleton; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void ExecuteResult([NotNull] ActionContext context)
|
public override void ExecuteResult([NotNull] ActionContext context)
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.StatusCode = 204;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
using Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.AspNet.Routing;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
public class EmptyResultTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void EmptyResult_ExecuteResult_IsANoOp()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var emptyResult = new EmptyResult();
|
||||||
|
|
||||||
|
var httpContext = new Mock<HttpContext>(MockBehavior.Strict);
|
||||||
|
var routeData = new RouteData();
|
||||||
|
var actionDescriptor = new ActionDescriptor();
|
||||||
|
|
||||||
|
var context = new ActionContext(httpContext.Object, routeData, actionDescriptor);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.DoesNotThrow(() => emptyResult.ExecuteResult(context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue