Beispiel #1
0
        public void LinqTable_GetTable_RegularStatement()
        {
            var table = Session.GetTable <AllDataTypesEntity>();
            var expectedDataTypesEntityRow = AllDataTypesEntity.GetRandomInstance();
            var uniqueKey = expectedDataTypesEntityRow.StringType;

            // insert record
            table.GetSession().Execute(table.Insert(expectedDataTypesEntityRow));

            VerifyStatement(QueryType.Query, GetTable.InsertCql, 1, expectedDataTypesEntityRow.GetColumnValues());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(GetTable.SelectCql, p => p.WithParam(uniqueKey))
                .ThenRowsSuccess(expectedDataTypesEntityRow.CreateRowsResult()));

            // select record
            var listOfAllDataTypesObjects =
                (from x in table where x.StringType.Equals(uniqueKey) select x).Execute().ToList();

            Assert.NotNull(listOfAllDataTypesObjects);
            Assert.AreEqual(1, listOfAllDataTypesObjects.Count);
            var actualDataTypesEntityRow = listOfAllDataTypesObjects.First();

            expectedDataTypesEntityRow.AssertEquals(actualDataTypesEntityRow);
        }
Beispiel #2
0
        public void LinqWhere_Recovers_From_Invalid_Query_Exception()
        {
            var table = new Table <Song>(Session, new MappingConfiguration().Define(
                                             new Map <Song>().TableName("tbl_recovers_invalid_test").PartitionKey(x => x.Title)));

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "SELECT Artist, Id, ReleaseDate, Title FROM tbl_recovers_invalid_test" +
                    " WHERE Title = ?",
                    p => p.WithParams("Do I Wanna Know"))
                .ThenServerError(ServerError.Invalid, "msg"));

            Assert.Throws <InvalidQueryException>(() => table.Where(x => x.Title == "Do I Wanna Know").Execute());

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "SELECT Artist, Id, ReleaseDate, Title FROM tbl_recovers_invalid_test" +
                    " WHERE Title = ?",
                    p => p.WithParams("Do I Wanna Know"))
                .ThenRowsSuccess(
                    ("Artist", DataType.GetDataType(typeof(string))),
                    ("Id", DataType.GetDataType(typeof(Guid))),
                    ("ReleaseDate", DataType.GetDataType(typeof(DateTimeOffset))),
                    ("Title", DataType.GetDataType(typeof(string)))));

            Assert.AreEqual(0, table.Where(x => x.Title == "Do I Wanna Know").Execute().Count());
        }
Beispiel #3
0
        public void Delete_DeleteOneEquals(bool async)
        {
            var table = new Table <AllDataTypesEntity>(Session, new MappingConfiguration());

            AllDataTypesEntity.PrimeCountQuery(TestCluster, _entityList.Count);
            var count = table.Count().Execute();

            Assert.AreEqual(_entityList.Count, count);

            AllDataTypesEntity entityToDelete = _entityList[0];

            var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
            var deleteQuery = selectQuery.Delete();

            if (async)
            {
                deleteQuery.ExecuteAsync().GetAwaiter().GetResult();
            }
            else
            {
                deleteQuery.Execute();
            }

            VerifyBoundStatement(
                $"DELETE FROM \"{AllDataTypesEntity.TableName}\" WHERE \"string_type\" = ?", 1, entityToDelete.StringType);

            TestCluster.PrimeDelete();
            AllDataTypesEntity.PrimeCountQuery(TestCluster, _entityList.Count - 1);

            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count - 1, count);
            TestCluster.PrimeFluent(b => entityToDelete.When(TestCluster, b).ThenVoidSuccess());
            Assert.AreEqual(0, selectQuery.Execute().ToList().Count);
        }
Beispiel #4
0
        public void LinqWhere_TupleWithCompositeKeys_Scopes()
        {
            var tableName = TestUtils.GetUniqueTableName();
            var map       = new Map <TestTable>()
                            .ExplicitColumns()
                            .Column(t => t.UserId, cm => cm.WithName("id"))
                            .Column(t => t.Date, cm => cm.WithName("date"))
                            .Column(t => t.TimeColumn, cm => cm.WithName("time"))
                            .PartitionKey(t => t.UserId)
                            .ClusteringKey(t => t.Date)
                            .ClusteringKey(t => t.TimeColumn)
                            .TableName(tableName);

            var table   = new Table <TestTable>(Session, new MappingConfiguration().Define(map));
            var anomObj = new
            {
                list = new List <Tuple <int, long> > {
                    Tuple.Create(0, 0L), Tuple.Create(1, 1L), Tuple.Create(0, 2L)
                }
            };

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND (date, time) IN ?",
                    rows => rows.WithParams(1, anomObj.list))
                .ThenRowsSuccess(new[] { "date", "id", "time" }, rows => rows.WithRow(1, 1, 1L)));

            var listInsideObjResults = table.Where(t => t.UserId == 1 && anomObj.list.Contains(Tuple.Create(t.Date, t.TimeColumn))).Execute();

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

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND (date, time) IN ?",
                    rows => rows.WithParams(1, _tupleList))
                .ThenRowsSuccess(new[] { "date", "id", "time" }, rows => rows.WithRow(1, 1, 1L)));

            var listOuterScopeResults = table.Where(t => t.UserId == 1 && _tupleList.Contains(Tuple.Create(t.Date, t.TimeColumn))).Execute();

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

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND (date, time) IN ?",
                    rows => rows.WithParams(1, TupleList))
                .ThenRowsSuccess(new[] { "date", "id", "time" }, rows => rows.WithRow(1, 1, 1L)));

            var listOuterStaticScopeResults = table.Where(t => t.UserId == 1 && TupleList.Contains(Tuple.Create(t.Date, t.TimeColumn))).Execute();

            Assert.NotNull(listOuterStaticScopeResults);
            Assert.AreEqual(1, listOuterStaticScopeResults.Count());
        }
