public void GetEnumSelectList_ReturnsExpectedItems(Type type, IEnumerable<SelectListItem> expected) { // Arrange var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var metadata = metadataProvider.GetMetadataForType(type); var htmlHelper = new TestHtmlHelper(metadataProvider); // Act var result = htmlHelper.GetEnumSelectList(type); // Assert // OrderBy is used because the order of the results may very depending on the platform / client. VerifySelectList( expected.OrderBy(item => item.Text, StringComparer.Ordinal), result.OrderBy(item => item.Text, StringComparer.Ordinal)); }
public void GetEnumSelectListType_WrapsGetEnumSelectListModelMetadata() { // Arrange var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var metadata = metadataProvider.GetMetadataForType(typeof(EnumWithFields)); var htmlHelper = new TestHtmlHelper(metadataProvider); // Act var result = htmlHelper.GetEnumSelectList(typeof(EnumWithFields)); // Assert Assert.Equal(metadata.ModelType, htmlHelper.Metadata.ModelType); Assert.Same(htmlHelper.SelectListItems, result); // No replacement of the underlying List VerifySelectList(htmlHelper.CopiedSelectListItems, result); // No change to the (mutable) items }
public void GetEnumSelectListTEnum_ThrowsWithFlagsEnum() { // Arrange var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var htmlHelper = new TestHtmlHelper(metadataProvider); // Act & Assert ExceptionAssert.ThrowsArgument( () => htmlHelper.GetEnumSelectList<EnumWithFlags>(), "TEnum", $"The type '{ typeof(EnumWithFlags).FullName }' is not supported."); }
public void GetEnumSelectListType_ThrowsWithNonStruct() { // Arrange var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var htmlHelper = new TestHtmlHelper(metadataProvider); // Act & Assert ExceptionAssert.ThrowsArgument( () => htmlHelper.GetEnumSelectList(typeof(ClassWithFields)), "enumType", $"The type '{ typeof(ClassWithFields).FullName }' is not supported."); }
public void GetEnumSelectList_ReturnsExpectedItems(Type type, IEnumerable<SelectListItem> expected) { // Arrange var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var metadata = metadataProvider.GetMetadataForType(type); var htmlHelper = new TestHtmlHelper(metadataProvider); // Act var result = htmlHelper.GetEnumSelectList(type); // Assert VerifySelectList(expected, result); }