forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandleErrorInfoTest.cs
More file actions
78 lines (66 loc) · 2.55 KB
/
Copy pathHandleErrorInfoTest.cs
File metadata and controls
78 lines (66 loc) · 2.55 KB
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) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.TestCommon;
using Moq;
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);
}
}
}