public void Test_InitialiseProp_NullValue() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(null); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
// ReSharper disable InconsistentNaming public void Test_InitialiseProp_NullValue() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.AreEqual(typeof (string), boProp.PropertyType); Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(null); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
public void Test_InitialiseProp_ValidDateTimeTodayString() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp("yesterday"); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(DateTime.Today.AddDays(-1), boProp.Value); }
public void Test_InitialiseProp_EmptyGuidString_B() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Guid guid = Guid.Empty; //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(guid.ToString("B")); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
public void Test_InitialiseProp_Valid() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string value = "Valid"; //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); }
public void Test_InitialiseProp_ValidInteger() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Int32 value = TestUtil.GetRandomInt(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); }
public void Test_InitialiseProp_ValidDateTime() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); DateTime value = DateTime.MinValue.AddDays(1); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); }
public void Test_InitialiseProp_ValidGuidString_B() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); string expectedString = Guid.NewGuid().ToString("B"); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(expectedString); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(expectedString, boProp.Value); Assert.IsTrue(boProp.Value is string, "Value should be a expectedString"); }
public void Test_InitialiseProp_ValidIntegerString() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Int32 expectedInteger = TestUtil.GetRandomInt(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(expectedInteger.ToString("d")); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(expectedInteger, boProp.Value); Assert.IsTrue(boProp.Value is Int32, "Value should be an Integer"); }
public void Test_ConstructBOPropWithValue() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("Name", typeof(string), PropReadWriteRule.WriteNotNew, "DD", "", false, false); const string value = "value"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BOProp prop1 = new BOProp(propDef, value); //---------------Test Result ----------------------- Assert.IsTrue(prop1.IsObjectNew); Assert.AreEqual(value, prop1.Value); Assert.AreEqual(value, prop1.PropertyValueToDisplay); }
public void Test_InitialiseProp_ValidGuid() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Guid value = Guid.NewGuid(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); Assert.AreEqual("", boProp.InvalidReason); Assert.IsTrue(boProp.IsValid); }
public void Test_ReadOnly_IsEditable_False() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("Name", "NN", "String", PropReadWriteRule.ReadOnly, "DD", "", false, false); BOProp prop1 = new BOProp(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(PropReadWriteRule.ReadOnly, prop1.PropDef.ReadWriteRule); //---------------Execute Test ---------------------- string message; bool isEditable = prop1.IsEditable(out message); //---------------Test Result ----------------------- Assert.IsFalse(isEditable); StringAssert.Contains("The property ", message); StringAssert.Contains("Name' is not editable since it is set up as ReadOnly", message); }
public void Test_WriteNew_NewObject_IsEditable_True() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("Name", "NN", "String", PropReadWriteRule.WriteNew, "DD", "", false, false); BOProp prop1 = new BOProp(propDef); prop1.IsObjectNew = true; //---------------Assert Precondition---------------- Assert.AreEqual(PropReadWriteRule.WriteNew, prop1.PropDef.ReadWriteRule); Assert.IsTrue(prop1.IsObjectNew); //---------------Execute Test ---------------------- string message; bool isEditable = prop1.IsEditable(out message); //---------------Test Result ----------------------- Assert.IsTrue(isEditable); Assert.AreEqual("", message); }
public void TestUpdatesProperties_UsingSecurityController() { //-------------Setup Test Pack ------------------ BOProp dateBoProp = new BOProp(new PropDef("DateLastUpdated", typeof(DateTime), PropReadWriteRule.ReadWrite, null)); BOProp userBoProp = new BOProp(new PropDef("UserLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null)); ISecurityController securityController = new MySecurityController(); BusinessObjectLastUpdatePropertiesLog log = new BusinessObjectLastUpdatePropertiesLog(userBoProp, dateBoProp, securityController); //-------------Test Pre-conditions -------------- //-------------Execute test --------------------- DateTime beforeUpdate = DateTime.Now; log.Update(); DateTime afterUpdate = DateTime.Now; //-------------Test Result ---------------------- Assert.IsNotNull(userBoProp.Value); Assert.AreEqual("MyUserName", userBoProp.Value); Assert.IsNotNull(dateBoProp.Value); Assert.IsTrue(beforeUpdate <= (DateTime)dateBoProp.Value); Assert.IsTrue(afterUpdate >= (DateTime)dateBoProp.Value); }
public void Test_InitialiseProp_ValidGuidString_B() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Guid guid = Guid.NewGuid(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(guid.ToString("B")); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(guid, boProp.Value); Assert.IsTrue(boProp.Value is Guid, "Value should be a guid"); Assert.AreEqual("", boProp.InvalidReason); Assert.IsTrue(boProp.IsValid); }
public void TestPropLengthForStrings() { PropDef propDef = new PropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 5); BOProp boProp = new BOProp(propDef); boProp.Value = "abcdef"; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); boProp.Value = null; Assert.IsTrue(boProp.IsValid); Assert.IsFalse(boProp.InvalidReason.Length > 0); boProp.Value = ""; Assert.IsTrue(boProp.IsValid); Assert.IsFalse(boProp.InvalidReason.Length > 0); boProp.Value = "abc"; Assert.IsTrue(boProp.IsValid); Assert.IsFalse(boProp.InvalidReason.Length > 0); boProp.Value = "abcde"; Assert.IsTrue(boProp.IsValid); Assert.IsFalse(boProp.InvalidReason.Length > 0); }
public void TestPropCompulsoryForBooleans() { PropDef propDef = new PropDef("TestProp", "System", "Boolean", PropReadWriteRule.ReadWrite, null, null, true, false); BOProp boProp = new BOProp(propDef); Assert.IsNull(boProp.Value); Assert.IsTrue(boProp.IsValid); boProp.Value = true; boProp.Value = null; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); boProp.Value = DBNull.Value; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); boProp.Value = ""; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); boProp.Value = true; Assert.IsTrue(boProp.IsValid); Assert.IsFalse(boProp.InvalidReason.Length > 0); }
public void TestPropCompulsoryForIntegers() { PropDef propDef = new PropDef("TestProp", "System", "Int32", PropReadWriteRule.ReadWrite, null, null, true, false); BOProp boProp = new BOProp(propDef); Assert.IsNull(boProp.Value); Assert.IsTrue(boProp.IsValid); boProp.Value = 44; boProp.Value = null; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); StringAssert.Contains("compulsory field", boProp.InvalidReason); boProp.Value = DBNull.Value; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); StringAssert.Contains("compulsory field", boProp.InvalidReason); boProp.Value = ""; Assert.IsFalse(boProp.IsValid); Assert.IsTrue(boProp.InvalidReason.Length > 0); StringAssert.Contains("compulsory field", boProp.InvalidReason); boProp.Value = 1; Assert.AreEqual("", boProp.InvalidReason); Assert.IsTrue(boProp.IsValid); boProp.Value = 0; Assert.AreEqual("", boProp.InvalidReason); Assert.IsTrue(boProp.IsValid); }
public void Test_SetValue_WhenCustomTypeWithATypeConverter() { //---------------Set up test pack------------------- var propDef = new PropDef("Name", typeof(EmailAddressWithTypeConverter), PropReadWriteRule.ReadWrite, "DD", null, false, false); const string expectedValue = "*****@*****.**"; var prop = new BOProp(propDef, null); //---------------Assert Precondition---------------- Assert.IsNull(prop.Value); //---------------Execute Test ---------------------- prop.Value = expectedValue; //---------------Test Result ----------------------- Assert.IsInstanceOf<EmailAddressWithTypeConverter>(prop.Value); Assert.AreEqual(expectedValue, prop.Value.ToString()); }
public void Test_Construct_WhenCustomType_WithDefault_ShouldSetPropValue() { //---------------Set up test pack------------------- var propDef = new PropDef("Name", typeof(EmailAddressAsCustomProperty), PropReadWriteRule.ReadWrite, "DD", null, false, false); const string expectedValue = "*****@*****.**"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var prop = new BOProp(propDef, expectedValue); var value = prop.Value; //---------------Test Result ----------------------- Assert.IsInstanceOf<EmailAddressAsCustomProperty>(prop.Value); Assert.AreEqual(expectedValue, value.ToString()); }
public void Test_BusinessObject_WhenSetAgainToSameBo_ShouldNotThrowError() { //---------------Set up test pack------------------- IPropDef propDef = CreateTestPropPropDef(); BOProp boProp = new BOProp(propDef); ClassDef.ClassDefs.Clear(); MyBO.LoadDefaultClassDef(); MyBO bo = new MyBO(); boProp.BusinessObject = bo; //---------------Assert Precondition---------------- Assert.AreSame(bo, boProp.BusinessObject); //---------------Execute Test ---------------------- Exception exception = null; try { boProp.BusinessObject = bo; } catch(Exception ex) { exception = ex; } //---------------Test Result ----------------------- Assert.IsNull(exception); Assert.AreSame(bo, boProp.BusinessObject); }
/// <summary> /// Adds the specified property value as a parameter /// </summary> /// <param name="prop">The business object property</param> private void AddPropToInsertStatement(BOProp prop) { if (!_firstField) { _dbFieldList.Append(", "); _dbValueList.Append(", "); } _dbFieldList.Append(_connection.SqlFormatter.DelimitField(prop.DatabaseFieldName)); string paramName = _gen.GetNextParameterName(); _dbValueList.Append(paramName); _insertSql.AddParameter(paramName, prop.Value, prop.PropertyType); _firstField = false; }
public void TestDisplayNameSetBeforeInvalid() { PropDef propDef = new PropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 5); BOProp boProp = new BOProp(propDef); Assert.IsFalse(boProp.InvalidReason.Contains("'TestProp'")); Assert.IsFalse(boProp.InvalidReason.Contains("'Test Prop'")); Assert.IsFalse(boProp.InvalidReason.Contains("'Test Property'")); // boProp.DisplayName = "Test Property"; boProp.Value = "abcdef"; Assert.IsFalse(boProp.InvalidReason.Contains("'TestProp'")); // Assert.IsFalse(boProp.InvalidReason.Contains("'Test Prop'")); // Assert.IsTrue(boProp.InvalidReason.Contains("'Test Property'")); }
public void Test_PropertyValueString_ValidGuidString() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Guid expectedGuid = Guid.NewGuid(); // boProp.InitialiseProp(expectedGuid.ToString("B")); //boProp.Value = expectedGuid.ToString("B"); boProp.Value = expectedGuid.ToString("B"); //---------------Assert Precondition---------------- Assert.IsNotNull(boProp.Value); Assert.IsTrue(boProp.Value is Guid); //---------------Execute Test ---------------------- string propertyValueString = boProp.PropertyValueString; //---------------Test Result ----------------------- //Assert.AreEqual(expectedGuid.ToString("B").ToUpperInvariant(), propertyValueString); Assert.AreEqual(expectedGuid.ToString(), propertyValueString); }
public void Test_PropertyValueString_Null() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); boProp.InitialiseProp(DBNull.Value); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- string propertyValueString = boProp.PropertyValueString; //---------------Test Result ----------------------- Assert.AreEqual("", propertyValueString, "Null persisted prop value should return null string"); }
public void Test_SetValue_InvalidString_RaiseError() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string invalid = "Invalid"; object originalPropValue = Guid.NewGuid(); boProp.Value = originalPropValue; //---------------Assert Precondition --------------- Assert.AreEqual(typeof (Guid), _propDef.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.Value = invalid; //expectedGuid.ToString("B"); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + invalid, ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("Guid", ex.Message); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
private void AddDiscriminatorProperties(ClassDef classDef, IBOPropCol propsToInclude, IBOPropCol discriminatorProps) { ClassDef classDefWithSTI = null; if (classDef.IsUsingSingleTableInheritance() || classDefWithSTI != null) { string discriminator = null; if (classDef.SuperClassDef != null) { discriminator = classDef.SuperClassDef.Discriminator; } else if (classDefWithSTI != null) { discriminator = classDefWithSTI.SuperClassDef.Discriminator; } if (discriminator == null) { throw new InvalidXmlDefinitionException("A super class has been defined " + "using Single Table Inheritance, but no discriminator column has been set."); } if (propsToInclude.Contains(discriminator) && _bo.Props.Contains(discriminator)) { var boProp = _bo.Props[discriminator]; boProp.Value = _bo.ClassDef.ClassName; } else if (!discriminatorProps.Contains(discriminator)) { var propDef = new PropDef(discriminator, typeof (string), PropReadWriteRule.ReadWrite, null); var discriminatorProp = new BOProp(propDef, _bo.ClassDef.ClassName); discriminatorProps.Add(discriminatorProp); } } if (classDef.IsUsingSingleTableInheritance()) { IClassDef superClassClassDef = classDef.SuperClassClassDef; AddDiscriminatorProperties((ClassDef) superClassClassDef, propsToInclude, discriminatorProps); } }
public void Test_BusinessObject_SetAndGet() { //---------------Set up test pack------------------- IPropDef propDef = CreateTestPropPropDef(); BOProp boProp = new BOProp(propDef); ClassDef.ClassDefs.Clear(); MyBO.LoadDefaultClassDef(); MyBO bo = new MyBO(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.BusinessObject); //---------------Execute Test ---------------------- boProp.BusinessObject = bo; //---------------Test Result ----------------------- Assert.AreSame(bo, boProp.BusinessObject); }
/// <summary> /// Determines which parent ID field to add to the insertion list, depending on which /// ID attribute was specified in the class definition. There are four possibilities: /// 1) The child contains a foreign key to the parent, with the parent ID's name /// 2) No attribute was given, assumes the above. /// 3) The child's ID has a copy of the parent's ID value /// 4) The child has no ID and just inherits the parent's ID (still has the parent's /// ID as a field in its own table) /// </summary> private void AddParentID(IBOPropCol propsToInclude) { IClassDef currentClassDef = _currentClassDef; while (currentClassDef.SuperClassClassDef != null && currentClassDef.SuperClassClassDef.PrimaryKeyDef == null) { currentClassDef = currentClassDef.SuperClassClassDef; } if (currentClassDef.SuperClassClassDef == null ||currentClassDef.SuperClassClassDef.PrimaryKeyDef == null) return; var superClassDef = (SuperClassDef) currentClassDef.SuperClassDef; var parentIDCopyFieldName = superClassDef.ID; var superClassPrimaryKeyDef = (PrimaryKeyDef) currentClassDef.SuperClassClassDef.PrimaryKeyDef; if (string.IsNullOrEmpty(parentIDCopyFieldName) || superClassPrimaryKeyDef.KeyName == parentIDCopyFieldName) { propsToInclude.Add( superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol()); } else if (parentIDCopyFieldName != currentClassDef.PrimaryKeyDef.KeyName) { if (superClassPrimaryKeyDef.Count > 1) { throw new InvalidXmlDefinitionException("For a super class definition " + "using class table inheritance, the ID attribute can only refer to a " + "parent with a single primary key. Leaving out the attribute will " + "allow composite primary keys where the child's copies have the same " + "field name as the parent."); } var parentProp = superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol()[superClassPrimaryKeyDef.KeyName]; var profDef = new PropDef(parentIDCopyFieldName, parentProp.PropertyType, PropReadWriteRule.ReadWrite, null); var newProp = new BOProp(profDef) {Value = parentProp.Value}; propsToInclude.Add(newProp); } }
public void Test_BusinessObject_WhenSetAgain_ShouldThrowError() { //---------------Set up test pack------------------- IPropDef propDef = CreateTestPropPropDef(); BOProp boProp = new BOProp(propDef); ClassDef.ClassDefs.Clear(); MyBO.LoadDefaultClassDef(); MyBO bo = new MyBO(); boProp.BusinessObject = bo; //---------------Assert Precondition---------------- Assert.AreSame(bo, boProp.BusinessObject); //---------------Execute Test ---------------------- try { boProp.BusinessObject = new MyBO(); Assert.Fail("Expected to throw a HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("Once a BOProp has been assigned to a BusinessObject it cannot be assigned to another BusinessObject.", ex.DeveloperMessage); } }