// Used when the ValueProvider contains the collection to be bound as multiple elements, e.g. foo[0], foo[1].
        private static List <TElement> BindComplexCollection(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            string indexPropertyName = ModelBindingHelper.CreatePropertyModelName(bindingContext.ModelName, "index");
            ValueProviderResult  valueProviderResultIndex = bindingContext.ValueProvider.GetValue(indexPropertyName);
            IEnumerable <string> indexNames = CollectionModelBinderUtil.GetIndexNamesFromValueProviderResult(valueProviderResultIndex);

            return(BindComplexCollectionFromIndexes(actionContext, bindingContext, indexNames));
        }
예제 #2
0
        public void GetIndexNamesFromValueProviderResult_ValueProviderResultIsNull_ReturnsNull()
        {
            // Act
            IEnumerable <string> indexNames = CollectionModelBinderUtil.GetIndexNamesFromValueProviderResult(null);

            // Assert
            Assert.Null(indexNames);
        }
예제 #3
0
        // Used when the ValueProvider contains the collection to be bound as multiple elements, e.g. foo[0], foo[1].
        private async Task <List <TElement> > BindComplexCollection(ModelBindingContext bindingContext)
        {
            var indexPropertyName        = ModelBindingHelper.CreatePropertyModelName(bindingContext.ModelName, "index");
            var valueProviderResultIndex = await bindingContext.ValueProvider.GetValueAsync(indexPropertyName);

            var indexNames = CollectionModelBinderUtil.GetIndexNamesFromValueProviderResult(valueProviderResultIndex);

            return(await BindComplexCollectionFromIndexes(bindingContext, indexNames));
        }
예제 #4
0
        public void GetIndexNamesFromValueProviderResult_ValueProviderResultReturnsEmptyArray_ReturnsNull()
        {
            // Arrange
            ValueProviderResult vpResult = new ValueProviderResult(new string[0], "", null);

            // Act
            IEnumerable <string> indexNames = CollectionModelBinderUtil.GetIndexNamesFromValueProviderResult(vpResult);

            // Assert
            Assert.Null(indexNames);
        }
예제 #5
0
        public void GetIndexNamesFromValueProviderResult_ValueProviderResultReturnsNonEmptyArray_ReturnsArray()
        {
            // Arrange
            ValueProviderResult vpResult = new ValueProviderResult(new[] { "foo", "bar", "baz" }, "foo,bar,baz", null);

            // Act
            IEnumerable <string> indexNames = CollectionModelBinderUtil.GetIndexNamesFromValueProviderResult(vpResult);

            // Assert
            Assert.NotNull(indexNames);
            Assert.Equal(new[] { "foo", "bar", "baz" }, indexNames.ToArray());
        }