Beispiel #1
0
        public async Task FormCollectionModelBinder_CustomFormCollection_BindSuccessful()
        {
            // Arrange
            var formCollection = new MyFormCollection(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);
            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_CustomFormCollection_BindSuccessful()
        {
            // Arrange
            var formCollection = new MyFormCollection(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);
            var form = Assert.IsAssignableFrom<IFormCollection>(result.Model);
            Assert.Equal(2, form.Count);
            Assert.Equal("value1", form["field1"]);
            Assert.Equal("value2", form["field2"]);
        }