MyModel _model = new MyModel() { PriceDate = new DateTime(2000, 1, 1)};
var helper = new System.Web.Mvc.HtmlHelper<MyModel>(new ViewContext(), new ViewPage());
var result = helper.DisplayFor(m => _model.PriceDate);
Assert.That(result, Is.EqualTo(expected));
I want to test that the output produced by calling DisplayFor is in the format specified by…
[DisplayFormat(DataFormatString = "{0:dd/MM/yy}")]
public DateTime? PriceDate { get; set; }
The code compiles but fails with a NullReferenceException at DisplayFor.
Can anyone help me make this work?
(Note: This is a trivial example of a larger problem)
The steps are quite long so I couldn’t write here. I wrote about it at my blog 😀
http://thoai-nguyen.blogspot.com/2011/07/unit-test-displayformat-attribute.html
Cheers