Beispiel #5
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 #6
0
 private void PrimeLinqCounterQuery(CounterEntityWithLinqAttributes counter)
 {
     TestCluster.PrimeDelete();
     TestCluster.PrimeFluent(
         b => b.WhenQuery(
             "SELECT \"Counter\", \"KeyPart1\", \"KeyPart2\" " +
             "FROM \"CounterEntityWithLinqAttributes\" " +
             "WHERE \"KeyPart1\" = ? AND \"KeyPart2\" = ?",
             when => counter.WithParams(when, "KeyPart1", "KeyPart2"))
         .ThenRowsSuccess(counter.CreateRowsResult()));
 }
Beispiel #7
0
        private void PrimeLinqCounterRangeQuery(
            IEnumerable <CounterEntityWithLinqAttributes> counters,
            string tableName   = "CounterEntityWithLinqAttributes",
            bool caseSensitive = true)
        {
            var cql = caseSensitive
                ? $"SELECT \"Counter\", \"KeyPart1\", \"KeyPart2\" FROM \"{tableName}\""
                : $"SELECT Counter, KeyPart1, KeyPart2 FROM {tableName}";

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(b => b.WhenQuery(cql).ThenRowsSuccess(AddRows(counters)));
        }
Beispiel #8
0
        ///////////////////////////////////////////////
        // Test Helpers
        //////////////////////////////////////////////

        // AllDataTypes

        private void WriteReadValidateUsingTableMethods(Table <AllDataTypesEntity> table)
        {
            TestCluster.PrimeDelete();
            var ksAndTable =
                table.KeyspaceName == null
                    ? $"\"{table.Name}\""
                    : $"\"{table.KeyspaceName}\".\"{table.Name}\"";

            var expectedDataTypesEntityRow = AllDataTypesEntity.GetRandomInstance();
            var uniqueKey = expectedDataTypesEntityRow.StringType;

            // insert record
            Session.Execute(table.Insert(expectedDataTypesEntityRow));

            VerifyStatement(
                QueryType.Query,
                string.Format(
                    AllDataTypesEntity.InsertCqlDefaultColumnsFormatStr,
                    ksAndTable),
                1,
                expectedDataTypesEntityRow.GetColumnValuesForDefaultColumns());

            // select record

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    string.Format(AllDataTypesEntity.SelectCqlDefaultColumnsFormatStr, ksAndTable),
                    p => p.WithParam(uniqueKey))
                .ThenRowsSuccess(
                    AllDataTypesEntity.GetDefaultColumns(),
                    r => r.WithRow(expectedDataTypesEntityRow.GetColumnValuesForDefaultColumns())));


            var listOfAllDataTypesObjects =
                (from x in table where x.StringType.Equals(uniqueKey) select x)
                .Execute().ToList();

            Assert.NotNull(listOfAllDataTypesObjects);
            Assert.AreEqual(1, listOfAllDataTypesObjects.Count);
            var actualDataTypesEntityRow = listOfAllDataTypesObjects.First();

            expectedDataTypesEntityRow.AssertEquals(actualDataTypesEntityRow);
        }
Beispiel #9
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 #10
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());
        }
