public void NullTaskObject() { var tc = new TestClass(); var obj = PropertyAdapter.Create <TestClass>(tc, null); Assert.Equal(new AsyncError("task is null"), obj.TryGetValue("TaskObject")); }
public void NullSimpleGenericType() { var tc = new TestClass(); var obj = PropertyAdapter.Create <TestClass>(tc, null); Assert.Equal(AsyncNull.Instance, obj.TryGetValue("GenericType")); }
public void SimpleObject() { var tc = new TestClass { SimpleObject = new { Name = "Fred" } }; var obj = PropertyAdapter.Create <TestClass>(tc, null); Assert.Equal("Fred", obj.TryGetValue("SimpleObject").TryGetValueAsString("Name")); }
public void AsyncStringProperty() { var tc = new TestClass { AsyncString = (IBifoqlString)"Hello".ToBifoqlObject() }; var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal; Assert.Equal("Hello", obj.TryGetValueAsString("AsyncString")); }
public void SimpleInteger() { var tc = new TestClass { Integer = 456 }; var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal; Assert.Equal(456, (int)obj.TryGetValueAsNumber("Integer")); }
public void SimpleNumber() { var tc = new TestClass { Number = 123.0 }; var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal; Assert.Equal(123.0, obj.TryGetValueAsNumber("Number")); }
public void SimpleProperty() { var tc = new TestClass { String = "Hello" }; var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal; Assert.Equal("Hello", obj.TryGetValueAsString("String")); }
public void AsyncTaskObject() { var tc = new TestClass { AsyncTaskObject = Task.FromResult <IBifoqlObject>("HI".ToBifoqlObject()) }; var obj = PropertyAdapter.Create <TestClass>(tc, null); Assert.Equal("HI", obj.TryGetValueAsString("AsyncTaskObject")); }
public void TaskObject() { var tc = new TestClass { TaskObject = Task.FromResult <object>(12345) }; var obj = PropertyAdapter.Create <TestClass>(tc, null); Assert.Equal(12345d, obj.TryGetValueAsNumber("TaskObject")); }
public void SimpleObjectTask() { var tc = new TestClass { TaskObject = Task.FromResult <object>(new Person { Name = "Bill" }) }; var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal; Assert.Equal("Bill", obj.TryGetValue("TaskObject").TryGetValueAsString("Name")); }
public void SimpleNamedType() { var tc = new TestClass { NamedType = new Person { Name = "Bill" } }; var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal; Assert.Equal("Bill", obj.TryGetValue("NamedType").TryGetValueAsString("Name")); }
public void SimpleAsyncGenericType() { var list = new List <IBifoqlObject> { "Hi".ToBifoqlObject() }; var tc = new TestClass { AsyncGenericType = list }; var obj = PropertyAdapter.Create <TestClass>(tc, null); var listObj = (IBifoqlArrayInternal)obj.TryGetValue("AsyncGenericType"); var hi = listObj[0]().Result.TryGetString(); Assert.Equal("Hi", hi); }
public void DictOfAsyncObjectTasks() { var dict = new Dictionary <string, Task <IBifoqlObject> > { ["a"] = Task.FromResult("ABC".ToBifoqlObject()) }; var tc = new TestClass() { DictOfAsyncObjectTasks = dict }; var obj = PropertyAdapter.Create <TestClass>(tc, null); IBifoqlLookupInternal lookup = (IBifoqlLookupInternal)obj.TryGetValue("DictOfAsyncObjectTasks"); Assert.Equal("ABC", lookup.TryGetValueAsString("a")); }
public async Task SimpleNestedAsyncGenericType() { var list = new List <IBifoqlObject> { "Hey".ToBifoqlObject() }; var listOfList = new List <IList <IBifoqlObject> > { list }; var tc = new TestClass { NestedAsyncGenericType = listOfList }; var obj = PropertyAdapter.Create <TestClass>(tc, null); var listObj = (IBifoqlArrayInternal)obj.TryGetValue("NestedAsyncGenericType"); var innerListObj = (IBifoqlArrayInternal)await listObj[0](); var hi = innerListObj[0]().Result.TryGetString(); Assert.Equal("Hey", hi); }
internal static IBifoqlObject ToBifoqlObject(this object o) { if (o is IBifoqlObject) { return((IBifoqlObject)o); } if (o == null) { return(AsyncNull.Instance); } var defaultValue = GetDefaultValueFunc(o); if (o is IBifoqlArray) { return(ConvertAsyncArray((IBifoqlArray)o)); } if (o is IBifoqlArraySync) { return(ConvertSyncArray((IBifoqlArraySync)o)); } if (o is IBifoqlMap) { return(ConvertAsyncMap((IBifoqlMap)o, defaultValue)); } if (o is IBifoqlMapSync) { return(ConvertSyncMap((IBifoqlMapSync)o, defaultValue)); } if (o is IBifoqlLookup) { return(new AsyncPureLookup(((IBifoqlLookup)o), defaultValue)); } if (o is IBifoqlLookupSync) { return(new SyncPureLookup((IBifoqlLookupSync)o, defaultValue)); } if (o is IBifoqlIndex) { return(ConvertAsyncIndex((IBifoqlIndex)o, defaultValue)); } if (o is IBifoqlIndexSync) { return(ConvertSyncIndex((IBifoqlIndexSync)o, defaultValue)); } if (o is DynamicDict) { return(ConvertDynamicDict((DynamicDict)o)); } if (o is IDictionary) { return(ConvertDictionary(o, toLookup: false)); } if (o is bool) { return(new AsyncBoolean(Convert.ToBoolean(o))); } if (o is int || o is uint || o is byte || o is sbyte || o is short || o is ushort || o is long || o is ulong || o is double || o is float) { return(new AsyncNumber(Convert.ToDouble(o))); } if (o is string || o.GetType().IsValueType) { return(new AsyncString(o.ToString())); } if (o is IEnumerable) { return(ConvertList(o)); } return(PropertyAdapter.Create(o, o.GetType(), defaultValue)); }
public void NullIsAllowed() { PropertyAdapter.Create <TestClass>(null, null); }