public void Attributes_Ignore() { var table = GetTable <PocoWithIgnoredAttributes>(); Assert.AreNotEqual(table.Name, table.Name.ToLower()); table.Create(); VerifyQuery( "CREATE TABLE PocoWithIgnoredAttributes " + "(SomeNonIgnoredDouble double, SomePartitionKey text, " + "PRIMARY KEY (SomePartitionKey))", 1); var mapper = GetMapper(); 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}'"; TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess( new[] { "somenonignoreddouble", "somepartitionkey" }, r => r.WithRow(pocoToUpload.SomeNonIgnoredDouble, pocoToUpload.SomePartitionKey))); // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val 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); }
public void Attributes_PartitionKey_ValueNull() { var table = GetTable <PocoWithIgnoredAttributes>(); table.Create(); var mapper = GetMapper(); PocoWithIgnoredAttributes pocoWithCustomAttributesLynqAndMappingIncluded = new PocoWithIgnoredAttributes { SomePartitionKey = null, IgnoredStringAttribute = Guid.NewGuid().ToString(), }; var err = Assert.Throws <InvalidQueryException>(() => mapper.Insert(pocoWithCustomAttributesLynqAndMappingIncluded)); Assert.AreEqual("Invalid null value for partition key part somepartitionkey", err.Message); }
public void Attributes_PartitionKey_ValueNull() { var table = GetTable <PocoWithIgnoredAttributes>(); table.Create(); var mapper = GetMapper(); PocoWithIgnoredAttributes pocoWithCustomAttributesLynqAndMappingIncluded = new PocoWithIgnoredAttributes { SomePartitionKey = null, IgnoredStringAttribute = Guid.NewGuid().ToString(), }; var err = Assert.Throws <InvalidQueryException>(() => mapper.Insert(pocoWithCustomAttributesLynqAndMappingIncluded)); string expectedErrMsg = "Invalid null value (for partition key part|in condition for column) somepartitionkey"; StringAssert.IsMatch(expectedErrMsg, err.Message); }
public void Attributes_Ignore_TableCreatedWithMappingAttributes() { var definition = new AttributeBasedTypeDefinition(typeof(PocoWithIgnoredAttributes)); var table = new Table <PocoWithIgnoredAttributes>(_session, new MappingConfiguration().Define(definition)); Assert.AreNotEqual(table.Name, table.Name.ToLower()); table.Create(); //var mapper = new Mapper(_session, new MappingConfiguration().Define(definition)); var mapper = new Mapper(_session, new MappingConfiguration()); PocoWithIgnoredAttributes pocoToUpload = new PocoWithIgnoredAttributes { SomePartitionKey = Guid.NewGuid().ToString(), IgnoredStringAttribute = Guid.NewGuid().ToString(), }; mapper.Insert(pocoToUpload); string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name.ToLower(), "somepartitionkey", pocoToUpload.SomePartitionKey); // Get records using mapped object, validate that the value from Cassandra was ignored in favor of the default val List <PocoWithIgnoredAttributes> records = mapper.Fetch <PocoWithIgnoredAttributes>(cqlSelect).ToList(); Assert.AreEqual(1, records.Count); Assert.AreEqual(pocoToUpload.SomePartitionKey, records[0].SomePartitionKey); PocoWithIgnoredAttributes 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 List <Row> 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)); string expectedErrMsg = "Column " + IgnoredStringAttribute + " not found"; Assert.AreEqual(expectedErrMsg, e.Message); }
public void Attributes_Ignore() { var table = GetTable <PocoWithIgnoredAttributes>(); Assert.AreNotEqual(table.Name, table.Name.ToLower()); table.Create(); var mapper = GetMapper(); var pocoToUpload = new PocoWithIgnoredAttributes { SomePartitionKey = Guid.NewGuid().ToString(), IgnoredStringAttribute = Guid.NewGuid().ToString(), }; mapper.Insert(pocoToUpload); 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 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); }