Esempio n. 1
0
        public void NullTaskObject()
        {
            var tc  = new TestClass();
            var obj = PropertyAdapter.Create <TestClass>(tc, null);

            Assert.Equal(new AsyncError("task is null"), obj.TryGetValue("TaskObject"));
        }
Esempio n. 2
0
        public void NullSimpleGenericType()
        {
            var tc  = new TestClass();
            var obj = PropertyAdapter.Create <TestClass>(tc, null);

            Assert.Equal(AsyncNull.Instance, obj.TryGetValue("GenericType"));
        }
Esempio n. 3
0
        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"));
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
        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"));
        }
Esempio n. 6
0
        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"));
        }
Esempio n. 7
0
        public void SimpleProperty()
        {
            var tc = new TestClass {
                String = "Hello"
            };
            var obj = PropertyAdapter.Create <TestClass>(tc, null) as IBifoqlLookupInternal;

            Assert.Equal("Hello", obj.TryGetValueAsString("String"));
        }
Esempio n. 8
0
        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"));
        }
Esempio n. 9
0
        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"));
        }
Esempio n. 10
0
        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"));
        }
Esempio n. 11
0
        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"));
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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"));
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
 public void NullIsAllowed()
 {
     PropertyAdapter.Create <TestClass>(null, null);
 }