public void Test_Constructor_WithLimitToList_AsTrue() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- SimpleLookupList source = new SimpleLookupList(new Dictionary<string, string>(), true); //---------------Test Result ----------------------- Assert.IsTrue(source.LimitToList); }
public void Test_LimitToList_Attribute_Default() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- SimpleLookupList source = new SimpleLookupList(new Dictionary<string, string>()); //---------------Test Result ----------------------- Assert.IsFalse(source.LimitToList); }
public void Test_SetLookupListForPropDef() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null); SimpleLookupList simpleLookupList = new SimpleLookupList(null); //---------------Assert Precondition---------------- Assert.IsInstanceOf(typeof(NullLookupList), propDef.LookupList); //---------------Execute Test ---------------------- propDef.LookupList = simpleLookupList; //---------------Test Result ----------------------- Assert.IsNotNull(propDef.LookupList); Assert.AreSame(propDef, simpleLookupList.PropDef); }
public void Test_TestLookupListCriteria() { //---------------Set up test pack------------------- PropDefStub propDef = new PropDefStub("PropName", typeof(int), PropReadWriteRule.ReadWrite, null, 99); Dictionary<string, string> collection = new Dictionary<string, string>(); SimpleLookupList simpleLookupList = new SimpleLookupList(collection); propDef.LookupList = simpleLookupList; //---------------Assert Precondition---------------- Assert.IsTrue(propDef.HasLookupList()); Assert.AreEqual(0, propDef.LookupList.GetLookupList().Count); Assert.IsFalse(propDef.LookupList.LimitToList); //---------------Execute Test ---------------------- string errorMessage = ""; bool isItemInList = propDef.CallIsLookupListItemValid(TestUtil.GetRandomInt(), ref errorMessage); //---------------Test Result ----------------------- Assert.IsTrue(string.IsNullOrEmpty(errorMessage), "The error message should be null since limit to list is false"); Assert.IsTrue(isItemInList); }
public void TestCreateBOPropWithLookupList_CorrectPropCreated_WithDefaultValue() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null,99); Dictionary<string, string> collection = new Dictionary<string, string>(); SimpleLookupList simpleLookupList = new SimpleLookupList(collection); propDef.LookupList = simpleLookupList; //-----Test PreCondition-------------------------- Assert.IsTrue(propDef.HasLookupList()); //---------------Execute Test ---------------------- IBOProp prop = propDef.CreateBOProp(true); //---------------Test Result ----------------------- Assert.IsInstanceOf(typeof(BOPropLookupList), prop); }
public void Test_NoPropDefSet_ThrowsError() { //---------------Set up test pack------------------- SimpleLookupList simpleLookupList = new SimpleLookupList(_collection); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { simpleLookupList.GetIDValueLookupList(); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (Exception ex) { StringAssert.Contains("There is an application setup error. There is no propdef set for the simple lookup list.", ex.Message); } //---------------Test Result ----------------------- }
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_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_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_SimpleLookupList_Int_GuidPropType() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(Guid), 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; //---------------Assert Precondition---------------- Assert.AreSame(propDef, simpleLookupList.PropDef); //---------------Execute Test ---------------------- try { simpleLookupList.GetIDValueLookupList(); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("There is an application setup error Please contact your system administrator", ex.Message); StringAssert.Contains("There is a class definition setup error the simple lookup list has lookup value items that are not of type", ex.DeveloperMessage); StringAssert.Contains("Guid", ex.DeveloperMessage); } }
public void Test_SimpleLookupList_Int_GetValue_NotExists() { //---------------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; Dictionary<string, string> list = simpleLookupList.GetIDValueLookupList(); //---------------Assert Precondition---------------- Assert.AreSame(propDef, simpleLookupList.PropDef); //---------------Execute Test ---------------------- string returnedValue; bool keyReturned = list.TryGetValue("3", out returnedValue); //---------------Test Result ----------------------- Assert.IsFalse(keyReturned); Assert.IsNull(returnedValue); }
private static PropDef GetPropDef_Int(int validInt, out SimpleLookupList simpleLookupList) { PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null); Dictionary<string, string> collection_int = new Dictionary<string, string> { { _validLookupValue, validInt.ToString() } }; simpleLookupList = new SimpleLookupList(collection_int); propDef.LookupList = simpleLookupList; return propDef; }
public void Test_SimpleLookupList_Int_String_GetKey_Exists() { //---------------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; Dictionary<string, string> list = simpleLookupList.GetLookupList(); //---------------Assert Precondition---------------- Assert.IsInstanceOf(typeof(SimpleLookupList), propDef.LookupList); Assert.AreSame(propDef, simpleLookupList.PropDef); //---------------Execute Test ---------------------- string returnedKey; bool keyReturned = list.TryGetValue(_validLookupValue, out returnedKey); //---------------Test Result ----------------------- Assert.IsTrue(keyReturned); Assert.AreEqual(validInt.ToString(), returnedKey); }
public void Test_SimpleLookupList_GetValue_NotExists() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null); SimpleLookupList simpleLookupList = new SimpleLookupList(_collection); propDef.LookupList = simpleLookupList; Dictionary<string, string> list = simpleLookupList.GetIDValueLookupList(); //---------------Assert Precondition---------------- Assert.IsInstanceOf(typeof(SimpleLookupList), propDef.LookupList); Assert.AreSame(propDef, simpleLookupList.PropDef); //---------------Execute Test ---------------------- string returnedValue; bool keyReturned = list.TryGetValue(NewGuidAsStdString(), out returnedValue); //---------------Test Result ----------------------- Assert.IsFalse(keyReturned); Assert.IsNull(returnedValue); }
public void Test_SetLookupList_SetsUpKeyLookupList() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null); SimpleLookupList simpleLookupList = new SimpleLookupList(_collection); //---------------Assert Precondition---------------- Assert.IsInstanceOf(typeof(NullLookupList), propDef.LookupList); Assert.AreEqual(_collection.Count, simpleLookupList.GetLookupList().Count); //---------------Execute Test ---------------------- propDef.LookupList = simpleLookupList; //---------------Test Result ----------------------- Assert.IsInstanceOf(typeof(SimpleLookupList), propDef.LookupList); Assert.AreSame(propDef, simpleLookupList.PropDef); Assert.AreEqual(_collection.Count, simpleLookupList.GetLookupList().Count); Assert.AreEqual(_collection.Count, simpleLookupList.GetIDValueLookupList().Count); }
public void Test_SimpleLookup_Create_SetsUpKeyLookupList() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null); //---------------Assert Precondition---------------- Assert.AreEqual(2, _collection.Count); //---------------Execute Test ---------------------- SimpleLookupList simpleLookupList = new SimpleLookupList(_collection); simpleLookupList.PropDef = propDef; //---------------Assert Precondition---------------- Assert.AreEqual(_collection.Count, simpleLookupList.GetLookupList().Count); Assert.IsNotNull(simpleLookupList.GetIDValueLookupList()); Assert.AreEqual(2, simpleLookupList.GetIDValueLookupList().Count); }