public void ContainsPrefix_ThrowsIfPrefixIsNull() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( delegate { valueProvider.ContainsPrefix(null); }, "prefix"); }
public void ContainsPrefix_ThrowsIfPrefixIsNull() { // Arrange DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( delegate { valueProvider.ContainsPrefix(null); }, "prefix"); }
public void ContainsPrefix_DoesNotContainEmptyPrefixIfBackingStoreIsEmpty() { // Arrange DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(new Dictionary<string, object>(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.IsFalse(result, "The '' prefix shouldn't have been present."); }
public void ContainsPrefix() { // Arrange DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(_backingStore, null); // Act bool result = valueProvider.ContainsPrefix("forty"); // Assert Assert.IsTrue(result); }
public void ContainsPrefix_DoesNotContainEmptyPrefixIfBackingStoreIsEmpty() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(new Dictionary <string, object>(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.False(result); }
public void ContainsPrefix() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(_backingStore, null); // Act bool result = valueProvider.ContainsPrefix("forty"); // Assert Assert.True(result); }
public void ContainsPrefix_DoesNotContainEmptyPrefixIfBackingStoreIsEmpty() { // Arrange DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(new Dictionary<string, object>(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.False(result); }
public void ContainsPrefix_DoesNotContainEmptyPrefixIfBackingStoreIsEmpty() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(new Dictionary <string, object>(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.IsFalse(result, "The '' prefix shouldn't have been present."); }
//=== Helpers /// <summary> Looks for value provider result. </summary> private object FindValue(ModelBindingContext bindingContext) { ValueProviderCollection vpc = bindingContext.ValueProvider as ValueProviderCollection; foreach (object vp in vpc) { if (vp is FormValueProvider) { FormValueProvider fvp = (FormValueProvider)vp; ValueProviderResult vpr = fvp.GetValue(bindingContext.ModelName); if (vpr != null) { return(vpr); } } else if (vp is DictionaryValueProvider <object> ) { DictionaryValueProvider <object> dvp = (DictionaryValueProvider <object>)vp; ValueProviderResult vpr = dvp.GetValue(bindingContext.ModelName); if (vpr != null) { return(vpr); } else if (dvp.ContainsPrefix(bindingContext.ModelName)) { return(vp); } } } return(null); }
/// <summary> Creates Model from Request. </summary> public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { // Provider DictionaryValueProvider <object> provider = GetDictionaryValueProvider(bindingContext); if (provider == null) { return(null); } // Check Type bool multiple = (bindingContext.ModelType == typeof(FormPost)) ? false : true; if (multiple) { List <FormPost> list = new List <FormPost>(); List <string> prefixes = new List <string>(); string prefixFormat = provider.ContainsPrefix(bindingContext.ModelName + "[0]") ? bindingContext.ModelName + "[{0}]" : "[{0}]"; int index = 0; while (provider.ContainsPrefix(string.Format(prefixFormat, index))) { string prefix = string.Format(prefixFormat, index); string _key_token = prefix + "." + key_token; string _prefix_metadata = prefix + "." + prefix_metadata; string _prefix_data = prefix + "." + prefix_data; FormPost formPost = new FormPost(); // Retrieve RequestVerificationToken formPost.RequestVerificationToken = ParseToken(bindingContext, provider, _key_token); // Retrieve Metadata formPost.Metadata = ParseMetadata(bindingContext, provider, _prefix_metadata); // Retrieve Data formPost.Data = ParseData(bindingContext, provider, _prefix_data); list.Add(formPost); index++; } return(list.AsEnumerable()); } else { string _key_token = key_token; string _prefix_metadata = prefix_metadata; string _prefix_data = prefix_data; if (provider.ContainsPrefix(bindingContext.ModelName)) { _key_token = bindingContext.ModelName + "." + key_token; _prefix_metadata = bindingContext.ModelName + "." + prefix_metadata; _prefix_data = bindingContext.ModelName + "." + prefix_data; } FormPost formPost = new FormPost(); // Retrieve RequestVerificationToken formPost.RequestVerificationToken = ParseToken(bindingContext, provider, _key_token); // Retrieve Metadata formPost.Metadata = ParseMetadata(bindingContext, provider, _prefix_metadata); // Retrieve Data formPost.Data = ParseData(bindingContext, provider, _prefix_data); return(formPost); } }