Exemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ///// **********
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new CustomJsonValueProviderFactory());
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();


            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            XmlConfigurator.Configure();
            DbHelper.getSessionFactory();

            ///// **********
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new CustomJsonValueProviderFactory()); **
            /////*************
        }
        public void GetValueProvider_NullControllerContext_ThrowsException() {
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            ExceptionHelper.ExpectArgumentNullException(delegate() {
                factory.GetValueProvider(controllerContext: null);    
            }, "controllerContext");
        }
        public void GetValueProvider_ComplexJsonObject() {
            // Arrange
            string jsonString = @"
[ { ""FirstName"": ""John"", ""LastName"": ""Doe"", ""Age"": 32,
    ""BillingAddress"": { ""Street"": ""1 Microsoft Way"", ""City"": ""Redmond"", ""State"": ""WA"", ""ZIP"": 98052 },
    ""ShippingAddress"": { ""Street"": ""123 Anywhere Ln"", ""City"": ""Anytown"", ""State"": ""ZZ"", ""ZIP"": 99999 }
  },
  { ""Enchiladas"": [ ""Delicious"", ""Nutritious"", null ] }
]
";

            ControllerContext cc = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert 1
            IValueProvider valueProvider = factory.GetValueProvider(cc);
            Assert.IsNotNull(valueProvider);

            // Act & assert 2
            Assert.IsTrue(valueProvider.ContainsPrefix("[0].billingaddress"), "[0].billingaddress prefix should have existed.");
            Assert.IsNull(valueProvider.GetValue("[0].billingaddress"), "[0].billingaddress key should not have existed.");

            ValueProviderResult vpResult1 = valueProvider.GetValue("[1].enchiladas[0]");
            Assert.IsNotNull(vpResult1);
            Assert.AreEqual("Delicious", vpResult1.AttemptedValue);
            Assert.AreEqual(CultureInfo.CurrentCulture, vpResult1.Culture);

            // null values should exist in the backing store as actual entries
            ValueProviderResult vpResult2 = valueProvider.GetValue("[1].enchiladas[2]");
            Assert.IsNotNull(vpResult2);
            Assert.IsNull(vpResult2.RawValue);
        }
        protected void Application_Start()
        {
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new MyJsonValueProviderFactory());
            MvcHandler.DisableMvcResponseHeader = true;
        }
        public void GetValueProvider_SimpleArrayJsonObject()
        {
            const string jsonString =
                @"
[ ""abc"", null, ""foobar"" ]
";
            ControllerContext        cc      = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert
            IValueProvider valueProvider = factory.GetValueProvider(cc);

            Assert.True(valueProvider.ContainsPrefix("[0]"));
            Assert.True(valueProvider.ContainsPrefix("[2]"));
            Assert.False(valueProvider.ContainsPrefix("[3]"));

            ValueProviderResult vpResult1 = valueProvider.GetValue("[0]");

            Assert.Equal("abc", vpResult1.AttemptedValue);
            Assert.Equal(CultureInfo.CurrentCulture, vpResult1.Culture);

            // null values should exist in the backing store as actual entries
            ValueProviderResult vpResult2 = valueProvider.GetValue("[1]");

            Assert.NotNull(vpResult2);
            Assert.Null(vpResult2.RawValue);
        }
Exemplo n.º 7
0
        protected override void Application_Start(object sender, EventArgs e)
        {
            //Disabled logger
            //AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config"));
            //find the default JsonVAlueProviderFactory
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new CustomJsonValueProviderFactory());
            base.Application_Start(sender, e);
        }
Exemplo n.º 8
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var actionName = (string)controllerContext.RouteData.Values["action"];
            var mapping    = GetMethodMapping(controllerContext, bindingContext, actionName);

            var method = new Method(new MethodDescriptor(mapping, controllerContext.GetActionDescriptor(actionName)));

            foreach (var parameter in method.Parameters)
            {
                ValueProviderResult result;
                if (parameter.IsModelCollection)
                {
                    var type       = typeof(List <>).MakeGenericType(parameter.UnderliningModel.ModelType);
                    var collection = Activator.CreateInstance(type);
                    var index      = 0;
                    while ((result = bindingContext.ValueProvider.GetValue(string.Format("{0}[{1}]", parameter.Name, index))) != null)
                    {
                        var item      = ModelBinder.GetModelValue(result, parameter.UnderliningModel.ModelType) ?? Activator.CreateInstance(parameter.UnderliningModel.ModelType);
                        var itemModel = new Model(parameter.UnderliningModel.ModelType, parameter.UnderliningModel.Descriptor, item);
                        foreach (var itemProperty in itemModel.Properties)
                        {
                            var itemPropertyName = string.Format("{0}[{1}].{2}", parameter.Name, index, itemProperty.Name);
                            var itemResult       = bindingContext.ValueProvider.GetValue(itemPropertyName);
                            if (itemResult != null)
                            {
                                itemProperty.Value = !itemProperty.IsModel
                                    ? ModelBinder.GetNonModelValue(itemResult, itemProperty.MemberType)
                                    : ModelBinder.GetModelValue(itemResult, itemProperty.MemberType);
                            }
                        }
                        type.GetMethod("Add").Invoke(collection, new[] { item });
                        index++;
                    }
                    parameter.Value = collection;
                }
                else
                {
                    result = bindingContext.ValueProvider.GetValue(parameter.Name);

                    if (result == null)
                    {
                        controllerContext.HttpContext.Request.InputStream.Position = 0;
                        var provider = new JsonValueProviderFactory().GetValueProvider(controllerContext);
                        if (provider != null)
                        {
                            result = provider.GetValue(parameter.Name);
                        }
                    }

                    if (result != null)
                    {
                        parameter.Value = !parameter.IsModel
                            ? ModelBinder.GetNonModelValue(result, parameter.MemberType)
                            : ModelBinder.GetModelValue(result, parameter.MemberType);
                    }
                }
            }
            return(method);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            var provider = new JsonValueProviderFactory();
            ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
        }
        public void GetValueProvider_NullControllerContext_ThrowsException()
        {
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            ExceptionHelper.ExpectArgumentNullException(delegate() {
                factory.GetValueProvider(controllerContext: null);
            }, "controllerContext");
        }
Exemplo n.º 11
0
 public TokenPassThroughProviderFactory(
     string token,
     string contentType,
     JsonValueProviderFactory existing)
 {
     _token       = token;
     _contentType = contentType;
     _existing    = existing;
 }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            var provider = new JsonValueProviderFactory();

            ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
        }
Exemplo n.º 13
0
        /// <summary>
        /// Adds the factory to the system
        /// </summary>
        public override void AddFactory()
        {
            JsonValueProviderFactory TempProvider = ValueProviderFactories.Factories.OfType <JsonValueProviderFactory>().FirstOrDefault();

            if (TempProvider != null)
            {
                ValueProviderFactories.Factories.Remove(TempProvider);
            }
            ValueProviderFactories.Factories.Add(this);
        }
        public JsonDotNetValueProviderFactory(
            JsonValueProviderFactory originalFactory,
            JsonSerializerSettings serializerSettings)
        {
            Guard.Against.Null(serializerSettings, nameof(serializerSettings));
            Guard.Against.Null(originalFactory, nameof(originalFactory));

            this.originalFactory    = originalFactory;
            this.serializerSettings = serializerSettings;
        }
        public void GetValueProvider_NullControllerContext_ThrowsException()
        {
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            Assert.ThrowsArgumentNull(
                delegate()
            {
                factory.GetValueProvider(controllerContext: null);
            },
                "controllerContext"
                );
        }
        public void GetValueProvider_NotJsonRequest_ReturnsNull() {
            // Arrange
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Expect(o => o.HttpContext.Request.ContentType).Returns("not JSON");

            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.IsNull(valueProvider);
        }
        public void GetValueProvider_NoJsonBody_ReturnsNull() {
            // Arrange
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Expect(o => o.HttpContext.Request.ContentType).Returns("application/json");
            mockControllerContext.Expect(o => o.HttpContext.Request.InputStream).Returns(new MemoryStream());

            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.IsNull(valueProvider);
        }
        public void GetValueProvider_NotJsonRequest_ReturnsNull()
        {
            // Arrange
            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.Setup(o => o.HttpContext.Request.ContentType).Returns("not JSON");

            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.Null(valueProvider);
        }
