Skip to content

Commit 03a9a81

Browse files
committed
add NullableInt test
1 parent 035d244 commit 03a9a81

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/Mvc/Mvc.Core/test/ModelBinding/Binders/CollectionModelBinderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public async Task BindSimpleCollection_RawValueWithNull_ReturnsListWithoutNull()
215215
{ "someName", "420" },
216216
};
217217
var context = GetModelBindingContext(valueProvider);
218-
var valueProviderResult = new ValueProviderResult(new[] { null, "42", "100", null, "200" });
218+
var valueProviderResult = new ValueProviderResult(new[] { null, "42", "", "100", null, "200" });
219219

220220
// Act
221221
var boundCollection = await binder.BindSimpleCollection(context, valueProviderResult);

src/Mvc/test/Mvc.FunctionalTests/CustomValueProviderTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public async Task CustomValueProvider_IntValues()
5757
Assert.Equal("[42,100,200]", content);
5858
}
5959

60+
[Fact]
61+
public async Task CustomValueProvider_NullableIntValues()
62+
{
63+
// Arrange
64+
var url = "http://localhost/CustomValueProvider/CustomValueProviderNullableIntValues";
65+
var request = new HttpRequestMessage(HttpMethod.Get, url);
66+
67+
// Act
68+
var response = await Client.SendAsync(request);
69+
var content = await response.Content.ReadAsStringAsync();
70+
71+
// Assert
72+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
73+
Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType);
74+
Assert.Equal("[null,42,null,100,null,200]", content);
75+
}
76+
6077
[Fact]
6178
public async Task CustomValueProvider_StringValues()
6279
{

src/Mvc/test/WebSites/BasicWebSite/Controllers/CustomValueProviderController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public string CustomValueProviderDisplayName(string customValueProviderDisplayNa
1616
public int[] CustomValueProviderIntValues(int[] customValueProviderIntValues)
1717
=> customValueProviderIntValues;
1818

19+
[HttpGet]
20+
public int?[] CustomValueProviderNullableIntValues(int?[] customValueProviderNullableIntValues)
21+
=> customValueProviderNullableIntValues;
22+
1923
[HttpGet]
2024
public string[] CustomValueProviderStringValues(string[] customValueProviderStringValues)
2125
=> customValueProviderStringValues;

src/Mvc/test/WebSites/BasicWebSite/ValueProviders/CustomValueProviderFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private class CustomValueProvider : IValueProvider
2020
{
2121
{ "customValueProviderDisplayName", context => context.ActionContext.ActionDescriptor.DisplayName },
2222
{ "customValueProviderIntValues", _ => new []{ null, "42", "100", null, "200" } },
23+
{ "customValueProviderNullableIntValues", _ => new []{ null, "42", "", "100", null, "200" } },
2324
{ "customValueProviderStringValues", _ => new []{ null, "foo", "", "bar", null, "baz" } },
2425
};
2526

0 commit comments

Comments
 (0)