forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpParameterBindingExtensionsTest.cs
More file actions
119 lines (100 loc) · 4.84 KB
/
Copy pathHttpParameterBindingExtensionsTest.cs
File metadata and controls
119 lines (100 loc) · 4.84 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
// 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.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Internal;
using System.Web.Http.ValueProviders;
using System.Web.Http.ValueProviders.Providers;
using Microsoft.TestCommon;
using Moq;
namespace System.Web.Http.ModelBinding
{
public class HttpParameterBindingExtensionsTest
{
[Fact]
public void WillReadUri_Throws_With_Null_ParameterBinding()
{
// Arrange
HttpParameterBinding binding = null;
// Act & Assert
Assert.ThrowsArgumentNull(() => binding.WillReadUri(), "parameterBinding");
}
[Fact]
public void WillReadUri_Returns_True_For_IValueProviderParameterBinding_Containing_Only_Standard_Uri_ValueProviders()
{
// Arrange
Mock<HttpParameterDescriptor> descriptorMock = new Mock<HttpParameterDescriptor>();
HttpParameterBinding bindingMock = new HttpValueProviderParameterBindingTestDouble(
descriptorMock.Object,
new List<ValueProviderFactory>()
{
new QueryStringValueProviderFactory(),
new RouteDataValueProviderFactory()
});
// Act
bool result = bindingMock.WillReadUri();
// Assert
Assert.True(result);
}
[Fact]
public void WillReadUri_Returns_False_For_IValueProviderParameterBinding_Containing_Non_Uri_ValueProviders()
{
// Arrange
Mock<HttpParameterDescriptor> descriptorMock = new Mock<HttpParameterDescriptor>();
Mock<ValueProviderFactory> valueProviderMock = new Mock<ValueProviderFactory>();
HttpParameterBinding bindingMock = new HttpValueProviderParameterBindingTestDouble(
descriptorMock.Object,
new List<ValueProviderFactory>()
{
new QueryStringValueProviderFactory(),
new RouteDataValueProviderFactory(),
valueProviderMock.Object,
});
// Act
bool result = bindingMock.WillReadUri();
// Assert
Assert.False(result);
}
[Fact]
public void WillReadUri_Returns_False_For_IValueProviderParameterBinding_Containing_No_ValueProviders()
{
// Arrange
Mock<HttpParameterDescriptor> descriptorMock = new Mock<HttpParameterDescriptor>();
HttpParameterBinding bindingMock = new HttpValueProviderParameterBindingTestDouble(
descriptorMock.Object,
new List<ValueProviderFactory>());
// Act
bool result = bindingMock.WillReadUri();
// Assert
Assert.False(result);
}
[Fact]
public void WillReadUri_Returns_False_For_HttpParameterBinding_Not_Implementing_IValueProviderParameterBinding()
{
// Arrange
Mock<HttpParameterDescriptor> descriptorMock = new Mock<HttpParameterDescriptor>();
Mock<HttpParameterBinding> bindingMock = new Mock<HttpParameterBinding>(descriptorMock.Object);
// Act
bool result = bindingMock.Object.WillReadUri();
// Assert
Assert.False(result);
}
class HttpValueProviderParameterBindingTestDouble : HttpParameterBinding, IValueProviderParameterBinding
{
public IEnumerable<ValueProviderFactory> Factories { get; set; }
public HttpValueProviderParameterBindingTestDouble(HttpParameterDescriptor descriptor, IEnumerable<ValueProviderFactory> factories) : base(descriptor)
{
Factories = factories;
}
public override Task ExecuteBindingAsync(Metadata.ModelMetadataProvider metadataProvider, HttpActionContext actionContext, Threading.CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public IEnumerable<ValueProviderFactory> ValueProviderFactories
{
get { return Factories; }
}
}
}
}