public void Null_ConvertToGenericInt_ThrowsArgument() { Assert.Throws <ArgumentException>(delegate { var convertedValue = ConversionUtility.ConvertValue <int>(null); }); }
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()); }
public void BoxedString_Unboxes() { object s1 = "my string"; string s2 = ConversionUtility.ConvertValue <string>(s1); Assert.Same(s1, s2); }
public void Null_ConvertToReflectionInt_ThrowsArgument() { Assert.Throws <ArgumentException>(delegate { var convertedValue = ConversionUtility.ConvertValue(null, typeof(int)); }); }
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); }
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); }
} = 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); }
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); }
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); } }
public void HugeNumberString_ConvertToInt_Fail() { Assert.Throws <OverflowException>(delegate { var convertedValue = ConversionUtility.ConvertValue <int>("87623458967234553"); }); }
public void Null_ConvertToNullableInt_AlsoNull() { var convertedValue = ConversionUtility.ConvertValue <int?>(null); Assert.Null(convertedValue); }
public void NullableInt_ConvertToInt_Equal() { var convertedValue = ConversionUtility.ConvertValue <int>(new int?(321)); Assert.Equal(321, convertedValue); }
public void Null_ConvertToString_AlsoNull() { var convertedValue = ConversionUtility.ConvertValue <string>(null); Assert.Null(convertedValue); }
public void TrueString_ConvertToInt_Fail() { Assert.Throws <FormatException>(delegate { var convertedValue = ConversionUtility.ConvertValue <int>("true"); }); }
public void TrueString_ConvertToBoolean_Parses() { var convertedValue = ConversionUtility.ConvertValue <bool>("true"); Assert.Equal(true, convertedValue); }
public void DateString_ConvertToDateTime_Parses() { var convertedValue = ConversionUtility.ConvertValue <DateTime>("2002-04-02"); Assert.Equal(new DateTime(2002, 04, 02), convertedValue); }
public void NumberString_ConvertToInt_Parses() { var convertedValue = ConversionUtility.ConvertValue <int>("4321"); Assert.Equal(4321, convertedValue); }
public void Int_ConvertToNullable_Equal() { var convertedValue = ConversionUtility.ConvertValue <int?>(321); Assert.Equal(321, convertedValue); }
public void HugeNumberString_ConvertToLong_Success() { var convertedValue = ConversionUtility.ConvertValue <long>("87623458967234553"); }