src/Cassandra.IntegrationTests/Linq/CqlOperatorTests/SubstractAssign.cs
/// <summary>
/// Use SubtractAssign to remove a single value from the middle of the list, then validate that the expected data remains in Cassandra
/// </summary>
Use SubtractAssign to remove a single value from the middle of the list, then validate that the expected data remains in Cassandra
Use SubtractAssign to remove a single value from the middle of the list then validate that the expected data remains in Cassandra
[Test]
        public void SubtractAssign_FromArray_OneValueOfMany_IndexNonZero()
        {
            var tupleArrayType = EntityWithArrayType.SetupDefaultTable(Session);
            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();
            table.Insert(singleEntity).Execute();
            var indexToRemove = 2;
            string[] valsToDelete = { singleEntity.ArrayType[indexToRemove] };
            var expectedEntity = singleEntity.Clone();
            tempList = expectedEntity.ArrayType.ToList();
            tempList.RemoveAt(indexToRemove);
            expectedEntity.ArrayType = tempList.ToArray();
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute();
            var rows = Session.Execute($"SELECT * from {table.Name} where id=\'{expectedEntity.Id}\'").GetRows().ToList();
            Assert.AreEqual(1, rows.Count);
            Assert.AreNotEqual(expectedEntity.ArrayType, singleEntity.ArrayType);
            Assert.AreEqual(expectedEntity.ArrayType, rows[0].GetValue<string[]>("arraytype"));
        }
[ Test ] public void SubtractAssign_FromArray_OneValueOfMany_IndexNonZero ( ) { var tupleArrayType = EntityWithArrayType . SetupDefaultTable ( Session ) ; var table = tupleArrayType . Item1 ; var expectedEntities = tupleArrayType . Item2 ; var singleEntity = expectedEntities . First ( ) ; var tempList = singleEntity . ArrayType . ToList ( ) ; tempList . AddRange ( new [ ] { " " , " " , " " , " " } ) ; singleEntity . ArrayType = tempList . ToArray ( ) ; table . Insert ( singleEntity ) . Execute ( ) ; var indexToRemove = 2 ; string [ ] valsToDelete = { singleEntity . ArrayType [ indexToRemove ] } ; var expectedEntity = singleEntity . Clone ( ) ; tempList = expectedEntity . ArrayType . ToList ( ) ; tempList . RemoveAt ( indexToRemove ) ; expectedEntity . ArrayType = tempList . ToArray ( ) ; table . Where ( t => t . Id == singleEntity . Id ) . Select ( t => new EntityWithArrayType { ArrayType = CqlOperator . SubstractAssign ( valsToDelete ) } ) . Update ( ) . Execute ( ) ; var rows = Session . Execute ( $" SELECT * from  { table . Name }  where id= \' { expectedEntity . Id } \' " ) . GetRows ( ) . ToList ( ) ; Assert . AreEqual ( 1 , rows . Count ) ; Assert . AreNotEqual ( expectedEntity . ArrayType , singleEntity . ArrayType ) ; Assert . AreEqual ( expectedEntity . ArrayType , rows [ 0 ] . GetValue < string [ ] > ( " " ) ) ; }
Use SubtractAssign to remove a single value from the middle of the list, then validate that the expected data remains in Cassandra
Use SubtractAssign to remove a single value from the middle of the list then validate that the expected data remains in Cassandra
// Overwrite one of the rows // Get Value to remove // SubstractAssign the values // Validate final state of the data