src/Cassandra.IntegrationTests/Linq/LinqMethods/Update.cs
/// <summary>
/// Successfully update multiple records using a Batch update
/// </summary>
Successfully update multiple records using a Batch update
Successfully update multiple records using a Batch update
[Test, TestCassandraVersion(2, 0)]
        public void LinqUpdate_Batch()
        {
            var table = new Table<Movie>(_session, new MappingConfiguration());
            table.CreateIfNotExists();
            var movieToUpdate1 = _movieList[1];
            var movieToUpdate2 = _movieList[2];
            var batch = new BatchStatement();
            var expectedMovie1 = new Movie(movieToUpdate1.Title, movieToUpdate1.Director, "something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate1.MovieMaker, 1212);
            var update1 = table.Where(m => m.Title == movieToUpdate1.Title && m.MovieMaker == movieToUpdate1.MovieMaker && m.Director == movieToUpdate1.Director)
                 .Select(m => new Movie { Year = expectedMovie1.Year, MainActor = expectedMovie1.MainActor })
                 .Update();
            batch.Add(update1);
            var expectedMovie2 = new Movie(movieToUpdate2.Title, movieToUpdate2.Director, "also_something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate2.MovieMaker, 1212);
            var update2 = table.Where(m => m.Title == movieToUpdate2.Title && m.MovieMaker == movieToUpdate2.MovieMaker && m.Director == movieToUpdate2.Director)
                 .Select(m => new Movie { Year = expectedMovie2.Year, MainActor = expectedMovie2.MainActor })
                 .Update();
            batch.Add(update2);
            table.GetSession().Execute(batch);
            var actualMovieList = table.Execute().ToList();
            Assert.AreEqual(_movieList.Count, actualMovieList.Count());
            Assert.AreNotEqual(expectedMovie1.MainActor, expectedMovie2.MainActor);
            Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie1));
            Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie2));
            Movie.AssertListContains(actualMovieList, expectedMovie1);
            Movie.AssertListContains(actualMovieList, expectedMovie2);
        }
[ Test , TestCassandraVersion ( 2 , 0 ) ] public void LinqUpdate_Batch ( ) { var table = new Table < Movie > ( _session , new MappingConfiguration ( ) ) ; table . CreateIfNotExists ( ) ; var movieToUpdate1 = _movieList [ 1 ] ; var movieToUpdate2 = _movieList [ 2 ] ; var batch = new BatchStatement ( ) ; var expectedMovie1 = new Movie ( movieToUpdate1 . Title , movieToUpdate1 . Director , " " + Randomm . RandomAlphaNum ( 10 ) , movieToUpdate1 . MovieMaker , 1212 ) ; var update1 = table . Where ( m => m . Title == movieToUpdate1 . Title && m . MovieMaker == movieToUpdate1 . MovieMaker && m . Director == movieToUpdate1 . Director ) . Select ( m => new Movie { Year = expectedMovie1 . Year , MainActor = expectedMovie1 . MainActor } ) . Update ( ) ; batch . Add ( update1 ) ; var expectedMovie2 = new Movie ( movieToUpdate2 . Title , movieToUpdate2 . Director , " " + Randomm . RandomAlphaNum ( 10 ) , movieToUpdate2 . MovieMaker , 1212 ) ; var update2 = table . Where ( m => m . Title == movieToUpdate2 . Title && m . MovieMaker == movieToUpdate2 . MovieMaker && m . Director == movieToUpdate2 . Director ) . Select ( m => new Movie { Year = expectedMovie2 . Year , MainActor = expectedMovie2 . MainActor } ) . Update ( ) ; batch . Add ( update2 ) ; table . GetSession ( ) . Execute ( batch ) ; var actualMovieList = table . Execute ( ) . ToList ( ) ; Assert . AreEqual ( _movieList . Count , actualMovieList . Count ( ) ) ; Assert . AreNotEqual ( expectedMovie1 . MainActor , expectedMovie2 . MainActor ) ; Assert . IsFalse ( Movie . ListContains ( _movieList , expectedMovie1 ) ) ; Assert . IsFalse ( Movie . ListContains ( _movieList , expectedMovie2 ) ) ; Movie . AssertListContains ( actualMovieList , expectedMovie1 ) ; Movie . AssertListContains ( actualMovieList , expectedMovie2 ) ; }
Successfully update multiple records using a Batch update
Successfully update multiple records using a Batch update
// Setup