public void TestNewCustomer_SetCustomerName_ToValidValue() { //When a property is set to a valid value for a compulsory field // that has a broken rule the rule is set to no longer broken. //---------------Set up test pack------------------- Customer customer = new Customer(); //---------------Assert Precondition---------------- Assert.IsTrue(customer.Status.IsNew); Assert.IsFalse(customer.Status.IsDirty); Assert.IsFalse(customer.Status.IsEditing); Assert.IsFalse(customer.Status.IsValid()); StringAssert.Contains("'Customer Name' is a compulsory field and has no value", customer.Status.IsValidMessage); //---------------Execute Test ---------------------- customer.CustomerName = "Valid Name"; customer.CustomerCode = "Code"; //---------------Test Result ----------------------- Assert.IsTrue(customer.Status.IsDirty); Assert.IsTrue(customer.Status.IsEditing); Assert.AreEqual("Valid Name", customer.CustomerName); Assert.IsTrue(customer.Status.IsValid()); Assert.AreEqual("", customer.Status.IsValidMessage); }
public void Test_SaveBOProp() { //Testing that when a customer is saved the Persisted Property // Value is updated to the PropertyValue //---------------Set up test pack------------------- Customer customer = new Customer(); const string newCustomerName = "Valid Name"; customer.CustomerName = newCustomerName; customer.CustomerCode = "Code"; IBOProp customerNameProp = customer.Props["CustomerName"]; //---------------Assert Precondition---------------- Assert.IsNull(customerNameProp.PersistedPropertyValue, "A new object should not have a persisted value"); Assert.AreEqual(newCustomerName, customerNameProp.Value); Assert.IsTrue(customerNameProp.IsDirty); //---------------Execute Test ---------------------- customer.Save(); //---------------Test Result ----------------------- Assert.AreEqual(newCustomerName, customerNameProp.Value); Assert.AreEqual(newCustomerName, customerNameProp.PersistedPropertyValue, "After saving the PersistedPropertyValue should be backed up to the property value"); Assert.IsFalse(customerNameProp.IsDirty); }
public void TestCreateNewCustomer_CustomerNameCompusory() { //-------------------------------------------------- //When a new customer is created it is created with any // broken rules for any // compulsory properties that do not have a default value set // (In this case Customer name). //-------------------------------------------------- //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- Customer customer = new Customer(); //---------------Test Result ----------------------- Assert.IsTrue(customer.Status.IsNew); Assert.IsNotNull(customer.CustomerID); Assert.IsFalse(customer.Status.IsDeleted); Assert.IsFalse(customer.Status.IsDirty); Assert.IsFalse(customer.Status.IsEditing); Assert.IsFalse(customer.Status.IsValid()); StringAssert.Contains("'Customer Name' is a compulsory field and has no value", customer.Status.IsValidMessage); }
protected static Customer CreateSavedCustomer() { Customer customer = new Customer(); customer.CustomerName = "Valid Name"; customer.CustomerCode = "Code"; customer.Save(); return customer; }
public void Test_RestoreNewCustomer() { //---------------Set up test pack------------------- Customer customer = new Customer(); customer.DateCustomerApproved = DateTime.Today.AddDays(-1); //---------------Assert Precondition---------------- Assert.AreNotEqual(DateTime.Today, customer.DateCustomerApproved); //---------------Execute Test ---------------------- customer.Restore(); //---------------Test Result ----------------------- Assert.AreEqual(DateTime.Today, customer.DateCustomerApproved); }
public void Test_BusinessObjectAuthorisation_AllowDelete_False() { //---------------Set up test pack------------------- IBusinessObjectAuthorisation authorisationStub = GetAuthorisationStub_CanDelete_False(); Customer customer = new Customer(); customer.SetAuthorisation(authorisationStub); //---------------Assert Precondition---------------- Assert.IsFalse(authorisationStub.IsAuthorised(BusinessObjectActions.CanDelete)); //---------------Execute Test ---------------------- string message; bool isDeletable = customer.IsDeletable(out message); //---------------Test Result ----------------------- Assert.IsFalse(isDeletable); StringAssert.Contains("The logged on user", message); StringAssert.Contains("is not authorised to delete ", message); }
public void Test_SaveValidCustomer() { //---------------Set up test pack------------------- Customer customer = new Customer(); customer.CustomerName = "Valid Name"; customer.CustomerCode = "Code"; //---------------Assert Precondition---------------- Assert.IsTrue(customer.Status.IsNew); Assert.IsTrue(customer.Status.IsDirty); //---------------Execute Test ---------------------- customer.Save(); //---------------Test Result ----------------------- Assert.IsFalse(customer.Status.IsNew); Assert.IsFalse(customer.Status.IsDirty); }
public void TestCreateNewCustomer_NoPropertyRules() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- Customer customer = new Customer(); //---------------Test Result ----------------------- Assert.IsTrue(customer.Status.IsNew); Assert.IsNotNull(customer.CustomerID); Assert.IsFalse(customer.Status.IsDeleted); Assert.IsFalse(customer.Status.IsDirty); Assert.IsFalse(customer.Status.IsEditing); Assert.IsTrue(customer.Status.IsValid()); Assert.AreEqual("", customer.Status.IsValidMessage); }
public void Test_BusinessObjectAuthorisation_AllowDelete() { //---------------Set up test pack------------------- IBusinessObjectAuthorisation authorisationStub = GetAuthorisationStub_CanDelete_True(); Customer customer = new Customer(); customer.SetAuthorisation(authorisationStub); //---------------Assert Precondition---------------- Assert.IsTrue(authorisationStub.IsAuthorised(BusinessObjectActions.CanDelete)); //---------------Execute Test ---------------------- string message; bool isDeletable = customer.IsDeletable(out message); //---------------Test Result ----------------------- Assert.IsTrue(isDeletable); Assert.AreEqual("", message); }
public void Test_SetCustomerName_ToValidValue() { //When a property is set to a valid value for a compulsory field // that has a broken rule the rule is set to no longer broken. //---------------Set up test pack------------------- Customer customer = new Customer(); IBOProp customerNameBoProp = customer.Props["CustomerName"]; //---------------Assert Precondition---------------- Assert.IsFalse(customerNameBoProp.IsDirty); Assert.IsFalse(customerNameBoProp.IsValid); StringAssert.Contains("'Customer Name' is a compulsory field and has no value", customerNameBoProp.InvalidReason); //---------------Execute Test ---------------------- customer.CustomerName = "Valid Name"; //---------------Test Result ----------------------- Assert.IsTrue(customerNameBoProp.IsDirty); Assert.IsTrue(customerNameBoProp.IsValid); Assert.AreEqual("", customerNameBoProp.InvalidReason); }
public void Test_CreateCustomerWithIdentity() { //This test shows the that the PrimaryKeyDef and BOPrimaryKey // are set up according to the class definition defined for // customer. It also shows that the CustomerID is automatically // set to a new GUID Value. //---------------Execute Test ---------------------- Customer customer = new Customer(); //---------------Test Result ----------------------- ClassDef customerClassDef = customer.ClassDef; PrimaryKeyDef primaryKeyDef = customerClassDef.PrimaryKeyDef; Assert.AreEqual(1, primaryKeyDef.Count); IPrimaryKey customerPrimaryKey = customer.ID; Assert.AreEqual(1, customerPrimaryKey.Count); Assert.IsTrue(customerPrimaryKey.Contains("CustomerID")); IBOProp customerIDBOProp = customerPrimaryKey["CustomerID"]; Assert.IsNotNull(customerIDBOProp.Value, "Since the CustomerID is an object id it should be set to a value"); }
public void Test_Save_Invalid_ValidCustomer() { //---------------Set up test pack------------------- Customer customer = new Customer(); customer.CustomerCode = "Code"; //---------------Assert Precondition---------------- Assert.IsTrue(customer.Status.IsNew); Assert.IsTrue(customer.Status.IsDirty); //---------------Execute Test ---------------------- try { customer.Save(); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BusObjectInAnInvalidStateException ex) { StringAssert.Contains("'Customer Name' is a compulsory field and has no value", ex.Message); } }
public void Test_SetCustomerName_ToInvalidValue() { //When a property is set to an In Valid Value for a compulsory field // that has no value the broken rule is changed from compulsory to // Invalid Value. //---------------Set up test pack------------------- Customer customer = new Customer(); IBOProp customerNameBoProp = customer.Props["CustomerName"]; //---------------Assert Precondition---------------- Assert.IsFalse(customerNameBoProp.IsDirty); Assert.IsFalse(customerNameBoProp.IsValid); StringAssert.Contains("'Customer Name' is a compulsory field and has no value", customerNameBoProp.InvalidReason); //---------------Execute Test ---------------------- customer.CustomerName = "Inv"; //---------------Test Result ----------------------- Assert.IsTrue(customerNameBoProp.IsDirty); Assert.IsFalse(customerNameBoProp.IsValid); StringAssert.Contains("'Inv' for property 'Customer Name' is not valid for the rule 'CustomerName'. The length cannot be less than 5 character", customerNameBoProp.InvalidReason); }
public void Test_SetCustomerCode_ForNewCustomer() { //A WriteNew property can be written to when the business object is new. //---------------Set up test pack------------------- Customer customer = new Customer(); IBOProp customerCodeBoProp = customer.Props["CustomerCode"]; //---------------Assert Precondition---------------- Assert.AreEqual(PropReadWriteRule.WriteNew, customerCodeBoProp.PropDef.ReadWriteRule); //---------------Execute Test ---------------------- customer.CustomerCode = "Code"; //---------------Test Result ----------------------- Assert.AreEqual("Code",customer.CustomerCode); }
public void Test_CreateCustomer_WithDefaultValue() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- Customer customer = new Customer(); //---------------Test Result ----------------------- Assert.IsNotNull(customer.DateCustomerApproved); Assert.AreEqual(DateTime.Today, customer.DateCustomerApproved); }
public void TestNewCustomer_SetCustomerName_ToInvalidValidValue_FromValidValue() { //When a property is set to an In Valid Value for a compulsory field // that has no value the broken rule is changed from compulsory to // Invalid Value. //---------------Set up test pack------------------- Customer customer = new Customer(); customer.CustomerName = "Valid Name"; customer.CustomerCode = "Code"; //---------------Assert Precondition---------------- Assert.IsTrue(customer.Status.IsValid()); Assert.AreEqual("", customer.Status.IsValidMessage); //---------------Execute Test ---------------------- customer.CustomerName = "Inv"; //---------------Test Result ----------------------- Assert.IsTrue(customer.Status.IsDirty); Assert.AreEqual("Inv", customer.CustomerName); Assert.IsFalse(customer.Status.IsValid()); StringAssert.Contains("'Inv' for property 'Customer Name' is not valid for the rule 'CustomerName'. The length cannot be less than 5 character", customer.Status.IsValidMessage); }
private Customer CreateNewCustomerValid() { Customer customer = new Customer(); customer.CustomerCode = "x" + GetRandomString(); customer.CustomerName = "y" + GetRandomString(); return customer; }
public void Test_BusinessObjectAuthorisation_AllowRead() { //---------------Set up test pack------------------- IBusinessObjectAuthorisation authorisationStub = new AuthorisationStub(); authorisationStub.AddAuthorisedRole("A Role", BusinessObjectActions.CanRead); Customer customer = new Customer(); customer.SetAuthorisation(authorisationStub); //---------------Assert Precondition---------------- Assert.IsTrue(authorisationStub.IsAuthorised(BusinessObjectActions.CanRead)); //---------------Execute Test ---------------------- string message; bool isReadable = customer.IsReadable(out message); //---------------Test Result ----------------------- Assert.IsTrue(isReadable); Assert.AreEqual("", message); }
public void Test_DeleteBO_Fail_AllowDelete_False() { //---------------Set up test pack------------------- IBusinessObjectAuthorisation authorisationStub = GetAuthorisationStub_CanDelete_False(); Customer customer = new Customer(); customer.SetAuthorisation(authorisationStub); //---------------Assert Precondition---------------- Assert.IsFalse(authorisationStub.IsAuthorised(BusinessObjectActions.CanDelete)); //---------------Execute Test ---------------------- try { customer.Delete(); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BusObjDeleteException ex) { StringAssert.Contains("The logged on user", ex.Message); StringAssert.Contains("is not authorised to delete ", ex.Message); } }