Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
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);
        }
Пример #8
0
        public void TryParsePropValue_ShouldTryToInstantiateCustomerProperty_ForCustomTypeWithNoTypeConverter()
        {
            //---------------Set up test pack-------------------
            const string emailAddToParse = "*****@*****.**";

            var propMapper = new GeneralDataMapper(typeof(EmailAddressAsCustomProperty));
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            object parsedValue;
            var    tryParsePropValue = propMapper.TryParsePropValue(emailAddToParse, out parsedValue);

            //---------------Test Result -----------------------
            Assert.IsTrue(tryParsePropValue);
            Assert.IsInstanceOf <EmailAddressAsCustomProperty>(parsedValue);
            Assert.AreEqual(emailAddToParse, ((EmailAddressAsCustomProperty)parsedValue).EmailAddress);
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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());
        }
Пример #11
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);
        }