public void Activate <T>(T controller, HandleInfo handleInfo) where T : ViewController { View view = controller.View; MockedEvent controlsCreated = null; MockedEvent currentObjectChanged = null; if (handleInfo != null) { if (handleInfo.ControlsCreated) { using (RecorderManager.StartRecording()) { view.ControlsCreated += null; } controlsCreated = RecorderManager.LastMockedEvent; } if (handleInfo.CurrentObjectChanged) { using (RecorderManager.StartRecording()) { view.CurrentObjectChanged += null; } currentObjectChanged = RecorderManager.LastMockedEvent; } } controller.Active.Clear(); controller.Active[""] = true; if (controlsCreated != null) { controlsCreatedHandler = (EventHandler)controlsCreated.GetEventHandle(); } if (currentObjectChanged != null) { currentObjectChangedHandler = (EventHandler)currentObjectChanged.GetEventHandle(); } }
private T createController <T>(Type objectType, bool activate, XPObjectSpace XPObjectSpace, HandleInfo handleInfo) where T : ViewController { XafTypesInfo.Instance.RegisterEntity(objectType); var source = new CollectionSource(XPObjectSpace, objectType); var listEditor = Isolate.Fake.Instance <ListEditor>(); Isolate.WhenCalled(() => listEditor.RequiredProperties).WillReturn(new string[0]); var listView = new ListView(source, listEditor); Isolate.WhenCalled(() => listView.ObjectTypeInfo).WillReturn(XafTypesInfo.CastTypeToTypeInfo(objectType)); Isolate.WhenCalled(() => listView.ObjectSpace).WillReturn(XPObjectSpace); var controller = Isolate.Fake.Instance <T>(Members.CallOriginal, ConstructorWillBe.Called); Isolate.WhenCalled(() => controller.Application).WillReturn(Isolate.Fake.Instance <XafApplication>()); controller.Active[""] = false; controller.SetView(listView); View view = controller.View; Isolate.WhenCalled(() => view.ObjectSpace).WillReturn(XPObjectSpace); if (activate) { Activate(controller, handleInfo); } return(controller); }
private T createListViewController <T>(PersistentBase currentObject, bool activate, XPObjectSpace XPObjectSpace, HandleInfo handleInfo) where T : ViewController, new() { var controller = createController <T>(currentObject.GetType(), activate, XPObjectSpace, handleInfo); XafApplication application = controller.Application; Isolate.WhenCalled(() => application.CreateObjectSpace()).WillReturn(XPObjectSpace); return(controller); }
private T createDetailViewController <T>(XPObjectSpace XPObjectSpace, PersistentBase currentObject, bool activate, HandleInfo handleInfo) where T : ViewController, new() { XafTypesInfo.Instance.RegisterEntity(currentObject.GetType().BaseType); XafTypesInfo.Instance.RegisterEntity(currentObject.GetType()); XPObjectSpace.Session.UpdateSchema(currentObject.GetType().BaseType); XPObjectSpace.Session.UpdateSchema(currentObject.GetType()); XPObjectSpace.Session.DataLayer.UpdateSchema(true, XPObjectSpace.Session.GetClassInfo(currentObject.GetType().BaseType)); XPObjectSpace.Session.DataLayer.UpdateSchema(true, XPObjectSpace.Session.GetClassInfo(currentObject.GetType())); var application = Isolate.Fake.Instance <XafApplication>(); Isolate.WhenCalled(() => application.CreateObjectSpace()).WillReturn(XPObjectSpace); var detailView = new DetailView(XPObjectSpace, currentObject, application, true); var conntroller = new T(); Isolate.WhenCalled(() => conntroller.Application).WillReturn(application); conntroller.Active[""] = false; conntroller.SetView(detailView); if (activate) { Activate(conntroller, handleInfo); } return(conntroller); }
public T CreateAndActivateController <T>(ViewType viewType, PersistentBase currentObject, HandleInfo handleInfo) where T : ViewController, new() { return(createController <T>(viewType, currentObject, true, handleInfo)); }
private T createController <T>(ViewType viewType, PersistentBase currentObject, bool activate, HandleInfo handleInfo) where T : ViewController, new() { if (currentObject.Session.IsNewObject(currentObject)) { currentObject.Session.Save(currentObject); } var XPObjectSpace = new XPObjectSpace(new UnitOfWork(currentObject.Session.DataLayer), XafTypesInfo.Instance); var persistentBase = XPObjectSpace.GetObject(currentObject); T controller = viewType == ViewType.ListView ? createListViewController <T>(persistentBase, activate, XPObjectSpace, handleInfo) : createDetailViewController <T>(XPObjectSpace, persistentBase, activate, handleInfo); var frame = new Frame(controller.Application, TemplateContext.View); frame.SetView(controller.View); Isolate.WhenCalled(() => controller.Frame).WillReturn(frame); if (activate) { controller.View.CurrentObject = persistentBase; } return(controller); }