1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using Moq;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Mvc.Test
{
public class HandleErrorInfoTest
{
[Fact]
public void ConstructorSetsProperties()
{
// Arrange
Exception exception = new Exception();
string controller = "SomeController";
string action = "SomeAction";
// Act
HandleErrorInfo viewData = new HandleErrorInfo(exception, controller, action);
// Assert
Assert.Same(exception, viewData.Exception);
Assert.Equal(controller, viewData.ControllerName);
Assert.Equal(action, viewData.ActionName);
}
[Fact]
public void ConstructorWithEmptyActionThrows()
{
Assert.ThrowsArgumentNullOrEmpty(
delegate { new HandleErrorInfo(new Exception(), "SomeController", String.Empty); }, "actionName");
}
[Fact]
public void ConstructorWithEmptyControllerThrows()
{
Assert.ThrowsArgumentNullOrEmpty(
delegate { new HandleErrorInfo(new Exception(), String.Empty, "SomeAction"); }, "controllerName");
}
[Fact]
public void ConstructorWithNullActionThrows()
{
Assert.ThrowsArgumentNullOrEmpty(
delegate { new HandleErrorInfo(new Exception(), "SomeController", null /* action */); }, "actionName");
}
[Fact]
public void ConstructorWithNullControllerThrows()
{
Assert.ThrowsArgumentNullOrEmpty(
delegate { new HandleErrorInfo(new Exception(), null /* controller */, "SomeAction"); }, "controllerName");
}
[Fact]
public void ConstructorWithNullExceptionThrows()
{
Assert.ThrowsArgumentNull(
delegate { new HandleErrorInfo(null /* exception */, "SomeController", "SomeAction"); }, "exception");
}
[Fact]
public void ErrorHandlingDoesNotFireIfCalledInChildAction()
{
// Arrange
HandleErrorAttribute attr = new HandleErrorAttribute();
Mock<ExceptionContext> context = new Mock<ExceptionContext>();
context.Setup(c => c.IsChildAction).Returns(true);
// Act
attr.OnException(context.Object);
// Assert
Assert.IsType<EmptyResult>(context.Object.Result);
}
}
}
|