public void ModelBinderFormat(string input, int expectdYear, int expectedMonth, int expectedDay) { var binder = new DateModelBinder(); var values = new DictionaryValueProvider <string>(new Dictionary <string, string> { { "Date", input } }, CultureInfo.InvariantCulture); var context = new ModelBindingContext { ValueProvider = values, ModelName = "Date" }; var obj = binder.BindModel(null, context); Assert.IsInstanceOf(typeof(Date), obj); DateTimeOffset date = (Date)obj; Assert.AreEqual(expectdYear, date.Year); Assert.AreEqual(expectedMonth, date.Month); Assert.AreEqual(expectedDay, date.Day); }
public void transform(HtmlDocument document, TemplateEnvironment environment, List <PageStackItem> pageDefinitions) { var formNode = document.DocumentNode.Select("[data-settings-form]").FirstOrDefault(); if (formNode != null) { var controlNode = formNode.Select("[data-settings-form-control]").FirstOrDefault(); if (controlNode != null) { var valueProvider = new DictionaryValueProvider(); int index = 0; foreach (var page in pageDefinitions) { if (index == stopEnumerationIndex) { break; } var definition = page.PageDefinition; foreach (var variable in definition.Vars) { valueProvider.Values["name"] = variable.Key; valueProvider.Values["prettyName"] = variable.Key; valueProvider.Values["value"] = variable.Value; var node = controlNode.CloneNode(true); node.InnerHtml = TextFormatter.formatText(node.InnerHtml, valueProvider, WebUtility.HtmlEncode); formNode.AppendChild(node); } } controlNode.Remove(); } } }
public ActionResult Index(FormCollection collection) { //Update the data if it hasn't been updated in a while DataObtainer.updated(); IValueProvider data = collection; if (CallbackManager.CurrentIsCallback) { var request = CallbackManager.GetCurrentCallbackData <CollectionViewRequest <object> >(); if (request != null && request.ExtraRequestData != null) { var extraData = request.ExtraRequestData.Cast <DictionaryEntry>() .ToDictionary(kvp => (string)kvp.Key, kvp => kvp.Value.ToString()); data = new DictionaryValueProvider <string>(extraData, CultureInfo.CurrentCulture); } } _gridDataModel.LoadPostData(data); List <GraphData.Transaction> reportList_ = new List <GraphData.Transaction>(DataObtainer.data.reportList); string[] filter = (string[])Session["Filter"]; //Filters from user selection if (filter != null) { reportList_ = reportList_.Where(x => filter.Contains(x.contract_name)).ToList(); } reportList_ = reportList_.GetRange(0, Math.Min(reportList_.Count, Convert.ToInt32(_gridDataModel.Options["items"].CurrentValue))); ViewBag.DemoOptions = _gridDataModel; ViewBag.FilterTypes = GetFilterTypes(_gridFilterModel); return(View("_DataTable", reportList_)); }
public void GetValueProviderReturnsNullIfKeyIsNotInChildActionDictionary() { // Arrange ChildActionValueProviderFactory factory = new ChildActionValueProviderFactory(); ControllerContext controllerContext = new ControllerContext(); controllerContext.RouteData = new RouteData(); controllerContext.RouteData.Values["forty-two"] = 42; DictionaryValueProvider <object> explictValueDictionary = new DictionaryValueProvider <object>(new RouteValueDictionary { { "forty-three", 42 } }, CultureInfo.CurrentUICulture); controllerContext.RouteData.Values[ChildActionValueProvider.ChildActionValuesKey] = explictValueDictionary; // Act IValueProvider valueProvider = factory.GetValueProvider(controllerContext); // Assert Assert.Equal(typeof(ChildActionValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue("forty-two"); Assert.Null(vpResult); }
public void GetValueProviderReturnsChildActionValue() { // Arrange ChildActionValueProviderFactory factory = new ChildActionValueProviderFactory(); ControllerContext controllerContext = new ControllerContext(); controllerContext.RouteData = new RouteData(); string conflictingKey = "conflictingKey"; controllerContext.RouteData.Values["conflictingKey"] = 43; DictionaryValueProvider<object> explictValueDictionary = new DictionaryValueProvider<object>(new RouteValueDictionary { { conflictingKey, 42 } }, CultureInfo.InvariantCulture); controllerContext.RouteData.Values[ChildActionValueProvider.ChildActionValuesKey] = explictValueDictionary; // Act IValueProvider valueProvider = factory.GetValueProvider(controllerContext); // Assert Assert.AreEqual(typeof(ChildActionValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue(conflictingKey); Assert.IsNotNull(vpResult, "Should have contained a value for key '" + conflictingKey + "'."); Assert.AreEqual(42, vpResult.RawValue); Assert.AreEqual("42", vpResult.AttemptedValue); Assert.AreEqual(CultureInfo.InvariantCulture, vpResult.Culture); }
public void Setup() { _dictionary = new Dictionary <string, object> { { "StringValue", "Value" }, { "IntValue", "47" }, { "Created", "2010-03-01 12:34:56.123" }, { "Updated", "2010-03-15 10:34:49.983" }, { "Duration", "12:34:56.123" }, { "SubClass.Street", "123 American Way" }, { "SubClass.City", "Tulsa" }, { "SubClass.State", "OK" }, //no enum value provided on purpose }; ValueProvider dictionaryProvider = new DictionaryValueProvider(_dictionary); ValueProvider jsonProvider = new JsonValueProvider(@"{ Names: [""One"", ""Two"", ""Three""], SubClass: { ZipCode: ""90210"" }, SubClasses: [ { ZipCode: ""68106"" }, { ZipCode: ""68154"" } ] }"); var providers = new MultipleValueProvider(new[] { dictionaryProvider, jsonProvider }); ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new TestModelBinderContext(providers); object obj = binder.Bind(typeof(BinderTestClass), context); _result = obj as BinderTestClass; }
public async Task Passes_NotAllDataAvaliable_DoesNotProperlyMatchesData() { var source = new Dictionary <string, object>() { { "Age", 1 }, { "Likes", 1 }, { "Genetics", "white" } }; IRuleTreeValueProvider valueProvider = new DictionaryValueProvider(source); IRuleTree tree = RuleTreeMockData.AgeAndLikes_GeneticsAndName; IRuleTreeAssembler assembler = new RuleTreeAssembler(valueProvider); await assembler.Assemble(tree); var ageNode = tree.BaseNode.Children.First() as GenericComparisonRule <int>; var likesNode = tree.BaseNode.Children.ElementAt(1) as GenericComparisonRule <int>; var geneticsNode = likesNode.Children.First().Children.First() as OptionsSearchParameter <string>; var nameNode = likesNode.Children.First().Children.ElementAt(1) as GenericComparisonRule <string>; Assert.Equal("Age", ageNode.Key); Assert.Equal(1, ageNode.ComparisonValue); Assert.Equal("Likes", likesNode.Key); Assert.Equal(1, likesNode.ComparisonValue); Assert.Equal("Genetics", geneticsNode.Key); Assert.Equal("white", geneticsNode.ComparisonValue); Assert.Equal("Name", nameNode.Key); Assert.Null(nameNode.ComparisonValue); }
public void GetValueProviderReturnsChildActionValue() { // Arrange ChildActionValueProviderFactory factory = new ChildActionValueProviderFactory(); ControllerContext controllerContext = new ControllerContext(); controllerContext.RouteData = new RouteData(); string conflictingKey = "conflictingKey"; controllerContext.RouteData.Values["conflictingKey"] = 43; DictionaryValueProvider <object> explictValueDictionary = new DictionaryValueProvider <object>(new RouteValueDictionary { { conflictingKey, 42 } }, CultureInfo.InvariantCulture); controllerContext.RouteData.Values[ChildActionValueProvider.ChildActionValuesKey] = explictValueDictionary; // Act IValueProvider valueProvider = factory.GetValueProvider(controllerContext); // Assert Assert.Equal(typeof(ChildActionValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue(conflictingKey); Assert.NotNull(vpResult); Assert.Equal(42, vpResult.RawValue); Assert.Equal("42", vpResult.AttemptedValue); Assert.Equal(CultureInfo.InvariantCulture, vpResult.Culture); }
public override IValueProvider GetValueProvider(ControllerContext controllerContext) { // first make sure we have a valid context if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } // now make sure we are dealing with a json request if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase)) { return(null); } // get a generic stream reader (get reader for the http stream) var streamReader = new StreamReader(controllerContext.HttpContext.Request.InputStream); // convert stream reader to a JSON Text Reader var jsonReader = new JsonTextReader(streamReader); // tell JSON to read if (!jsonReader.Read()) { return(null); } // make a new Json serializer var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() }; var jsonSerializer = JsonSerializer.Create(settings); // add the dyamic object converter to our serializer jsonSerializer.Converters.Add(new ExpandoObjectConverter()); // use JSON.NET to deserialize object to a dynamic (expando) object Object jsonObject; // if we start with a "[", treat this as an array if (jsonReader.TokenType == JsonToken.StartArray) { jsonObject = jsonSerializer.Deserialize <List <ExpandoObject> >(jsonReader); } else { jsonObject = jsonSerializer.Deserialize <ExpandoObject>(jsonReader); } // create a backing store to hold all properties for this deserialization var backingStore = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); // add all properties to this backing store AddToBackingStore(backingStore, String.Empty, jsonObject); // return the object in a dictionary value provider so the MVC understands it var valueProvider = new DictionaryValueProvider <object>(backingStore, CultureInfo.CurrentCulture); return(valueProvider); }
/// <summary> Get value provider. </summary> private DictionaryValueProvider <object> GetDictionaryValueProvider(ModelBindingContext bindingContext) { ValueProviderCollection vpc = bindingContext.ValueProvider as ValueProviderCollection; DictionaryValueProvider <object> vp = vpc.Where(x => x.GetType() == typeof(DictionaryValueProvider <object>)).FirstOrDefault() as DictionaryValueProvider <object>; return(vp); }
public void ContainsPrefix_ThrowsIfPrefixIsNull() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( delegate { valueProvider.ContainsPrefix(null); }, "prefix"); }
public void GetValue_ThrowsIfKeyIsNull() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( delegate { valueProvider.GetValue(null); }, "key"); }
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() { // 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.IsFalse(result, "The '' prefix shouldn't have been present."); }
public void GetValue_ReturnsNullIfKeyNotFound() { // Arrange DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(_backingStore, null); // Act ValueProviderResult vpResult = valueProvider.GetValue("nineteen.eighty"); // Assert Assert.IsNull(vpResult); }
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 object InitializeFromDictionary(Type objectType, IDictionary<string, object> values) { ValueProvider dictionaryProvider = new DictionaryValueProvider(values); ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new InitializerModelBinderContext(dictionaryProvider); object obj = binder.Bind(objectType, context); return obj; }
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 object InitializeFromDictionary(Type objectType, IDictionary <string, object> values) { ValueProvider dictionaryProvider = new DictionaryValueProvider(values); ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new InitializerModelBinderContext(dictionaryProvider); object obj = binder.Bind(objectType, context); return(obj); }
/// <summary>Creates a <see cref="ModelBindingContext"/> that is used to pass to the model binder that is being tested.</summary> /// <param name="formValue">The value that is "send" to the binder.</param> /// <returns>The created context.</returns> private static ModelBindingContext CreateModelBindingContext(string formValue) { IValueProvider valueProvider = new DictionaryValueProvider <string>(new Dictionary <string, string> { { "SomeValue", formValue } }, null); ModelBindingContext bindingContext = new ModelBindingContext { ModelName = "SomeValue", ValueProvider = valueProvider }; return(bindingContext); }
public void GetValue_ReturnsNullIfKeyNotFound() { // Arrange DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(_backingStore, null); // Act ValueProviderResult vpResult = valueProvider.GetValue("nineteen.eighty"); // Assert Assert.Null(vpResult); }
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); }
/// <summary>Creates a <see cref="ModelBindingContext"/> that is used to pass to the model binder that is being tested.</summary> /// <param name="formValue">The value that is "send" to the binder.</param> /// <param name="destinationType">The destination type.</param> /// <returns>The created context.</returns> private static ModelBindingContext CreateModelBindingContext(object formValue, Type destinationType) { IValueProvider valueProvider = new DictionaryValueProvider <object>(new Dictionary <string, object> { { "SomeValue", formValue } }, null); ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(null, destinationType); ModelBindingContext bindingContext = new ModelBindingContext { ModelName = "SomeValue", ValueProvider = valueProvider, ModelMetadata = metadata }; return(bindingContext); }
public void TestGetValueIfDictionaryHasDecimalValues() { var dict = new Dictionary <string, decimal> { ["Key1"] = 27.67m, ["Key2"] = 64m, }; var provider = new DictionaryValueProvider <decimal>(); Assert.AreEqual(dict["Key1"], provider.GetValue("Key1", dict)); Assert.AreEqual(dict["Key2"], provider.GetValue("Key2", dict)); }
public void GetValue() { // Arrange CultureInfo culture = CultureInfo.GetCultureInfo("fr-FR"); DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("nineteen.eighty.four"); // Assert Assert.IsNotNull(vpResult); Assert.AreEqual(new DateTime(1984, 1, 1), vpResult.RawValue); Assert.AreEqual("01/01/1984 00:00:00", vpResult.AttemptedValue); Assert.AreEqual(culture, vpResult.Culture); }
public override bool TryGetValueProvider(object target, string name, out IValueProvider provider) { provider = default(IValueProvider); if (target is IDictionary) { var dictionary = (IDictionary)target; if (dictionary.Contains(name)) { provider = new DictionaryValueProvider(dictionary, name); } } return provider != null; }
public void GetValue() { // Arrange CultureInfo culture = CultureInfo.GetCultureInfo("fr-FR"); DictionaryValueProvider <object> valueProvider = new DictionaryValueProvider <object>(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("nineteen.eighty.four"); // Assert Assert.NotNull(vpResult); Assert.Equal(new DateTime(1984, 1, 1), vpResult.RawValue); Assert.Equal("01/01/1984 00:00:00", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void MissingNotificationIdReturnsNotFound() { // Set a new value provider containing an non GUID value so that parsing fails. var newDictionaryValueProv = new DictionaryValueProvider <object>( new Dictionary <string, object>() { { "id", new { } } }, null); controller.ValueProvider = newDictionaryValueProv; filter.OnActionExecuting(actionExecutingContext); var result = (HttpStatusCodeResult)actionExecutingContext.Result; Assert.Equal((int)HttpStatusCode.NotFound, result.StatusCode); }
public void Should_throw_error_when_query_string_parameter_not_found() { const string badParameter = "Bad Value"; ControllerContext controllerContext = GetControllerContext("foo", badParameter); var values = new Dictionary <string, string>(); var valueProvider = new DictionaryValueProvider <string>(values, CultureInfo.InvariantCulture); var context = new ModelBindingContext { ModelName = "foo", ValueProvider = valueProvider }; var binder = new KeyedModelBinder <TEntity, TRepository>(null); BindResult model = binder.BindModel(controllerContext, context); Assert.That(model.Value, Is.Null); }
/// <summary> Parse Metadata values. </summary> private Metadata ParseMetadata(ModelBindingContext bindingContext, DictionaryValueProvider <object> provider, string prefix) { Metadata metadata = new Metadata(); IDictionary <string, string> keys = provider.GetKeysFromPrefix(prefix); foreach (string shortKey in keys.Keys) { string key = prefix + "." + shortKey; string value = GetValue(bindingContext, key); metadata[shortKey] = value; } return(metadata); }
private static ValueProvider CreateValueProvider(object value) { ValueProvider provider; if (value is IDictionary <string, object> dict) { provider = new DictionaryValueProvider(dict); } else if (value is NameValueCollection coll) { provider = new DictionaryValueProvider(coll); } else { provider = new TypeDescriptorValueProvider(value); } return(provider); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { string prefix = "__metadata"; DictionaryValueProvider <object> provider = GetDictionaryValueProvider(bindingContext); IDictionary <string, string> keys = provider.GetKeysFromPrefix(prefix); Metadata metadata = new Metadata(); foreach (string shortKey in keys.Keys) { string key = prefix + "." + shortKey; string value = GetValue(bindingContext, key); metadata[shortKey] = value; } return(metadata); }
public async Task Passes_NotAllDataAvaliable_DoesNotPass() { var source = new Dictionary <string, object>() { { "Age", 1 }, { "Likes", 1 } }; IRuleTreeValueProvider valueProvider = new DictionaryValueProvider(source); IRuleTree tree = RuleTreeMockData.AgeAndLikes_GeneticsAndName; IRuleTreeAssembler assembler = new RuleTreeAssembler(valueProvider); await assembler.Assemble(tree); var result = await tree.Passes(); Assert.False(result); }
internal static RouteData GetRouteData( HttpContextBase httpContext, string actionName, string controllerName, RouteValueDictionary additionalRouteValues, bool isChildRequest) { if (String.IsNullOrEmpty(actionName)) { throw new ArgumentException("Value cannot be null or empty.", "actionName"); } if (String.IsNullOrEmpty(controllerName)) { throw new ArgumentException("Value cannot be null or empty.", "controllerName"); } var routeData = new RouteData(); var routeValues = MergeDictionaries(additionalRouteValues, routeData.Values); routeValues["action"] = actionName; routeValues["controller"] = controllerName; //routeValues["area"] = SitecoreMvcAreaRegistration.SitecoreAreaName; if (isChildRequest) { if (routeValues.ContainsKey("area")) { routeValues.Remove("area"); } if (additionalRouteValues != null) { if (additionalRouteValues.ContainsKey("area")) { additionalRouteValues.Remove("area"); } routeValues[ChildActionValuesKey] = new DictionaryValueProvider<object>(additionalRouteValues, CultureInfo.InvariantCulture); } } return CreateRouteData(new SitecoreRoute(), routeValues, new RouteValueDictionary()); }
internal static RouteData GetRouteData( HttpContextBase httpContext, string actionName, string controllerName, RouteValueDictionary additionalRouteValues, bool isChildRequest) { if (String.IsNullOrEmpty(actionName)) { throw new ArgumentException("Value cannot be null or empty.", "actionName"); } if (String.IsNullOrEmpty(controllerName)) { throw new ArgumentException("Value cannot be null or empty.", "controllerName"); } var routeData = new RouteData(); var routeValues = MergeDictionaries(additionalRouteValues, routeData.Values); routeValues["action"] = actionName; routeValues["controller"] = controllerName; //routeValues["area"] = SitecoreMvcAreaRegistration.SitecoreAreaName; if (isChildRequest) { if (routeValues.ContainsKey("area")) { routeValues.Remove("area"); } if (additionalRouteValues != null) { if (additionalRouteValues.ContainsKey("area")) { additionalRouteValues.Remove("area"); } routeValues[ChildActionValuesKey] = new DictionaryValueProvider <object>(additionalRouteValues, CultureInfo.InvariantCulture); } } return(CreateRouteData(new SitecoreRoute(), routeValues, new RouteValueDictionary())); }
public void GetValueProviderReturnsNullIfKeyIsNotInChildActionDictionary() { // Arrange ChildActionValueProviderFactory factory = new ChildActionValueProviderFactory(); ControllerContext controllerContext = new ControllerContext(); controllerContext.RouteData = new RouteData(); controllerContext.RouteData.Values["forty-two"] = 42; DictionaryValueProvider<object> explictValueDictionary = new DictionaryValueProvider<object>(new RouteValueDictionary { { "forty-three", 42 } }, CultureInfo.CurrentUICulture); controllerContext.RouteData.Values[ChildActionValueProvider.ChildActionValuesKey] = explictValueDictionary; // Act IValueProvider valueProvider = factory.GetValueProvider(controllerContext); // Assert Assert.AreEqual(typeof(ChildActionValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue("forty-two"); Assert.IsNull(vpResult, "ChildActionValueProvider should not have contained a value for key 'forty-two'."); }
public void Mvc3FixedModelBinder_BindModelComplexTypeWithEnumAsInt_ValueIsCorrectlyParsed() { /* Create the test subject */ Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder(); ControllerContext controllerContext = new ControllerContext(); IValueProvider valueProvider = new DictionaryValueProvider <object>(new Dictionary <string, object> { { "SomeValue", 3 }, { "SomeOtherValue", "42" } }, null); ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(MyModel)); ModelBindingContext bindingContext = new ModelBindingContext { ModelName = string.Empty, ValueProvider = valueProvider, ModelMetadata = metadata }; MyModel model = (MyModel)testSubject.BindModel(controllerContext, bindingContext); Assert.IsNotNull(model); Assert.AreEqual(TestEnum.ValueC, model.SomeValue); Assert.AreEqual(42, model.SomeOtherValue); }
public void TestGetValue() { var dict = new Dictionary <string, object> { ["StrParam"] = "value1", ["IntParam"] = 5, ["BoolParam"] = true, ["GuidParam"] = Guid.NewGuid(), }; var provider = new DictionaryValueProvider <object>(); Assert.AreEqual(dict["StrParam"], provider.GetValue("StrParam", dict)); Assert.AreEqual(dict["IntParam"], provider.GetValue("IntParam", dict)); Assert.AreEqual(dict["BoolParam"], provider.GetValue("BoolParam", dict)); Assert.AreEqual(dict["GuidParam"], provider.GetValue("GuidParam", dict)); ExceptionAssert.Throws <ArgumentException>(() => provider.GetValue(null, dict)); ExceptionAssert.Throws <KeyNotFoundException>(() => provider.GetValue(" StrParam ", dict), "Key \" StrParam \" was not found in dictionary"); ExceptionAssert.Throws <KeyNotFoundException>(() => provider.GetValue("strParam", dict), "Key \"strParam\" was not found in dictionary"); ExceptionAssert.Throws <KeyNotFoundException>(() => provider.GetValue("BadParam", dict), "Key \"BadParam\" was not found in dictionary"); }
public override IValueProvider GetValueProvider(ControllerContext controllerContext) { if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } object jsonData = GetDeserializedObject(controllerContext); if (jsonData == null) { return(null); } Dictionary <string, object> backingStore = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); AddToBackingStore(backingStore, String.Empty, jsonData); var result = new DictionaryValueProvider <object>(backingStore, CultureInfo.CurrentCulture); return(result); }
public void GetValue_ThrowsIfKeyIsNull() { // Arrange DictionaryValueProvider<object> valueProvider = new DictionaryValueProvider<object>(_backingStore, null); // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { valueProvider.GetValue(null); }, "key"); }