Add test coverage for Flags enum binding
This commit is contained in:
parent
f9f59fe58b
commit
ceaa9a9251
|
|
@ -189,6 +189,32 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||||
Assert.True(bindingContext.ModelState.ContainsKey("theModelName"));
|
Assert.True(bindingContext.ModelState.ContainsKey("theModelName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("0", 0)]
|
||||||
|
[InlineData("1", 1)]
|
||||||
|
[InlineData("13", 13)]
|
||||||
|
[InlineData("Value1", 1)]
|
||||||
|
[InlineData("Value8, Value4", 12)]
|
||||||
|
public async Task BindModel_BindsFlagsEnumModels(string flagsEnumValue, int expected)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var bindingContext = GetBindingContext(typeof(FlagsEnum));
|
||||||
|
bindingContext.ValueProvider = new SimpleValueProvider
|
||||||
|
{
|
||||||
|
{ "theModelName", flagsEnumValue }
|
||||||
|
};
|
||||||
|
|
||||||
|
var binder = new SimpleTypeModelBinder();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await binder.BindModelAsync(bindingContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.True(result.IsModelSet);
|
||||||
|
var boundModel = Assert.IsType<FlagsEnum>(result.Model);
|
||||||
|
Assert.Equal((FlagsEnum)expected, boundModel);
|
||||||
|
}
|
||||||
|
|
||||||
private static ModelBindingContext GetBindingContext(Type modelType)
|
private static ModelBindingContext GetBindingContext(Type modelType)
|
||||||
{
|
{
|
||||||
return new ModelBindingContext
|
return new ModelBindingContext
|
||||||
|
|
@ -203,5 +229,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||||
private sealed class TestClass
|
private sealed class TestClass
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
private enum FlagsEnum
|
||||||
|
{
|
||||||
|
Value1 = 1,
|
||||||
|
Value2 = 2,
|
||||||
|
Value4 = 4,
|
||||||
|
Value8 = 8
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue