public void GetValueProvider()
        {
            // Arrange
            ControllerContext controllerContext = new ControllerContext();
            IValueProvider[] expectedValueProviders = new[]
            {
                new Mock<IValueProvider>().Object,
                new Mock<IValueProvider>().Object
            };

            Mock<ValueProviderFactory> mockFactory1 = new Mock<ValueProviderFactory>();
            mockFactory1.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[0]);
            Mock<ValueProviderFactory> mockFactory2 = new Mock<ValueProviderFactory>();
            mockFactory2.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[1]);

            ValueProviderFactoryCollection factories = new ValueProviderFactoryCollection()
            {
                mockFactory1.Object,
                mockFactory2.Object
            };

            // Act
            ValueProviderCollection valueProviders = (ValueProviderCollection)factories.GetValueProvider(controllerContext);

            // Assert
            Assert.Equal(expectedValueProviders, valueProviders.ToArray());
        }
Esempio n. 2
0
        public void GetValueProviderDelegatesToResolver()
        {
            //Arrange
            ControllerContext controllerContext = new ControllerContext();

            IValueProvider[] expectedValueProviders = new IValueProvider[] {
                new Mock <IValueProvider>().Object,
                new Mock <IValueProvider>().Object
            };

            Mock <ValueProviderFactory> mockFactory1 = new Mock <ValueProviderFactory>();

            mockFactory1.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[0]);
            Mock <ValueProviderFactory> mockFactory2 = new Mock <ValueProviderFactory>();

            mockFactory2.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[1]);

            Resolver <IEnumerable <ValueProviderFactory> > resolver = new Resolver <IEnumerable <ValueProviderFactory> > {
                Current = new[] { mockFactory1.Object, mockFactory2.Object }
            };
            ValueProviderFactoryCollection factories = new ValueProviderFactoryCollection(resolver);

            // Act
            ValueProviderCollection valueProviders = (ValueProviderCollection)factories.GetValueProvider(controllerContext);

            // Assert
            CollectionAssert.AreEqual(expectedValueProviders, valueProviders.ToArray());
        }
        public void DefaultConstructor() {
            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Assert
            Assert.AreEqual(0, collection.Count);
        }
Esempio n. 4
0
 /// <summary>The add value providers.</summary>
 /// <param name="factories">The factories.</param>
 private static void AddValueProviders(ValueProviderFactoryCollection factories)
 {
     factories.Add(new CookieValueProviderFactory());
     factories.Add(new SessionValueProviderFactory());
     factories.Add(new ModelStateValueProviderFactory());
     factories.Add(new UserValueProviderFactory());
 }
Esempio n. 5
0
        public void GetValueProvider()
        {
            // Arrange
            ControllerContext controllerContext = new ControllerContext();

            IValueProvider[] expectedValueProviders = new IValueProvider[] {
                new Mock <IValueProvider>().Object,
                new Mock <IValueProvider>().Object
            };

            Mock <ValueProviderFactory> mockFactory1 = new Mock <ValueProviderFactory>();

            mockFactory1.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[0]);
            Mock <ValueProviderFactory> mockFactory2 = new Mock <ValueProviderFactory>();

            mockFactory2.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[1]);

            ValueProviderFactoryCollection factories = new ValueProviderFactoryCollection()
            {
                mockFactory1.Object,
                mockFactory2.Object
            };

            // Act
            ValueProviderCollection valueProviders = (ValueProviderCollection)factories.GetValueProvider(controllerContext);

            // Assert
            CollectionAssert.AreEqual(expectedValueProviders, valueProviders.ToArray());
        }
        public void GetValueProviderDelegatesToResolver()
        {
            // Arrange
            ControllerContext controllerContext = new ControllerContext();

            IValueProvider[] expectedValueProviders = new[]
            {
                new Mock <IValueProvider>().Object,
                new Mock <IValueProvider>().Object
            };

            Mock <ValueProviderFactory> mockFactory1 = new Mock <ValueProviderFactory>();

            mockFactory1.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[0]);
            Mock <ValueProviderFactory> mockFactory2 = new Mock <ValueProviderFactory>();

            mockFactory2.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[1]);

            var resolver = new Mock <IDependencyResolver>();

            resolver.Setup(r => r.GetServices(typeof(ValueProviderFactory))).Returns(new[] { mockFactory1.Object, mockFactory2.Object });
            ValueProviderFactoryCollection factories = new ValueProviderFactoryCollection(new ValueProviderFactory[0], resolver.Object);

            // Act
            ValueProviderCollection valueProviders = (ValueProviderCollection)factories.GetValueProvider(controllerContext);

            // Assert
            Assert.Equal(expectedValueProviders, valueProviders.ToArray());
        }
    public static void Config(ValueProviderFactoryCollection factories)
    {
        var jsonProviderFactory = factories.OfType <JsonValueProviderFactory>().Single();

        factories.Remove(jsonProviderFactory);
        factories.Add(new CustomJsonValueProviderFactory());
    }
 public static void Init(this ValueProviderFactoryCollection valueProviderFactories)
 {
     valueProviderFactories.Clear();
     //valueProviderFactories.Add(new PostDataProviderFactory());
     valueProviderFactories.Add(new FormValueProviderFactory());
     valueProviderFactories.Add(new RouteDataValueProviderFactory());
     valueProviderFactories.Add(new QueryStringValueProviderFactory());
 }
        public void DefaultConstructor()
        {
            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Assert
            Assert.Empty(collection);
        }
