public void Should_return_all_movie_translated_to_a_movies_response_when_no_genre_specified_in_request(
            IWebApiMovieRestContext context,
            GetMoviesRequestHandler getMoviesRequestHandler,
            GetMoviesRequest getMovieRequest,
            MoviesResponse moviesResponse
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a GetMoviesRequestHandler constructed with the context"
            .And(() => getMoviesRequestHandler = new GetMoviesRequestHandler(context));

            "And a GetMoviesRequest with no genre specified".
            And(() => getMovieRequest = new GetMoviesRequest());

            "After handling the GetMoviesRequest"
            .When(() => moviesResponse = getMoviesRequestHandler.Handle(getMovieRequest));

            "The MovieResponse should be all existing Movies in the database translated".Then(() =>
            {
                var existingMoviesTranslated = new WebApiMovieRestInitializer()
                                               .SeedMovies()
                                               .ToResponse();

                moviesResponse.ShouldBeEquivalentTo(
                    existingMoviesTranslated,
                    // do not compare ids or links (as ids will be different)
                    o => o.Excluding(x => x.PropertyInfo.Name == "Id" || x.PropertyInfo.Name == "Links")
                    );
            });
        }
Ejemplo n.º 2
0
        public void Should_return_movie_translated_to_a_movies_response_when_movie_is_found(
            IWebApiMovieRestContext context,
            GetMovieRequestHandler getMovieRequestHandler,
            Movie newMovie,
            GetMovieRequest getMovieRequest,
            MoviesResponse moviesResponse
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a GetMovieRequestHandler constructed with the context"
            .And(() => getMovieRequestHandler = new GetMovieRequestHandler(context));

            "And a new Movie that has been inserted into the database"
            .And(() => newMovie = Db.InsertMovie(new MovieBuilder()));

            "And a GetMovieRequest containing the id of the newly inserted Movie".
            And(() => getMovieRequest = new GetMovieRequest()
            {
                MovieId = newMovie.Id
            });

            "After handling the GetMovieRequest"
            .When(() => moviesResponse = getMovieRequestHandler.Handle(getMovieRequest));

            "The MovieResponse should be the newly inserted Movie translated"
            .Then(() => moviesResponse.ShouldBeEquivalentTo(newMovie.Yield().ToResponse()));
        }
Ejemplo n.º 3
0
        public void Should_create_movie_and_use_existing_genre_if_genre_exists(
            IWebApiMovieRestContext context,
            CreateMovieRequestHandler createMovieRequestHandler,
            Genre alreadyExistingGenre,
            Movie newMovie,
            CreateMovieRequest createMovieRequest,
            MoviesResponse moviesResponse,
            Movie createdMovie
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a CreateMovieRequestHandler constructed with the context"
            .And(() => createMovieRequestHandler = new CreateMovieRequestHandler(context));

            "And a Genre that already exists in the database".And(() =>
            {
                var alreadyExistingGenreName = new WebApiMovieRestInitializer()
                                               .SeedMovies().First()
                                               .Genres.First()
                                               .Name;

                alreadyExistingGenre = Db.GetGenreByName(alreadyExistingGenreName);
            });

            "And a CreateMovieRequest containing a genre that exists in the database".
            And(() => createMovieRequest = new CreateMovieRequestBuilder().WithGenres(new[] { alreadyExistingGenre.Name }));

            "After handling the CreateMovieRequest"
            .When(() => moviesResponse = createMovieRequestHandler.Handle(createMovieRequest));

            "And commiting the WebApiMovieRestContext"
            .When(() => context.Commit());

            "Then a Movie should have be created in the database".Then(() =>
            {
                var createdMovieId = moviesResponse.Movies.First().Id;
                createdMovie       = Db.GetMovieById(createdMovieId);

                createdMovie.Should().NotBeNull();
            });

            "And the already existing Genre should have be used".Then(() =>
                                                                      createdMovie.Genres.Single().ShouldBeEquivalentTo(alreadyExistingGenre));

            "And the new movie should have the same values as the request"
            .Then(() => createdMovie.ShouldBeEquivalentTo(createMovieRequest, o => o.ExcludingMissingProperties()));

            "And the new movie should have the same genre as the request"
            .Then(() => createdMovie.Genres.Single().Name.Should().Be(createMovieRequest.Genres[0]));

            "And the MovieResponse should be the newly created Movie translated"
            .Then(() => moviesResponse.ShouldBeEquivalentTo(createdMovie.Yield().ToResponse()));
        }
Ejemplo n.º 4
0
        public void Should_update_movie_and_use_existing_genre_if_genre_exists(
            IWebApiMovieRestContext context,
            UpdateMovieRequestHandler updateMovieRequestHandler,
            Genre alreadyExistingGenre,
            Movie newMovie,
            UpdateMovieRequest updateMovieRequest,
            MoviesResponse moviesResponse,
            Movie updatedMovie
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a UpdateMovieRequestHandler constructed with the context"
            .And(() => updateMovieRequestHandler = new UpdateMovieRequestHandler(context));

            "And a new Movie that has been inserted into the database".And(() =>
            {
                newMovie = new MovieBuilder().WithGenres(new[] { new Genre("new genre") });

                using (var dbContext = new WebApiMovieRestContext())
                {
                    dbContext.Movies.Add(newMovie);
                    dbContext.SaveChanges();
                }
            });

            "And a Genre that already exists in the database".And(() =>
            {
                var alreadyExistingGenreName = new WebApiMovieRestInitializer()
                                               .SeedMovies().First()
                                               .Genres.First()
                                               .Name;

                using (var dbContext = new WebApiMovieRestContext())
                {
                    alreadyExistingGenre = dbContext.Genres.Single(genre => genre.Name == alreadyExistingGenreName);
                }
            });

            "And a UpdateMovieRequest containing the id of the newly inserted Movie and genre that exists in the database".
            And(() => updateMovieRequest = new UpdateMovieRequestBuilder()
                                           .WithMovieId(newMovie.Id)
                                           .WithDirector("new director")
                                           .WithGenres(new[] { alreadyExistingGenre.Name })
                                           .WithImdbId("newimdbid")
                                           .WithPlot("new plot")
                                           .WithRating(0.1m)
                                           .WithReleaseDate(new DateTime(2000, 01, 01))
                                           .WithTitle("new title"));

            "After handling the UpdateMovieRequest"
            .When(() => moviesResponse = updateMovieRequestHandler.Handle(updateMovieRequest));

            "And commiting the WebApiMovieRestContext"
            .When(() => context.Commit());

            "And retrieving the updated Movie".When(() =>
            {
                using (var dbContext = new WebApiMovieRestContext())
                {
                    updatedMovie = dbContext.Movies
                                   .Include(movie => movie.Genres)
                                   .SingleOrDefault(movie => movie.Id == newMovie.Id);
                }
            });

            "Then the already existing Genre should have be used".Then(() =>
                                                                       updatedMovie.Genres.Single().ShouldBeEquivalentTo(alreadyExistingGenre));

            "And the new movie should have the same values as the request"
            .Then(() => updatedMovie.ShouldBeEquivalentTo(updateMovieRequest, o => o.ExcludingMissingProperties()));

            "And the new movie should have the same genre as the request"
            .Then(() => updatedMovie.Genres.Single().Name.Should().Be(updateMovieRequest.Genres[0]));

            "And the MovieResponse should be the newly updated Movie translated"
            .Then(() => moviesResponse.ShouldBeEquivalentTo(updatedMovie.Yield().ToResponse()));
        }