Beispiel #1
0
        public void LinqWhere_Boolean()
        {
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "SELECT \"BooleanType\", \"DateTimeOffsetType\", \"DateTimeType\", \"DecimalType\", " +
                    "\"DictionaryStringLongType\", \"DictionaryStringStringType\", \"DoubleType\", \"FloatType\", " +
                    "\"GuidType\", \"Int64Type\", \"IntType\", \"ListOfGuidsType\", \"ListOfStringsType\", " +
                    "\"NullableIntType\", \"StringType\" " +
                    $"FROM \"{ManyDataTypesEntity.TableName}\" " +
                    $"WHERE \"BooleanType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(true))
                .ThenRowsSuccess(ManyDataTypesEntity.GetColumnsWithTypes()));

            //there are no records with BooleanType == true
            var rs = _manyDataTypesEntitiesTable.Where(m => m.BooleanType).Execute();

            Assert.NotNull(rs);
            var rows = rs.ToArray();

            Assert.AreEqual(0, rows.Length);
            var guid = Guid.NewGuid();
            var data = new ManyDataTypesEntity
            {
                BooleanType        = true,
                DateTimeOffsetType = DateTimeOffset.Now,
                DateTimeType       = DateTime.Now,
                DecimalType        = 10,
                DoubleType         = 10.0,
                FloatType          = 10.0f,
                GuidType           = guid,
                IntType            = 10,
                StringType         = "Boolean True"
            };

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "SELECT \"BooleanType\", \"DateTimeOffsetType\", \"DateTimeType\", \"DecimalType\", " +
                    "\"DictionaryStringLongType\", \"DictionaryStringStringType\", \"DoubleType\", \"FloatType\", " +
                    "\"GuidType\", \"Int64Type\", \"IntType\", \"ListOfGuidsType\", \"ListOfStringsType\", " +
                    "\"NullableIntType\", \"StringType\" " +
                    $"FROM \"{ManyDataTypesEntity.TableName}\" " +
                    $"WHERE \"BooleanType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(true))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));

            rs = _manyDataTypesEntitiesTable.Where(m => m.BooleanType).Execute();
            Assert.NotNull(rs);
            rows = rs.ToArray();
            Assert.AreEqual(1, rows.Length);
            Assert.AreEqual(guid, rows[0].GuidType);
            Assert.AreEqual("Boolean True", rows[0].StringType);
            Assert.IsTrue(rows[0].BooleanType);
        }
Beispiel #2
0
        public void LinqWhere_ShortScopes()
        {
            var          guid = Guid.NewGuid();
            const string pk   = "Boolean True";
            var          data = new ManyDataTypesEntity
            {
                BooleanType        = true,
                DateTimeOffsetType = DateTimeOffset.Now,
                DateTimeType       = DateTime.Now,
                DecimalType        = 11,
                DoubleType         = 11.0,
                FloatType          = 11.0f,
                GuidType           = guid,
                IntType            = 11,
                Int64Type          = 11,
                StringType         = pk
            };

            _manyDataTypesEntitiesTable.Insert(data).Execute();
            //Get poco using constant short
            const short expectedShortValue = 11;
            var         rs = _manyDataTypesEntitiesTable
                             .Where(m => m.StringType == pk && m.IntType == expectedShortValue).AllowFiltering().Execute();

            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.IntType == ExpectedShortValue)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && ExpectedShortValue == m.IntType)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && expectedShortValue == m.IntType)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.Int64Type == expectedShortValue)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && expectedShortValue == m.Int64Type)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.Int64Type == ExpectedShortValue)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && ExpectedShortValue == m.Int64Type)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
            _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.IntType == expectedShortValue)
            .AllowFiltering().Delete();
        }
Beispiel #3
0
        private string GetSimpleStatementInsertString(ManyDataTypesEntity entity)
        {
            string strForSimpleStatement = string.Format(_simpleStatementInsertFormat,
                                                         new object[] {
                entity.StringType, entity.GuidType, entity.BooleanType, entity.DecimalType,
                entity.DoubleType, entity.FloatType, entity.IntType, entity.Int64Type
            });

            return(strForSimpleStatement);
        }