Exemplo n.º 19
0
        protected void Application_Start()
        {
            // This will return xml for any url with ?format=xml that and accepts "application/xml" content
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(new System.Net.Http.Formatting.QueryStringMapping("format", "xml", "application/xml"));

            GlobalConfiguration.Configure(WebApiConfig.Register);

            AreaRegistration.RegisterAllAreas();

            ObjectFactory.Initialize(x => { x.AddRegistry <StructureMapRegistry>(); });
            ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //06-04-2017: Implement custom RedisSessionStateProvider
            SharePointConfig.RegisterProvider();

            // Source: http://haacked.com/archive/2010/04/15/
            // sending-json-to-an-asp-net-mvc-action-method-argument.aspx
            // This must be added to accept JSON as request
            //ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
            // This must be added to accept XML as request
            // Source: http://www.nogginbox.co.uk/blog/xml-to-asp.net-mvc-action-method
            ValueProviderFactories.Factories.Add(new XmlValueProviderFactory());

            // case 43410 - code from https://forums.asp.net/t/1751116.aspx?How+to+increase+maxJsonLength+for+JSON+POST+in+MVC3
            //find the default JsonVAlueProviderFactory
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add custom JSON provider
            ValueProviderFactories.Factories.Add(new FvJsonValueProviderFactory());
        }
        public void GetValueProvider_NoJsonBody_ReturnsNull()
        {
            // Arrange
            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.Setup(o => o.HttpContext.Request.ContentType).Returns("application/json");
            mockControllerContext.Setup(o => o.HttpContext.Request.InputStream).Returns(new MemoryStream());

            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.Null(valueProvider);
        }
        public void GetValueProvider_SimpleDictionaryJsonObject() {
            const string jsonString = @"
{   ""FirstName"":""John"",
    ""LastName"": ""Doe""
}";

            ControllerContext cc = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert
            IValueProvider valueProvider = factory.GetValueProvider(cc);
            Assert.IsTrue(valueProvider.ContainsPrefix("firstname"));
            
            ValueProviderResult vpResult1 = valueProvider.GetValue("firstname");
            Assert.AreEqual("John", vpResult1.AttemptedValue);
            Assert.AreEqual(CultureInfo.CurrentCulture, vpResult1.Culture);
        }
        public void GetValueProvider_ComplexJsonObject()
        {
            // Arrange
            const string jsonString =
                @"
[
  { 
    ""BillingAddress"": {
      ""Street"": ""1 Microsoft Way"",
      ""City"": ""Redmond"",
      ""State"": ""WA"",
      ""ZIP"": 98052 },
    ""ShippingAddress"": { 
      ""Street"": ""123 Anywhere Ln"",
      ""City"": ""Anytown"",
      ""State"": ""ZZ"",
      ""ZIP"": 99999 }
  },
  { 
    ""Enchiladas"": [ ""Delicious"", ""Nutritious""]
  }
]
";

            ControllerContext        cc      = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert
            IValueProvider valueProvider = factory.GetValueProvider(cc);

            Assert.NotNull(valueProvider);

            Assert.True(valueProvider.ContainsPrefix("[0].billingaddress"));
            Assert.Null(valueProvider.GetValue("[0].billingaddress"));

            Assert.True(valueProvider.ContainsPrefix("[0].billingaddress.street"));
            Assert.NotNull(valueProvider.GetValue("[0].billingaddress.street"));

            ValueProviderResult vpResult1 = valueProvider.GetValue("[1].enchiladas[0]");

            Assert.NotNull(vpResult1);
            Assert.Equal("Delicious", vpResult1.AttemptedValue);
            Assert.Equal(CultureInfo.CurrentCulture, vpResult1.Culture);
        }
        public void GetValueProvider_SimpleDictionaryJsonObject()
        {
            const string jsonString = @"
{   ""FirstName"":""John"",
    ""LastName"": ""Doe""
}";

            ControllerContext        cc      = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert
            IValueProvider valueProvider = factory.GetValueProvider(cc);

            Assert.True(valueProvider.ContainsPrefix("firstname"));

            ValueProviderResult vpResult1 = valueProvider.GetValue("firstname");

            Assert.Equal("John", vpResult1.AttemptedValue);
            Assert.Equal(CultureInfo.CurrentCulture, vpResult1.Culture);
        }
