Model mapper for web models for use in the CMS
Inheritance: AbstractFluentMappingEngine
        protected virtual void Init()
        {
            var attributeTypeRegistry = new CmsAttributeTypeRegistry();
            AttributeTypeRegistry.SetCurrent(attributeTypeRegistry);

            FrameworkContext = new FakeFrameworkContext();

            var hive = CreateHiveManager();
            
            RebelApplicationContext = CreateApplicationContext(hive);

            var resolverContext = new MockedMapResolverContext(FrameworkContext, hive, new MockedPropertyEditorFactory(RebelApplicationContext), new MockedParameterEditorFactory());
            var webmModelMapper = new CmsModelMapper(resolverContext);

            FrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(FrameworkContext) }));

            DevDataset = DemoDataHelper.GetDemoData(RebelApplicationContext, attributeTypeRegistry);
            FixedPropertyEditors = new FixedPropertyEditors(RebelApplicationContext);

            //ensure model binders
            ModelBinders.Binders.Remove(typeof(HiveId));
            ModelBinders.Binders.Add(typeof(HiveId), new HiveIdModelBinder());
            ModelBinders.Binders.Remove(typeof(DocumentTypeEditorModel));
            ModelBinders.Binders.Add(typeof(DocumentTypeEditorModel), new DocumentTypeModelBinder());
            ModelBinders.Binders.Remove(typeof(SizeModelBinder));
            ModelBinders.Binders.Add(typeof(SizeModelBinder), new SizeModelBinder());

            //set the model meta data provider
            ModelMetadataProviders.Current = new RebelModelMetadataProvider();
        }
        public void Setup()
        {
            _nhibernateTestSetup = new NhibernateTestSetupHelper();

            var storageProvider = new IoHiveTestSetupHelper(_nhibernateTestSetup.FakeFrameworkContext);

            Hive = new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                _nhibernateTestSetup.ReadonlyProviderSetup,
                                _nhibernateTestSetup.ProviderSetup,
                                _nhibernateTestSetup.FakeFrameworkContext),
                            storageProvider.CreateGroup("uploader", "storage://file-uploader"),
                        },
                    _nhibernateTestSetup.FakeFrameworkContext);

            var appContext = new FakeRebelApplicationContext(Hive, false);

            var resolverContext = new MockedMapResolverContext(_nhibernateTestSetup.FakeFrameworkContext, Hive, new MockedPropertyEditorFactory(appContext), new MockedParameterEditorFactory());
            var webmModelMapper = new CmsModelMapper(resolverContext);
            var renderModelMapper = new RenderTypesModelMapper(resolverContext);

            _nhibernateTestSetup.FakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, renderModelMapper, new FrameworkModelMapper(_nhibernateTestSetup.FakeFrameworkContext) }));

            var membersMembershipProvider = new MembersMembershipProvider { AppContext = appContext };
            membersMembershipProvider.Initialize("MembersMembershipProvider", new NameValueCollection());
            MembershipService = new MembershipService<Member, MemberProfile>(appContext.FrameworkContext, Hive,
                "security://member-profiles", "security://member-groups", Framework.Security.Model.FixedHiveIds.MemberProfileVirtualRoot,
                membersMembershipProvider, Enumerable.Empty<MembershipProviderElement>());

            PublicAccessService = new PublicAccessService(Hive, MembershipService, appContext.FrameworkContext);

            var serializer = new ServiceStackSerialiser();
            SerializationService = new SerializationService(serializer);
        }
        public void TestSetup()
        {
            this.Setup = new NhibernateTestSetupHelper();
            this._singleProvider = new ProviderMappingGroup("default", new WildcardUriMatch(new Uri("content://")), this.Setup.ReadonlyProviderSetup, this.Setup.ProviderSetup, this.Setup.FakeFrameworkContext);
            this.HiveManager = new HiveManager(this._singleProvider, this._singleProvider.FrameworkContext);

            this.AppContext = new FakeRebelApplicationContext(this.HiveManager, false);

            this._resolverContext = new MockedMapResolverContext(this.HiveManager.FrameworkContext, this.HiveManager, new MockedPropertyEditorFactory(this.AppContext), new MockedParameterEditorFactory());

            //mappers
            var cmsModelMapper = new CmsModelMapper(this._resolverContext);
            var persistenceToRenderModelMapper = new RenderTypesModelMapper(this._resolverContext);
            
            this.Setup.FakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { cmsModelMapper, persistenceToRenderModelMapper }));

            var membersMembershipProvider = new MembersMembershipProvider { AppContext = AppContext };
            MembershipService = new MembershipService<Member, MemberProfile>(AppContext.FrameworkContext, HiveManager,
                "security://member-profiles", "security://member-groups", Framework.Security.Model.FixedHiveIds.MemberProfileVirtualRoot,
                membersMembershipProvider, Enumerable.Empty<MembershipProviderElement>());

            PublicAccessService = new PublicAccessService(HiveManager, MembershipService, AppContext.FrameworkContext);
        }
        private HiveId ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext)
        {

            var modelBinder = new HiveIdModelBinder();
            var httpContextFactory = new FakeHttpContextFactory("~/Rebel/Editors/ContentEditor/Edit/1", routeData);



            var fakeFrameworkContext = new FakeFrameworkContext();
            var hive = FakeHiveCmsManager.New(fakeFrameworkContext);
            var appContext = new FakeRebelApplicationContext(hive);
            var resolverContext = new MockedMapResolverContext(fakeFrameworkContext, hive, new MockedPropertyEditorFactory(appContext), new MockedParameterEditorFactory());
            var webmModelMapper = new CmsModelMapper(resolverContext);

            fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(fakeFrameworkContext) }));
            var rebelApplicationContext = new FakeRebelApplicationContext(hive);

            controllerContext = new ControllerContext(
                httpContextFactory.RequestContext,
                new ContentEditorController(new FakeBackOfficeRequestContext(rebelApplicationContext)));

            //put both the form and route values in the value provider
            var routeDataValueProvider = new RouteDataValueProvider(controllerContext);
            var values = new ValueProviderCollection(new List<IValueProvider>()
                                                         {
                                                             form, 
                                                             routeDataValueProvider
                                                         });

            bindingContext = GetBindingContext(new HiveId(1), values);

            //do the binding!

            var model = modelBinder.BindModel(controllerContext, bindingContext);

            //assert!

            Assert.That(model, Is.InstanceOf<HiveId>(), "Model isn't a HiveId");
            var boundModel = (HiveId)model;
            return boundModel;
        }