forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionLoggerContextTests.cs
More file actions
131 lines (106 loc) · 4.42 KB
/
Copy pathExceptionLoggerContextTests.cs
File metadata and controls
131 lines (106 loc) · 4.42 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// 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 System.Net.Http;
using System.Web.Http.Controllers;
using Microsoft.TestCommon;
namespace System.Web.Http.ExceptionHandling
{
public class ExceptionLoggerContextTests
{
[Fact]
public void Constructor_IfExceptionContextIsNull_Throws()
{
// Arrange
ExceptionContext context = null;
// Act & Assert
Assert.ThrowsArgumentNull(() => CreateProductUnderTest(context), "exceptionContext");
}
[Fact]
public void ExceptionContextGet_ReturnsSpecifiedInstance()
{
// Arrange
ExceptionContext expectedContext = CreateMinimalValidContext();
ExceptionLoggerContext product = CreateProductUnderTest(expectedContext);
// Act
ExceptionContext context = product.ExceptionContext;
// Assert
Assert.Same(expectedContext, context);
}
[Fact]
public void ExceptionGet_ReturnsSpecifiedInstance()
{
// Arrange
Exception expectedException = new InvalidOperationException();
ExceptionContext context = new ExceptionContext(expectedException, ExceptionCatchBlocks.HttpServer);
ExceptionLoggerContext product = CreateProductUnderTest(context);
// Act
Exception exception = product.Exception;
// Assert
Assert.Same(expectedException, exception);
}
[Fact]
public void CatchBlockGet_ReturnsSpecifiedInstance()
{
// Arrange
ExceptionContextCatchBlock expectedCatchBlock = new ExceptionContextCatchBlock("IgnoreName", false, false);
ExceptionContext context = new ExceptionContext(new Exception(), expectedCatchBlock);
ExceptionLoggerContext product = CreateProductUnderTest(context);
// Act
ExceptionContextCatchBlock catchBlock = product.CatchBlock;
// Assert
Assert.Same(expectedCatchBlock, catchBlock);
}
[Fact]
public void RequestGet_ReturnsSpecifiedInstance()
{
// Arrange
using (HttpRequestMessage expectedRequest = new HttpRequestMessage())
{
ExceptionContext context = new ExceptionContext(new Exception(), ExceptionCatchBlocks.HttpServer, expectedRequest);
ExceptionLoggerContext product = CreateProductUnderTest(context);
// Act
HttpRequestMessage request = product.Request;
// Assert
Assert.Same(expectedRequest, request);
}
}
[Fact]
public void RequestContextGet_ReturnsSpecifiedInstance()
{
// Arrange
HttpRequestContext expectedRequestContext = new HttpRequestContext();
ExceptionContext context = CreateMinimalValidContext(expectedRequestContext);
ExceptionLoggerContext product = CreateProductUnderTest(context);
// Act
HttpRequestContext requestContext = product.RequestContext;
// Assert
Assert.Same(expectedRequestContext, requestContext);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CallsHandlerGet_ReturnsCatchBlockCallsHandler(bool expectedCallsHandler)
{
// Arrange
ExceptionContext context = new ExceptionContext(new Exception(),
new ExceptionContextCatchBlock("IgnoreName", isTopLevel: false,
callsHandler: expectedCallsHandler));
ExceptionLoggerContext product = CreateProductUnderTest(context);
// Act
bool callsHandler = product.CallsHandler;
// Assert
Assert.Equal(expectedCallsHandler, callsHandler);
}
private static ExceptionContext CreateMinimalValidContext(HttpRequestContext context = null)
{
return new ExceptionContext(new Exception(), ExceptionCatchBlocks.HttpServer)
{
RequestContext = context,
};
}
private static ExceptionLoggerContext CreateProductUnderTest(ExceptionContext exceptionContext)
{
return new ExceptionLoggerContext(exceptionContext);
}
}
}