forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOwinResponseExtensionsTests.cs
More file actions
97 lines (82 loc) · 3.57 KB
/
Copy pathOwinResponseExtensionsTests.cs
File metadata and controls
97 lines (82 loc) · 3.57 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
// 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Microsoft.TestCommon;
using Moq;
namespace System.Web.Http.Owin
{
public class OwinResponseExtensionsTests
{
[Fact]
public void DisableBuffering_IfActionIsAvailable_CallsAction()
{
// Arrange
bool bufferingDisabled = false;
Action disableBufferingAction = () => bufferingDisabled = true;
IDictionary<string, object> environment = CreateStubEnvironment(disableBufferingAction);
IOwinResponse response = CreateStubResponse(environment);
// Act
OwinResponseExtensions.DisableBuffering(response);
// Assert
Assert.True(bufferingDisabled);
}
[Fact]
public void DisableBuffering_IfResponseIsNull_Throws()
{
// Arrange
IOwinResponse response = null;
// Act & Assert
Assert.ThrowsArgumentNull(() => OwinResponseExtensions.DisableBuffering(response), "response");
}
[Fact]
public void DisableBuffering_IfEnvironmentIsNull_DoesNotThrow()
{
// Arrange
IDictionary<string, object> environment = null;
IOwinResponse response = CreateStubResponse(environment);
// Act & Assert
Assert.DoesNotThrow(() => response.DisableBuffering());
}
[Fact]
public void DisableBuffering_IfServerDisableResponseBufferingIsAbsent_DoesNotThrow()
{
// Arrange
Mock<IDictionary<string, object>> environmentMock = new Mock<IDictionary<string,object>>(MockBehavior.Strict);
IDictionary<string, object> environment = CreateStubEnvironment(null, hasDisableBufferingAction: false);
IOwinResponse response = CreateStubResponse(environment);
// Act & Assert
Assert.DoesNotThrow(() => response.DisableBuffering());
}
[Fact]
public void DisableBuffering_IfServerDisableResponseBufferingIsNotAction_DoesNotThrow()
{
// Arrange
object nonAction = new object();
IDictionary<string, object> environment = CreateStubEnvironment(nonAction);
IOwinResponse response = CreateStubResponse(environment);
// Act & Assert
Assert.DoesNotThrow(() => response.DisableBuffering());
}
private static IDictionary<string, object> CreateStubEnvironment(object disableBufferingAction)
{
return CreateStubEnvironment(disableBufferingAction, hasDisableBufferingAction: true);
}
private static IDictionary<string, object> CreateStubEnvironment(object disableBufferingAction, bool hasDisableBufferingAction)
{
Mock<IDictionary<string, object>> mock = new Mock<IDictionary<string, object>>(MockBehavior.Strict);
mock.Setup(d => d.TryGetValue("server.DisableResponseBuffering", out disableBufferingAction)).Returns(hasDisableBufferingAction);
return mock.Object;
}
private static IOwinResponse CreateStubResponse(IDictionary<string, object> environment)
{
Mock<IOwinResponse> mock = new Mock<IOwinResponse>(MockBehavior.Strict);
mock.SetupGet(r => r.Environment).Returns(environment);
return mock.Object;
}
}
}