Example #1
0
        public void Create_With_Frozen_Collection_Value()
        {
            string createQuery = null;
            var    serializer  = new SerializerManager(ProtocolVersion.MaxSupported);
            var    sessionMock = GetSessionMock(serializer);

            sessionMock
            .Setup(s => s.Execute(It.IsAny <string>()))
            .Returns(() => new RowSet())
            .Callback <string>(q => createQuery = q);
            var definition = new Map <UdtAndTuplePoco>()
                             .PartitionKey(c => c.Id1)
                             .Column(c => c.Id1, cm => cm.WithName("id"))
                             .Column(c => c.UdtList1, cm => cm.WithName("my_list").WithFrozenValue())
                             .Column(c => c.TupleMapValue1, cm => cm.WithName("my_map").WithFrozenValue())
                             .ExplicitColumns()
                             .TableName("tbl1");
            var udtInfo = new UdtColumnInfo("song");

            udtInfo.Fields.Add(new ColumnDesc {
                Name = "title", TypeCode = ColumnTypeCode.Ascii
            });
            udtInfo.Fields.Add(new ColumnDesc {
                Name = "releasedate", TypeCode = ColumnTypeCode.Timestamp
            });
            var udtMap = UdtMap.For <Song>();

            udtMap.SetSerializer(serializer.GetCurrentSerializer());
            udtMap.Build(udtInfo);
            serializer.SetUdtMap("song", udtMap);
            var table = GetTable <UdtAndTuplePoco>(sessionMock.Object, definition);

            table.Create();
            Assert.AreEqual("CREATE TABLE tbl1 (id uuid, my_list list<frozen<\"song\">>, my_map map<text, frozen<tuple<double, double>>>, PRIMARY KEY (id))", createQuery);
        }
        public void Should_SkipMetadata_When_NotBoundStatement(ProtocolVersion version)
        {
            var serializerManager = new SerializerManager(version);
            var stmt         = new SimpleStatement("DUMMY QUERY");
            var queryOptions = new QueryOptions();
            var request      = (QueryRequest)RequestHandler.GetRequest(stmt, serializerManager.GetCurrentSerializer(), GetRequestOptions(queryOptions));

            Assert.IsFalse(request.SkipMetadata);
        }
        public void Should_NotSkipMetadata_When_BoundStatementDoesNotContainColumnDefinitions(ProtocolVersion version)
        {
            var serializerManager = new SerializerManager(version);
            var ps           = GetPrepared(serializerManager: serializerManager);
            var stmt         = ps.Bind();
            var queryOptions = new QueryOptions();
            var request      = (ExecuteRequest)RequestHandler.GetRequest(stmt, serializerManager.GetCurrentSerializer(), GetRequestOptions(queryOptions));

            Assert.IsFalse(request.SkipMetadata);
        }
        public void Should_SkipMetadata_When_BoundStatementContainsColumnDefinitionsAndProtocolSupportsNewResultMetadataId(
            ProtocolVersion version, bool isSet)
        {
            var serializerManager = new SerializerManager(version);
            var rsMetadata        = new RowSetMetadata {
                Columns = new[] { new CqlColumn() }
            };
            var ps           = GetPrepared(new byte[16], serializerManager, rsMetadata);
            var stmt         = ps.Bind();
            var queryOptions = new QueryOptions();
            var request      = (ExecuteRequest)RequestHandler.GetRequest(stmt, serializerManager.GetCurrentSerializer(), GetRequestOptions(queryOptions));

            Assert.AreEqual(isSet, request.SkipMetadata);
        }
Example #5
0
        public static RowSet CreateMultipleValuesRowSet <T>(string[] columnNames, T[] genericValues, int rowLength = 1)
        {
            var serializer = new SerializerManager(ProtocolVersion.MaxSupported);
            var rs         = new RowSet();

            rs.Columns = new CqlColumn[columnNames.Length];
            for (var i = 0; i < columnNames.Length; i++)
            {
                IColumnInfo typeInfo;
                var         type = typeof(T);
                if (type == typeof(Object))
                {
                    //Try to guess by value
                    if (genericValues[i] == null)
                    {
                        throw new Exception("Test data could not be generated, value at index " + i + " could not be encoded");
                    }
                    type = genericValues[i].GetType();
                }
                var typeCode = serializer.GetCurrentSerializer().GetCqlType(type, out typeInfo);
                rs.Columns[i] = new CqlColumn
                {
                    Name     = columnNames[i],
                    TypeCode = typeCode,
                    TypeInfo = typeInfo,
                    Type     = typeof(T),
                    Index    = i
                };
            }
            var columnIndexes = rs.Columns.ToDictionary(c => c.Name, c => c.Index);

            for (var i = 0; i < rowLength; i++)
            {
                var values = genericValues
                             .Select(v => (object)v)
                             .ToArray();
                var row = new Row(values, rs.Columns, columnIndexes);
                rs.AddRow(row);
            }
            return(rs);
        }
Example #6
0
        /// <summary>
        /// Returns a RowSet with 1 column
        /// </summary>
        public static RowSet GetSingleColumnRowSet <T>(string columnName, T[] values)
        {
            var serializer = new SerializerManager(ProtocolVersion.MaxSupported);
            var rs         = new RowSet();
            var typeCode   = serializer.GetCurrentSerializer().GetCqlType(typeof(T), out IColumnInfo typeInfo);

            rs.Columns = new[]
            {
                new CqlColumn {
                    Name = columnName, TypeCode = typeCode, TypeInfo = typeInfo, Type = typeof(T), Index = 0
                }
            };
            var columnIndexes = rs.Columns.ToDictionary(c => c.Name, c => c.Index);

            foreach (var v in values)
            {
                var row = new Row(new object[] { v }, rs.Columns, columnIndexes);
                rs.AddRow(row);
            }
            return(rs);
        }