blob: 581bbf1e19f423381179843411bb4b769b95f91d (
plain)
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
79
80
81
82
83
84
85
86
87
|
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Mvc.Test
{
public class AsyncTimeoutAttributeTest
{
[Fact]
public void ConstructorThrowsIfDurationIsOutOfRange()
{
// Act & assert
Assert.ThrowsArgumentOutOfRange(() => new AsyncTimeoutAttribute(-1000), "duration",
@"The timeout value must be non-negative or Timeout.Infinite.");
}
[Fact]
public void DurationProperty()
{
// Act
AsyncTimeoutAttribute attr = new AsyncTimeoutAttribute(45);
// Assert
Assert.Equal(45, attr.Duration);
}
[Fact]
public void OnActionExecutingSetsTimeoutPropertyOnController()
{
// Arrange
AsyncTimeoutAttribute attr = new AsyncTimeoutAttribute(45);
MyAsyncController controller = new MyAsyncController();
controller.AsyncManager.Timeout = 0;
ActionExecutingContext filterContext = new ActionExecutingContext()
{
Controller = controller
};
// Act
attr.OnActionExecuting(filterContext);
// Assert
Assert.Equal(45, controller.AsyncManager.Timeout);
}
[Fact]
public void OnActionExecutingThrowsIfControllerIsNotAsyncManagerContainer()
{
// Arrange
AsyncTimeoutAttribute attr = new AsyncTimeoutAttribute(45);
ActionExecutingContext filterContext = new ActionExecutingContext()
{
Controller = new MyController()
};
// Act & assert
Assert.Throws<InvalidOperationException>(
delegate { attr.OnActionExecuting(filterContext); },
@"The controller of type 'System.Web.Mvc.Test.AsyncTimeoutAttributeTest+MyController' must subclass AsyncController or implement the IAsyncManagerContainer interface.");
}
[Fact]
public void OnActionExecutingThrowsIfFilterContextIsNull()
{
// Arrange
AsyncTimeoutAttribute attr = new AsyncTimeoutAttribute(45);
// Act & assert
Assert.ThrowsArgumentNull(
delegate { attr.OnActionExecuting(null); }, "filterContext");
}
private class MyController : ControllerBase
{
protected override void ExecuteCore()
{
throw new NotImplementedException();
}
}
private class MyAsyncController : AsyncController
{
}
}
}
|