Exemplo n.º 24
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);



            /*
             * The following is a solution to POSTing large Json payloads to controller.
             * Appears to be a known issue - where controller does not look at web.config setting for maxJsonLength value
             *
             * Solution from:
             * https://forums.asp.net/t/1751116.aspx?How+to+increase+maxJsonLength+for+JSON+POST+in+MVC3
             *
             *
             * Replaces the serializer with the custom serializer that sets the maxJsonLength value
             */
            //find the default JsonVAlueProviderFactory
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new CustomJsonValueProviderFactory());
        }
Exemplo n.º 25
0
        /// <summary>
        /// Setups this instance.
        /// </summary>
        public static void Setup()
        {
            //find the default JsonVAlueProviderFactory
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new LargeJsonValueProviderFactory());
        }
Exemplo n.º 26
0
        public void Configuration(IAppBuilder app)
        {
            //ConfigureAuth(app);
            JsonValueProviderFactory jsonValueProviderFactory = null;

            foreach (var factory in ValueProviderFactories.Factories)
            {
                if (factory is JsonValueProviderFactory)
                {
                    jsonValueProviderFactory = factory as JsonValueProviderFactory;
                }
            }

            //remove the default JsonVAlueProviderFactory
            if (jsonValueProviderFactory != null)
            {
                ValueProviderFactories.Factories.Remove(jsonValueProviderFactory);
            }

            //add the custom one
            ValueProviderFactories.Factories.Add(new CustomJsonValueProviderFactory());
        }
        public void GetValueProvider_SimpleArrayJsonObject() {
            const string jsonString = @"
[ ""abc"", null, ""foobar"" ]
";
            ControllerContext cc = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert
            IValueProvider valueProvider = factory.GetValueProvider(cc);
            Assert.IsTrue(valueProvider.ContainsPrefix("[0]"));
            Assert.IsTrue(valueProvider.ContainsPrefix("[2]"));
            Assert.IsFalse(valueProvider.ContainsPrefix("[3]"));

            ValueProviderResult vpResult1 = valueProvider.GetValue("[0]");
            Assert.AreEqual("abc", vpResult1.AttemptedValue);
            Assert.AreEqual(CultureInfo.CurrentCulture, vpResult1.Culture);

            // null values should exist in the backing store as actual entries
            ValueProviderResult vpResult2 = valueProvider.GetValue("[1]");
            Assert.IsNotNull(vpResult2);
            Assert.IsNull(vpResult2.RawValue);
        }
Exemplo n.º 28
0
        public IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            // Use empty value provider by default to prevent use of ASP.NET MVC default value providers
            // Its not the purpose of this simulator framework to validate the ASP.NET MVC default value
            // providers. Either a value provider is not need in case model values are predefined or a
            // custom implementation is provided.
            var valueProviders = new ValueProviderCollection();

            if (ValueProvider != null)
            {
                valueProviders.Add(ValueProvider);
            }
            valueProviders.Add(new SimulatorValueProvider(controllerContext, new CultureInfo("nl-NL")));

            var factory           = new JsonValueProviderFactory();
            var jsonValueProvider = factory.GetValueProvider(controllerContext);

            if (jsonValueProvider != null)
            {
                valueProviders.Add(jsonValueProvider);
            }

            return(valueProviders);
        }
        public void GetValueProvider_ComplexJsonObject()
        {
            // Arrange
            string jsonString = @"
[ { ""FirstName"": ""John"", ""LastName"": ""Doe"", ""Age"": 32,
    ""BillingAddress"": { ""Street"": ""1 Microsoft Way"", ""City"": ""Redmond"", ""State"": ""WA"", ""ZIP"": 98052 },
    ""ShippingAddress"": { ""Street"": ""123 Anywhere Ln"", ""City"": ""Anytown"", ""State"": ""ZZ"", ""ZIP"": 99999 }
  },
  { ""Enchiladas"": [ ""Delicious"", ""Nutritious"", null ] }
]
";

            ControllerContext        cc      = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert 1
            IValueProvider valueProvider = factory.GetValueProvider(cc);

            Assert.IsNotNull(valueProvider);

            // Act & assert 2
            Assert.IsTrue(valueProvider.ContainsPrefix("[0].billingaddress"), "[0].billingaddress prefix should have existed.");
            Assert.IsNull(valueProvider.GetValue("[0].billingaddress"), "[0].billingaddress key should not have existed.");

            ValueProviderResult vpResult1 = valueProvider.GetValue("[1].enchiladas[0]");

            Assert.IsNotNull(vpResult1);
            Assert.AreEqual("Delicious", vpResult1.AttemptedValue);
            Assert.AreEqual(CultureInfo.CurrentCulture, vpResult1.Culture);

            // null values should exist in the backing store as actual entries
            ValueProviderResult vpResult2 = valueProvider.GetValue("[1].enchiladas[2]");

            Assert.IsNotNull(vpResult2);
            Assert.IsNull(vpResult2.RawValue);
        }
        public void GetValueProvider_ComplexJsonObject()
        {
            // Arrange
            const string jsonString = @"
[
  { 
    ""BillingAddress"": {
      ""Street"": ""1 Microsoft Way"",
      ""City"": ""Redmond"",
      ""State"": ""WA"",
      ""ZIP"": 98052 },
    ""ShippingAddress"": { 
      ""Street"": ""123 Anywhere Ln"",
      ""City"": ""Anytown"",
      ""State"": ""ZZ"",
      ""ZIP"": 99999 }
  },
  { 
    ""Enchiladas"": [ ""Delicious"", ""Nutritious""]
  }
]
";

            ControllerContext cc = GetJsonEnabledControllerContext(jsonString);
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            // Act & assert
            IValueProvider valueProvider = factory.GetValueProvider(cc);
            Assert.NotNull(valueProvider);

            Assert.True(valueProvider.ContainsPrefix("[0].billingaddress"));
            Assert.Null(valueProvider.GetValue("[0].billingaddress"));

            Assert.True(valueProvider.ContainsPrefix("[0].billingaddress.street"));
            Assert.NotNull(valueProvider.GetValue("[0].billingaddress.street"));

            ValueProviderResult vpResult1 = valueProvider.GetValue("[1].enchiladas[0]");
            Assert.NotNull(vpResult1);
            Assert.Equal("Delicious", vpResult1.AttemptedValue);
            Assert.Equal(CultureInfo.CurrentCulture, vpResult1.Culture);
        }
        public void GetValueProvider_NullControllerContext_ThrowsException()
        {
            JsonValueProviderFactory factory = new JsonValueProviderFactory();

            Assert.ThrowsArgumentNull(delegate() { factory.GetValueProvider(controllerContext: null); }, "controllerContext");
        }