Beispiel #4
0
        private void DoSimpleStatementInsertTest(ConsistencyLevel expectedConsistencyLevel)
        {
            string          simpleStatementStr = GetSimpleStatementInsertString(ManyDataTypesEntity.GetRandomInstance());
            SimpleStatement simpleStatement    = new SimpleStatement(simpleStatementStr);

            simpleStatement = (SimpleStatement)simpleStatement.SetConsistencyLevel(expectedConsistencyLevel);
            var result = _session.Execute(simpleStatement);

            Assert.AreEqual(expectedConsistencyLevel, result.Info.AchievedConsistency);

            var selectResult = _session.Execute(_defaultSelectStatement);

            Assert.AreEqual(_defaultPocoList.Count + 1, selectResult.GetRows().ToList().Count);
        }
Beispiel #5
0
        public void Consistency_SimpleStatement_Serial_Insert_Success()
        {
            SetupSessionAndCluster(_defaultNodeCountOne);
            string          simpleStatementStr = GetSimpleStatementInsertString(ManyDataTypesEntity.GetRandomInstance());
            SimpleStatement simpleStatement    = new SimpleStatement(simpleStatementStr);

            simpleStatement = (SimpleStatement)simpleStatement.SetConsistencyLevel(ConsistencyLevel.Quorum).SetSerialConsistencyLevel(ConsistencyLevel.Serial);
            var result = _session.Execute(simpleStatement);

            Assert.AreEqual(ConsistencyLevel.Quorum, result.Info.AchievedConsistency);

            var selectResult = _session.Execute(_defaultSelectStatement);

            Assert.AreEqual(_defaultPocoList.Count + 1, selectResult.GetRows().ToList().Count);
        }
Beispiel #6
0
        private void DoPreparedInsertTest(ConsistencyLevel expectedConsistencyLevel)
        {
            ManyDataTypesEntity mdtp = ManyDataTypesEntity.GetRandomInstance();

            object[] vals = ConvertEntityToObjectArray(mdtp);

            // NOTE: We have to re-prepare every time since there is a unique Keyspace used for every test
            PreparedStatement preparedInsertStatement = _session.Prepare(_preparedInsertStatementAsString).SetConsistencyLevel(expectedConsistencyLevel);
            BoundStatement    boundStatement          = preparedInsertStatement.Bind(vals);
            var result = _session.Execute(boundStatement);

            Assert.AreEqual(expectedConsistencyLevel, result.Info.AchievedConsistency);

            var selectResult = _session.Execute(_defaultSelectStatement);

            Assert.AreEqual(_defaultPocoList.Count + 1, selectResult.GetRows().ToList().Count);
        }
Beispiel #7
0
        private static object[] ConvertEntityToObjectArray(ManyDataTypesEntity mdtp)
        {
            // ToString() Example output:
            // INSERT INTO "ManyDataTypesPoco" ("StringType", "GuidType", "DateTimeType", "DateTimeOffsetType", "BooleanType",
            // "DecimalType", "DoubleType", "FloatType", "NullableIntType", "IntType", "Int64Type",
            // "TimeUuidType", "NullableTimeUuidType", "DictionaryStringLongType", "DictionaryStringStringType", "ListOfGuidsType", "ListOfStringsType") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

            object[] vals =
            {
                mdtp.StringType,               mdtp.GuidType,                   mdtp.DateTimeType,    mdtp.DateTimeOffsetType, mdtp.BooleanType,
                mdtp.DecimalType,              mdtp.DoubleType,                 mdtp.FloatType,       mdtp.NullableIntType,    mdtp.IntType,    mdtp.Int64Type,
                // mdtp.TimeUuidType,
                // mdtp.NullableTimeUuidType,
                mdtp.DictionaryStringLongType, mdtp.DictionaryStringStringType, mdtp.ListOfGuidsType, mdtp.ListOfStringsType,
            };

            return(vals);
        }
Beispiel #8
0
        public void Consistency_PreparedStatement_Serial_Insert_Success()
        {
            ManyDataTypesEntity mdtp = ManyDataTypesEntity.GetRandomInstance();

            object[] vals = ConvertEntityToObjectArray(mdtp);
            SetupSessionAndCluster(_defaultNodeCountOne);

            PreparedStatement preparedInsertStatement = _session.Prepare(_preparedInsertStatementAsString);
            BoundStatement    boundStatement          = preparedInsertStatement.SetConsistencyLevel(ConsistencyLevel.Quorum).Bind(vals);

            boundStatement.SetSerialConsistencyLevel(ConsistencyLevel.Serial);
            var result = _session.Execute(boundStatement);

            Assert.AreEqual(ConsistencyLevel.Quorum, result.Info.AchievedConsistency);

            var selectResult = _session.Execute(_defaultSelectStatement);

            Assert.AreEqual(_defaultPocoList.Count + 1, selectResult.GetRows().ToList().Count);
        }
