Пример #1
0
        public void Attributes_CompositeKey_FirstPartOfKeyNull()
        {
            MappingConfiguration config = new MappingConfiguration();

            config.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(PocoWithCompositeKey), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithCompositeKey)));
            var table = new Table <PocoWithCompositeKey>(_session, config);

            table.Create();
            List <Guid> listOfGuids = new List <Guid>()
            {
                new Guid(), new Guid()
            };

            var cqlClient = GetMapper();
            PocoWithCompositeKey pocoWithCustomAttributes = new PocoWithCompositeKey
            {
                ListOfGuids       = listOfGuids,
                SomePartitionKey1 = Guid.NewGuid().ToString(),
                SomePartitionKey2 = null,
                IgnoredString     = Guid.NewGuid().ToString(),
            };
            var err = Assert.Throws <InvalidQueryException>(() => cqlClient.Insert(pocoWithCustomAttributes));

            Assert.AreEqual("Invalid null value for partition key part somepartitionkey2", err.Message);
        }
Пример #2
0
        public void Attributes_CompositeKey()
        {
            var definition = new AttributeBasedTypeDefinition(typeof(PocoWithCompositeKey));
            var table      = new Table <PocoWithCompositeKey>(_session, new MappingConfiguration().Define(definition));

            table.Create();

            List <Guid> listOfGuids = new List <Guid>()
            {
                new Guid(), new Guid()
            };

            var mapper = new Mapper(_session, new MappingConfiguration().Define(definition));
            PocoWithCompositeKey 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
            List <PocoWithCompositeKey> 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
            List <Row> 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);
        }
Пример #3
0
        public void Attributes_CompositeKey_AllFieldsNull()
        {
            MappingConfiguration config = new MappingConfiguration();

            config.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(PocoWithCompositeKey), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(PocoWithCompositeKey)));
            var table = new Table <PocoWithCompositeKey>(_session, config);

            table.Create();
            var cqlClient = GetMapper();
            PocoWithCompositeKey pocoWithCustomAttributes = new PocoWithCompositeKey
            {
                ListOfGuids       = null,
                SomePartitionKey1 = null,
                SomePartitionKey2 = null,
                IgnoredString     = null,
            };

            var    err            = Assert.Throws <InvalidQueryException>(() => cqlClient.Insert(pocoWithCustomAttributes));
            string expectedErrMsg = "Invalid null value (for partition key part|in condition for column) somepartitionkey1";

            StringAssert.IsMatch(expectedErrMsg, err.Message);
        }