示例#1
0
 public void Null_ConvertToGenericInt_ThrowsArgument()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         var convertedValue = ConversionUtility.ConvertValue <int>(null);
     });
 }
示例#2
0
        public TItem TryLocateItem(IEngineRepository <TItem> navRepository, object findValue)
        {
            TValue convertedValue = ConversionUtility.ConvertValue <TValue>(findValue);
            var    predicate      = IdentifierExpressionHelpers.GetIdentifierPredicate(_getLocatorValueExpression, convertedValue);

            return(navRepository.GetAllItems().Where(predicate).SingleOrDefault());
        }
示例#3
0
        public void BoxedString_Unboxes()
        {
            object s1 = "my string";
            string s2 = ConversionUtility.ConvertValue <string>(s1);

            Assert.Same(s1, s2);
        }
示例#4
0
 public void Null_ConvertToReflectionInt_ThrowsArgument()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         var convertedValue = ConversionUtility.ConvertValue(null, typeof(int));
     });
 }
示例#5
0
        public void DateTime_ConvertToString_ParsesBack()
        {
            var dateTime       = new DateTime(2004, 07, 21);
            var convertedValue = ConversionUtility.ConvertValue <string>(dateTime);
            var parsedBack     = DateTime.Parse(convertedValue);

            Assert.Equal(dateTime, parsedBack);
        }
示例#6
0
        public async Task SetValueAsync(IDeferredItem <TItem> item, object deserializedValue, IDataTransaction dataTransaction)
        {
            TNav navValue = ConversionUtility.ConvertValue <TNav>(deserializedValue);

            await item.LoadAsync();

            _setter.SetNavItem(item.LoadedItem, navValue);
        }
示例#7
0
        } = true;                                 // TODO really always true?

        public void SetValue(TItem item, string identifier)
        {
            var    propertyInfo   = PropertyInfoUtilities.GetPropertyInfoFromLambda(_getterExpr);
            object convertedValue = ConversionUtility.ConvertValue(identifier, propertyInfo.PropertyType);

            propertyInfo.SetValue(item, convertedValue);

            // TODO use below?
            //IdentifierExpressionHelpers.SetIdentifier(item, _getterExpr, identifier);
        }
示例#8
0
        public async Task SetValueAsync(IDeferredItem <TItem> item, object deserializedValue, IDataTransaction dataTransaction)
        {
            await item.LoadAsync();

            if (item.LoadedItem == null)
            {
                throw new ArgumentNullException(nameof(item.LoadedItem), "Cannot set field value for this item because the item is null.");
            }

            object convertedValue = ConversionUtility.ConvertValue(deserializedValue, _propertyInfo.PropertyType);

            _propertyInfo.SetValue(item.LoadedItem, convertedValue);
        }
示例#9
0
 public Expression <Func <TItem, bool> > GetPredicate(string identifier)
 {
     try
     {
         TReturn convertedIdentifier = ConversionUtility.ConvertValue <TReturn>(identifier);
         return(IdentifierExpressionHelpers.GetIdentifierPredicate(_getterExpr, convertedIdentifier));
     }
     catch (Exception ex) when(ex is FormatException || ex is InvalidCastException)
     {
         // TODO hiding exception.. includes FormatException thrown in ConversionUtility
         return(null);
     }
 }
示例#10
0
 public void HugeNumberString_ConvertToInt_Fail()
 {
     Assert.Throws <OverflowException>(delegate {
         var convertedValue = ConversionUtility.ConvertValue <int>("87623458967234553");
     });
 }
示例#11
0
        public void Null_ConvertToNullableInt_AlsoNull()
        {
            var convertedValue = ConversionUtility.ConvertValue <int?>(null);

            Assert.Null(convertedValue);
        }
示例#12
0
        public void NullableInt_ConvertToInt_Equal()
        {
            var convertedValue = ConversionUtility.ConvertValue <int>(new int?(321));

            Assert.Equal(321, convertedValue);
        }
示例#13
0
        public void Null_ConvertToString_AlsoNull()
        {
            var convertedValue = ConversionUtility.ConvertValue <string>(null);

            Assert.Null(convertedValue);
        }
示例#14
0
 public void TrueString_ConvertToInt_Fail()
 {
     Assert.Throws <FormatException>(delegate {
         var convertedValue = ConversionUtility.ConvertValue <int>("true");
     });
 }
示例#15
0
        public void TrueString_ConvertToBoolean_Parses()
        {
            var convertedValue = ConversionUtility.ConvertValue <bool>("true");

            Assert.Equal(true, convertedValue);
        }
示例#16
0
        public void DateString_ConvertToDateTime_Parses()
        {
            var convertedValue = ConversionUtility.ConvertValue <DateTime>("2002-04-02");

            Assert.Equal(new DateTime(2002, 04, 02), convertedValue);
        }
示例#17
0
        public void NumberString_ConvertToInt_Parses()
        {
            var convertedValue = ConversionUtility.ConvertValue <int>("4321");

            Assert.Equal(4321, convertedValue);
        }
示例#18
0
        public void Int_ConvertToNullable_Equal()
        {
            var convertedValue = ConversionUtility.ConvertValue <int?>(321);

            Assert.Equal(321, convertedValue);
        }
示例#19
0
 public void HugeNumberString_ConvertToLong_Success()
 {
     var convertedValue = ConversionUtility.ConvertValue <long>("87623458967234553");
 }