protected internal virtual void OnDifferenceObjectSaving(ModelDifferenceObject modelDifferenceObject, Dictionary diffDictionary)
 {
     Dictionary dictionary = modelDifferenceObject.GetCombinedModel();
     dictionary.CombineWith(diffDictionary);
     modelDifferenceObject.Model = dictionary.GetDiffs();
     objectSpace.CommitChanges();
 }
Example #2
0
        public void If_User_Has_Permnission_To_Combine_With_Application_Model_Combination_Should_Occur()
        {
            ModelCombinePermission permission = null;
            Isolate.WhenCalled(() => SecuritySystem.IsGranted(null)).DoInstead(context =>
            {
                permission = context.Parameters[0] as ModelCombinePermission;
                return true;
            });
            var modelAspectObject = new ModelDifferenceObject(Session.DefaultSession){Model =DefaultDictionary,PersistentApplication = new PersistentApplication(Session.DefaultSession)};
            var queryModelAspectObject = Isolate.Fake.InstanceAndSwapAll<QueryModelDifferenceObject>();
            Isolate.WhenCalled(() => queryModelAspectObject.GetActiveModelDifference(  "")).WillReturn(modelAspectObject);
            var store = new XpoUserModelDictionaryDifferenceStore( Isolate.Fake.Instance<XafApplication>());
            var aspectObject = new UserModelDifferenceObject(Session.DefaultSession){
                                                                                        PersistentApplication = new PersistentApplication(Session.DefaultSession),
                                                                                        NonPersistent = true,
                                                                                        Model = DefaultDictionary2
                                                                                    };
            
            store.OnDifferenceObjectSaving(aspectObject, new Dictionary());


            Assert.IsNotNull(permission);
            Assert.AreEqual(ApplicationModelCombineModifier.Allow, permission.Modifier);
            Assert.IsFalse(modelAspectObject.IsNewObject);
            Assert.IsNotNull(new ApplicationNodeWrapper(modelAspectObject.Model).BOModel.FindClassByName("MyClass2"));
        }
        public void When_Saving_Should_Combine_With_Diffs(){
            var modelDictionaryDifferenceStore = Isolate.Fake.Instance<XpoModelDictionaryDifferenceStore>(Members.CallOriginal);
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession);

            modelDictionaryDifferenceStore.OnDifferenceObjectSaving(modelDifferenceObject, DefaultDictionary);

            Assert.AreEqual(DefaultDictionary.RootNode.ToXml(), modelDifferenceObject.Model.RootNode.ToXml());
        }
Example #4
0
        public void AddAspects(ModelDifferenceObject modelDifferenceObject){

            if (_dictionary== null)
                _dictionary = modelDifferenceObject.Model;
            AddAspects(modelDifferenceObject.Model);
            if (_modelDifferenceObject != null) 
                _modelDifferenceObject.Model=_dictionary;
        }
        public void Can_Be_Deleted(){
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)};
            modelDifferenceObject.Save();

            modelDifferenceObject.Delete();

            Assert.IsTrue(modelDifferenceObject.IsDeleted);
        }
        public void Can_Be_Cloned(){
            
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)};

            var xpSimpleObject = new Cloner().CloneTo(modelDifferenceObject, typeof (ModelDifferenceObject));

            Assert.IsNotNull(xpSimpleObject);
        }
        public void When_Changing_PrefferedLanguage_Then_Model_CurrentAspect_Should_Be_ModelDifference_CurrentLanguage(){
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)};
            var dictionary = DefaultDictionary;
            modelDifferenceObject.Model=dictionary;

            modelDifferenceObject.PreferredAspect = "el ";

            Assert.AreEqual(modelDifferenceObject.CurrentLanguage, modelDifferenceObject.Model.CurrentAspect);
        }
        private static void SetUp(ModelDifferenceObject modelDifferenceObject)
        {

            modelDifferenceObject.DateCreated = DateTime.Now;
            modelDifferenceObject.Name = "AutoCreated " + DateTime.Now;
            var dictionary = new Dictionary(new DictionaryNode(ApplicationNodeWrapper.NodeName), Schema.GetCommonSchema());
            modelDifferenceObject.Model=dictionary;
            
        }
        public void Cause_PersistentApplication_ShouldBe_Unique_Should_Query_DataStore_Befare_Creating_New(){
            var application = new PersistentApplication(Session.DefaultSession){UniqueName = "appName"};
            application.Save();
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession);


            modelDifferenceObject.InitializeMembers("", "appName");

            Assert.AreEqual(application, modelDifferenceObject.PersistentApplication);
        }
        public void When_Changing_PreferredAspect_To_Default_Then_XmlContent_Should_Have_Only_The_Default_diff(){

            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = new PersistentApplication(Session.DefaultSession) { Model = new Dictionary(Schema.GetCommonSchema()) } };
            DefaultDictionary.AddAspect("el", elDictionary.RootNode);
            modelDifferenceObject.Model = DefaultDictionary;

            modelDifferenceObject.PreferredAspect = DictionaryAttribute.DefaultLanguage;

            Assert.AreEqual(new DictionaryXmlReader().ReadFromString(DefaultClassXml).ToXml(), new DictionaryXmlReader().ReadFromString(modelDifferenceObject.XmlContent).ToXml());
        }
        public void PersistentApplication_Is_Required()
        {
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = null };

            var validationResult = new RuleSet().ValidateTarget(modelDifferenceObject, ContextIdentifier.Save);

            var validationResultItem = validationResult.Results.Where(item => item.Rule is RuleRequiredField && item.Rule.UsedProperties.Contains(modelDifferenceObject.GetPropertyInfo(x => x.PersistentApplication).Name)).FirstOrDefault();
            Assert.IsNull(modelDifferenceObject.PersistentApplication);
            Assert.IsNotNull(validationResultItem);
            Assert.AreEqual(ValidationState.Invalid, validationResultItem.State);
        }
        public void When_Changing_PrefferedAspect_To_Non_Default_Then_XmlContent_SHould_CurrentAspect_Diffs()
        {
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = new PersistentApplication(Session.DefaultSession) { Model = new Dictionary(Schema.GetCommonSchema()) } };
            DefaultDictionary.AddAspect("el", elDictionary.RootNode);
            modelDifferenceObject.Model = DefaultDictionary;

            modelDifferenceObject.PreferredAspect = "el";

            Assert.AreEqual(new DictionaryXmlReader().ReadFromString(elClassXml).ToXml(), new DictionaryXmlReader().ReadFromString(modelDifferenceObject.XmlContent).ToXml());

        }
Example #13
0
        public void When_Updating_Model_It_Should_Add_AllCultures_As_Predifined_Values_Of_CurrentLanguage_Member(){
            var dictionary = DictionaryFactory.Create(typeof(ModelDifferenceObject));
            var module = new ModelDifferenceModule();
            Isolate.WhenCalled(() => module.GetAllCultures()).WillReturn("test");

            module.UpdateModel(dictionary);

            var name = new ModelDifferenceObject(Session.DefaultSession).GetPropertyInfo(x=>x.PreferredAspect).Name;
            var single = new ApplicationNodeWrapper(dictionary).BOModel.FindClassByType(typeof(ModelDifferenceObject)).AllProperties.Where(wrapper => wrapper.Name==name).Single();
            Assert.AreEqual("test", single.Node.GetAttributeValue("PredefinedValues"));
        }
Example #14
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
//            return;
            string modelId = typeof(MasterDetailStore).Name;
            if (new QueryModelDifferenceObject(Session).GetActiveModelDifference(modelId) == null)
            {
                ModelDifferenceObject modelDifferenceObject =
                    new ModelDifferenceObject(Session).InitializeMembers(modelId);
                modelDifferenceObject.Name = modelId;
                modelDifferenceObject.Save();
            }
        }
        public void Many_Disabled_Objects_With_Same_ApplicationName_DifferenceType_Can_Exist(DifferenceType differenceType, ValidationState validationState)
        {
            var ruleSet = new RuleSet();

            var persistentApplication = new PersistentApplication(Session.DefaultSession);
            new ModelDifferenceObject(Session.DefaultSession) { Disabled = true, PersistentApplication = persistentApplication }.Save();

            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { Disabled = true, PersistentApplication = persistentApplication };
            Isolate.WhenCalled(() => modelDifferenceObject.DifferenceType).WillReturn(differenceType);
            RuleSetValidationResult target = ruleSet.ValidateTarget(modelDifferenceObject, ContextIdentifier.Save);

            var resultItem = target.Results.Where(item => item.Rule is RuleCombinationOfPropertiesIsUnique).Single();
            Assert.AreEqual(validationState, resultItem.State);
        }
        public void CurrentObjectModel_Should_Be_Equal_CurrentObject_PersistentApp_Not_Modified_Cloned_Combined_With_Controller_Diffs(){

            string s = "<Application><BOModel><Class Name=\"MyClass2\" Caption=\"el\"></Class></BOModel></Application>";
            var modelEditorPropertyEditor = new ModelEditorPropertyEditor(null, null);
            Isolate.WhenCalled(() => modelEditorPropertyEditor.Control.Controller.IsModified).WillReturn(true);
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession);
            Isolate.WhenCalled(() => modelEditorPropertyEditor.CurrentObject).WillReturn(modelDifferenceObject);
            Isolate.WhenCalled(() => modelDifferenceObject.PersistentApplication.Model.Clone()).WillReturn(DefaultDictionary2);
            Isolate.WhenCalled(() => modelEditorPropertyEditor.Control.Controller.Dictionary.GetDiffs()).WillReturn(new Dictionary(new DictionaryXmlReader().ReadFromString(s),Schema.GetCommonSchema()));

            modelEditorPropertyEditor.ModifyCurrentObjectModel();
            
            Assert.AreEqual("el", new ApplicationNodeWrapper(modelDifferenceObject.Model).BOModel.FindClassByName("MyClass2").Caption);
        }
        public void As_Active_Difference_Will_Return_Active_ModelActiveObjects()
        {
            var store = Isolate.Fake.Instance<XpoModelDictionaryDifferenceStore>(Members.CallOriginal, ConstructorWillBe.Called,
                                                                         Session.DefaultSession,
                                                                         Isolate.Fake.Instance<XafApplication>(), false);
            Isolate.Fake.StaticMethods(typeof(ModelDifferenceObjectBuilder));
            var modelStoreObject = new ModelDifferenceObject(Session.DefaultSession);
            var queryModelDifferenceObject = Isolate.Fake.InstanceAndSwapAll<QueryModelDifferenceObject>();
            Isolate.WhenCalled(() => queryModelDifferenceObject.GetActiveModelDifference("")).WillReturn(modelStoreObject);

            ModelDifferenceObject newDifference = store.GetActiveDifferenceObject();

            Assert.AreEqual(modelStoreObject, newDifference);
        }
        public void When_Changing_XmlContent_It_Should_Be_Validated_Against_Application_Schema(){
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession){
                                                                                             PersistentApplication =new PersistentApplication(Session.DefaultSession) { Model = DefaultDictionary }
                                                                                         };
            var dictionary = Isolate.Fake.InstanceAndSwapAll<Dictionary>(Members.CallOriginal,ConstructorWillBe.Called);
            bool validated = false;
            Isolate.WhenCalled(() => dictionary.Validate()).DoInstead(context => validated= true);

            
            modelDifferenceObject.XmlContent = "<Application/>";

            Assert.IsTrue(validated);

        }
        public void DateCreated_Can_Not_Be_Null(DifferenceType differenceType, ValidationState validationState)
        {

            var o = new ModelDifferenceObject(Session.DefaultSession);
            Isolate.WhenCalled(() => o.DifferenceType).WillReturn(differenceType);
            var ruleSet = new RuleSet();

            RuleSetValidationResult target = ruleSet.ValidateTarget(o, ContextIdentifier.Save);

            RuleSetValidationResultItem @default = target.Results.Where(
                item =>
                item.Rule is RuleRequiredField &&
                ((RuleRequiredField)item.Rule).TargetMember.Name == o.GetPropertyInfo(x => x.DateCreated).Name).FirstOrDefault();
            Assert.AreEqual(validationState, @default.State);
        }
 protected internal override void OnDifferenceObjectSaving(ModelDifferenceObject userModelDifferenceObject, Dictionary diffDictionary){
     var userStoreObject = ((UserModelDifferenceObject) userModelDifferenceObject);
     if (!userStoreObject.NonPersistent){
         base.OnDifferenceObjectSaving(userModelDifferenceObject, diffDictionary);
     }
     if (SecuritySystem.Instance is ISecurityComplex&& IsGranted()){
         ObjectSpace space = Application.CreateObjectSpace();
         IQueryable<ModelDifferenceObject> differences = GetDifferences(space);
         foreach (var difference in differences){
             combineDifference(userModelDifferenceObject, diffDictionary, difference);
         }
         space.CommitChanges();
     }
     
 }
        public void CurrentObject_Model_Should_Be_Validated_Every_Time_CurrentObject_Is_Saving(){
            var editor = new ModelEditorPropertyEditor(null, null);
            bool validated = false;
            Isolate.WhenCalled(() => editor.Control.Controller.Dictionary.GetDiffs()).ReturnRecursiveFake();
            Isolate.WhenCalled(() => editor.Control.Controller.Dictionary.Validate()).DoInstead(context => validated=true);
            var objectSpace = new ObjectSpace(new UnitOfWork(XpoDefault.DataLayer),XafTypesInfo.Instance);
            var modelDifferenceObject = new ModelDifferenceObject(objectSpace.Session) { PersistentApplication = new PersistentApplication(objectSpace.Session) };
            editor.CurrentObject = modelDifferenceObject;
            editor.Setup(objectSpace, Isolate.Fake.Instance<XafApplication>());

            objectSpace.CommitChanges();

            Assert.IsTrue(validated);

        }
        public void Should_InitializeMembers()
        {

            var controller = new ViewControllerFactory().CreateController<CreateNewDifferenceObjectViewController>(ViewType.DetailView,new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)});
            
            var modelAspectObject = new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)};
            bool called = false;
            Isolate.WhenCalled(() => modelAspectObject.InitializeMembers("", "")).DoInstead(context =>
            {
                called = true;
                return modelAspectObject;
            });

            controller.OnObjectCreated(null, new ObjectCreatedEventArgs(modelAspectObject, null));

            Assert.IsTrue(called);
        }
        public void Same_Application_Objets_Cannot_Exist(DifferenceType differenceType, ValidationState validationState)
        {
            var ruleSet = new RuleSet();
            var persistentApplication = new PersistentApplication(Session.DefaultSession);
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = persistentApplication };
            modelDifferenceObject.Save();

            var modelDifferenceObject1 = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = persistentApplication };
            Isolate.WhenCalled(() => modelDifferenceObject1.DifferenceType).WillReturn(differenceType);

            RuleSetValidationResult target = ruleSet.ValidateTarget(modelDifferenceObject1, ContextIdentifier.Save);


            Assert.IsInstanceOfType(typeof(RuleCombinationOfPropertiesIsUnique), target.Results[0].Rule);
            Assert.AreEqual(validationState, target.Results[0].State);


        }
