TryParsePropValue() public méthode

This method provides a the functionality to convert any object to the appropriate type for the particular BOProp Type. e.g it will convert a valid guid string to a valid Guid Object.
public TryParsePropValue ( object valueToParse, object &returnValue ) : bool
valueToParse object The value to be converted
returnValue object
Résultat bool
 public void TryParsePropValue_WhenValueNull_ShouldReturnNull()
 {
     //---------------Set up test pack-------------------
     var propMapper = new GeneralDataMapper(typeof(int));
     object returnValue;
     //---------------Execute Test ----------------------
     var result = propMapper.TryParsePropValue(null, out returnValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(result);
     Assert.IsNull(returnValue);
 }
 public void TryParsePropValue_ShouldSetReturnValueSame_WhenValueToParseIsAlreadyCorrectType_ForReferenceType()
 {
     //---------------Set up test pack-------------------
     var dataMapper = new GeneralDataMapper(typeof (Image));
     Image valueToParse = new Bitmap(200, 200);
     object returnValue;
     //---------------Execute Test ----------------------
     var result = dataMapper.TryParsePropValue(valueToParse, out returnValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(result);
     Assert.AreSame(valueToParse, returnValue);
 }
 public void TryParsePropValue_ShouldSetReturnValueEqual_WhenValueToParseIsAlreadyCorrectType_ForValueType()
 {
     //---------------Set up test pack-------------------
     var dataMapper = new GeneralDataMapper(typeof (int));
     int valueToParse = TestUtil.GetRandomInt();
     object returnValue;
     //---------------Execute Test ----------------------
     var result = dataMapper.TryParsePropValue(valueToParse, out returnValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(result);
     Assert.AreEqual(valueToParse, returnValue);
 }      
        public void TryParsePropValue_ShouldParseValue_ForCustomTypeWithATypeConverter()
        {
            //---------------Set up test pack-------------------
            const string emailAddToParse = "*****@*****.**";

            var propMapper = new GeneralDataMapper(typeof(EmailAddressWithTypeConverter));
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            object parsedValue;
            var tryParsePropValue = propMapper.TryParsePropValue(emailAddToParse, out parsedValue);
            //---------------Test Result -----------------------
            Assert.IsTrue(tryParsePropValue);
            Assert.IsInstanceOf<EmailAddressWithTypeConverter>(parsedValue);
            Assert.AreEqual(emailAddToParse, ((EmailAddressWithTypeConverter)parsedValue).EmailAddress);
        }
        public void TryParsePropValue_ShouldThrowInvalidCastException_WhenTypeCannotBeConverted()
        {
            //---------------Set up test pack-------------------
            var propMapper = new GeneralDataMapper(typeof(ConsoleColor));
            object parsedValue;
            //---------------Execute Test ----------------------
            try
            {
                propMapper.TryParsePropValue(ConsoleKey.Z, out parsedValue);
                Assert.Fail("should fail when there's no way to convert");
                //---------------Test Result -----------------------
            }
            catch (InvalidCastException ex)
            {
                StringAssert.Contains("Invalid cast from", ex.Message);
            }

        }
 public void TryParsePropValue_ShouldConvert_WhenTypeCanBeConverted()
 {
     //---------------Set up test pack-------------------
     var propMapper = new GeneralDataMapper(typeof(int));
     int expectedValue = TestUtil.GetRandomInt();
     object parsedValue;
     //---------------Execute Test ----------------------
     var result = propMapper.TryParsePropValue(expectedValue.ToString(), out parsedValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(result);
     Assert.AreEqual(expectedValue, parsedValue);
 }
 public void TryParsePropValue_ForEnumType_ShouldParseStringToEnumType()
 {
     //---------------Set up test pack-------------------
     var propMapper = new GeneralDataMapper(typeof(ConsoleColor));
     var expectedValue = ConsoleColor.Blue;
     string valueAsString = Enum.GetName(typeof (ConsoleColor), expectedValue);
     object parsedValue;
     //---------------Execute Test ----------------------
     var result = propMapper.TryParsePropValue(valueAsString, out parsedValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(result);
     Assert.AreEqual(expectedValue, parsedValue);
 }
Exemple #8
0
        public void Test_BOPropGeneralDataMapper_TryParseCustomProperty_StringValue()
        {
            //---------------Set up test pack-------------------
            string test = "test";
            GeneralDataMapper generalDataMapper = new GeneralDataMapper(typeof(LongText));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object returnValue;
            generalDataMapper.TryParsePropValue(test, out returnValue);
            //---------------Test Result -----------------------
            Assert.IsNotNull(returnValue);
            Assert.IsInstanceOf(typeof(LongText), returnValue);
            LongText longText = (LongText) returnValue;
            Assert.AreSame(test, longText.Value);
        }
Exemple #9
0
        public void Test_BOPropGeneralDataMapper_TryParseCustomProperty_InheritedLongText()
        {
            //---------------Set up test pack-------------------
            LongText longText = new ExtendedLongText("test");
            GeneralDataMapper generalDataMapper = new GeneralDataMapper(typeof(LongText));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object returnValue;
            generalDataMapper.TryParsePropValue(longText, out returnValue);
            //---------------Test Result -----------------------
            Assert.IsNotNull(returnValue);
            Assert.AreSame(longText, returnValue);
        }
        public void Test_BOPropGeneralDataMapper_TryParseCustomProperty_StringValue()
        {
            //---------------Set up test pack-------------------
            const string test = "test";
            var generalDataMapper = new GeneralDataMapper(typeof(SimpleValueObjectStub));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object returnValue;
            generalDataMapper.TryParsePropValue(test, out returnValue);
            //---------------Test Result -----------------------
            Assert.IsNotNull(returnValue);
            Assert.IsInstanceOf(typeof(SimpleValueObjectStub), returnValue);
            var valueObject = (SimpleValueObjectStub) returnValue;
            Assert.AreSame(test, valueObject.ToString());
        }
        public void Test_BOPropGeneralDataMapper_TryParseCustomProperty_InheritedCustomProperty()
        {
            //---------------Set up test pack-------------------
            var valueObject = new SimpleValueObjectStub("test");
            var generalDataMapper = new GeneralDataMapper(typeof(CustomProperty));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object returnValue;
            generalDataMapper.TryParsePropValue(valueObject, out returnValue);
            //---------------Test Result -----------------------
            Assert.IsNotNull(returnValue);
            Assert.AreSame(valueObject, returnValue);
        }