src/Cassandra.IntegrationTests/Linq/CqlOperatorTests/SubstractAssign.cs
/// <summary>
/// Use SubtractAssign to remove all values from a list since they are all the same value
/// </summary>
Use SubtractAssign to remove all values from a list since they are all the same value
Use SubtractAssign to remove all values from a list since they are all the same value
[Test]
        public void SubtractAssign_FromArray_Duplicates()
        {
            var tupleArrayType = EntityWithArrayType.SetupDefaultTable(Session);
            var table = tupleArrayType.Item1;
            var expectedEntities = tupleArrayType.Item2;
            var singleEntity = expectedEntities.First();
            Assert.AreEqual(1, singleEntity.ArrayType.Length); 
            var indexToRemove = 0;
            singleEntity.ArrayType.ToList().AddRange(new[] { singleEntity.ArrayType[indexToRemove], singleEntity.ArrayType[indexToRemove], singleEntity.ArrayType[indexToRemove] });
            table.Insert(singleEntity).Execute();
            var rows = Session.Execute($"SELECT * from {table.Name} where id=\'{singleEntity.Id}\'").GetRows().ToList();
            Assert.AreEqual(1, rows.Count);
            var actualArr = rows[0].GetValue<string[]>("arraytype");
            Assert.AreEqual(singleEntity.ArrayType, actualArr);
            var valsToDelete = new [] { singleEntity.ArrayType[indexToRemove] };
            var expectedEntity = singleEntity.Clone();
            expectedEntity.ArrayType = new string[] {};
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute();
            rows = Session.Execute($"SELECT * from {table.Name} where id=\'{expectedEntity.Id}\'").GetRows().ToList();
            Assert.AreEqual(1, rows.Count);
            var probablyNullArr = rows[0].GetValue<object>("arraytype");
            Assert.AreEqual(null, probablyNullArr);
        }
[ Test ] public void SubtractAssign_FromArray_Duplicates ( ) { var tupleArrayType = EntityWithArrayType . SetupDefaultTable ( Session ) ; var table = tupleArrayType . Item1 ; var expectedEntities = tupleArrayType . Item2 ; var singleEntity = expectedEntities . First ( ) ; Assert . AreEqual ( 1 , singleEntity . ArrayType . Length ) ; var indexToRemove = 0 ; singleEntity . ArrayType . ToList ( ) . AddRange ( new [ ] { singleEntity . ArrayType [ indexToRemove ] , singleEntity . ArrayType [ indexToRemove ] , singleEntity . ArrayType [ indexToRemove ] } ) ; table . Insert ( singleEntity ) . Execute ( ) ; var rows = Session . Execute ( $" SELECT * from  { table . Name }  where id= \' { singleEntity . Id } \' " ) . GetRows ( ) . ToList ( ) ; Assert . AreEqual ( 1 , rows . Count ) ; var actualArr = rows [ 0 ] . GetValue < string [ ] > ( " " ) ; Assert . AreEqual ( singleEntity . ArrayType , actualArr ) ; var valsToDelete = new [ ] { singleEntity . ArrayType [ indexToRemove ] } ; var expectedEntity = singleEntity . Clone ( ) ; expectedEntity . ArrayType = new string [ ] { } ; table . Where ( t => t . Id == singleEntity . Id ) . Select ( t => new EntityWithArrayType { ArrayType = CqlOperator . SubstractAssign ( valsToDelete ) } ) . Update ( ) . Execute ( ) ; rows = Session . Execute ( $" SELECT * from  { table . Name }  where id= \' { expectedEntity . Id } \' " ) . GetRows ( ) . ToList ( ) ; Assert . AreEqual ( 1 , rows . Count ) ; var probablyNullArr = rows [ 0 ] . GetValue < object > ( " " ) ; Assert . AreEqual ( null , probablyNullArr ) ; }
Use SubtractAssign to remove all values from a list since they are all the same value
Use SubtractAssign to remove all values from a list since they are all the same value
// make sure there's only one value in the list // Overwrite one of the rows, validate the data got there // Get single value to remove // SubstractAssign the values // Validate final state of the data