public async Task BindModel_ReturnsNull_ForOtherTypes() { // Arrange var bindingContext = GetBindingContext(new SimpleValueProvider(), typeof(int[])); var binder = new ByteArrayModelBinder(); // Act var binderResult = await binder.BindModelResultAsync(bindingContext); // Assert Assert.Equal(default(ModelBindingResult), binderResult); }
public async Task BindModel() { // Arrange var valueProvider = new SimpleValueProvider() { { "foo", "Fys1" } }; var bindingContext = GetBindingContext(valueProvider, typeof(byte[])); var binder = new ByteArrayModelBinder(); // Act var binderResult = await binder.BindModelResultAsync(bindingContext); // Assert Assert.NotNull(binderResult); var bytes = Assert.IsType <byte[]>(binderResult.Model); Assert.Equal(new byte[] { 23, 43, 53 }, bytes); }
public async Task BindModel_ReturnsWithIsModelSetFalse_WhenValueNotFound() { // Arrange var valueProvider = new SimpleValueProvider() { { "someName", "" } }; var bindingContext = GetBindingContext(valueProvider, typeof(byte[])); var binder = new ByteArrayModelBinder(); // Act var binderResult = await binder.BindModelResultAsync(bindingContext); // Assert Assert.NotNull(binderResult); Assert.False(binderResult.IsModelSet); Assert.Equal("foo", binderResult.Key); Assert.Null(binderResult.Model); Assert.Empty(bindingContext.ModelState); // No submitted data for "foo". }
public async Task BindModelAddsModelErrorsOnInvalidCharacters() { // Arrange var expected = "The value '\"Fys1\"' is not valid for Byte[]."; var valueProvider = new SimpleValueProvider() { { "foo", "\"Fys1\"" } }; var bindingContext = GetBindingContext(valueProvider, typeof(byte[])); var binder = new ByteArrayModelBinder(); // Act var binderResult = await binder.BindModelResultAsync(bindingContext); // Assert Assert.NotNull(binderResult); Assert.False(bindingContext.ModelState.IsValid); var error = Assert.Single(bindingContext.ModelState["foo"].Errors); Assert.Equal(expected, error.ErrorMessage); }