Address review comments
- XML comments for changed `TemplateInfo` properties - correct `DefaultDisplayTemplateTests` and `DefaultEditorTemplateTests` namespaces - add a couple of low-level `TemplateInfo` tests
This commit is contained in:
parent
bbf470bd34
commit
172a5a5500
|
|
@ -29,12 +29,27 @@ namespace Microsoft.AspNet.Mvc
|
||||||
_visitedObjects = new HashSet<object>(original._visitedObjects);
|
_visitedObjects = new HashSet<object>(original._visitedObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the formatted model value.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will never return <c>null</c> to avoid problems when using HTML helpers within a template. Otherwise the
|
||||||
|
/// helpers could find elements in the `ViewDataDictionary`, not the intended Model properties.
|
||||||
|
/// </remarks>
|
||||||
|
/// <value>The formatted model value.</value>
|
||||||
public object FormattedModelValue
|
public object FormattedModelValue
|
||||||
{
|
{
|
||||||
get { return _formattedModelValue; }
|
get { return _formattedModelValue; }
|
||||||
set { _formattedModelValue = value ?? string.Empty; }
|
set { _formattedModelValue = value ?? string.Empty; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the HTML field prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will never return <c>null</c> for consistency with <see cref="FormattedModelValue"/>.
|
||||||
|
/// </remarks>
|
||||||
|
/// <value>The HTML field prefix.</value>
|
||||||
public string HtmlFieldPrefix
|
public string HtmlFieldPrefix
|
||||||
{
|
{
|
||||||
get { return _htmlFieldPrefix; }
|
get { return _htmlFieldPrefix; }
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Core.Test
|
namespace Microsoft.AspNet.Mvc.Core
|
||||||
{
|
{
|
||||||
public class DefaultDisplayTemplateTests
|
public class DefaultDisplayTemplateTests
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Core.Test
|
namespace Microsoft.AspNet.Mvc.Core
|
||||||
{
|
{
|
||||||
public class DefaultEditorTemplatesTests
|
public class DefaultEditorTemplatesTests
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Rendering
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
public class ViewDataOfTTest
|
public class ViewDataOfTTest
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
public void SettingModelWorksForCompatibleTypes()
|
public void SettingModelWorksForCompatibleTypes()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string value = "some value";
|
var value = "some value";
|
||||||
var viewDataOfT = new ViewDataDictionary<object>(new DataAnnotationsModelMetadataProvider());
|
var viewDataOfT = new ViewDataDictionary<object>(new DataAnnotationsModelMetadataProvider());
|
||||||
ViewDataDictionary viewData = viewDataOfT;
|
ViewDataDictionary viewData = viewDataOfT;
|
||||||
|
|
||||||
|
|
@ -47,5 +47,47 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Same(value, viewDataOfT.Model);
|
Assert.Same(value, viewDataOfT.Model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void PropertiesInitializedCorrectly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var viewData = new ViewDataDictionary<string>(new DataAnnotationsModelMetadataProvider());
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Empty(viewData);
|
||||||
|
Assert.Equal(0, viewData.Count);
|
||||||
|
Assert.False(viewData.IsReadOnly);
|
||||||
|
|
||||||
|
Assert.NotNull(viewData.Keys);
|
||||||
|
Assert.Empty(viewData.Keys);
|
||||||
|
|
||||||
|
Assert.Null(viewData.Model);
|
||||||
|
Assert.NotNull(viewData.ModelMetadata);
|
||||||
|
Assert.NotNull(viewData.ModelState);
|
||||||
|
|
||||||
|
Assert.NotNull(viewData.TemplateInfo);
|
||||||
|
Assert.Equal(0, viewData.TemplateInfo.TemplateDepth);
|
||||||
|
Assert.Equal(string.Empty, viewData.TemplateInfo.FormattedModelValue);
|
||||||
|
Assert.Equal(string.Empty, viewData.TemplateInfo.HtmlFieldPrefix);
|
||||||
|
|
||||||
|
Assert.NotNull(viewData.Values);
|
||||||
|
Assert.Empty(viewData.Values);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TemplateInfoPropertiesAreNeverNull()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var viewData = new ViewDataDictionary<string>(new DataAnnotationsModelMetadataProvider());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
viewData.TemplateInfo.FormattedModelValue = null;
|
||||||
|
viewData.TemplateInfo.HtmlFieldPrefix = null;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(string.Empty, viewData.TemplateInfo.FormattedModelValue);
|
||||||
|
Assert.Equal(string.Empty, viewData.TemplateInfo.HtmlFieldPrefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue