public void Test_BO_GetPropertyValue_Fail_AllowRead_False() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanRead_False(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); //---------------Assert Precondition---------------- Assert.IsFalse(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanRead)); string message; Assert.IsFalse(prop1.IsReadable(out message)); //---------------Execute Test ---------------------- try { myBoStub.GetPropertyValue("Prop1"); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BOPropReadException ex) { StringAssert.Contains("The logged on user is not authorised to read the Prop1 ", ex.Message); } }
public void Test_GetValue_AllowRead_True() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanRead_True(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); myBoStub.Save(); //---------------Assert Precondition---------------- Assert.IsTrue(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanRead)); string message; Assert.IsTrue(prop1.IsReadable(out message)); //---------------Execute Test ---------------------- const string newPropValue = "1112"; prop1.Value = newPropValue; //---------------Test Result ----------------------- Assert.IsTrue(prop1.IsDirty); Assert.AreEqual(newPropValue, prop1.Value); }
public void Test_SetValue_Fail_AllowUpdate_False() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanUpdate_False(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); myBoStub.Save(); //---------------Assert Precondition---------------- Assert.IsFalse(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanUpdate)); Assert.IsFalse(myBoStub.Status.IsNew); string message; Assert.IsFalse(prop1.IsEditable(out message)); //---------------Execute Test ---------------------- const string newPropValue = "1112"; try { prop1.Value = newPropValue; Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BOPropWriteException ex) { StringAssert.Contains("The logged on user is not authorised to update the Prop1 ", ex.Message); } }
///<summary> /// Returns whether the BOProperty is Editable or not. The BOProp may not be editable /// based on a number of factors. /// 1) If its ReadWrite Rules are set to ReadOnly etc. /// 2) The user may not have permissions to edit this property Value. ///</summary> ///<param name="message"></param> ///<returns></returns> public virtual bool IsEditable(out string message) { if (!AreReadWriteRulesEditable(out message)) { return(false); } if (_boPropAuthorisation == null) { return(true); } if (!_boPropAuthorisation.IsAuthorised(this, BOPropActions.CanUpdate)) { message = string.Format ("The logged on user {0} is not authorised to update the {1} ", Thread.CurrentPrincipal.Identity.Name, this.PropertyName); return(false); } return(true); }
public void Test_IsReadable_ViaIBOProp_BOPropAuthorisation_AllowRead_True() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanRead_True(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); //---------------Assert Precondition---------------- propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanRead); //---------------Execute Test ---------------------- string message; bool isReadable = myBoStub.Props["Prop1"].IsReadable(out message); //---------------Test Result ----------------------- Assert.IsTrue(isReadable); Assert.AreEqual("", message); }
public void Test_BOPropAuthorisation_AllowUpdate_False() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanUpdate_False(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); //---------------Assert Precondition---------------- Assert.IsFalse(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanUpdate)); //---------------Execute Test ---------------------- string message; bool isEditable = prop1.IsEditable(out message); //---------------Test Result ----------------------- Assert.IsFalse(isEditable); StringAssert.Contains("The logged on user", message); StringAssert.Contains(" is not authorised to update ", message); }