Beispiel #9
0
        private ITestCluster SetupSessionAndCluster(int nodes, Dictionary <string, string> replication = null)
        {
            ITestCluster testCluster = TestClusterManager.GetTestCluster(nodes);

            _session = testCluster.Session;
            _ksName  = TestUtils.GetUniqueKeyspaceName();
            _session.CreateKeyspace(_ksName, replication);
            TestUtils.WaitForSchemaAgreement(_session.Cluster);
            _session.ChangeKeyspace(_ksName);
            _table = new Table <ManyDataTypesEntity>(_session, new MappingConfiguration());
            _table.Create();
            _defaultPocoList   = ManyDataTypesEntity.GetDefaultAllDataTypesList();
            _preparedStatement = _session.Prepare(_preparedInsertStatementAsString);
            foreach (var manyDataTypesEntity in _defaultPocoList)
            {
                _session.Execute(GetBoundInsertStatementBasedOnEntity(manyDataTypesEntity));
            }

            return(testCluster);
        }
Beispiel #10
0
        public void LinqWhere_BooleanScopes()
        {
            //Get no records
            const bool all = true;

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "SELECT \"BooleanType\", \"DateTimeOffsetType\", \"DateTimeType\", \"DecimalType\", " +
                    "\"DictionaryStringLongType\", \"DictionaryStringStringType\", \"DoubleType\", \"FloatType\", " +
                    "\"GuidType\", \"Int64Type\", \"IntType\", \"ListOfGuidsType\", \"ListOfStringsType\", " +
                    "\"NullableIntType\", \"StringType\" " +
                    $"FROM \"{ManyDataTypesEntity.TableName}\" " +
                    $"WHERE \"BooleanType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(all))
                .ThenRowsSuccess(ManyDataTypesEntity.GetColumnsWithTypes()));
            var rs = _manyDataTypesEntitiesTable.Where(m => m.BooleanType == all).Execute();

            Assert.NotNull(rs);
            Assert.AreEqual(0, rs.Count());

            //get all records
            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "SELECT \"BooleanType\", \"DateTimeOffsetType\", \"DateTimeType\", \"DecimalType\", " +
                    "\"DictionaryStringLongType\", \"DictionaryStringStringType\", \"DoubleType\", \"FloatType\", " +
                    "\"GuidType\", \"Int64Type\", \"IntType\", \"ListOfGuidsType\", \"ListOfStringsType\", " +
                    "\"NullableIntType\", \"StringType\" " +
                    $"FROM \"{ManyDataTypesEntity.TableName}\" " +
                    $"WHERE \"BooleanType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(false))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(_manyDataTypesEntitiesList.First().GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.BooleanType == bool.Parse("false")).Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
        }
Beispiel #11
0
        ///////////////////////////////////////
        ///  Test Helper Methods
        ///////////////////////////////////////

        private void DoBatchInsertTest(ConsistencyLevel expectedConsistencyLevel)
        {
            // Add a few more records via batch statement
            BatchStatement batch = new BatchStatement();

            batch.SetConsistencyLevel(expectedConsistencyLevel);
            var addlPocoList = ManyDataTypesEntity.GetDefaultAllDataTypesList();

            foreach (var manyDataTypesPoco in addlPocoList)
            {
                string          simpleStatementStr = GetSimpleStatementInsertString(manyDataTypesPoco);
                SimpleStatement simpleStatement    = new SimpleStatement(simpleStatementStr);
                batch.Add(simpleStatement);
            }

            // Validate Results
            var result = _session.Execute(batch);

            Assert.AreEqual(expectedConsistencyLevel, result.Info.AchievedConsistency);
            int totalExpectedRecords = _defaultPocoList.Count + addlPocoList.Count;

            result = _session.Execute(_defaultSelectStatement);
            Assert.AreEqual(totalExpectedRecords, result.GetRows().ToList().Count);
        }
