public void Attributes_Column_NoCustomLabel() { // Setup var expectedTotalRecords = 1; var definition = new AttributeBasedTypeDefinition(typeof(SimplePocoWithColumnAttribute)); var table = new Linq::Table <SimplePocoWithColumnAttribute>(_session, new MappingConfiguration().Define(definition)); Assert.AreNotEqual(table.Name, table.Name.ToLower()); table.Create(); var defaultInstance = new SimplePocoWithColumnAttribute(); var mapper = new Mapper(_session, new MappingConfiguration().Define(definition)); mapper.Insert(defaultInstance); // Validate using mapped Fetch var cqlSelectAll = "select * from " + table.Name.ToLower(); var instancesQueried = mapper.Fetch <SimplePocoWithColumnAttribute>(cqlSelectAll).ToList(); Assert.AreEqual(expectedTotalRecords, instancesQueried.Count); var cqlSelect = $"SELECT * from \"{table.Name.ToLower()}\" where {"somepartitionkey"}='{defaultInstance.SomePartitionKey}'"; var actualObjectsInOrder = mapper.Fetch <SimplePocoWithColumnAttribute>(cqlSelect).ToList(); Assert.AreEqual(expectedTotalRecords, actualObjectsInOrder.Count); // Validate using straight cql to verify column names var rows = _session.Execute(cqlSelect).GetRows().ToList(); Assert.AreEqual(expectedTotalRecords, rows.Count); Assert.AreEqual(defaultInstance.SomeColumn, rows[0].GetValue <int>("somecolumn")); }
public void Attributes_Column_CustomLabels() { // Setup var expectedTotalRecords = 1; var definition = new AttributeBasedTypeDefinition(typeof(SimplePocoWithColumnLabel_CustomColumnName)); var table = new Linq::Table <SimplePocoWithColumnLabel_CustomColumnName>(_session, new MappingConfiguration().Define(definition)); Assert.AreEqual(typeof(SimplePocoWithColumnLabel_CustomColumnName).Name, table.Name); // Assert table name is case sensitive now Assert.AreNotEqual(typeof(SimplePocoWithColumnLabel_CustomColumnName).Name, typeof(SimplePocoWithColumnLabel_CustomColumnName).Name.ToLower()); // Assert table name is case senstive table.Create(); var defaultInstance = new SimplePocoWithColumnLabel_CustomColumnName(); var mapper = new Mapper(_session, new MappingConfiguration().Define(definition)); mapper.Insert(defaultInstance); // Validate using mapped Fetch var cqlSelect = $"SELECT * from \"{table.Name.ToLower()}\" where {"someCaseSensitivePartitionKey"}='{defaultInstance.SomePartitionKey}'"; var actualObjectsInOrder = mapper.Fetch <SimplePocoWithColumnLabel_CustomColumnName>(cqlSelect).ToList(); Assert.AreEqual(expectedTotalRecords, actualObjectsInOrder.Count); Assert.AreEqual(defaultInstance.SomeColumn, actualObjectsInOrder[0].SomeColumn); // Validate using straight cql to verify column names var rows = _session.Execute(cqlSelect).GetRows().ToList(); Assert.AreEqual(expectedTotalRecords, rows.Count); Assert.AreEqual(defaultInstance.SomeColumn, rows[0].GetValue <int>("some_column_label_thats_different")); }
public void Attributes_CompositeKey() { var definition = new AttributeBasedTypeDefinition(typeof(PocoWithCompositeKey)); var table = new Linq::Table <PocoWithCompositeKey>(_session, new MappingConfiguration().Define(definition)); table.Create(); var listOfGuids = new List <Guid>() { new Guid(), new Guid() }; var mapper = new Mapper(_session, new MappingConfiguration().Define(definition)); var pocoWithCustomAttributes = new PocoWithCompositeKey { ListOfGuids = listOfGuids, SomePartitionKey1 = Guid.NewGuid().ToString(), SomePartitionKey2 = Guid.NewGuid().ToString(), IgnoredString = Guid.NewGuid().ToString(), }; mapper.Insert(pocoWithCustomAttributes); // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val var records = mapper.Fetch <PocoWithCompositeKey>("SELECT * from " + table.Name).ToList(); Assert.AreEqual(1, records.Count); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey1, records[0].SomePartitionKey1); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey2, records[0].SomePartitionKey2); Assert.AreEqual(pocoWithCustomAttributes.ListOfGuids, records[0].ListOfGuids); Assert.AreEqual(new PocoWithCompositeKey().IgnoredString, records[0].IgnoredString); // Query for the column that the Linq table create created, verify no value was uploaded to it var rows = _session.Execute("SELECT * from " + table.Name).GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey1, rows[0].GetValue <string>("somepartitionkey1")); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey2, rows[0].GetValue <string>("somepartitionkey2")); Assert.AreEqual(pocoWithCustomAttributes.ListOfGuids, rows[0].GetValue <List <Guid> >("listofguids")); var ex = Assert.Throws <ArgumentException>(() => rows[0].GetValue <string>("ignoredstring")); Assert.AreEqual("Column ignoredstring not found", ex.Message); }
public void Attributes_MultipleClusteringKeys() { var config = new MappingConfiguration(); config.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(PocoWithClusteringKeys), () => Linq::LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithClusteringKeys))); var table = new Linq::Table <PocoWithClusteringKeys>(_session, config); table.Create(); var cqlClient = new Mapper(_session, config); var pocoWithCustomAttributes = new PocoWithClusteringKeys { SomePartitionKey1 = Guid.NewGuid().ToString(), SomePartitionKey2 = Guid.NewGuid().ToString(), Guid1 = Guid.NewGuid(), Guid2 = Guid.NewGuid(), }; cqlClient.Insert(pocoWithCustomAttributes); // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val var records = cqlClient.Fetch <PocoWithClusteringKeys>("SELECT * from " + table.Name).ToList(); Assert.AreEqual(1, records.Count); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey1, records[0].SomePartitionKey1); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey2, records[0].SomePartitionKey2); Assert.AreEqual(pocoWithCustomAttributes.Guid1, records[0].Guid1); Assert.AreEqual(pocoWithCustomAttributes.Guid2, records[0].Guid2); // Query for the column that the Linq table create created, verify no value was uploaded to it var rows = _session.Execute("SELECT * from " + table.Name).GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey1, rows[0].GetValue <string>("somepartitionkey1")); Assert.AreEqual(pocoWithCustomAttributes.SomePartitionKey2, rows[0].GetValue <string>("somepartitionkey2")); Assert.AreEqual(pocoWithCustomAttributes.Guid1, rows[0].GetValue <Guid>("guid1")); Assert.AreEqual(pocoWithCustomAttributes.Guid2, rows[0].GetValue <Guid>("guid2")); }
public void Attributes_Ignore_LinqAndMappingAttributes() { var config = new MappingConfiguration(); config.MapperFactory.PocoDataFactory.AddDefinitionDefault( typeof(PocoWithIgnrdAttr_LinqAndMapping), () => Linq::LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithIgnrdAttr_LinqAndMapping))); var table = new Linq::Table <PocoWithIgnrdAttr_LinqAndMapping>(Session, config); table.Create(); VerifyQuery( "CREATE TABLE \"pocowithignrdattr_linqandmapping\" " + "(\"ignoredstringattribute\" text, \"somenonignoreddouble\" double, " + "\"somepartitionkey\" text, PRIMARY KEY (\"somepartitionkey\"))", 1); var cqlClient = GetMapper(); var pocoToInsert = new PocoWithIgnrdAttr_LinqAndMapping { SomePartitionKey = Guid.NewGuid().ToString(), IgnoredStringAttribute = Guid.NewGuid().ToString(), }; cqlClient.Insert(pocoToInsert); VerifyBoundStatement( "INSERT INTO PocoWithIgnrdAttr_LinqAndMapping (SomeNonIgnoredDouble, SomePartitionKey) " + "VALUES (?, ?)", 1, pocoToInsert.SomeNonIgnoredDouble, pocoToInsert.SomePartitionKey); // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val var cqlSelect = "SELECT * from " + table.Name; TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess( new[]
public void Attributes_Ignore_LinqAndMappingAttributes() { var config = new MappingConfiguration(); config.MapperFactory.PocoDataFactory.AddDefinitionDefault( typeof(PocoWithIgnrdAttr_LinqAndMapping), () => Linq::LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithIgnrdAttr_LinqAndMapping))); var table = new Linq::Table <PocoWithIgnrdAttr_LinqAndMapping>(_session, config); table.Create(); var cqlClient = GetMapper(); var pocoToInsert = new PocoWithIgnrdAttr_LinqAndMapping { SomePartitionKey = Guid.NewGuid().ToString(), IgnoredStringAttribute = Guid.NewGuid().ToString(), }; cqlClient.Insert(pocoToInsert); // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val var records = cqlClient.Fetch <PocoWithIgnrdAttr_LinqAndMapping>("SELECT * from " + table.Name).ToList(); Assert.AreEqual(1, records.Count); Assert.AreEqual(pocoToInsert.SomePartitionKey, records[0].SomePartitionKey); var defaultPoco = new PocoWithIgnrdAttr_LinqAndMapping(); Assert.AreEqual(defaultPoco.IgnoredStringAttribute, records[0].IgnoredStringAttribute); Assert.AreEqual(defaultPoco.SomeNonIgnoredDouble, records[0].SomeNonIgnoredDouble); // Query for the column that the Linq table create created, verify no value was uploaded to it var rows = _session.Execute("SELECT * from " + table.Name).GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreEqual(pocoToInsert.SomePartitionKey, rows[0].GetValue <string>("somepartitionkey")); Assert.AreEqual(pocoToInsert.SomeNonIgnoredDouble, rows[0].GetValue <double>("somenonignoreddouble")); Assert.AreEqual(null, rows[0].GetValue <string>(IgnoredStringAttribute)); }
public void Attributes_Ignore_TableCreatedWithMappingAttributes() { var definition = new AttributeBasedTypeDefinition(typeof(PocoWithIgnoredAttributes)); var table = new Linq::Table <PocoWithIgnoredAttributes>(Session, new MappingConfiguration().Define(definition)); Assert.AreNotEqual(table.Name, table.Name.ToLower()); table.Create(); VerifyQuery( "CREATE TABLE PocoWithIgnoredAttributes " + "(SomeNonIgnoredDouble double, SomePartitionKey text, " + "PRIMARY KEY (SomePartitionKey))", 1); //var mapper = new Mapper(Session, new MappingConfiguration().Define(definition)); var mapper = new Mapper(Session, new MappingConfiguration()); var pocoToUpload = new PocoWithIgnoredAttributes { SomePartitionKey = Guid.NewGuid().ToString(), IgnoredStringAttribute = Guid.NewGuid().ToString(), }; mapper.Insert(pocoToUpload); VerifyBoundStatement( "INSERT INTO PocoWithIgnoredAttributes (SomeNonIgnoredDouble, SomePartitionKey) " + "VALUES (?, ?)", 1, pocoToUpload.SomeNonIgnoredDouble, pocoToUpload.SomePartitionKey); var cqlSelect = $"SELECT * from \"{table.Name.ToLower()}\" where \"somepartitionkey\"='{pocoToUpload.SomePartitionKey}'"; // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess( new[] { "somenonignoreddouble", "somepartitionkey" }, r => r.WithRow(pocoToUpload.SomeNonIgnoredDouble, pocoToUpload.SomePartitionKey))); var records = mapper.Fetch <PocoWithIgnoredAttributes>(cqlSelect).ToList(); Assert.AreEqual(1, records.Count); Assert.AreEqual(pocoToUpload.SomePartitionKey, records[0].SomePartitionKey); var defaultPoco = new PocoWithIgnoredAttributes(); Assert.AreNotEqual(defaultPoco.IgnoredStringAttribute, pocoToUpload.IgnoredStringAttribute); Assert.AreEqual(defaultPoco.IgnoredStringAttribute, records[0].IgnoredStringAttribute); Assert.AreEqual(defaultPoco.SomeNonIgnoredDouble, records[0].SomeNonIgnoredDouble); // Query for the column that the Linq table create created, verify no value was uploaded to it var rows = Session.Execute(cqlSelect).GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreEqual(pocoToUpload.SomePartitionKey, rows[0].GetValue <string>("somepartitionkey")); Assert.AreEqual(pocoToUpload.SomeNonIgnoredDouble, rows[0].GetValue <double>("somenonignoreddouble")); // Verify there was no column created for the ignored column var e = Assert.Throws <ArgumentException>(() => rows[0].GetValue <string>(IgnoredStringAttribute)); var expectedErrMsg = "Column " + IgnoredStringAttribute + " not found"; Assert.AreEqual(expectedErrMsg, e.Message); }