예제 #1
0
 public static void AssertEquals(Movie expectedMovie, Movie actualMovie)
 {
     Assert.AreEqual(expectedMovie.MainActor, actualMovie.MainActor);
     Assert.AreEqual(expectedMovie.MovieMaker, actualMovie.MovieMaker);
     Assert.AreEqual(expectedMovie.Title, actualMovie.Title);
     Assert.AreEqual(expectedMovie.ExampleSet, actualMovie.ExampleSet);
     Assert.AreEqual(expectedMovie.Director, actualMovie.Director);
     Assert.AreEqual(expectedMovie.Year, actualMovie.Year);
 }
예제 #2
0
        public void LinqTable_UpdateIf_AppliedInfo_Test()
        {
            _movieTable.CreateIfNotExists();
            var movie = new Movie()
            {
                Title = "Dead Poets Society",
                Year = 1989,
                MainActor = "Robin Williams",
                Director = "Peter Weir",
                MovieMaker = "Touchstone"
            };
            _movieTable.Insert(movie).SetConsistencyLevel(ConsistencyLevel.Quorum).Execute();

            var retrievedMovie = _movieTable
                .FirstOrDefault(m => m.Title == "Dead Poets Society" && m.MovieMaker == "Touchstone")
                .Execute();
            Movie.AssertEquals(movie, retrievedMovie);
            Assert.NotNull(retrievedMovie);
            Assert.AreEqual(1989, retrievedMovie.Year);
            Assert.AreEqual("Robin Williams", retrievedMovie.MainActor);

            var appliedInfo = _movieTable
                .Where(m => m.Title == "Dead Poets Society" && m.MovieMaker == "Touchstone" && m.Director == "Peter Weir")
                .Select(m => new Movie { MainActor = "Robin McLaurin Williams" })
                .UpdateIf(m => m.Year == 1989)
                .Execute();
            Assert.True(appliedInfo.Applied);
            Assert.Null(appliedInfo.Existing);

            retrievedMovie = _movieTable
                .FirstOrDefault(m => m.Title == "Dead Poets Society" && m.MovieMaker == "Touchstone")
                .Execute();
            Assert.NotNull(retrievedMovie);
            Assert.AreEqual(1989, retrievedMovie.Year);
            Assert.AreEqual("Robin McLaurin Williams", retrievedMovie.MainActor);

            //Should not update as the if clause is not satisfied
            var updateIf = _movieTable
                .Where(m => m.Title == "Dead Poets Society" && m.MovieMaker == "Touchstone" && m.Director == "Peter Weir")
                .Select(m => new Movie { MainActor = "WHOEVER" })
                .UpdateIf(m => m.Year == 1500);
            string updateIfToStr = updateIf.ToString();
            Console.WriteLine(updateIfToStr);

            appliedInfo = updateIf.Execute();
            Assert.False(appliedInfo.Applied);
            Assert.AreEqual(1989, appliedInfo.Existing.Year);
            retrievedMovie = _movieTable
                .FirstOrDefault(m => m.Title == "Dead Poets Society" && m.MovieMaker == "Touchstone")
                .Execute();
            Assert.NotNull(retrievedMovie);
            Assert.AreEqual("Robin McLaurin Williams", retrievedMovie.MainActor);
        }
예제 #3
0
 public static bool ListContains(List<Movie> expectedMovies, Movie actualMovie)
 {
     foreach (var expectedMovie in expectedMovies)
     {
         try
         {
             AssertEquals(actualMovie, expectedMovie);
             return true;
         }
         catch (AssertionException) { }
     }
     return false;
 }
예제 #4
0
        public void Update_Single_ToDifferentValues()
        {
            // Setup
            Movie movieToUpdate = _movieList[1];

            // Update to different values
            var expectedMovie = new Movie(movieToUpdate.Title + "_something_different", movieToUpdate.Director, movieToUpdate.MainActor + "_something_different", movieToUpdate.MovieMaker, 1212, MovieRating.C);
            _mapper.Update(expectedMovie);

            List<Movie> actualMovieList = _movieTable.Execute().ToList();
            Assert.AreEqual(_movieList.Count, actualMovieList.Count());
            Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie));
            Movie.AssertListContains(actualMovieList, expectedMovie);
            Assert.IsFalse(Movie.ListContains(actualMovieList, movieToUpdate));
        }
예제 #5
0
        public void LinqUpdate_Single_Async()
        {
            // Setup
            Table<Movie> table = new Table<Movie>(_session, new MappingConfiguration());
            table.CreateIfNotExists();
            Movie movieToUpdate = _movieList[1];

            var expectedMovie = new Movie(movieToUpdate.Title, movieToUpdate.Director, "something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate.MovieMaker, 1212);
            table.Where(m => m.Title == movieToUpdate.Title && m.MovieMaker == movieToUpdate.MovieMaker && m.Director == movieToUpdate.Director)
                 .Select(m => new Movie { Year = expectedMovie.Year, MainActor = expectedMovie.MainActor })
                 .Update()
                 .Execute();

            List<Movie> actualMovieList = table.ExecuteAsync().Result.ToList();
            Assert.AreEqual(_movieList.Count, actualMovieList.Count());
            Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie));
            Movie.AssertListContains(actualMovieList, expectedMovie);
        }
예제 #6
0
 public void LinqInsert_MissingPartitionKey_Sync_Test()
 {
     var table = new Table<Movie>(_session, new MappingConfiguration());
     Movie objectMissingPartitionKey = new Movie() {MainActor = "doesntmatter"};
     string expectedErrMsg = "Invalid null value in condition for column unique_movie_title";
     try
     {
         table.Insert(objectMissingPartitionKey).Execute();
     }
     catch (InvalidQueryException e)
     {
         Console.WriteLine(e.Message);
         Assert.IsTrue(e.Message.Contains(expectedErrMsg));
     }
 }
예제 #7
0
 public void LinqInsert_MissingPartitionKey_Async_Test()
 {
     var table = new Table<Movie>(_session, new MappingConfiguration());
     Movie objectMissingPartitionKey = new Movie() {MainActor = "doesntmatter"};
     string expectedErrMsg = "Invalid null value in condition for column unique_movie_title";
     try
     {
         table.Insert(objectMissingPartitionKey).ExecuteAsync().Wait();
     }
     catch (Exception e) // Exception is gathered from the async task
     {
         int maxLayers = 50;
         int layersChecked = 0;
         while (layersChecked < maxLayers && !e.InnerException.Message.Contains(expectedErrMsg))
         {
             layersChecked++;
             e = e.InnerException;
         }
         Assert.AreEqual(expectedErrMsg, e.InnerException.Message);
     }
 }
예제 #8
0
        public void Update_PartitionKeyOmitted()
        {
            // Setup
            Movie movieToUpdate = _movieList[1];

            // Update to different values
            var expectedMovie = new Movie(movieToUpdate.Title + "_something_different", movieToUpdate.Director, "something_different_" + Randomm.RandomAlphaNum(10), null, 1212);
            var err = Assert.Throws<InvalidQueryException>(() => _mapper.Update(expectedMovie));
            string expectedErrMsg = "Invalid null value (for partition key part|in condition for column) moviemaker";
            StringAssert.IsMatch(expectedErrMsg, err.Message);
        }
예제 #9
0
 public static Movie GetRandomMovie()
 {
     Movie movie = new Movie
     {
         Title = "SomeMovieTitle_" + Randomm.RandomAlphaNum(10),
         Director = "SomeMovieDirector_" + Randomm.RandomAlphaNum(10),
         MainActor = "SomeMainActor_" + Randomm.RandomAlphaNum(10),
         MovieMaker = "SomeFilmMaker_" + Randomm.RandomAlphaNum(10),
         Year = Randomm.RandomInt(),
         Rating = (MovieRating)(Randomm.RandomInt() % ((int)MovieRating.C))
     };
     return movie;
 }
예제 #10
0
        public void Update_NoSuchRecord()
        {
            // Setup
            Movie movieToUpdate = _movieList[1];

            // Update to different values
            var expectedMovie = new Movie(movieToUpdate.Title + "_something_different", movieToUpdate.Director, "something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate.MovieMaker + "_something_different", 1212, MovieRating.C);
            _mapper.Update(expectedMovie);

            List<Movie> actualMovieList = _movieTable.Execute().ToList();
            Assert.AreEqual(_movieList.Count + 1, actualMovieList.Count());
            Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie));
            Assert.IsTrue(Movie.ListContains(actualMovieList, expectedMovie));
            Movie.AssertListContains(actualMovieList, movieToUpdate);
        }
예제 #11
0
 public static void AssertListContains(List<Movie> expectedMovies, Movie actualMovie)
 {
     Assert.IsTrue(ListContains(expectedMovies, actualMovie));
 }
예제 #12
0
        public void Update_PartitionKeyOmitted()
        {
            // Setup
            Movie movieToUpdate = _movieList[1];

            // Update to different values
            var expectedMovie = new Movie(movieToUpdate.Title + "_something_different", movieToUpdate.Director, "something_different_" + Randomm.RandomAlphaNum(10), null, 1212, MovieRating.C);
            var err = Assert.Throws<InvalidQueryException>(() => _mapper.Update(expectedMovie));
            Assert.AreEqual("Invalid null value for partition key part moviemaker", err.Message);
        }
예제 #13
0
 public RowsResult CreateAppliedInfoRowsResult()
 {
     return(AddAppliedInfoRow(Movie.GetEmptyAppliedInfoRowsResult()));
 }
예제 #14
0
        public void LinqUpdate_Batch()
        {
            // Setup
            Table<Movie> table = new Table<Movie>(_session, new MappingConfiguration());
            table.CreateIfNotExists();
            Movie movieToUpdate1 = _movieList[1];
            Movie movieToUpdate2 = _movieList[2];

            BatchStatement 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);

            List<Movie> 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);
        }
예제 #15
0
 public void LinqInsert_MissingPartitionKey_Async_Test()
 {
     var table = new Table<Movie>(_session, new MappingConfiguration());
     Movie objectMissingPartitionKey = new Movie() {MainActor = "doesntmatter"};
     
     try
     {
         table.Insert(objectMissingPartitionKey).ExecuteAsync().Wait();
     }
     catch (Exception e) // Exception is gathered from the async task
     {
         int maxLayers = 50;
         int layersChecked = 0;
         while (layersChecked < maxLayers && !e.GetType().Equals(typeof(InvalidQueryException)))
         {
             layersChecked++;
             e = e.InnerException;
         }
         Assert.IsInstanceOf<InvalidQueryException>(e);
     }
 }
예제 #16
0
 public void LinqInsert_MissingPartitionKey_Sync_Test()
 {
     var table = new Table<Movie>(_session, new MappingConfiguration());
     Movie objectMissingPartitionKey = new Movie() {MainActor = "doesntmatter"};
     Assert.Throws<InvalidQueryException>(() => table.Insert(objectMissingPartitionKey).Execute());
 }
예제 #17
0
 public RowsResult CreateRowsResult()
 {
     return(AddRow(Movie.GetEmptyRowsResult()));
 }
예제 #18
0
 public static void AssertListContains(List <Movie> expectedMovies, Movie actualMovie)
 {
     Assert.IsTrue(ListContains(expectedMovies, actualMovie));
 }