Esempio n. 10
0
        public void DefaultConstructor()
        {
            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Assert
            Assert.AreEqual(0, collection.Count);
        }
        public void DefaultConstructor()
        {
            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Assert
            Assert.Empty(collection);
        }
        public void AddNullValueProviderFactoryThrows()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { collection.Add(null); },
                "item");
        }
Esempio n. 13
0
 public static void Init(this ValueProviderFactoryCollection valueProviderFactories)
 {
     valueProviderFactories.Clear();
     valueProviderFactories.Add(new FormValueProviderFactory());
     valueProviderFactories.Add(new RouteDataValueProviderFactory());
     valueProviderFactories.Add(new QueryStringValueProviderFactory());
     //valueProviderFactories.Add(new ChildActionValueProviderFactory());
     //valueProviderFactories.Add(new JsonValueProviderFactory());
     //valueProviderFactories.Add(new HttpFileCollectionValueProviderFactory());
 }
        public void AddNullValueProviderFactoryThrows()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { collection.Add(null); },
                "item");
        }
        public void AddNullValueProviderFactoryThrows() {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    collection.Add(null);
                },
                "item");
        }
Esempio n. 16
0
        internal ModelConfigurationSettings()
        {
            _binders            = new ModelBinderCollection();
            _valueProviders     = new ValueProviderFactoryCollection();
            _validatorProviders = new ModelValidatorProviderCollection();

            InitDefaultBinders();
            InitDefaultBinderProviders();
            InitDefaultValueProviders();
            InitDefaultValidatorProviders();
        }
        internal ModelConfigurationSettings()
        {
            _binders = new ModelBinderCollection();
			_valueProviders = new ValueProviderFactoryCollection();
			_validatorProviders = new ModelValidatorProviderCollection();

			InitDefaultBinders();
			InitDefaultBinderProviders();
			InitDefaultValueProviders();
			InitDefaultValidatorProviders();
        }
        public void ListWrappingConstructor() {
            // Arrange
            List<ValueProviderFactory> list = new List<ValueProviderFactory>() {
                new FormValueProviderFactory()
            };

            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection(list);

            // Assert
            CollectionAssert.AreEqual(list, collection);
        }
        public void SetNullValueProviderFactoryThrows()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            collection.Add(new Mock <ValueProviderFactory>().Object);

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { collection[0] = null; },
                "item");
        }
Esempio n. 20
0
        public void AddNullValueProviderFactoryThrows()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                collection.Add(null);
            },
                "item");
        }
Esempio n. 21
0
        public void ListWrappingConstructor()
        {
            // Arrange
            List <ValueProviderFactory> list = new List <ValueProviderFactory>()
            {
                new FormValueProviderFactory()
            };

            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection(list);

            // Assert
            CollectionAssert.AreEqual(list, collection);
        }
Esempio n. 22
0
        public void SetItem()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            collection.Add(new Mock <ValueProviderFactory>().Object);

            ValueProviderFactory newFactory = new Mock <ValueProviderFactory>().Object;

            // Act
            collection[0] = newFactory;

            // Assert
            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(newFactory, collection[0]);
        }
