public void Test_BOPropLookupList_InitialiseProp_ValidID() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(GetPropDef_Guid_WithLookupList()); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- boProp.InitialiseProp(_validID); //---------------Test Result ----------------------- Assert.AreEqual(_validID, boProp.Value); Assert.IsInstanceOf(typeof (Guid), boProp.Value); }
public void Test_SetValue_NewBusinessObject_NotInList() { //Assert.Fail("Not yet implemented"); //Check Validation of lookup list does not make invalid BOProp boProp = new BOPropLookupList(_propDef_int); BOWithIntID savedBoWithIntID = new BOWithIntID(); savedBoWithIntID.IntID = TestUtil.GetRandomInt(); savedBoWithIntID.TestField = TestUtil.GetRandomString(); //---------------Assert Precondition---------------- Assert.AreEqual(typeof(int), _propDef_int.PropertyType); //---------------Execute Test ---------------------- boProp.Value = savedBoWithIntID; //---------------Test Result ----------------------- Assert.AreEqual(savedBoWithIntID.ID.GetAsValue(), boProp.Value); Assert.AreEqual(savedBoWithIntID.TestField, boProp.PropertyValueToDisplay); Assert.AreEqual("", boProp.IsValidMessage); Assert.IsTrue(boProp.IsValid); }
public void Test_GetBusinessObject_PersistedBusinessObject_NoClassDefOverloadedMethod() { //Check Validation of lookup list does not make invalid ClassDef.ClassDefs.Clear(); BOWithIntID.LoadClassDefWithIntID(); BOPropLookupList boProp = new BOPropLookupList(_propDef_int); BOWithIntID savedBoWithIntID = new BOWithIntID {IntID = TestUtil.GetRandomInt(), TestField = TestUtil.GetRandomString()}; savedBoWithIntID.Save(); boProp.Value = savedBoWithIntID; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IBusinessObject returnedBusinessObject = boProp.GetBusinessObjectForProp(); //---------------Test Result ----------------------- Assert.AreSame(savedBoWithIntID, returnedBusinessObject); }
public void Test_InialiseProp_ValidintString() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_int); int expectIntID = (int) _validBusinessObject.ID.GetAsValue(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(expectIntID.ToString()); //---------------Test Result ----------------------- Assert.IsInstanceOf(typeof (int), boProp.Value); Assert.AreEqual(expectIntID, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_InitialiseProp_ValidDisplayValueString() { BOProp boProp = new BOPropLookupList(_propDef_int); //---------------Assert Precondition---------------- Assert.AreEqual(typeof (int), _propDef_int.PropertyType); Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.InitialiseProp(_validLookupValue); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { StringAssert.Contains("this value cannot be converted to a System.Int32", ex.Message); } // //---------------Test Result ----------------------- // Assert.AreEqual(_validBusinessObject.ID.GetAsValue(), boProp.Value); // Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_BOPropLookupList_Int_PropValueToDisplay_NullValue() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(GetPropDef_Int_WithLookupList()); boProp.InitialiseProp(null); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- object propertyValueToDisplay = boProp.PropertyValueToDisplay; //---------------Test Result ----------------------- Assert.IsNull(propertyValueToDisplay); }
public void Test_BOPropLookupList_Int_PropValueToDisplay_ValidInt() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(GetPropDef_Int_WithLookupList()); boProp.InitialiseProp(_validBusinessObject.IntID); //---------------Assert Precondition---------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(_validBusinessObject.IntID, boProp.Value); //---------------Execute Test ---------------------- object propertyValueToDisplay = boProp.PropertyValueToDisplay; //---------------Test Result ----------------------- Assert.AreEqual(_validBusinessObject.IntID, boProp.Value); Assert.AreEqual(_validLookupValue, propertyValueToDisplay); }
public void Test_InitialiseProp_ValidGuidString_P() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); Guid guid = Guid.NewGuid(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(guid.ToString("P")); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.IsTrue(boProp.Value is Guid, "Value should be a guid"); Assert.AreEqual(guid, boProp.Value); }
public void Test_BOPropLookupList_Int_PropValueToDisplay_InvalidInt() { //GetPropertyValueToDisplay where the guid value is not // in the lookup list (should return null) //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null); const int validInt = 1; Dictionary<string, string> collection_int = new Dictionary<string, string> { { _validLookupValue, validInt.ToString() } }; SimpleLookupList simpleLookupList = new SimpleLookupList(collection_int); propDef.LookupList = simpleLookupList; BOProp boProp = new BOPropLookupList(propDef); boProp.InitialiseProp(3); //---------------Assert Precondition---------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(3, boProp.Value); Assert.IsFalse(boProp.IsDirty); //---------------Execute Test ---------------------- object propertyValueToDisplay = boProp.PropertyValueToDisplay; //---------------Test Result ----------------------- Assert.IsNull(propertyValueToDisplay); }
public void Test_BOPropLookupList_PropValueToDisplay_InvalidGuid() { //GetPropertyValueToDisplay where the guid value is not // in the lookup list (should return null) //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); Guid invalidGuid = Guid.NewGuid(); boProp.InitialiseProp(invalidGuid); //---------------Assert Precondition---------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(invalidGuid, boProp.Value); //---------------Execute Test ---------------------- object propertyValueToDisplay = boProp.PropertyValueToDisplay; //---------------Test Result ----------------------- Assert.IsNull( propertyValueToDisplay); }
public void Test_BOPropLookupList_PropValueToDisplay_ValidGuidStringLookUpList() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null); propDef.LookupList = new SimpleLookupList(_collection_GuidString); BOProp boProp = new BOPropLookupList(propDef); Guid guid = _validGuid; //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(guid); //---------------Test Result ----------------------- Assert.AreEqual(guid, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_BOPropLookupList_PropValueToDisplay_ValidGuid() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); boProp.InitialiseProp(_validGuid); //---------------Assert Precondition---------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(_validGuid, boProp.Value); //---------------Execute Test ---------------------- object propertyValueToDisplay = boProp.PropertyValueToDisplay; //---------------Test Result ----------------------- Assert.AreEqual(_validGuid, boProp.Value); Assert.AreEqual(_validLookupValue, propertyValueToDisplay); }
public void Test_BOPropLookupList_CreateWithLookupList() { //---------------Set up test pack------------------- PropDef def = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null) {LookupList = new SimpleLookupList(_collection)}; //---------------Assert Precondition---------------- Assert.IsTrue(def.HasLookupList()); //---------------Execute Test ---------------------- BOPropLookupList boPropLookupList = new BOPropLookupList(def); //---------------Test Result ----------------------- Assert.IsNotNull(boPropLookupList); }
public void Test_InialiseProp_ValidGuid() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(_validID); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.IsInstanceOf(typeof (Guid), boProp.Value); Assert.AreEqual(_validID, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_SetValue_SetLookupValue_WhereIsAStringThatCanBeParsedToInt() { //This test is a compromise we cannot get this test and //Test_SetValue_SetLookupValue_WhereIsAStringThatCanBeParsedToInt_ExistsAsAnotherValueInList working // as well as the string property working since they have mutually exclusive logic. // We have compromised by allowing this test to not set the lookup value correctly and to return a null // The most common use of lookups in guids and strings and it works reliably for these scenarious. // The final result is that if a developer has a lookup list where the display values are integers // the lookup will not work reliably. //---------------Set up test pack------------------- const int validInt = 5; PropDef propDef1 = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null); const int validLookupValue_ThatIsAnInt = 555; Dictionary<string, string> collection_int = new Dictionary<string, string> { { validLookupValue_ThatIsAnInt.ToString(), validInt.ToString() } }; SimpleLookupList simpleLookupList = new SimpleLookupList(collection_int); propDef1.LookupList = simpleLookupList; PropDef propDef = propDef1; BOProp boProp = new BOPropLookupList(propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); Assert.IsTrue(simpleLookupList.GetIDValueLookupList().ContainsKey(validInt.ToString())); Assert.IsTrue(simpleLookupList.GetIDValueLookupList().ContainsValue(validLookupValue_ThatIsAnInt.ToString())); //---------------Execute Test ---------------------- boProp.Value = validLookupValue_ThatIsAnInt; //---------------Test Result ----------------------- Assert.AreEqual(validInt, boProp.Value); object propertyValueToDisplay = boProp.PropertyValueToDisplay; Assert.AreEqual(validLookupValue_ThatIsAnInt.ToString(), propertyValueToDisplay); Assert.IsTrue(boProp.IsValid); // object validInt = boProp.PropertyValueToDisplay; // Assert.AreEqual(null, propertyValueToDisplay); // Assert.IsFalse(boProp.IsValid); }
public void Test_InialiseProp_ValidGuidString() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(_validGuid.ToString()); //---------------Test Result ----------------------- Assert.AreEqual(_validGuid, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_SetValue_SetLookupValue_WhereIsAStringThatCanBeParsedToInt_ExistsAsAnotherValueInList() { //---------------Set up test pack------------------- const int validInt = 5; PropDef propDef1 = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null); const int validLookupValue_ThatIsAnInt = 555; Dictionary<string, string> collection_int = new Dictionary<string, string> { { validLookupValue_ThatIsAnInt.ToString(), validInt.ToString() }, { validInt.ToString(), "999"} }; SimpleLookupList simpleLookupList = new SimpleLookupList(collection_int); propDef1.LookupList = simpleLookupList; PropDef propDef = propDef1; BOProp boProp = new BOPropLookupList(propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); Assert.IsTrue(simpleLookupList.GetIDValueLookupList().ContainsKey(validInt.ToString())); Assert.IsTrue(simpleLookupList.GetIDValueLookupList().ContainsValue(validLookupValue_ThatIsAnInt.ToString())); //---------------Execute Test ---------------------- boProp.Value = validInt; //---------------Test Result ----------------------- Assert.AreEqual(validInt, boProp.Value); object propertyValueToDisplay = boProp.PropertyValueToDisplay; Assert.AreEqual(validLookupValue_ThatIsAnInt.ToString(), propertyValueToDisplay); }
public void Test_InialiseProp_EmptyGuid() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(Guid.Empty); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
public void Test_BOPropLookupList_Int_InitialiseProp_ValidBusinessObject() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(GetPropDef_Int_WithLookupList()); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- boProp.InitialiseProp(_validBusinessObject); //---------------Test Result ----------------------- Assert.AreEqual(_validBusinessObject.ID.GetAsValue(), boProp.Value); Assert.IsInstanceOf(typeof (int), boProp.Value); }
public void Test_InitialiseProp_ValidDisplayValueString() { BOProp boProp = new BOPropLookupList(_propDef_guid); //---------------Assert Precondition---------------- Assert.AreEqual(typeof(Guid), _propDef_guid.PropertyType); Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(_validLookupValue); //---------------Test Result ----------------------- Assert.AreEqual(_validGuid, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_BOPropLookupList_Int_PropValueToDisplay_InvalidInt() { //GetPropertyValueToDisplay where the guid value is not // in the lookup list (should return null) //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(GetPropDef_Int_WithLookupList()); int intNotInLookupList = _validIntID + 22; boProp.InitialiseProp(intNotInLookupList); boProp.Validate(); //---------------Assert Precondition---------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(intNotInLookupList, boProp.Value); Assert.IsFalse(boProp.IsValid); //---------------Execute Test ---------------------- object propertyValueToDisplay = boProp.PropertyValueToDisplay; //---------------Test Result ----------------------- Assert.IsNull(propertyValueToDisplay); }
public void Test_SetValue_InvalidString() { BOProp boProp = new BOPropLookupList(_propDef_guid); const string invalid = "Invalid"; object originalPropValue = _validGuid; boProp.Value = originalPropValue; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(Guid), _propDef_guid.PropertyType); Assert.IsNotNull(boProp.Value); Assert.IsTrue(boProp.IsValid); //---------------Execute Test ---------------------- try { boProp.Value = invalid; Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { //You are trying to set the value for a lookup property PropName to 'Invalid' this value does not exist in the lookup list StringAssert.Contains(boProp.PropertyName + " cannot be set to '" + invalid + "'", ex.Message); StringAssert.Contains("this value cannot be converted to a System.Guid", ex.Message); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_Initialise_InvalidString() { BOProp boProp = new BOPropLookupList(_propDef_int); const string invalid = "Invalid"; //---------------Assert Precondition---------------- Assert.AreEqual(typeof (int), _propDef_int.PropertyType); Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.InitialiseProp(invalid); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to '" + invalid + "'", ex.Message); StringAssert.Contains("this value cannot be converted to a System.Int32", ex.Message); Assert.AreEqual(null, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_SetValue_ValidDisplayValueString() { BOProp boProp = new BOPropLookupList(_propDef_guid); object originalPropValue = Guid.NewGuid(); boProp.Value = originalPropValue; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(Guid), _propDef_guid.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- boProp.Value = _validLookupValue; //---------------Test Result ----------------------- Assert.AreEqual(_validGuid, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_SetValue_PersistedBusinessObject_InList() { //Assert.Fail("Not yet implemented"); BOProp boProp = new BOPropLookupList(_propDef_int); const int originalPropValue = 99; boProp.Value = originalPropValue; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(int), _propDef_int.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- boProp.Value = _validLookupValue; //---------------Test Result ----------------------- Assert.AreEqual(_validBusinessObject.ID.GetAsValue(), boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_SetValue_EmptyGuid() { //---------------Set up test pack------------------- BOProp boProp = new BOPropLookupList(_propDef_guid); //---------------Execute Test ---------------------- boProp.Value = Guid.Empty; //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); Assert.IsTrue(boProp.IsValid); Assert.IsNull(boProp.PropertyValueToDisplay); }
private IBusinessObject GetBusinessObjectStub() { PropDefCol propDefCol = new PropDefCol {_propDef_int}; PrimaryKeyDef def = new PrimaryKeyDef {_propDef_int}; def.IsGuidObjectID = false; ClassDef classDef = new ClassDef(typeof (BusinessObjectStub), def, propDefCol, new KeyDefCol(), null); BusinessObjectStub businessObjectStub = new BusinessObjectStub(classDef); BOProp prop = new BOPropLookupList(_propDef_int); businessObjectStub.Props.Remove(prop.PropertyName); businessObjectStub.Props.Add(prop); return businessObjectStub; }
public void Test_SetValue_ValidIntID() { //---------------Set up test pack------------------- SimpleLookupList simpleLookupList; const int validInt = 5; PropDef propDef = GetPropDef_Int(validInt, out simpleLookupList); BOProp boProp = new BOPropLookupList(propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); Assert.IsTrue(simpleLookupList.GetIDValueLookupList().ContainsKey(validInt.ToString())); //---------------Execute Test ---------------------- boProp.Value = validInt; //---------------Test Result ----------------------- Assert.AreEqual(validInt, boProp.Value); object propertyValueToDisplay = boProp.PropertyValueToDisplay; Assert.AreEqual(_validLookupValue, propertyValueToDisplay); }
public void Test_GetBusinessObject_SavedBusinessObject_NotInList() { //Assert.Fail("Not yet implemented"); //Check Validation of lookup list does not make invalid ClassDef.ClassDefs.Clear(); IClassDef classDefWithIntID = BOWithIntID.LoadClassDefWithIntID(); BOPropLookupList boProp = new BOPropLookupList(_propDef_int); BOWithIntID unSavedBoWithIntID = new BOWithIntID {IntID = TestUtil.GetRandomInt(), TestField = TestUtil.GetRandomString()}; unSavedBoWithIntID.Save(); FixtureEnvironment.ClearBusinessObjectManager(); boProp.Value = unSavedBoWithIntID; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IBusinessObject returnedBusinessObject = boProp.GetBusinessObjectForProp(classDefWithIntID); //---------------Test Result ----------------------- Assert.AreSame(unSavedBoWithIntID, returnedBusinessObject); }
public void Test_SetValue_ValidDisplayValueString() { MyBO.LoadDefaultClassDef(); BOProp boProp = new BOPropLookupList(_propDefGuid); object originalPropValue = Guid.NewGuid(); boProp.Value = originalPropValue; //---------------Assert Precondition---------------- PropDef propDef = (PropDef) boProp.PropDef; Assert.AreEqual(typeof (Guid), propDef.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- boProp.Value = _validLookupValue; //---------------Test Result ----------------------- Assert.AreEqual(_validBusinessObject.ID.GetAsValue(), boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }