forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyValuePairModelBinderProviderTest.cs
More file actions
61 lines (52 loc) · 2.09 KB
/
Copy pathKeyValuePairModelBinderProviderTest.cs
File metadata and controls
61 lines (52 loc) · 2.09 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
// 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.Web.Http.Metadata.Providers;
using System.Web.Http.Util;
using Microsoft.TestCommon;
namespace System.Web.Http.ModelBinding.Binders
{
public class KeyValuePairModelBinderProviderTest
{
[Fact]
public void GetBinder_CorrectModelTypeAndValueProviderEntries_ReturnsBinder()
{
// Arrange
ModelBindingContext bindingContext = new ModelBindingContext
{
ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(KeyValuePair<int, string>)),
ModelName = "foo",
ValueProvider = new SimpleHttpValueProvider
{
{ "foo.key", 42 },
{ "foo.value", "someValue" }
}
};
KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider();
// Act
IModelBinder binder = binderProvider.GetBinder(null, bindingContext.ModelType);
// Assert
Assert.IsType<KeyValuePairModelBinder<int, string>>(binder);
}
[Fact]
public void GetBinder_ModelTypeIsIncorrect_ReturnsNull()
{
// Arrange
ModelBindingContext bindingContext = new ModelBindingContext
{
ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(List<int>)),
ModelName = "foo",
ValueProvider = new SimpleHttpValueProvider
{
{ "foo.key", 42 },
{ "foo.value", "someValue" }
}
};
KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider();
// Act
IModelBinder binder = binderProvider.GetBinder(null, bindingContext.ModelType);
// Assert
Assert.Null(binder);
}
}
}