public void ShouldBindAnEnumValue() { var collection = new ValueProviderCollection(); var nameValueCollection = new NameValueCollection { {"someVariable", EnumFixture.Value2.Name} }; collection.Add(new FormCollection(nameValueCollection)); var modelMetadata = new ModelMetadata(new EmptyModelMetadataProvider(), null, null, typeof(EnumFixture), "someProperty"); var bindingContext = new ModelBindingContext { ModelMetadata = modelMetadata, ValueProvider = collection, ModelName = "someVariable" }; var binderDictionary = new ModelBinderDictionary(); var binder = new EnumModelBinder(binderDictionary); var retrieved = binder.BindModel(null, bindingContext); Assert.IsInstanceOfType(retrieved, typeof(EnumFixture)); var @enum = retrieved as EnumFixture; Assert.AreEqual(EnumFixture.Value2, @enum); }
public void BinderShouldBindValues() { var controllerContext = new ControllerContext(); var binders = new ModelBinderDictionary { { typeof(Foo), new DefaultModelBinder() } }; var input = new FormCollection { { "fooInstance[Bar1].Value", "bar1value" }, { "fooInstance[Bar2].Value", "bar2value" } }; var foos = new[] { new Foo {Name = "Bar1", Value = "uno"}, new Foo {Name = "Bar2", Value = "dos"}, new Foo {Name = "Bar3", Value = "tres"}, }; var providers = new EmptyModelMetadataProvider(); var bindingContext = new ModelBindingContext { ModelMetadata = providers.GetMetadataForType(() => foos, foos.GetType()), ModelName = "fooInstance", ValueProvider = input.ToValueProvider() }; var binder = new KeyedListModelBinder<Foo>(binders, providers, foo => foo.Name); var result = (IList<Foo>)binder.BindModel(controllerContext, bindingContext); Assert.That(result.Count, Is.EqualTo(3)); Assert.That(result[0].Value, Is.EqualTo("bar1value")); Assert.That(result[1].Value, Is.EqualTo("bar2value")); }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { container.Configure(x => { x.For<IAtomPubService>().Singleton().Add<AtomPubService>(); //this is default controller for all, no name given x.For<IController>().Add<AtomPubController>(); }); RegisterController<AtomPubController>(container); RegisterRoutes<AtomPubRouteRegistrar>(container, routes); //register main site master page RegisterPage(container, new Page("Site") { Areas = new[] { "head", "nav", "content", "sidetop", "sidemid", "sidebot", "foot", "tail" }, SupportedScopes = SupportedScopes.EntireSite | SupportedScopes.Workspace | SupportedScopes.Collection | SupportedScopes.Entry }); //register other pages RegisterPage(container, new Page("AtomPubIndex", "Site") { SupportedScopes = SupportedScopes.EntireSite | SupportedScopes.Collection | SupportedScopes.Workspace }); RegisterPage(container, new Page("AtomPubResource", "Site") { SupportedScopes = SupportedScopes.Entry }); }
public EnumModelBinder(ModelBinderDictionary binders) { if (binders == null) throw new ArgumentNullException("binders"); _defaultBinder = binders.DefaultBinder; binders.DefaultBinder = this; }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { RegisterController<WizardController>(container); //RegisterGlobalAsset(globalAssets, "wizard.css"); RegisterPage(container, new Page("Wizard") //master page { Assets = new[] { new Asset("wizard.css", WizardAssetGroup) }, Areas = new[] { "content", "tail" }, SupportedScopes = SupportedScopes.EntireSite }); RegisterPage(container, new Page("WizardBasicSettings", "Wizard")); RegisterPage(container, new Page("WizardComplete", "Wizard")); RegisterPage(container, new Page("WizardSetupChoice", "Wizard") { Areas = new[] { "setupOptions" }, SupportedScopes = SupportedScopes.EntireSite }); RegisterPage(container, new Page("WizardTestInstall", "Wizard")); RegisterPage(container, new Page("WizardThemeChoice", "Wizard")); this.AddRoute(routes, new SiteRoute() { Name = "Wizard", Route = new Route("Wizard/{action}", new RouteValueDictionary(new { controller = "Wizard" }), new MvcRouteHandler()), Merit = DefaultMerit }); this.AddRoute(routes, new SiteRoute() { Name = "WizardCatchAll", Route = new Route("{*all}", new RouteValueDictionary(new { controller = "Wizard", action = "CatchAll" }), new MvcRouteHandler()), Merit = (int)MeritLevel.High + 10000 }); }
public void GetBinderResolvesBindersWithCorrectPrecedence() { // Proper order of precedence: // 1. Binder registered in the global table // 2. Binder attribute defined on the type // 3. Default binder // Arrange IModelBinder registeredFirstBinder = new Mock<IModelBinder>().Object; ModelBinderDictionary binders = new ModelBinderDictionary() { { typeof(MyFirstConvertibleType), registeredFirstBinder } }; IModelBinder defaultBinder = new Mock<IModelBinder>().Object; binders.DefaultBinder = defaultBinder; // Act IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType)); IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType)); IModelBinder binder3 = binders.GetBinder(typeof(object)); // Assert Assert.AreSame(registeredFirstBinder, binder1, "First binder should have been matched in the registered binders table."); Assert.IsInstanceOfType(binder2, typeof(MySecondBinder), "Second binder should have been matched on the type."); Assert.AreSame(defaultBinder, binder3, "Third binder should have been the fallback."); }
public LyniconBinder() { // Use this as the default binder in the scope of BindModel on this binder only var binders = new ModelBinderDictionary(); ModelBinders.Binders.Do(kvp => binders.Add(kvp.Key, kvp.Value)); binders.DefaultBinder = this; this.Binders = binders; }
public static void RegisterModelBinders(ModelBinderDictionary modelBinderDictionary) { modelBinderDictionary.Add(typeof(FacebookAuthResponse), new JsonModelBinder<FacebookAuthResponse>("authResponse")); modelBinderDictionary.Add(typeof(FacebookNotificationResponse), new JsonModelBinder<FacebookNotificationResponse>("facebookNotificationResponse")); modelBinderDictionary.Add(typeof(VerseEngineeringUser), new VerseEngineeringUserBinder()); modelBinderDictionary.Add(typeof(FacebookAccessToken), DependencyResolver.Current.GetService<FacebookAccessTokenModelBinder>()); modelBinderDictionary.Add(typeof(HideCandidateVersesFlag), new HideCandidateVersesFlagModelBinder()); }
public void DefaultBinderProperty() { // Arrange ModelBinderDictionary binders = new ModelBinderDictionary(); IModelBinder binder = new Mock<IModelBinder>().Object; // Act & assert MemberHelper.TestPropertyWithDefaultInstance(binders, "DefaultBinder", binder); }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { container.Configure(c => c.For<IRaterService>().Add<RaterService>()); RegisterController<RaterController>(container); RegisterWidget<RaterWidget>(container); RegisterRoutes<RaterRouteRegistrar>(container, routes); }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { container.Configure(x => x.For<IAnnotateService>().Singleton().Add<AnnotateService>()); RegisterController<AnnotateController>(container); RegisterWidget<AnnotateListWidget>(container); RegisterRoutes<AnnotateRouteRegistrar>(container, routes); }
public RegisterModelBindersTests() { modelBinders = new ModelBinderDictionary(); modelBinder = new FakeModelBinder(); serviceLocator = new Mock<FakeServiceLocator>(); registration = new RegisterModelBinders(modelBinders); }
private static ModelBinderDictionary CreateDefaultBinderDictionary() { // We can't add a binder to the HttpPostedFileBase type as an attribute, so we'll just // prepopulate the dictionary as a convenience to users. ModelBinderDictionary binders = new ModelBinderDictionary() { { typeof(HttpPostedFileBase), new HttpPostedFileBaseModelBinder() } }; return binders; }
public static void RegisterBinder(ModelBinderDictionary binders) { FileCollectionModelBinder binder = new FileCollectionModelBinder(); binders[typeof(HttpPostedFileBase[])] = binder; binders[typeof(IEnumerable<HttpPostedFileBase>)] = binder; binders[typeof(ICollection<HttpPostedFileBase>)] = binder; binders[typeof(IList<HttpPostedFileBase>)] = binder; binders[typeof(Collection<HttpPostedFileBase>)] = binder; binders[typeof(List<HttpPostedFileBase>)] = binder; }
public void DefaultBinderIsInstanceOfDefaultModelBinder() { // Arrange ModelBinderDictionary binders = new ModelBinderDictionary(); // Act IModelBinder defaultBinder = binders.DefaultBinder; // Assert Assert.IsInstanceOfType(defaultBinder, typeof(DefaultModelBinder)); }
public void DefaultBinderIsInstanceOfDefaultModelBinder() { // Arrange ModelBinderDictionary binders = new ModelBinderDictionary(); // Act IModelBinder defaultBinder = binders.DefaultBinder; // Assert Assert.AreEqual(typeof(DefaultModelBinder), defaultBinder.GetType()); }
public static void RegisterModelBinders(ModelBinderDictionary modelBinders, HttpConfiguration config) { modelBinders.Add(typeof(ArticleSlug), new ArticleSlugModelBinder()); modelBinders.Add(typeof(ArticleRevisionDate), new ArticleRevisionDateModelBinder()); modelBinders.Add(typeof(bool?), new BooleanModelBinder()); modelBinders.Add(typeof(bool), new BooleanModelBinder()); AddWebApiModelBinder(config, typeof(ArticleSlug), new ArticleSlugModelBinder()); AddWebApiModelBinder(config, typeof(ArticleRevisionDate), new ArticleRevisionDateModelBinder()); }
// Ensures that when JSON is deserialized null strings become empty.strings before persisting to the database. public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { bindingContext.ModelMetadata.ConvertEmptyStringToNull = false; Binders = new ModelBinderDictionary { DefaultBinder = this }; return base.BindModel(controllerContext, bindingContext); }
public MvcConfigModule(RouteCollection routes, BundleCollection bundles, HandlebarsTemplateTransform jsTemplateTransform, ModelBinderDictionary modelBinders, GlobalFilterCollection globalFilters) { _routes = routes; _bundles = bundles; _jsTemplateTransform = jsTemplateTransform; _modelBinders = modelBinders; _globalFilters = globalFilters; }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { RegisterController<MenuController>(container); RegisterWidget<MenuCustomWidget>(container); RegisterWidget(container, new CompositeWidget("MenuWidget", "Menu", "MenuWidget") { SupportedScopes = SupportedScopes.All, Description = "This widget will automatically create links to your *visible* collections.", AreaHints = new[] { "nav" } }); }
private static ModelBinderDictionary CreateDefaultBinderDictionary() { // We can't add a binder to the HttpPostedFileBase type as an attribute, so we'll just // prepopulate the dictionary as a convenience to users. ModelBinderDictionary binders = new ModelBinderDictionary() { #if UNDEF { typeof(HttpPostedFileBase), new HttpPostedFileBaseModelBinder() }, { typeof(byte[]), new ByteArrayModelBinder() }, { typeof(Binary), new LinqBinaryModelBinder() } #endif }; return binders; }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { RegisterController<WidgetController>(container); RegisterWidget<LiteralWidget>(container); RegisterWidget(container, new ConfigLinkWidget()); RegisterWidget(container, new ConfigLinkWidget("WidgetConfigLinkWidget", new[] { new Asset("WidgetConfig.css", AdminPlugin.AdminAssetGroup)})); RegisterWidget(container, new FeedConfigLinkWidget() { Assets = new[] { new Asset("WidgetConfig.css", AdminPlugin.AdminAssetGroup) } }); }
public static void RegisterBinders(ModelBinderDictionary binders) { var types = Assembly.GetCallingAssembly().GetTypes(); foreach (var binderType in types.Where(x => x.BaseType == typeof(DefaultModelBinder))) { var binder = (IModelBinder)Activator.CreateInstance(binderType); var modelName = binderType.Name.Substring(0, binderType.Name.Length - "Binder".Length); var type = types.First(y => y.Name == modelName); binders.Add(type, binder); } }
public void Init() { var clock = new StubClock(); var appDataFolder = new StubAppDataFolder(clock); _controllerBuilder = new ControllerBuilder(); _routeCollection = new RouteCollection(); _modelBinderDictionary = new ModelBinderDictionary(); _viewEngineCollection = new ViewEngineCollection { new WebFormViewEngine() }; _container = OrchardStarter.CreateHostContainer( builder => { builder.RegisterInstance(new StubShellSettingsLoader()).As<IShellSettingsManager>(); builder.RegisterType<RoutePublisher>().As<IRoutePublisher>(); builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>(); builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>(); builder.RegisterType<StubExtensionManager>().As<IExtensionManager>(); builder.RegisterType<StubVirtualPathMonitor>().As<IVirtualPathMonitor>(); builder.RegisterInstance(appDataFolder).As<IAppDataFolder>(); builder.RegisterInstance(_controllerBuilder); builder.RegisterInstance(_routeCollection); builder.RegisterInstance(_modelBinderDictionary); builder.RegisterInstance(_viewEngineCollection); builder.RegisterAutoMocking() .Ignore<IExtensionFolders>() .Ignore<IRouteProvider>() .Ignore<IHttpRouteProvider>() .Ignore<IModelBinderProvider>() .Ignore<IWorkContextEvents>() .Ignore<IOwinMiddlewareProvider>(); }); _lifetime = _container.BeginLifetimeScope(); _container.Mock<IContainerProvider>() .SetupGet(cp => cp.ApplicationContainer).Returns(_container); _container.Mock<IContainerProvider>() .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime); _container.Mock<IContainerProvider>() .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose()); _container.Mock<IShellDescriptorManager>() .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor)); _container.Mock<IOrchardShellEvents>() .Setup(e => e.Activated()); _container.Mock<IOrchardShellEvents>() .Setup(e => e.Terminating()).Callback(() => new object()); }
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."); }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { RegisterWidget(container, new CompositeWidget("GA4AtomSiteWidget", "GA4AtomSite", "Widget") { Description = "This widget adds Google Analytics tracking code to the page, that is capable of tracking javascript disabled browsers as well.", SupportedScopes = SupportedScopes.All, OnGetConfigInclude = (p) => new ConfigLinkInclude(p, "GA4AtomSite", "Config"), OnValidate = (i) => { var gaInclude = new GA4AtomSiteInclude(i); return !string.IsNullOrEmpty(gaInclude.GoogleAccountID); }, AreaHints = new[] { "foot", "tail" } }); RegisterController<GA4AtomSiteController>(container); }
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); }
public void Init() { _controllerBuilder = new ControllerBuilder(); _routeCollection = new RouteCollection(); _modelBinderDictionary = new ModelBinderDictionary(); _viewEngineCollection = new ViewEngineCollection { new WebFormViewEngine() }; _container = OrchardStarter.CreateHostContainer( builder => { builder.RegisterInstance(new StubShellSettingsLoader()).As<IShellSettingsManager>(); builder.RegisterType<StubContainerProvider>().As<IContainerProvider>().InstancePerLifetimeScope(); builder.RegisterType<RoutePublisher>().As<IRoutePublisher>(); builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>(); builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>(); builder.RegisterType<StubExtensionManager>().As<IExtensionManager>(); builder.RegisterInstance(_controllerBuilder); builder.RegisterInstance(_routeCollection); builder.RegisterInstance(_modelBinderDictionary); builder.RegisterInstance(_viewEngineCollection); builder.RegisterAutoMocking() .Ignore<IExtensionFolders>() .Ignore<IRouteProvider>() .Ignore<IModelBinderProvider>(); }); _lifetime = _container.BeginLifetimeScope(); _container.Mock<IContainerProvider>() .SetupGet(cp => cp.ApplicationContainer).Returns(_container); _container.Mock<IContainerProvider>() .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime); _container.Mock<IContainerProvider>() .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose()); _container.Mock<IShellDescriptorManager>() .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor)); var temp = Path.GetTempFileName(); File.Delete(temp); Directory.CreateDirectory(temp); _container.Resolve<IAppDataFolder>() .SetBasePath(temp); var updater = new ContainerUpdater(); updater.RegisterInstance(_container).SingleInstance(); updater.Update(_lifetime); }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { RegisterWidget(container, new CompositeWidget("TwitterWidget", "Twitter", "Widget") { Description = "This widget displays tweets from a public twitter feed.", Assets = new string[] { "TwitterPlugin.css" }.Select(a => new Asset(a)), SupportedScopes = SupportedScopes.All, OnGetConfigInclude = (p) => new ConfigLinkInclude(p, "Twitter", "Config"), OnValidate = (i) => { var ti = new TwitterInclude(i); return !string.IsNullOrEmpty(ti.Username) && ti.Count > 0; }, AreaHints = new[] { "sidetop", "sidemid", "sidebot" } }); RegisterController<TwitterController>(container); }
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets) { RegisterController<ContactController>(container); RegisterWidget(container, new CompositeWidget("ContactWidget", "Contact", "ContactWidget") { SupportedScopes = Domain.SupportedScopes.All, Description = "This widget adds a contact form that user can send an email to you.", Assets = new Asset[] { new Asset("Contact.css"), new Asset("Contact.js") }, AreaHints = new[] { "content" } }); RegisterWidget(container, new CompositeWidget("ContactSettingsWidget", "Contact", "ContactSettings") { SupportedScopes = Domain.SupportedScopes.Workspace, Description = "This widget allows you to modify the contact form settings for any contact forms placed within a workspace.", AreaHints = new[] { "settingsPane" } }); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(ArchiveData)] = new ArchiveDataModelBinder(); modelBinders[typeof(Area)] = new AreaModelBinder(); modelBinders[typeof(Comment)] = new CommentModelBinder(); modelBinders[typeof(PostBase)] = new PostBaseModelBinder(); modelBinders[typeof(Post)] = new PostModelBinder(); modelBinders[typeof(Page)] = new PageModelBinder(); modelBinders[typeof(SearchCriteria)] = new SearchCriteriaModelBinder(); modelBinders[typeof(Tag)] = new TagModelBinder(); modelBinders[typeof(UserBase)] = new UserBaseModelBinder(); modelBinders[typeof(Site)] = new SiteModelBinder(); modelBinders[typeof(Plugin)] = new PluginModelBinder(); modelBinders[typeof(AreaSearchCriteria)] = new AreaSearchCriteriaModelBinder(); modelBinders[typeof(User)] = new UserModelBinder(); modelBinders[typeof(PostAddress)] = new PostAddressModelBinder(); modelBinders[typeof(FileAddress)] = new FileAddressModelBinder(); modelBinders[typeof(FileInput)] = new FileInputModelBinder(); modelBinders[typeof(FileContentInput)] = new FileContentInputModelBinder(); }
private static void registerModelBinders() { ModelBinderDictionary binders = System.Web.Mvc.ModelBinders.Binders; binders[typeof(ArchiveData)] = new ArchiveDataModelBinder(); binders[typeof(Area)] = new AreaModelBinder(); binders[typeof(Comment)] = new CommentModelBinder(); binders[typeof(PostBase)] = new PostBaseModelBinder(); binders[typeof(Post)] = new PostModelBinder(); binders[typeof(Page)] = new PageModelBinder(); binders[typeof(SearchCriteria)] = new SearchCriteriaModelBinder(); binders[typeof(Tag)] = new TagModelBinder(); binders[typeof(UserBase)] = new UserBaseModelBinder(); binders[typeof(Site)] = new SiteModelBinder(); binders[typeof(Plugin)] = new PluginModelBinder(); binders[typeof(AreaSearchCriteria)] = new AreaSearchCriteriaModelBinder(); binders[typeof(User)] = new UserModelBinder(); //TODO: (erikpo) Once we have the plugin model completed, load up all available model binders here instead of hardcoding them. }
public void GetBinderConsultsProviders() { //Arrange Type modelType = typeof(string); IModelBinder expectedBinderFromProvider = new Mock <IModelBinder>().Object; Mock <IModelBinderProvider> locatedProvider = new Mock <IModelBinderProvider>(); locatedProvider.Setup(p => p.GetBinder(modelType)) .Returns(expectedBinderFromProvider); Mock <IModelBinderProvider> secondProvider = new Mock <IModelBinderProvider>(); ModelBinderProviderCollection providers = new ModelBinderProviderCollection(new IModelBinderProvider[] { locatedProvider.Object, secondProvider.Object }); ModelBinderDictionary binders = new ModelBinderDictionary(providers); //Act IModelBinder returnedBinder = binders.GetBinder(modelType); //Assert Assert.AreSame(expectedBinderFromProvider, returnedBinder); }
public void Execute(IDictionary <string, object> state) { OxiteConfigurationSection config = container.Resolve <OxiteConfigurationSection>(); IModulesLoaded modulesLoaded = this.container.Resolve <IModulesLoaded>(); RouteCollection routes = this.container.Resolve <RouteCollection>(); IFilterRegistry filterRegistry = this.container.Resolve <FilterRegistry>(); ModelBinderDictionary modelBinders = this.container.Resolve <ModelBinderDictionary>(); filterRegistry.Clear(); modelBinders.Clear(); //todo: (nheskew) get plugin routes registered on load in the right order instead of just clearing the routes before module init routes.Clear(); foreach (OxiteModuleConfigurationElement module in config.Modules) { IOxiteModule moduleInstance = modulesLoaded.Load(config, module); if (moduleInstance != null) { moduleInstance.RegisterWithContainer(); moduleInstance.Initialize(); moduleInstance.RegisterFilters(filterRegistry); moduleInstance.RegisterModelBinders(modelBinders); this.container.RegisterInstance(modulesLoaded); } } routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.LoadFromModules(modulesLoaded); routes.LoadCatchAllFromModules(modulesLoaded); container.RegisterInstance(filterRegistry); }
protected static void Establish(Type[] types = null, bool isAjax = true) { typeof(DispatcherControllerBase).GetField("types", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, new List <Type>()); dispatcher = Pleasure.Mock <IDispatcher>(); IoCFactory.Instance.StubTryResolve(dispatcher.Object); controller = new FakeDispatcher(); var requestBase = Pleasure.MockAsObject <HttpRequestBase>(mock => { if (isAjax) { mock.SetupGet(r => r.Headers).Returns(new NameValueCollection { { "X-Requested-With", "XMLHttpRequest" } }); } mock.SetupGet(r => r.Form).Returns(new NameValueCollection() { { "[0].Name", "Value" }, { "[1].Name", "Value" }, }); }); controller.ControllerContext = new ControllerContext(Pleasure.MockStrictAsObject <HttpContextBase>(mock => mock.SetupGet(r => r.Request).Returns(requestBase)), new RouteData(), controller); controller.ValueProvider = Pleasure.MockStrictAsObject <IValueProvider>(mock => mock.Setup(r => r.GetValue(Pleasure.MockIt.IsAny <string>())).Returns(new ValueProviderResult(string.Empty, string.Empty, Thread.CurrentThread.CurrentCulture))); var modelBinderDictionary = new ModelBinderDictionary(); var modelBinder = Pleasure.MockAsObject <IModelBinder>(mock => mock.Setup(r => r.BindModel(Pleasure.MockIt.IsAny <ControllerContext>(), Pleasure.MockIt.IsAny <ModelBindingContext>()))); foreach (var type in types.Recovery(new Type[] { })) { modelBinderDictionary.Add(type, modelBinder); } controller.SetValue("Binders", modelBinderDictionary); }
public void GetBinderDoesNotReturnDefaultBinderIfAskedNotTo() { // Proper order of precedence: // 1. Binder registered in the global table // 2. Binder attribute defined on the type // 3. <null> // Arrange IModelBinder registeredFirstBinder = new Mock <IModelBinder>().Object; ModelBinderDictionary binders = new ModelBinderDictionary() { { typeof(MyFirstConvertibleType), registeredFirstBinder } }; // Act IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType), false /* fallbackToDefault */); IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType), false /* fallbackToDefault */); IModelBinder binder3 = binders.GetBinder(typeof(object), false /* fallbackToDefault */); // Assert Assert.AreSame(registeredFirstBinder, binder1, "First binder should have been matched in the registered binders table."); Assert.IsInstanceOfType(binder2, typeof(MySecondBinder), "Second binder should have been matched on the type."); Assert.IsNull(binder3, "Third binder should have returned null since asked not to use default."); }
public void GetBinderDoesNotReturnDefaultBinderIfAskedNotTo() { // Proper order of precedence: // 1. Binder registered in the global table // 2. Binder attribute defined on the type // 3. <null> // Arrange IModelBinder registeredFirstBinder = new Mock <IModelBinder>().Object; ModelBinderDictionary binders = new ModelBinderDictionary() { { typeof(MyFirstConvertibleType), registeredFirstBinder } }; // Act IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType), false /* fallbackToDefault */); IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType), false /* fallbackToDefault */); IModelBinder binder3 = binders.GetBinder(typeof(object), false /* fallbackToDefault */); // Assert Assert.Same(registeredFirstBinder, binder1); Assert.IsType <MySecondBinder>(binder2); Assert.Null(binder3); }
internal static void RegisterModelBinders(ModelBinderDictionary modelBinderDictionary) { modelBinderDictionary.Add(typeof(CreateOrEditPostModel), new CreateOrEditPostCustomDataBinder()); }
public static void RegisterModelBinders(ModelBinderDictionary modelBinders) { GlobalModelBinders.Register(modelBinders); }
public ModelBinderPublisher(ModelBinderDictionary binders) { _binders = binders; }
internal static void Initialize(ModelBinderDictionary binders, ModelBinderProviderCollection providers) { binders.Clear(); binders.DefaultBinder = new ExtensibleModelBinderAdapter(providers); }
/// <summary> /// 注册模型绑定 /// </summary> /// <param name="modelBinders">模型绑定器</param> public override void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders.Add(new KeyValuePair <Type, IModelBinder>(typeof(int[]), new Int32ArrayModelBinder())); }
public static void RegisterCustomBinders(ModelBinderDictionary binders) { AddFilterNodeBindings(binders); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(PageAddress)] = new PageAddressModelBinder(); modelBinders[typeof(PageInput)] = new PageInputModelBinder(); modelBinders[typeof(ContentItemsInput)] = new ContentItemsInputModelBinder(); }
public static void RegisterGlobalBindings(ModelBinderDictionary binders, HttpConfiguration configuration) { ModelBinders.Binders.Add(typeof(VersionCheckDetails), new VersionCheckDetailsModelBinder()); }
public static void Register(ModelBinderDictionary binder) { binder.Add(typeof(ObjectId), new ObjectIdBinder()); binder.Add(typeof(string[]), new StringArrayBinder()); binder.Add(typeof(int[]), new IntArrayBinder()); }
public static void RegisterModelBinders(ModelBinderDictionary binders) { binders.Add(typeof(decimal), new DecimalModelBinder()); binders.Add(typeof(decimal?), new DecimalModelBinder()); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(SearchCriteria)] = new SearchCriteriaModelBinder(); }
// For unit tests public void SetModelBinderDictionary(ModelBinderDictionary modelBinderDictionary) { Binders = modelBinderDictionary; }
public static void RegisterBindles(ModelBinderDictionary modelBinder) { //modelBinder.Add(typeof(AddRoleVm), new JsonNetModelBinder()); }
/// <summary> /// Globally-used model binders /// </summary> public static void Register(ModelBinderDictionary modelBinders) { modelBinders.DefaultBinder = new CustomModelBinder(); modelBinders.Add(typeof(BirthDateModelBinder), new BirthDateModelBinder()); }
public static void RegisterBinders(ModelBinderDictionary modelBinderDictionary) { modelBinderDictionary.Add(typeof(FilterRequest), new LegacyFilterRequestModelBinder()); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(UserChangePasswordInput)] = new UserChangePasswordInputModelBinder(); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(TagAddress)] = new TagAddressModelBinder(); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(Tag)] = container.Resolve <TagModelBinder>(); }
public static void RegisterBinder(ModelBinderDictionary binders) { EnumerationBinderHelper.RegisterBinders(binders, typeof(Repository).Assembly); EnumerationBinderHelper.RegisterBinders(binders, typeof(BinderConfig).Assembly); }
public void RegisterModelBinders(ModelBinderDictionary modelBinders) { modelBinders[typeof(Site)] = new SiteModelBinder(); modelBinders[typeof(DialogSelection)] = new DialogSelectionModelBinder(); }
public static void RegisterBinders(ModelBinderDictionary binders) { binders.UseAuthorizationModelBinder(); binders.Add(typeof(string), new TrimStringModelBinder()); }
public static void RegisterCustomModelBinders(ModelBinderDictionary modelBinders) { modelBinders.Add(typeof(DateTime), new DateTimeModelBinder()); modelBinders.Add(typeof(DateTime?), new DateTimeModelBinder()); }