Beispiel #11
0
        public void LinqWhere_TupleWithCompositeKeys()
        {
            var tableName = TestUtils.GetUniqueTableName();
            var map       = new Map <TestTable>()
                            .ExplicitColumns()
                            .Column(t => t.UserId, cm => cm.WithName("id"))
                            .Column(t => t.Date, cm => cm.WithName("date"))
                            .Column(t => t.TimeColumn, cm => cm.WithName("time"))
                            .PartitionKey(t => t.UserId)
                            .ClusteringKey(t => t.Date)
                            .ClusteringKey(t => t.TimeColumn)
                            .TableName(tableName);

            var table     = new Table <TestTable>(Session, new MappingConfiguration().Define(map));
            var localList = new List <Tuple <int, long> > {
                Tuple.Create(0, 0L), Tuple.Create(0, 2L)
            };

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND (date, time) IN ?",
                    rows => rows.WithParams(1, localList))
                .ThenRowsSuccess(
                    ("date", DataType.GetDataType(typeof(int))),
                    ("id", DataType.GetDataType(typeof(int))),
                    ("time", DataType.GetDataType(typeof(long)))));

            var emptyResults = table.Where(t => t.UserId == 1 && localList.Contains(Tuple.Create(t.Date, t.TimeColumn))).Execute();

            Assert.NotNull(emptyResults);
            Assert.AreEqual(0, emptyResults.ToArray().Length);

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND (date, time) IN ?",
                    rows => rows.WithParams(1, new List <Tuple <int, long> >()))
                .ThenRowsSuccess(
                    ("date", DataType.GetDataType(typeof(int))),
                    ("id", DataType.GetDataType(typeof(int))),
                    ("time", DataType.GetDataType(typeof(long)))));

            emptyResults = table.Where(t => t.UserId == 1 && new List <Tuple <int, long> >().Contains(Tuple.Create(t.Date, t.TimeColumn))).Execute();
            Assert.NotNull(emptyResults);
            Assert.AreEqual(0, emptyResults.ToArray().Length);

            localList.Add(Tuple.Create(1, 1L)); //adding to list existent tuple

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND (date, time) IN ?",
                    rows => rows.WithParams(1, localList))
                .ThenRowsSuccess(new[] { "date", "id", "time" }, rows => rows.WithRow(1, 1, 1L)));

            var tCreateResults = table.Where(t => t.UserId == 1 && localList.Contains(Tuple.Create(t.Date, t.TimeColumn))).Execute();

            Assert.NotNull(tCreateResults);
            var tCreateResultsArr = tCreateResults.ToArray();

            Assert.AreEqual(1, tCreateResultsArr.Length);
            var tCreateResultObj = tCreateResultsArr[0];

            Assert.AreEqual(1, tCreateResultObj.UserId);
            Assert.AreEqual(1, tCreateResultObj.Date);
            Assert.AreEqual(1, tCreateResultObj.UserId);
        }
Beispiel #12
0
        public void LinqWhere_TupleWithClusteringKeys()
        {
            var tableName = TestUtils.GetUniqueTableName();
            var map       = new Map <TestTable>()
                            .ExplicitColumns()
                            .Column(t => t.UserId, cm => cm.WithName("id"))
                            .Column(t => t.Date, cm => cm.WithName("date"))
                            .Column(t => t.TimeColumn, cm => cm.WithName("time"))
                            .PartitionKey(t => t.UserId)
                            .ClusteringKey(t => t.Date)
                            .TableName(tableName);

            var table = new Table <TestTable>(Session, new MappingConfiguration().Define(map));
            var data  = new TestTable
            {
                UserId     = 1,
                Date       = 1,
                TimeColumn = 1
            };
            var localList = new List <int> {
                0, 2
            };

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND date IN ?",
                    rows => rows.WithParams(1, localList))
                .ThenRowsSuccess(
                    ("date", DataType.GetDataType(typeof(int))),
                    ("id", DataType.GetDataType(typeof(int))),
                    ("time", DataType.GetDataType(typeof(long)))));

            var emptyResults = table.Where(t => t.UserId == 1 && localList.Contains(t.Date)).Execute();

            Assert.NotNull(emptyResults);
            Assert.AreEqual(0, emptyResults.ToArray().Length);

            localList.Add(1); //adding to list existent tuple

            TestCluster.PrimeDelete();
            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT date, id, time FROM {tableName} " +
                    "WHERE id = ? AND date IN ?",
                    rows => rows.WithParams(1, localList))
                .ThenRowsSuccess(
                    new [] { "date", "id", "time" },
                    rows => rows.WithRow(data.Date, data.UserId, data.TimeColumn)));

            var tCreateResults = table.Where(t => t.UserId == 1 && localList.Contains(t.Date)).Execute();

            Assert.NotNull(tCreateResults);
            var tCreateResultsArr = tCreateResults.ToArray();

            Assert.AreEqual(1, tCreateResultsArr.Length);
            var tCreateResultObj = tCreateResultsArr[0];

            Assert.AreEqual(1, tCreateResultObj.UserId);
            Assert.AreEqual(1, tCreateResultObj.Date);
            Assert.AreEqual(1, tCreateResultObj.UserId);

            //invalid case: string.Contains
            Assert.Throws <InvalidOperationException>(() =>
                                                      table.Where(t => t.UserId == 1 && "error".Contains($"{t.Date}")).Execute());
        }