public void CollectionTemplateUsesRealObjectTypes() { // Arrange HtmlHelper html = MakeHtmlHelper <List <object> >( new List <object> { 1, 2.3, "Hello World" } ); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal( Environment.NewLine + "Model = 1, ModelType = System.Int32, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)" + Environment.NewLine + "Model = 2.3, ModelType = System.Double, PropertyName = (null), HtmlFieldName = [1], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)" + Environment.NewLine + "Model = Hello World, ModelType = System.String, PropertyName = (null), HtmlFieldName = [2], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result ); }
public void CollectionTemplateWithMultiItemCollection() { // Arrange HtmlHelper html = MakeHtmlHelper <List <string> >( new List <string> { "foo", "bar", "baz" } ); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal( Environment.NewLine + "Model = foo, ModelType = System.String, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)" + Environment.NewLine + "Model = bar, ModelType = System.String, PropertyName = (null), HtmlFieldName = [1], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)" + Environment.NewLine + "Model = baz, ModelType = System.String, PropertyName = (null), HtmlFieldName = [2], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result ); }
public void CollectionTemplateNonEnumerableModelThrows() { // Arrange HtmlHelper html = MakeHtmlHelper <object>(new object()); // Act & Assert Assert.Throws <InvalidOperationException>( () => DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback), "The Collection template was used with an object of type 'System.Object', which does not implement System.IEnumerable." ); }
public void CollectionTemplateWithNullModel() { // Arrange HtmlHelper html = MakeHtmlHelper <object>(null); // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal(String.Empty, result); }
public void CollectionTemplateWithSingleItemCollectionWithoutPrefix() { // Arrange HtmlHelper html = MakeHtmlHelper <List <string> >(new List <string> { "foo" }); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal(@" Model = foo, ModelType = System.String, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }
public void CollectionTemplateNullItemInStronglyTypedCollectionUsesModelTypeFromIEnumerable() { // Arrange HtmlHelper html = MakeHtmlHelper <List <IHttpHandler> >(new List <IHttpHandler> { null }); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal(@" Model = (null), ModelType = System.Web.IHttpHandler, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }
public void CollectionTemplateNullITemInWeaklyTypedCollectionUsesModelTypeOfString() { // Arrange HtmlHelper html = MakeHtmlHelper <ArrayList>(new ArrayList { null }); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal(@" Model = (null), ModelType = System.String, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }
public void CollectionTemplateNullItemInCollectionOfNullableValueTypesDoesNotDiscardNullable() { // Arrange HtmlHelper html = MakeHtmlHelper <List <int?> >(new List <int?> { 1, null, 2 }); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultDisplayTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal(@" Model = 1, ModelType = System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = (null), ModelType = System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PropertyName = (null), HtmlFieldName = [1], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = 2, ModelType = System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PropertyName = (null), HtmlFieldName = [2], TemplateName = (null), Mode = ReadOnly, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }