Ejemplo n.º 1
0
        public void The_MovieRatedByCritics_event_should_be_unchanged_with_the_same_rating()
        {
            var movieId        = Guid.NewGuid();
            var ratedByCritics = new MovieRatedByCritics(movieId, 60);

            var repo = new DummyMovieProjectionRepository();

            repo.List[movieId] = new MovieProjection {
                Id = movieId, CriticsScore = 60
            };

            var handler = new MovieProjectionHandlers(repo);

            handler.Handle(ratedByCritics);

            repo.List.Count.Should().Be(1);
            repo.List.Values.ShouldBeEquivalentTo(new[]
            {
                new MovieProjection
                {
                    Id           = movieId,
                    CriticsScore = 60
                }
            });
        }
Ejemplo n.º 2
0
        public void The_MovieRatedByCritics_event_should_keep_a_roling_average()
        {
            var movieId        = Guid.NewGuid();
            var ratedByCritics = new MovieRatedByCritics(movieId, 60);

            var repo = new DummyMovieProjectionRepository();

            repo.List[movieId] = new MovieProjection {
                Id = movieId, CriticsScore = 50
            };

            var handler = new MovieProjectionHandlers(repo);

            handler.Handle(ratedByCritics);

            repo.List.Count.Should().Be(1);
            repo.List.Values.ShouldBeEquivalentTo(new[]
            {
                new MovieProjection
                {
                    Id           = movieId,
                    CriticsScore = 51
                }
            });
        }
Ejemplo n.º 3
0
 public void Handle(MovieRatedByCritics movieRated)
 {
     UpdateMovie(movieRated.MovieId,
                 m =>
     {
         if (m.CriticsScore.HasValue)
         {
             m.CriticsScore = (int)Math.Round(0.9 * m.CriticsScore.Value + 0.1 * movieRated.Rating, 0);
         }
         else
         {
             m.CriticsScore = movieRated.Rating;
         }
     });
 }