Example #24
0
        public void Before_Application_Saving_Current_Object_Should_Validate_ModelEditorControl_Dictionary()
        {
            
            bool validated = false;
            var editor = new ModelEditorPropertyEditor(null, null);
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession);
            Isolate.WhenCalled(() => editor.CurrentObject).WillReturn(modelDifferenceObject);
            Isolate.WhenCalled(() => editor.Control.Controller.Dictionary.Validate()).DoInstead(context => validated=true);
            var objectSpace = Isolate.Fake.Instance<ObjectSpace>();
            using (RecorderManager.StartRecording()){
                objectSpace.ObjectSaving += null;
            }
            editor.Setup(objectSpace, null);
            var handler = (EventHandler<ObjectManipulatingEventArgs>) RecorderManager.LastMockedEvent.GetEventHandle();

            handler.Invoke(this,new ObjectManipulatingEventArgs(modelDifferenceObject));

            Assert.IsTrue(validated);
        }
        public void Create_A_New_DifferenceObject_If_No_Active_DifferenceObject_Found()
        {
            var modelAspectObject = new ModelDifferenceObject(Session.DefaultSession);
            Isolate.Swap.AllInstances<ModelDifferenceObject>().With(modelAspectObject);
            Isolate.WhenCalled(() => modelAspectObject.Save()).IgnoreCall();
            var application = Isolate.Fake.Instance<XafApplication>();
            application.ApplicationName = "ApplicationName";
            var dictionary = new Dictionary(Schema.GetCommonSchema());
            Isolate.WhenCalled(() => dictionary.Aspects).WillReturn(new List<string> { "aspect" });
            Isolate.WhenCalled(() => application.Model).WillReturn(dictionary);
            var store = Isolate.Fake.Instance<XpoDictionaryDifferenceStore>(Members.CallOriginal, ConstructorWillBe.Called, new object[] { Session.DefaultSession, application });
            Isolate.WhenCalled(() => store.GetNewDifferenceObject(null)).WillReturn(modelAspectObject);
            Isolate.WhenCalled(() => store.GetActiveDifferenceObject()).WillReturn(null);


            store.SaveDifference(dictionary);

            Isolate.Verify.WasCalledWithAnyArguments(() => modelAspectObject.Save());
        }
