Exemple #1
0
        public void EncodeDecodeSingleValuesFactoryTest()
        {
            var initialValues = new object[]
            {
                new object[] { "just utf8 text olé!", ColumnTypeCode.Text },
                new object[] { "just ascii text", ColumnTypeCode.Ascii },
                new object[] { 123, ColumnTypeCode.Int },
                new object[] { Int64.MinValue + 100, ColumnTypeCode.Bigint },
                new object[] { 44F, ColumnTypeCode.Float },
                new object[] { -320D, ColumnTypeCode.Double },
                new object[] { 99.89770M, ColumnTypeCode.Decimal },
                new object[] { new DateTime(2010, 4, 29), ColumnTypeCode.Timestamp },
                new object[] { new DateTimeOffset(new DateTime(2010, 4, 29)), ColumnTypeCode.Timestamp },
                new object[] { new IPAddress(new byte[] { 10, 0, 5, 5 }), ColumnTypeCode.Inet },
                new object[] { Guid.NewGuid(), ColumnTypeCode.Uuid },
                new object[] { false, ColumnTypeCode.Boolean },
                new object[] { new byte [] { 1, 2 }, ColumnTypeCode.Blob }
            };

            foreach (object[] value in initialValues)
            {
                byte[] encoded = TypeInterpreter.InvCqlConvert(value[0]);
                Assert.AreEqual(value[0], TypeInterpreter.CqlConvert(encoded, (ColumnTypeCode)value[1], null, value[0].GetType()));
            }
        }
Exemple #2
0
        public void EncodeDecodeListSetFactoryTest()
        {
            var initialValues = new object[]
            {
                new object[] { new List <int>(new [] { 1, 2, 1000 }), ColumnTypeCode.List, new ListColumnInfo()
                               {
                                   ValueTypeCode = ColumnTypeCode.Int
                               } },
                new object[] { new List <double>(new [] { -1D, 2.333D, 1.2D }), ColumnTypeCode.List, new ListColumnInfo()
                               {
                                   ValueTypeCode = ColumnTypeCode.Double
                               } },
                new object[] { new List <decimal>(new [] { -1M, 2.333M, 1.2M }), ColumnTypeCode.Set, new SetColumnInfo()
                               {
                                   KeyTypeCode = ColumnTypeCode.Decimal
                               } }
            };

            foreach (object[] value in initialValues)
            {
                byte[] encoded = TypeInterpreter.InvCqlConvert(value[0]);
                Assert.AreEqual(value[0], TypeInterpreter.CqlConvert(encoded, (ColumnTypeCode)value[1], (IColumnInfo)value[2], value[0].GetType()));
            }
        }
Exemple #3
0
        public void EncodeDecodeSingleValuesDefaultsFactory()
        {
            var initialValues = new object[]
            {
                new object[] { "just utf8 text olé!", ColumnTypeCode.Text },
                new object[] { 123, ColumnTypeCode.Int },
                new object[] { Int64.MinValue + 100, ColumnTypeCode.Bigint },
                new object[] { -144F, ColumnTypeCode.Float },
                new object[] { 1120D, ColumnTypeCode.Double },
                new object[] { -9999.89770M, ColumnTypeCode.Decimal },
                new object[] { new DateTimeOffset(new DateTime(2010, 4, 29)), ColumnTypeCode.Timestamp },
                new object[] { new IPAddress(new byte[] { 10, 0, 5, 5 }), ColumnTypeCode.Inet },
                new object[] { Guid.NewGuid(), ColumnTypeCode.Uuid },
                new object[] { true, ColumnTypeCode.Boolean },
                new object[] { new byte [] { 255, 128, 64, 32, 16, 9, 9 }, ColumnTypeCode.Blob }
            };

            foreach (object[] value in initialValues)
            {
                byte[] encoded = TypeInterpreter.InvCqlConvert(value[0]);
                //Set object as the target CSharp type, it should get the default value
                Assert.AreEqual(value[0], TypeInterpreter.CqlConvert(encoded, (ColumnTypeCode)value[1], null, typeof(object)));
            }
        }