public void Test_Construct() { //---------------Set up test pack------------------- string propertyName = TestUtil.GetRandomString(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- ReflectionPropertyMapper boPropertyMapper = new ReflectionPropertyMapper(propertyName); //---------------Test Result ----------------------- Assert.AreEqual(propertyName, boPropertyMapper.PropertyName); Assert.IsNull(boPropertyMapper.BusinessObject);; }
public void Test_BusinessObject_GetAndSet() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string propertyName = "FirstName"; ReflectionPropertyMapper boPropertyMapper = new ReflectionPropertyMapper(propertyName); //---------------Assert Precondition---------------- Assert.IsNull(boPropertyMapper.BusinessObject); //---------------Execute Test ---------------------- boPropertyMapper.BusinessObject = contactPersonTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject); }
public void Test_SetPropertyValue_ShouldSetBOPropsValue() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string propName = "ReflectiveProp"; IBOPropertyMapper boPropertyMapper = new ReflectionPropertyMapper(propName) { BusinessObject = contactPersonTestBO }; //---------------Assert Precondition---------------- Assert.IsNull(contactPersonTestBO.ReflectiveProp); //---------------Execute Test ---------------------- var expectedPropValue = RandomValueGen.GetRandomString(); boPropertyMapper.SetPropertyValue(expectedPropValue); //---------------Test Result ----------------------- Assert.AreEqual(expectedPropValue, contactPersonTestBO.ReflectiveProp); }
public void Test_GetPropertyValue_WhenBONull_ShouldRaiseError() { //---------------Set up test pack------------------- const string propName = "ReflectiveProp"; ReflectionPropertyMapper boPropertyMapper = new ReflectionPropertyMapper(propName); //---------------Assert Precondition---------------- Assert.IsNull(boPropertyMapper.BusinessObject); //---------------Execute Test ---------------------- try { boPropertyMapper.GetPropertyValue(); Assert.Fail("Expected to throw an HabaneroApplicationException"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { string expectedErrorMessage = string.Format( "Tried to GetPropertyValue the ReflectionPropertyMapper for Property '{0}' when the BusinessObject is not set " , propName); StringAssert.Contains(expectedErrorMessage, ex.Message); } }
public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedProperty_ShouldThrowError() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string propertyName = "SomeNonExistentProperty"; ReflectionPropertyMapper boPropertyMapper = new ReflectionPropertyMapper(propertyName); //---------------Assert Precondition---------------- Assert.IsNull(boPropertyMapper.BusinessObject); //---------------Execute Test ---------------------- try { boPropertyMapper.BusinessObject = contactPersonTestBO; Assert.Fail("Expected to throw a HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (InvalidPropertyException ex) { StringAssert.Contains("The property '" + propertyName + "' on '" + contactPersonTestBO.ClassDef.ClassName + "' cannot be found. Please contact your system administrator.", ex.Message); Assert.IsNull(boPropertyMapper.BusinessObject); } }