Esempio n. 23
0
 public static void FixMvcModelBindingIssue()
 {
     ValueProviderFactories.Factories.Clear();
     var factories = new ValueProviderFactoryCollection()
     {
         new FixedChildActionValueProviderFactory(),
         new FixedFormValueProviderFactory(),
         new FixedJsonValueProviderFactory(),
         new FixedRouteDataValueProviderFactory(),
         new FixedQueryStringValueProviderFactory(),
         new FixedHttpFileCollectionValueProviderFactory()
     };
     foreach (var factory in factories)
     {
         ValueProviderFactories.Factories.Add(factory);
     }
 }
        public void SetItem()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            collection.Add(new Mock <ValueProviderFactory>().Object);

            ValueProviderFactory newFactory = new Mock <ValueProviderFactory>().Object;

            // Act
            collection[0] = newFactory;

            // Assert
            ValueProviderFactory factory = Assert.Single(collection);

            Assert.Equal(newFactory, factory);
        }
        public void ValueProviderFactoryCollectionCombinedItemsCaches()
        {
            // Arrange
            var factories = new ValueProviderFactory[] 
            {
                new Mock<ValueProviderFactory>(MockBehavior.Strict).Object, 
                new Mock<ValueProviderFactory>(MockBehavior.Strict).Object
            };
            var collection = new ValueProviderFactoryCollection(factories);

            // Act
            var combined1 = collection.CombinedItems;
            var combined2 = collection.CombinedItems;

            // Assert
            Assert.Equal(factories, combined1);
            Assert.Same(combined1, combined2);
        }
        public void ValueProviderFactoryCollectionCombinedItemsCaches()
        {
            // Arrange
            var factories = new ValueProviderFactory[]
            {
                new Mock <ValueProviderFactory>(MockBehavior.Strict).Object,
                new Mock <ValueProviderFactory>(MockBehavior.Strict).Object
            };
            var collection = new ValueProviderFactoryCollection(factories);

            // Act
            var combined1 = collection.CombinedItems;
            var combined2 = collection.CombinedItems;

            // Assert
            Assert.Equal(factories, combined1);
            Assert.Same(combined1, combined2);
        }
Esempio n. 27
0
        public static void FixMvcModelBindingIssue()
        {
            ValueProviderFactories.Factories.Clear();
            var factories = new ValueProviderFactoryCollection()
            {
                new FixedChildActionValueProviderFactory(),
                new FixedFormValueProviderFactory(),
                new FixedJsonValueProviderFactory(),
                new FixedRouteDataValueProviderFactory(),
                new FixedQueryStringValueProviderFactory(),
                new FixedHttpFileCollectionValueProviderFactory()
            };

            foreach (var factory in factories)
            {
                ValueProviderFactories.Factories.Add(factory);
            }
        }
        private static void TestCacheReset(Action <ValueProviderFactoryCollection> mutatingAction)
        {
            // Arrange
            var providers = new List <ValueProviderFactory>()
            {
                new Mock <ValueProviderFactory>(MockBehavior.Strict).Object,
                new Mock <ValueProviderFactory>(MockBehavior.Strict).Object
            };
            var collection = new ValueProviderFactoryCollection(providers);

            // Act
            mutatingAction(collection);

            ValueProviderFactory[] combined = collection.CombinedItems;

            // Assert
            Assert.Equal(providers, combined);
        }
Esempio n. 29
0
        public static void RegisterGlobalFilters(
            ValueProviderFactoryCollection factories,
            IContainer container)
        {
            // Remove Default Json Value Provider Factory (JavaScriptSerializer)
            var defaultJsonValueProvider = factories
                                           .OfType <JsonValueProviderFactory>()
                                           .FirstOrDefault();

            if (defaultJsonValueProvider is object)
            {
                factories.Remove(defaultJsonValueProvider);
            }

            var serializerSettings = container.Resolve <JsonSerializerSettings>();

            // Add Custom Json Value Provider Factory (Json.Net)
            factories.Add(new JsonDotNetValueProviderFactory(defaultJsonValueProvider, serializerSettings));
        }
        public void ValueProviderFactoryCollectionCombinedItemsDelegatesToResolver()
        {
            // Arrange
            var firstFactory        = new Mock <ValueProviderFactory>();
            var secondFactory       = new Mock <ValueProviderFactory>();
            var thirdFactory        = new Mock <ValueProviderFactory>();
            var dependencyFactories = new ValueProviderFactory[] { firstFactory.Object, secondFactory.Object };
            var collectionFactories = new ValueProviderFactory[] { thirdFactory.Object };
            var expectedFactories   = new ValueProviderFactory[] { firstFactory.Object, secondFactory.Object, thirdFactory.Object };

            var resolver = new Mock <IDependencyResolver>();

            resolver.Setup(r => r.GetServices(typeof(ValueProviderFactory))).Returns(dependencyFactories);

            var factories = new ValueProviderFactoryCollection(collectionFactories, resolver.Object);

            // Act
            ValueProviderFactory[] combined = factories.CombinedItems;

            // Assert
            Assert.Equal(expectedFactories, combined);
        }
Esempio n. 31
0
 public static void RegisterValueProviderFactories(ValueProviderFactoryCollection factories)
 {
     factories.Add(new EntityValueProviderFactory());
 }
        private static void TestCacheReset(Action<ValueProviderFactoryCollection> mutatingAction)
        {
            // Arrange
            var providers = new List<ValueProviderFactory>() 
            {
                new Mock<ValueProviderFactory>(MockBehavior.Strict).Object, 
                new Mock<ValueProviderFactory>(MockBehavior.Strict).Object
            };
            var collection = new ValueProviderFactoryCollection(providers);

            // Act
            mutatingAction(collection);

            ValueProviderFactory[] combined = collection.CombinedItems;

            // Assert
            Assert.Equal(providers, combined);
        }
