Move two recently-added `[HiddenInput]` tests into `CachedDataAnnotationsModelMetadataProviderTest`
This commit is contained in:
parent
4351ddd092
commit
0595e9ebc9
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
|
|
@ -34,6 +35,36 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
Assert.False(provider.GetMetadataForProperty(null, type, "ScaffoldColumnFalse").ShowForEdit);
|
Assert.False(provider.GetMetadataForProperty(null, type, "ScaffoldColumnFalse").ShowForEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HiddenInputWorksOnProperty()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var provider = new DataAnnotationsModelMetadataProvider();
|
||||||
|
var metadata = provider.GetMetadataForType(modelAccessor: null, modelType: typeof(ClassWithHiddenProperties));
|
||||||
|
var property = metadata.Properties.First(m => string.Equals("DirectlyHidden", m.PropertyName));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = property.HideSurroundingHtml;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO #1000; enable test once we detect attributes on the property's type
|
||||||
|
public void HiddenInputWorksOnPropertyType()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var provider = new DataAnnotationsModelMetadataProvider();
|
||||||
|
var metadata = provider.GetMetadataForType(modelAccessor: null, modelType: typeof(ClassWithHiddenProperties));
|
||||||
|
var property = metadata.Properties.First(m => string.Equals("OfHiddenType", m.PropertyName));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = property.HideSurroundingHtml;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
private class ScaffoldColumnModel
|
private class ScaffoldColumnModel
|
||||||
{
|
{
|
||||||
public int NoAttribute { get; set; }
|
public int NoAttribute { get; set; }
|
||||||
|
|
@ -44,5 +75,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
[ScaffoldColumn(scaffold: false)]
|
[ScaffoldColumn(scaffold: false)]
|
||||||
public int ScaffoldColumnFalse { get; set; }
|
public int ScaffoldColumnFalse { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HiddenInput(DisplayValue = false)]
|
||||||
|
private class HiddenClass
|
||||||
|
{
|
||||||
|
public string Property { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ClassWithHiddenProperties
|
||||||
|
{
|
||||||
|
[HiddenInput(DisplayValue = false)]
|
||||||
|
public string DirectlyHidden { get; set; }
|
||||||
|
|
||||||
|
public HiddenClass OfHiddenType { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,53 +164,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
Assert.Equal(expectedResult, result);
|
Assert.Equal(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void HiddenInputWorksOnProperty()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var provider = new DataAnnotationsModelMetadataProvider();
|
|
||||||
var metadata = provider.GetMetadataForType(modelAccessor: null, modelType: typeof(ClassWithHiddenProperties));
|
|
||||||
var property = metadata.Properties.First(m => string.Equals("DirectlyHidden", m.PropertyName));
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = property.HideSurroundingHtml;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.True(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO #1000; enable test once we detect attributes on the property's type
|
|
||||||
public void HiddenInputWorksOnPropertyType()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var provider = new DataAnnotationsModelMetadataProvider();
|
|
||||||
var metadata = provider.GetMetadataForType(modelAccessor: null, modelType: typeof(ClassWithHiddenProperties));
|
|
||||||
var property = metadata.Properties.First(m => string.Equals("OfHiddenType", m.PropertyName));
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = property.HideSurroundingHtml;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.True(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ClassWithDisplayableColumn
|
private class ClassWithDisplayableColumn
|
||||||
{
|
{
|
||||||
public string Property { get; set; }
|
public string Property { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[HiddenInput(DisplayValue = false)]
|
|
||||||
private class HiddenClass
|
|
||||||
{
|
|
||||||
public string Property { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ClassWithHiddenProperties
|
|
||||||
{
|
|
||||||
[HiddenInput(DisplayValue = false)]
|
|
||||||
public string DirectlyHidden { get; set; }
|
|
||||||
|
|
||||||
public HiddenClass OfHiddenType { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue