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_GetPropertyValue_ShouldSetBOPropsValue() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string propName = "ReflectiveProp"; IBOPropertyMapper boPropertyMapper = new ReflectionPropertyMapper(propName) { BusinessObject = contactPersonTestBO }; var expectedPropValue = RandomValueGen.GetRandomString(); contactPersonTestBO.ReflectiveProp = expectedPropValue; //---------------Assert Precondition---------------- Assert.IsNotNull(contactPersonTestBO.ReflectiveProp); Assert.AreEqual(expectedPropValue, contactPersonTestBO.ReflectiveProp); //---------------Execute Test ---------------------- object actualValue = boPropertyMapper.GetPropertyValue(); //---------------Test Result ----------------------- Assert.AreEqual(expectedPropValue, actualValue); Assert.AreEqual(expectedPropValue, contactPersonTestBO.ReflectiveProp); }