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_FromList_Duplicates()
        {
            var tupleListType = EntityWithListType.SetupDefaultTable(Session);
            var table = tupleListType.Item1;
            var expectedEntities = tupleListType.Item2;
            var singleEntity = expectedEntities.First();
            Assert.AreEqual(1, singleEntity.ListType.Count); 
            var indexToRemove = 0;
            singleEntity.ListType.AddRange(new[] { singleEntity.ListType[indexToRemove], singleEntity.ListType[indexToRemove], singleEntity.ListType[indexToRemove] });
            table.Insert(singleEntity).Execute();
            var entityListPreTest = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();
            Assert.AreEqual(singleEntity.ListType.Count, entityListPreTest[0].ListType.Count);
            singleEntity.AssertEquals(entityListPreTest[0]);
            var valsToDelete = new List<int>() { singleEntity.ListType[indexToRemove] };
            var expectedEntity = singleEntity.Clone();
            expectedEntity.ListType.Clear();
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithListType { ListType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute();
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();
            Assert.AreEqual(1, entityList.Count);
            Assert.AreNotEqual(expectedEntity.ListType, singleEntity.ListType);
            expectedEntity.AssertEquals(entityList[0]);
        }
[ Test ] public void SubtractAssign_FromList_Duplicates ( ) { var tupleListType = EntityWithListType . SetupDefaultTable ( Session ) ; var table = tupleListType . Item1 ; var expectedEntities = tupleListType . Item2 ; var singleEntity = expectedEntities . First ( ) ; Assert . AreEqual ( 1 , singleEntity . ListType . Count ) ; var indexToRemove = 0 ; singleEntity . ListType . AddRange ( new [ ] { singleEntity . ListType [ indexToRemove ] , singleEntity . ListType [ indexToRemove ] , singleEntity . ListType [ indexToRemove ] } ) ; table . Insert ( singleEntity ) . Execute ( ) ; var entityListPreTest = table . Where ( m => m . Id == singleEntity . Id ) . ExecuteAsync ( ) . Result . ToList ( ) ; Assert . AreEqual ( singleEntity . ListType . Count , entityListPreTest [ 0 ] . ListType . Count ) ; singleEntity . AssertEquals ( entityListPreTest [ 0 ] ) ; var valsToDelete = new List < int > ( ) { singleEntity . ListType [ indexToRemove ] } ; var expectedEntity = singleEntity . Clone ( ) ; expectedEntity . ListType . Clear ( ) ; table . Where ( t => t . Id == singleEntity . Id ) . Select ( t => new EntityWithListType { ListType = CqlOperator . SubstractAssign ( valsToDelete ) } ) . Update ( ) . Execute ( ) ; var entityList = table . Where ( m => m . Id == singleEntity . Id ) . ExecuteAsync ( ) . Result . ToList ( ) ; Assert . AreEqual ( 1 , entityList . Count ) ; Assert . AreNotEqual ( expectedEntity . ListType , singleEntity . ListType ) ; expectedEntity . AssertEquals ( entityList [ 0 ] ) ; }
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