Example #26
0
        public void Some_Properties_Should_Change(){
            DateTime dateTime = DateTime.Now;
            Mock mock = MockManager.Mock(typeof (CloneObjectViewController),Constructor.NotMocked);
            mock.CallBase.ExpectAlways("CloneObject");
            var singleChoiceActionExecuteEventArgs = Isolate.Fake.InstanceAndSwapAll<SingleChoiceActionExecuteEventArgs>();
            var data = new ModelDifferenceObject(Session.DefaultSession){Name = "name"};
            Isolate.WhenCalled(() => singleChoiceActionExecuteEventArgs.ShowViewParameters.CreatedView.CurrentObject).WillReturn(data);
            var persistentApplication = new PersistentApplication(Session.DefaultSession);
            var controller = new ViewControllerFactory().CreateController<CloneObjectViewController>(ViewType.DetailView, new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = persistentApplication});
            controller.CloneObjectAction.Active.Clear();
            
            controller.CloneObjectAction.DoExecute(new ChoiceActionItem(new DictionaryNode(""), data));

            Assert.IsNull(data.Name);
            Assert.IsTrue(data.Disabled);
            Assert.GreaterThan(data.DateCreated, dateTime);
            Assert.AreEqual(persistentApplication, data.PersistentApplication);
            
        }
            public void When_Saving_Combine_With_Application_InstanceModel()
            {
                var controller = Isolate.Fake.Instance<CombineActiveModelDictionaryController<ModelDifferenceObject>>(Members.CallOriginal);
                controller.Application = Isolate.Fake.Instance<XafApplication>();

                var dictionary = DefaultDictionary;
                var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession)
                                            {
                                                Model = dictionary,
                                                PersistentApplication =new PersistentApplication(Session.DefaultSession) { Name = "appNAme" }
                                            };
                Isolate.WhenCalled(() => controller.GetActiveDifference(null, null)).WithExactArguments().WillReturn(modelDifferenceObject);


                controller.ObjectSpaceOnObjectSaved(null, new ObjectManipulatingEventArgs(modelDifferenceObject));


                Assert.IsNotNull(new ApplicationNodeWrapper(controller.Application.Model).BOModel.FindClassByType(typeof(User)));

            }
 public static void SetUp(ModelDifferenceObject modelDifferenceObject, string applicationTypeName)
 {
     SetUp(modelDifferenceObject);
     
 }
Example #29
0
 public DictionaryCombiner(ModelDifferenceObject modelDifferenceObject){
     _modelDifferenceObject = modelDifferenceObject;
 }
        public void When_PrefferedAspect_Change_Then_Its_Aspect_Should_Be_Added_To_ALl_Models(){
            var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)};
            Dictionary dictionary = DefaultDictionary;
            modelDifferenceObject.Model=dictionary;
            modelDifferenceObject.PersistentApplication.Model=DefaultDictionary2;

            modelDifferenceObject.PreferredAspect = "el blah";

            Assert.AreEqual("el", modelDifferenceObject.CurrentLanguage);
            Assert.Contains(modelDifferenceObject.Model.Aspects,"el");
            Assert.Contains(modelDifferenceObject.PersistentApplication.Model.Aspects,"el");
        }