Beispiel #1
0
        public void Initialize_ReplacesOriginalCollection()
        {
            // Arrange
            ModelBinderDictionary oldBinders = new ModelBinderDictionary();

            oldBinders[typeof(int)] = new Mock <IModelBinder>().Object;
            ModelBinderProviderCollection newBinderProviders = new ModelBinderProviderCollection();

            // Act
            ModelBinderConfig.Initialize(oldBinders, newBinderProviders);

            // Assert
            Assert.Empty(oldBinders);

            var shimBinder = Assert.IsType <ExtensibleModelBinderAdapter>(oldBinders.DefaultBinder);

            Assert.Same(newBinderProviders, shimBinder.Providers);
        }
Beispiel #2
0
        public void Initialize_ReplacesOriginalCollection()
        {
            // Arrange
            ModelBinderDictionary oldBinders = new ModelBinderDictionary();

            oldBinders[typeof(int)] = new Mock <IModelBinder>().Object;
            ModelBinderProviderCollection newBinderProviders = new ModelBinderProviderCollection();

            // Act
            ModelBinderConfig.Initialize(oldBinders, newBinderProviders);

            // Assert
            Assert.AreEqual(0, oldBinders.Count, "Old binder dictionary should have been cleared.");

            ExtensibleModelBinderAdapter shimBinder = oldBinders.DefaultBinder as ExtensibleModelBinderAdapter;

            Assert.IsNotNull(shimBinder, "The default binder for the old system should have been replaced with a compatibility shim.");
            Assert.AreSame(newBinderProviders, shimBinder.Providers, "Providers collection was not passed through correctly.");
        }