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_It_Should_Combined_With_Application_Diffs(){ Isolate.WhenCalled(() => Validator.RuleSet.ValidateAll(null, null)).ReturnRecursiveFake(); var modelDictionaryDifferenceStore = new XpoUserModelDictionaryDifferenceStore( Isolate.Fake.Instance<XafApplication>()); var modelDifferenceObject = new UserModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession),Model = DefaultDictionary}; modelDictionaryDifferenceStore.OnDifferenceObjectSaving(modelDifferenceObject, elDictionary); Assert.AreEqual("el", new ApplicationNodeWrapper(modelDifferenceObject.Model).BOModel.FindClassByName("MyClass").Caption); }
public void When_A_New_UserDifferenceObject_Is_Saved_it_Should_Contain_Same_NUmber_Of_Aspect_As_The_Application(){ var application = Isolate.Fake.Instance<XafApplication>(); Isolate.WhenCalled(() => application.Model.Aspects).WillReturn(new List<string>{DictionaryAttribute.DefaultLanguage,"el"}); var store = new XpoUserModelDictionaryDifferenceStore( application); Isolate.WhenCalled(() => store.GetActiveDifferenceObjects()).WillReturn(new List<ModelDifferenceObject>().AsQueryable()); Dictionary dictionary = null; Isolate.WhenCalled(() => store.SaveDifference(null)).DoInstead(context => dictionary=(Dictionary) context.Parameters[0]); store.LoadDifference(Schema.GetCommonSchema()); Assert.AreEqual(2, dictionary.Aspects.Count); }
public void If_No_ActiveDifference_Found_Then_A_New_UserDifferenceObject_Should_Be_Saved() { var application = Isolate.Fake.Instance<XafApplication>(); application.ApplicationName = "appName"; var store = new XpoUserModelDictionaryDifferenceStore(application); Isolate.WhenCalled(() => store.GetActiveDifferenceObjects()).WillReturn(new List<ModelDifferenceObject>().AsQueryable()); Isolate.WhenCalled(() => store.GetActiveDifferenceObjects()).CallOriginal(); bool saved = false; Isolate.WhenCalled(() => store.SaveDifference(null)).DoInstead(context => { saved = true; }); store.LoadDifference(Schema.GetCommonSchema()); Assert.IsTrue(saved); }
public void As_Active_UserDifference_Will_Return_Active_UserDifferenceObject() { var store = new XpoUserModelDictionaryDifferenceStore( Isolate.Fake.Instance<XafApplication>()); Isolate.Fake.StaticMethods(typeof(UserDifferenceObjectBuilder)); var userStoreObject = new UserModelDifferenceObject(Session.DefaultSession); var queryUserDifferenceObject = Isolate.Fake.InstanceAndSwapAll<QueryUserModelDifferenceObject>(); Isolate.WhenCalled(() => queryUserDifferenceObject.GetActiveModelDifference("")).WillReturn(userStoreObject); ModelDifferenceObject modelDifferenceObject = store.GetActiveDifferenceObject(); Assert.AreEqual(userStoreObject, modelDifferenceObject); }
public void if_AspectObject_Is_Not_Persistent_WillNot_be_saved(bool nonPersistent) { var store = new XpoUserModelDictionaryDifferenceStore(Isolate.Fake.Instance<XafApplication>()); var modelStoreObject = new UserModelDifferenceObject(Session.DefaultSession){ PersistentApplication = new PersistentApplication(Session.DefaultSession), NonPersistent = nonPersistent }; Isolate.WhenCalled(() => modelStoreObject.Save()).WillThrow(new NotImplementedException()); Isolate.WhenCalled(() => store.GetActiveDifferenceObject()).WillReturn(modelStoreObject); var dictionary = new Dictionary(Schema.GetCommonSchema()); Isolate.WhenCalled(() => dictionary.Aspects).WillReturn(new List<string> { "aspect" }); Isolate.Fake.StaticMethods(typeof(Validator)); store.SaveDifference(dictionary); }
public void CauseOf_Application_Is_Unique_It_Should_Check_DataStore_Before_Creating_New() { var modelDictionaryDifferenceStore = new XpoUserModelDictionaryDifferenceStore(Isolate.Fake.Instance<XafApplication>()); new PersistentApplication(Session.DefaultSession) { Name = "appName" }.Save(); var application = Isolate.Fake.InstanceAndSwapAll<QueryPersistentApplication>(); var persistentApplication = new PersistentApplication(Session.DefaultSession); Isolate.WhenCalled(() => application.Find("")).WillReturn(persistentApplication); Isolate.WhenCalled(() => modelDictionaryDifferenceStore.OnDifferenceObjectSaving(null, new Dictionary())).IgnoreCall(); Isolate.WhenCalled(() => modelDictionaryDifferenceStore.GetActiveDifferenceObject()).WillReturn(null); Isolate.WhenCalled(() => modelDictionaryDifferenceStore.GetNewDifferenceObject(null)).WillReturn(new ModelDifferenceObject(Session.DefaultSession)); modelDictionaryDifferenceStore.SaveDifference(new Dictionary(Schema.GetCommonSchema())); Isolate.Verify.WasCalledWithAnyArguments(() => application.Find("")); }
public void When_A_New_DifferenceObject_Is_Requested_Will_Return_A_UserDifferenceObject() { Isolate.Fake.ISecurityComplex(); XafTypesInfo.Instance.RegisterEntity(typeof(UserModelDifferenceObject)); UserDifferenceObjectBuilder.CreateDynamicMembers(null); var store = new XpoUserModelDictionaryDifferenceStore( Isolate.Fake.Instance<XafApplication>()); ModelDifferenceObject modelDifferenceObject = store.GetNewDifferenceObject( Isolate.Fake.Instance<ObjectSpace>()); Assert.IsTrue(modelDifferenceObject.IsNewObject); var collection = (XPCollection)modelDifferenceObject.GetMemberValue("Users"); Assert.AreEqual(1, collection.Count); Assert.AreEqual(SecuritySystem.CurrentUser, collection[0]); }
public void As_ActiveUserDifferences_Will_Return_A_Concat_Of_Active_UserDifferenceObjects_And_RoleDifferenceObjects() { var store = new XpoUserModelDictionaryDifferenceStore( Isolate.Fake.Instance<XafApplication>()); var userDifferenceObject1 = new UserModelDifferenceObject(Session.DefaultSession); var queryUserDifferenceObject = Isolate.Fake.InstanceAndSwapAll<QueryUserModelDifferenceObject>(); Isolate.WhenCalled(() => queryUserDifferenceObject.GetActiveModelDifferences("")).WillReturn(new List<UserModelDifferenceObject> { userDifferenceObject1 }.AsQueryable()); var roleDifferenceObject = new RoleModelDifferenceObject(Session.DefaultSession); var queryRoleDifferenceObject = Isolate.Fake.InstanceAndSwapAll<QueryRoleModelDifferenceObject>(); Isolate.WhenCalled(() => queryRoleDifferenceObject.GetActiveModelDifferences("")).WillReturn(new List<RoleModelDifferenceObject> { roleDifferenceObject }.AsQueryable()); IQueryable<ModelDifferenceObject> queryable = store.GetActiveDifferenceObjects(); Assert.AreEqual(2, queryable.Count()); Assert.AreEqual(userDifferenceObject1, queryable.ToList()[1]); Assert.AreEqual(roleDifferenceObject, queryable.ToList()[0]); }
public void Is_A_Combination_Of_All_Models_Assign_to_Current_User_For_Current_Aspect_And_Application() { var store = new XpoUserModelDictionaryDifferenceStore( Isolate.Fake.Instance<XafApplication>()); var modelDifferenceObject = new UserModelDifferenceObject(Session.DefaultSession) { Model = DefaultDictionary, PersistentApplication = new PersistentApplication(Session.DefaultSession) { Model = PersistentAppDictionary } }; Isolate.WhenCalled(() => store.GetActiveDifferenceObjects()). WillReturnCollectionValuesOf(new List<ModelDifferenceObject>{ modelDifferenceObject, new UserModelDifferenceObject(Session.DefaultSession) {Model = DefaultDictionary2,PersistentApplication = new PersistentApplication(Session.DefaultSession){Model = new Dictionary(Schema.GetCommonSchema())}} }.AsQueryable()); Dictionary dictionary = store.LoadDifference(Schema.GetCommonSchema()); var wrapper = new ApplicationNodeWrapper(dictionary).BOModel; Assert.IsNotNull(wrapper.FindClassByName("MyClass")); Assert.IsNotNull(wrapper.FindClassByName("MyClass2")); }