public void GetTypeArgumentsForUpdatableGenericCollection_ModelTypeWrongNumberOfGenericArguments_Fail() { // Arrange ModelMetadata modelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(KeyValuePair <int, string>)); // Act Type[] typeArguments = CollectionModelBinderUtil.GetTypeArgumentsForUpdatableGenericCollection(typeof(ICollection <>), null, modelMetadata); // Assert Assert.Null(typeArguments); }
public void GetTypeArgumentsForUpdatableGenericCollection_ModelTypeOpenGeneric_Fail() { // Arrange ModelMetadata modelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(IList <>)); // Act Type[] typeArguments = CollectionModelBinderUtil.GetTypeArgumentsForUpdatableGenericCollection(null, null, modelMetadata); // Assert Assert.Null(typeArguments); }
public void GetTypeArgumentsForUpdatableGenericCollection_ReadWriteReference_NewInstanceNotAssignableToModelType_MutableInstance_Success() { // Arrange ModelMetadata modelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(() => new Collection <int>(), typeof(Collection <int>)); modelMetadata.IsReadOnly = false; // Act Type[] typeArguments = CollectionModelBinderUtil.GetTypeArgumentsForUpdatableGenericCollection(typeof(ICollection <>), typeof(List <>), modelMetadata); // Assert Assert.Equal(new[] { typeof(int) }, typeArguments); }
public void GetTypeArgumentsForUpdatableGenericCollection_ReadOnlyReference_ModelIsNull_Fail() { // Arrange ModelMetadata modelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(IList <int>)); modelMetadata.IsReadOnly = true; // Act Type[] typeArguments = CollectionModelBinderUtil.GetTypeArgumentsForUpdatableGenericCollection(typeof(ICollection <>), typeof(List <>), modelMetadata); // Assert Assert.Null(typeArguments); }
public void GetTypeArgumentsForUpdatableGenericCollection_ReadOnlyReference_ModelInstanceMutable_Valid() { // Arrange ModelMetadata modelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(() => new List <int>(), typeof(IList <int>)); modelMetadata.IsReadOnly = true; // Act Type[] typeArguments = CollectionModelBinderUtil.GetTypeArgumentsForUpdatableGenericCollection(typeof(IList <>), typeof(List <>), modelMetadata); // Assert Assert.Equal(new[] { typeof(int) }, typeArguments); }
public void GetTypeArgumentsForUpdatableGenericCollection_ReadOnlyReference_ModelInstanceOfWrongType_Fail() { // Arrange ModelMetadata modelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(() => new HashSet <int>(), typeof(ICollection <int>)); modelMetadata.IsReadOnly = true; // Act Type[] typeArguments = CollectionModelBinderUtil.GetTypeArgumentsForUpdatableGenericCollection(typeof(IList <>), typeof(List <>), modelMetadata); // Assert // HashSet<> is not an IList<>, so we can't update Assert.Null(typeArguments); }