public void Attributes_PartitionKey_ValueNull_LinqAndMappingAttributes() { MappingConfiguration config = new MappingConfiguration(); config.MapperFactory.PocoDataFactory.AddDefinitionDefault( typeof(PocoWithIgnrdAttr_LinqAndMapping), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithIgnrdAttr_LinqAndMapping))); var table = new Table <PocoWithIgnrdAttr_LinqAndMapping>(_session, config); table.Create(); var cqlClient = GetMapper(); PocoWithIgnrdAttr_LinqAndMapping pocoWithCustomAttributesLinqAndMapping = new PocoWithIgnrdAttr_LinqAndMapping { SomePartitionKey = null, IgnoredStringAttribute = Guid.NewGuid().ToString(), }; var err = Assert.Throws <InvalidQueryException>(() => cqlClient.Insert(pocoWithCustomAttributesLinqAndMapping)); Assert.AreEqual("Invalid null value for partition key part somepartitionkey", err.Message); }
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() { MappingConfiguration config = new MappingConfiguration(); config.MapperFactory.PocoDataFactory.AddDefinitionDefault( typeof(PocoWithIgnrdAttr_LinqAndMapping), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithIgnrdAttr_LinqAndMapping))); var table = new Table <PocoWithIgnrdAttr_LinqAndMapping>(_session, config); table.Create(); var cqlClient = GetMapper(); PocoWithIgnrdAttr_LinqAndMapping 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 List <PocoWithIgnrdAttr_LinqAndMapping> records = cqlClient.Fetch <PocoWithIgnrdAttr_LinqAndMapping>("SELECT * from " + table.Name).ToList(); Assert.AreEqual(1, records.Count); Assert.AreEqual(pocoToInsert.SomePartitionKey, records[0].SomePartitionKey); PocoWithIgnrdAttr_LinqAndMapping 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 List <Row> 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)); }