public async Task FormCollectionModelBinder_ValidType_BindSuccessful() { // Arrange var formCollection = new FormCollection(new Dictionary <string, StringValues> { { "field1", "value1" }, { "field2", "value2" } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotEqual(ModelBindingResult.NoResult, result); Assert.True(result.IsModelSet); var entry = bindingContext.ValidationState[result.Model]; Assert.True(entry.SuppressValidation); Assert.Null(entry.Key); Assert.Null(entry.Metadata); var form = Assert.IsAssignableFrom <IFormCollection>(result.Model); Assert.Equal(2, form.Count); Assert.Equal("value1", form["field1"]); Assert.Equal("value2", form["field2"]); }
public async Task FormCollectionModelBinder_ValidType_BindSuccessful() { // Arrange var formCollection = new FormCollection(new Dictionary <string, string[]> { { "field1", new string[] { "value1" } }, { "field2", new string[] { "value2" } } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(FormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotNull(result); Assert.True(result.IsModelSet); Assert.NotNull(result.ValidationNode); Assert.True(result.ValidationNode.SuppressValidation); var form = Assert.IsAssignableFrom <IFormCollection>(result.Model); Assert.Equal(2, form.Count); Assert.Equal("value1", form["field1"]); Assert.Equal("value2", form["field2"]); }
public async Task FormCollectionModelBinder_ValidType_BindSuccessful() { // Arrange var formCollection = new FormCollection(new Dictionary<string, string[]> { { "field1", new string[] { "value1" } }, { "field2", new string[] { "value2" } } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(FormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotNull(result); Assert.True(result.IsModelSet); Assert.NotNull(result.ValidationNode); Assert.True(result.ValidationNode.SuppressValidation); var form = Assert.IsAssignableFrom<IFormCollection>(result.Model); Assert.Equal(2, form.Count); Assert.Equal("value1", form["field1"]); Assert.Equal("value2", form["field2"]); }
public async Task FormCollectionModelBinder_ValidType_BindSuccessful() { // Arrange var formCollection = new FormCollection(new Dictionary<string, StringValues> { { "field1", "value1" }, { "field2", "value2" } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotEqual(ModelBindingResult.NoResult, result); Assert.True(result.IsModelSet); var entry = bindingContext.ValidationState[result.Model]; Assert.True(entry.SuppressValidation); Assert.Null(entry.Key); Assert.Null(entry.Metadata); var form = Assert.IsAssignableFrom<IFormCollection>(result.Model); Assert.Equal(2, form.Count); Assert.Equal("value1", form["field1"]); Assert.Equal("value2", form["field2"]); }
public async Task FormCollectionModelBinder_NoForm_BindSuccessful_ReturnsEmptyFormCollection() { // Arrange var httpContext = GetMockHttpContext(null, hasForm: false); var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotNull(result); Assert.IsType(typeof(FormCollection), result.Model); Assert.Empty((FormCollection)result.Model); }
public async Task FormCollectionModelBinder_NoForm_BindSuccessful_ReturnsEmptyFormCollection() { // Arrange var httpContext = GetMockHttpContext(null, hasForm: false); var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotEqual(ModelBindingResult.NoResult, result); var form = Assert.IsAssignableFrom <IFormCollection>(result.Model); Assert.Empty(form); }
public async Task FormCollectionModelBinder_FormCollectionConcreteType_BindFails() { // Arrange var formCollection = new FormCollection(new Dictionary <string, StringValues> { { "field1", "value1" }, { "field2", new string[] { "value2" } } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(FormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.Equal(ModelBindingResult.NoResult, result); }
public async Task FormCollectionModelBinder_InvalidType_BindFails() { // Arrange var formCollection = new FormCollection(new Dictionary<string, string[]> { { "field1", new string[] { "value1" } }, { "field2", new string[] { "value2" } } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(string), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.Null(result); }
public async Task FormCollectionModelBinder_InvalidType_BindFails() { // Arrange var formCollection = new FormCollection(new Dictionary <string, string[]> { { "field1", new string[] { "value1" } }, { "field2", new string[] { "value2" } } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(string), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.Null(result); }
public async Task FormCollectionModelBinder_FormCollectionConcreteType_BindFails() { // Arrange var formCollection = new FormCollection(new Dictionary<string, StringValues> { { "field1", "value1" }, { "field2", new string[] { "value2" } } }); var httpContext = GetMockHttpContext(formCollection); var bindingContext = GetBindingContext(typeof(FormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.Equal(ModelBindingResult.NoResult, result); }
public async Task FormCollectionModelBinder_NoForm_BindSuccessful_ReturnsEmptyFormCollection() { // Arrange var httpContext = GetMockHttpContext(null, hasForm: false); var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext); var binder = new FormCollectionModelBinder(); // Act var result = await binder.BindModelAsync(bindingContext); // Assert Assert.NotEqual(ModelBindingResult.NoResult, result); var form = Assert.IsAssignableFrom<IFormCollection>(result.Model); Assert.Empty(form); }