Пример #1
0
        public void Prepend_ToArray_QueryUsingCql()
        {
            var(table, expectedEntities) = EntityWithArrayType.GetDefaultTable(Session, _tableName);

            var arrToAdd = new string[]
            {
                "random_" + Randomm.RandomAlphaNum(10),
                "random_" + Randomm.RandomAlphaNum(10),
                "random_" + Randomm.RandomAlphaNum(10),
            };
            var listReversed = arrToAdd.ToList();

            listReversed.Reverse();
            var arrReversed = listReversed.ToArray();

            var singleEntity   = expectedEntities.First();
            var expectedEntity = singleEntity.Clone();
            var strValsAsList  = new List <string>();

            strValsAsList.AddRange(expectedEntity.ArrayType);
            strValsAsList.InsertRange(0, arrReversed);
            expectedEntity.ArrayType = strValsAsList.ToArray();

            // Append the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType {
                ArrayType = CqlOperator.Prepend(arrToAdd)
            })
            .Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ? + ArrayType WHERE Id = ?",
                1,
                arrToAdd, singleEntity.Id);
        }
Пример #2
0
        public void SubtractAssign_FromArray_ValNotInArray()
        {
            var tupleArrayType   = EntityWithArrayType.GetDefaultTable(Session, _tableName);
            var table            = tupleArrayType.Item1;
            var expectedEntities = tupleArrayType.Item2;
            var singleEntity     = expectedEntities.First();

            string[] valsToDelete = { "9999" };

            // make sure this value is not in the array
            Assert.AreEqual(1, singleEntity.ArrayType.Length);
            Assert.AreNotEqual(valsToDelete[0], singleEntity.ArrayType[0]);

            // SubstractAssign the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType
            {
                ArrayType = CqlOperator.SubstractAssign(valsToDelete)
            }).Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType - ? WHERE Id = ?",
                1,
                valsToDelete, singleEntity.Id);
        }
Пример #3
0
        public void Prepend_ToArray()
        {
            var tupleArrayType   = EntityWithArrayType.GetDefaultTable(Session, _tableName);
            var table            = tupleArrayType.Item1;
            var expectedEntities = tupleArrayType.Item2;

            var arrToAdd = new string[]
            {
                "random_" + Randomm.RandomAlphaNum(10),
                "random_" + Randomm.RandomAlphaNum(10),
                "random_" + Randomm.RandomAlphaNum(10),
            };
            var singleEntity = expectedEntities.First();

            // Append the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType {
                ArrayType = CqlOperator.Prepend(arrToAdd)
            })
            .Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ? + ArrayType WHERE Id = ?",
                1,
                arrToAdd, singleEntity.Id);
        }
Пример #4
0
        public void SubtractAssign_FromArray_OneValueOfMany_IndexNonZero()
        {
            var tupleArrayType   = EntityWithArrayType.GetDefaultTable(Session, _tableName);
            var table            = tupleArrayType.Item1;
            var expectedEntities = tupleArrayType.Item2;
            var singleEntity     = expectedEntities.First();
            var tempList         = singleEntity.ArrayType.ToList();

            tempList.AddRange(new[] { "999", "9999", "99999", "999999" });
            singleEntity.ArrayType = tempList.ToArray();

            // Get Value to remove
            var indexToRemove = 2;

            string[] valsToDelete   = { singleEntity.ArrayType[indexToRemove] };
            var      expectedEntity = singleEntity.Clone();

            tempList = expectedEntity.ArrayType.ToList();
            tempList.RemoveAt(indexToRemove);
            expectedEntity.ArrayType = tempList.ToArray();

            // SubstractAssign the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType
            {
                ArrayType = CqlOperator.SubstractAssign(valsToDelete)
            }).Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType - ? WHERE Id = ?",
                1,
                valsToDelete, singleEntity.Id);
        }
Пример #5
0
        public void SubtractAssign_FromArray_Duplicates()
        {
            var tupleArrayType   = EntityWithArrayType.GetDefaultTable(Session, _tableName);
            var table            = tupleArrayType.Item1;
            var expectedEntities = tupleArrayType.Item2;
            var singleEntity     = expectedEntities.First();

            Assert.AreEqual(1, singleEntity.ArrayType.Length); // make sure there's only one value in the list
            var indexToRemove = 0;

            singleEntity.ArrayType.ToList().AddRange(new[] { singleEntity.ArrayType[indexToRemove], singleEntity.ArrayType[indexToRemove], singleEntity.ArrayType[indexToRemove] });

            // Get single value to remove
            var valsToDelete   = new[] { singleEntity.ArrayType[indexToRemove] };
            var expectedEntity = singleEntity.Clone();

            expectedEntity.ArrayType = new string[] { };

            // SubstractAssign the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType
            {
                ArrayType = CqlOperator.SubstractAssign(valsToDelete)
            }).Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType - ? WHERE Id = ?",
                1,
                valsToDelete, singleEntity.Id);
        }
Пример #6
0
        public void Append_ToArray_AppendEmptyArray_QueryUsingCql()
        {
            var(table, expectedEntities) = EntityWithArrayType.GetDefaultTable(Session, _tableName);

            var arrToAdd       = new string[] { };
            var singleEntity   = expectedEntities.First();
            var expectedEntity = singleEntity.Clone();
            var strValsAsList  = new List <string>();

            strValsAsList.AddRange(expectedEntity.ArrayType);
            strValsAsList.AddRange(arrToAdd);
            expectedEntity.ArrayType = strValsAsList.ToArray();

            // Append the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType {
                ArrayType = CqlOperator.Append(arrToAdd)
            })
            .Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType + ? WHERE Id = ?",
                1,
                arrToAdd, singleEntity.Id);
        }
Пример #7
0
        public void SubtractAssign_FromArray_EmptyArray()
        {
            var tupleArrayType   = EntityWithArrayType.GetDefaultTable(Session, _tableName);
            var table            = tupleArrayType.Item1;
            var expectedEntities = tupleArrayType.Item2;
            var singleEntity     = expectedEntities.First();

            string[] valsToDelete = { };

            // SubstractAssign the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType
            {
                ArrayType = CqlOperator.SubstractAssign(valsToDelete)
            }).Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType - ? WHERE Id = ?",
                1,
                valsToDelete, singleEntity.Id);
        }
Пример #8
0
        public void SubtractAssign_FromArray_AllValues_QueryUsingCql()
        {
            var(table, expectedEntities) = EntityWithArrayType.GetDefaultTable(Session, _tableName);

            var singleEntity   = expectedEntities.First();
            var expectedEntity = singleEntity.Clone();

            expectedEntity.ArrayType = new string[] { };

            // SubstractAssign the values
            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithArrayType
            {
                ArrayType = CqlOperator.SubstractAssign(singleEntity.ArrayType)
            }).Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType - ? WHERE Id = ?",
                1,
                singleEntity.ArrayType, singleEntity.Id);
        }