public void CollectionTemplateNonEnumerableModelThrows() { // Arrange HtmlHelper html = MakeHtmlHelper <object>(new object()); // Act & Assert ExceptionHelper.ExpectInvalidOperationException( () => DefaultEditorTemplates.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 = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.AreEqual(String.Empty, result); }
public void CollectionTemplateNullItemInStronglyTypedCollectionUsesModelTypeFromIEnumerable() { // Arrange HtmlHelper html = MakeHtmlHelper <List <IHttpHandler> >(new List <IHttpHandler> { null }); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = null; // Act string result = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.AreEqual(@" Model = (null), ModelType = System.Web.IHttpHandler, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = Edit, 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 = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.AreEqual(@" Model = (null), ModelType = System.String, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }
public void CollectionTemplateWithSingleItemCollectionWithPrefix() { // Arrange HtmlHelper html = MakeHtmlHelper <List <string> >(new List <string> { "foo" }); html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "ModelProperty"; // Act string result = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.AreEqual(@" Model = foo, ModelType = System.String, PropertyName = (null), HtmlFieldName = ModelProperty[0], TemplateName = (null), Mode = Edit, 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 = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.AreEqual(@" Model = 1, ModelType = System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = (null), ModelType = System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PropertyName = (null), HtmlFieldName = [1], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = 2, ModelType = System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PropertyName = (null), HtmlFieldName = [2], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }
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 = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.AreEqual(@" Model = 1, ModelType = System.Int32, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = 2.3, ModelType = System.Double, PropertyName = (null), HtmlFieldName = [1], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = Hello World, ModelType = System.String, PropertyName = (null), HtmlFieldName = [2], TemplateName = (null), Mode = Edit, 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 = DefaultEditorTemplates.CollectionTemplate(html, CollectionSpyCallback); // Assert Assert.Equal(@" Model = foo, ModelType = System.String, PropertyName = (null), HtmlFieldName = [0], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = bar, ModelType = System.String, PropertyName = (null), HtmlFieldName = [1], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null) Model = baz, ModelType = System.String, PropertyName = (null), HtmlFieldName = [2], TemplateName = (null), Mode = Edit, TemplateInfo.HtmlFieldPrefix = , AdditionalViewData = (null)", result); }