Beispiel #12
0
        public void LinqWhere_Boolean()
        {
            var rs = _manyDataTypesEntitiesTable.Execute();

            Assert.NotNull(rs);
            Assert.Greater(rs.Count(), 0);
            //there are no records with BooleanType == true
            rs = _manyDataTypesEntitiesTable.Where(m => m.BooleanType).Execute();
            Assert.NotNull(rs);
            var rows = rs.ToArray();

            Assert.AreEqual(0, rows.Length);
            var guid = Guid.NewGuid();
            var data = new ManyDataTypesEntity
            {
                BooleanType        = true,
                DateTimeOffsetType = DateTimeOffset.Now,
                DateTimeType       = DateTime.Now,
                DecimalType        = 10,
                DoubleType         = 10.0,
                FloatType          = 10.0f,
                GuidType           = guid,
                IntType            = 10,
                StringType         = "Boolean True"
            };

            _manyDataTypesEntitiesTable.Insert(data).Execute();
            rs = _manyDataTypesEntitiesTable.Where(m => m.BooleanType).Execute();
            Assert.NotNull(rs);
            rows = rs.ToArray();
            Assert.AreEqual(1, rows.Length);
            Assert.AreEqual(guid, rows[0].GuidType);
            Assert.AreEqual("Boolean True", rows[0].StringType);
            Assert.IsTrue(rows[0].BooleanType);
            _manyDataTypesEntitiesTable.Select(m => m).Where(m => m.StringType == data.StringType).Delete().Execute();
        }
Beispiel #13
0
        private BoundStatement GetBoundInsertStatementBasedOnEntity(ManyDataTypesEntity entity)
        {
            BoundStatement boundStatement = _preparedStatement.Bind(ConvertEntityToObjectArray(entity));

            return(boundStatement);
        }
Beispiel #14
0
        public void LinqWhere_ShortScopes()
        {
            var cqlSelect =
                "SELECT \"BooleanType\", \"DateTimeOffsetType\", \"DateTimeType\", \"DecimalType\", " +
                "\"DictionaryStringLongType\", \"DictionaryStringStringType\", \"DoubleType\", \"FloatType\", " +
                "\"GuidType\", \"Int64Type\", \"IntType\", \"ListOfGuidsType\", \"ListOfStringsType\", " +
                "\"NullableIntType\", \"StringType\" " +
                $"FROM \"{ManyDataTypesEntity.TableName}\" ";

            var          guid = Guid.NewGuid();
            const string pk   = "Boolean True";
            var          data = new ManyDataTypesEntity
            {
                BooleanType        = true,
                DateTimeOffsetType = DateTimeOffset.Now,
                DateTimeType       = DateTime.Now,
                DecimalType        = 11,
                DoubleType         = 11.0,
                FloatType          = 11.0f,
                GuidType           = guid,
                IntType            = 11,
                Int64Type          = 11,
                StringType         = pk
            };

            //Get poco using constant short
            const short expectedShortValue = 11;

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"IntType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (int)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));

            var rs = _manyDataTypesEntitiesTable
                     .Where(m => m.StringType == pk && m.IntType == expectedShortValue).AllowFiltering().Execute();

            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"IntType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (int)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));

            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.IntType == ExpectedShortValue)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"IntType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (int)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && ExpectedShortValue == m.IntType)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"IntType\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (int)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && expectedShortValue == m.IntType)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"Int64Type\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (long)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.Int64Type == expectedShortValue)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"Int64Type\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (long)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && expectedShortValue == m.Int64Type)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"Int64Type\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (long)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && m.Int64Type == ExpectedShortValue)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    cqlSelect +
                    "WHERE \"StringType\" = ? AND \"Int64Type\" = ? " +
                    "ALLOW FILTERING",
                    p => p.WithParams(pk, (long)expectedShortValue))
                .ThenRowsSuccess(
                    ManyDataTypesEntity.GetColumnsWithTypes(),
                    r => r.WithRow(data.GetColumnValues())));
            rs = _manyDataTypesEntitiesTable.Where(m => m.StringType == pk && ExpectedShortValue == m.Int64Type)
                 .AllowFiltering().Execute();
            Assert.NotNull(rs);
            Assert.AreEqual(1, rs.Count());
        }