Esempio n. 1
0
        private static SetType <T> ConvertFrom(object o)
        {
            var type = new SetType <T>();

            type.SetValue(o);
            return(type);
        }
Esempio n. 2
0
        private static TOut ConvertTo <TOut>(SetType <T> type)
        {
            if (type == null)
            {
                return(default(TOut));
            }

            return(type.GetValue <TOut>());
        }
Esempio n. 3
0
        public static List <TOut> To <TOut>(SetType <T> obj)
        {
            //Check to make sure we can convert
            if (ComponentType.CreateInstance().CanConvertTo(typeof(TOut)))
            {
                return(new List <TOut>(obj.Select(o => o.GetValue <TOut>())));
            }

            throw new ArgumentException(string.Format("can't convert SetType of type {1} to List of type {0} to ",
                                                      typeof(T), typeof(TOut)));
        }
Esempio n. 4
0
        public void CassandraType_Cast()
        {
            //arrange
            var expected = _setType;

            //act
            SetType <UTF8Type> actualType = expected;
            CassandraObject    actual     = actualType;

            //assert
            Assert.True(expected.SequenceEqual((CassandraObject[])actual));
        }
Esempio n. 5
0
        public void Implicit_ByteArray_Cast()
        {
            //arrange
            var expected = _setType;

            byte[] expectedBytes = GetBytes(_setType.Cast <CassandraObject>().ToList());

            //act
            SetType <UTF8Type> actual = expectedBytes;

            //assert
            Assert.True(expected.SequenceEqual(actual));
        }
Esempio n. 6
0
        public void JavaBytes_to_SetType()
        {
            //arrange
            var expected = new CassandraObject[] { (BytesType)_setType[0].GetValue <string>(), (BytesType)_setType[1].GetValue <string>() };

            //act
            var actual = new SetType <BytesType>();

            actual.SetValueFromBigEndian(_javaByteOrder);

            //assert
            Assert.True(expected.SequenceEqual((CassandraObject[])actual));
        }
Esempio n. 7
0
        public void Explicit_List_Cast()
        {
            //arrange
            List <int> expected = new List <int>()
            {
                1, 2, 3
            };
            SetType <IntegerType> actualType = SetType <IntegerType> .From(expected);

            //act
            CassandraObject actual       = actualType;
            var             actualValues = actual.GetValue <List <object> >();

            //assert
            Assert.True(expected.SequenceEqual(actualValues.Select(Convert.ToInt32)));
        }