Esempio n. 33
0
 public ValueProviderFactoryRegister(ValueProviderFactoryCollection valueProviderFactories)
 {
     Guard.ArgumentNotNull(valueProviderFactories, "valueProviderFactories");
     ValueProviderFactories = valueProviderFactories;
 }
 public ValueProviderFactoryRegister(ValueProviderFactoryCollection valueProviderFactories)
 {
     Guard.ArgumentNotNull(valueProviderFactories, "valueProviderFactories");
     ValueProviderFactories = valueProviderFactories;
 }
        public void SetItem()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();
            collection.Add(new Mock<ValueProviderFactory>().Object);

            ValueProviderFactory newFactory = new Mock<ValueProviderFactory>().Object;

            // Act
            collection[0] = newFactory;

            // Assert
            Assert.Single(collection);
            Assert.Equal(newFactory, collection[0]);
        }
Esempio n. 36
0
 private void RegisterFactories(ValueProviderFactoryCollection valueProviderFactories)
 {
     valueProviderFactories.Add(new JsonValueProviderFactory());
 }
        public void ValueProviderFactoryCollectionCombinedItemsDelegatesToResolver()
        {
            // Arrange
            var firstFactory = new Mock<ValueProviderFactory>();
            var secondFactory = new Mock<ValueProviderFactory>();
            var thirdFactory = new Mock<ValueProviderFactory>();
            var dependencyFactories = new ValueProviderFactory[] { firstFactory.Object, secondFactory.Object };
            var collectionFactories = new ValueProviderFactory[] { thirdFactory.Object };
            var expectedFactories = new ValueProviderFactory[] { firstFactory.Object, secondFactory.Object, thirdFactory.Object };

            var resolver = new Mock<IDependencyResolver>();
            resolver.Setup(r => r.GetServices(typeof(ValueProviderFactory))).Returns(dependencyFactories);

            var factories = new ValueProviderFactoryCollection(collectionFactories, resolver.Object);

            // Act
            ValueProviderFactory[] combined = factories.CombinedItems;

            // Assert
            Assert.Equal(expectedFactories, combined);
        }
        public void GetValueProviderDelegatesToResolver()
        {
            // Arrange
            ControllerContext controllerContext = new ControllerContext();
            IValueProvider[] expectedValueProviders = new[]
            {
                new Mock<IValueProvider>().Object,
                new Mock<IValueProvider>().Object
            };

            Mock<ValueProviderFactory> mockFactory1 = new Mock<ValueProviderFactory>();
            mockFactory1.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[0]);
            Mock<ValueProviderFactory> mockFactory2 = new Mock<ValueProviderFactory>();
            mockFactory2.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[1]);

            var resolver = new Mock<IDependencyResolver>();
            resolver.Setup(r => r.GetServices(typeof(ValueProviderFactory))).Returns(new[] { mockFactory1.Object, mockFactory2.Object });
            ValueProviderFactoryCollection factories = new ValueProviderFactoryCollection(new ValueProviderFactory[0], resolver.Object);

            // Act
            ValueProviderCollection valueProviders = (ValueProviderCollection)factories.GetValueProvider(controllerContext);

            // Assert
            Assert.Equal(expectedValueProviders, valueProviders.ToArray());
        }
        public void SetNullValueProviderFactoryThrows()
        {
            // Arrange
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();
            collection.Add(new Mock<ValueProviderFactory>().Object);

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { collection[0] = null; },
                "item");
        }
Esempio n. 40
0
 public static void RegisterValueProviders(ValueProviderFactoryCollection factories)
 {
     factories.Add(new CookieValueProviderFactory());
 }
        public void GetValueProviderDelegatesToResolver()
        {
            //Arrange
            ControllerContext controllerContext = new ControllerContext();
            IValueProvider[] expectedValueProviders = new[]
            {
                new Mock<IValueProvider>().Object,
                new Mock<IValueProvider>().Object
            };

            Mock<ValueProviderFactory> mockFactory1 = new Mock<ValueProviderFactory>();
            mockFactory1.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[0]);
            Mock<ValueProviderFactory> mockFactory2 = new Mock<ValueProviderFactory>();
            mockFactory2.Setup(o => o.GetValueProvider(controllerContext)).Returns(expectedValueProviders[1]);

            Resolver<IEnumerable<ValueProviderFactory>> resolver = new Resolver<IEnumerable<ValueProviderFactory>> { Current = new[] { mockFactory1.Object, mockFactory2.Object } };
            ValueProviderFactoryCollection factories = new ValueProviderFactoryCollection(resolver);

            // Act
            ValueProviderCollection valueProviders = (ValueProviderCollection)factories.GetValueProvider(controllerContext);

            // Assert
            Assert.Equal(expectedValueProviders, valueProviders.ToArray());
        }