public void ValidateBindingContextThrowsIfBindingContextIsNull() { // Act & assert Assert.ThrowsArgumentNull( () => ModelBindingHelper.ValidateBindingContext(null, typeof(string), true), "bindingContext"); }
public void ValidateBindingContextThrowsIfModelMetadataIsNull() { // Arrange ModelBindingContext bindingContext = new ModelBindingContext(); // Act & assert Assert.Throws <ArgumentException>( () => ModelBindingHelper.ValidateBindingContext(bindingContext, typeof(string), true), @"The binding context cannot have a null ModelMetadata. Parameter name: bindingContext"); }
public void ValidateBindingContextThrowsIfModelMetadataIsNull() { // Arrange ModelBindingContext bindingContext = new ModelBindingContext(); // Act & assert Assert.ThrowsArgument( () => ModelBindingHelper.ValidateBindingContext(bindingContext, typeof(string), true), "bindingContext", "The binding context cannot have a null ModelMetadata."); }
public void ValidateBindingContext_SuccessWithNullModel() { // Arrange ModelBindingContext bindingContext = new ModelBindingContext { ModelMetadata = GetMetadata(typeof(string)) }; // Act ModelBindingHelper.ValidateBindingContext(bindingContext, typeof(string), true); // Assert // Nothing to do - if we got this far without throwing, the test succeeded }
public void ValidateBindingContextThrowsIfModelTypeIsWrong() { // Arrange ModelBindingContext bindingContext = new ModelBindingContext { ModelMetadata = GetMetadata(typeof(object)) }; // Act & assert Assert.Throws <ArgumentException>( () => ModelBindingHelper.ValidateBindingContext(bindingContext, typeof(string), true), @"The binding context has a ModelType of 'System.Object', but this binder can only operate on models of type 'System.String'. Parameter name: bindingContext"); }
public void ValidateBindingContextThrowsIfModelIsNullButCannotBe() { // Arrange ModelBindingContext bindingContext = new ModelBindingContext { ModelMetadata = GetMetadata(typeof(string)) }; // Act & assert Assert.Throws <ArgumentException>( () => ModelBindingHelper.ValidateBindingContext(bindingContext, typeof(string), false), @"The binding context has a null Model, but this binder requires a non-null model of type 'System.String'. Parameter name: bindingContext"); }
public void ValidateBindingContextThrowsIfModelInstanceIsWrongType() { // Arrange ModelBindingContext bindingContext = new ModelBindingContext { ModelMetadata = GetMetadata(typeof(string)) }; bindingContext.ModelMetadata.Model = 42; // Act & assert Assert.ThrowsArgument( () => ModelBindingHelper.ValidateBindingContext(bindingContext, typeof(string), allowNullModel: true), "bindingContext", "The binding context has a Model of type 'System.Int32', but this binder can only operate on models of type 'System.String'."); }