コード例 #1
0
        public void Should_return_all_genres_translated_to_a_genres_response(
            IWebApiMovieRestContext context,
            GetGenresRequestHandler getGenresRequestHandler,
            GetGenresRequest getGenreRequest,
            GenresResponse genresResponse
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a GetGenresRequestHandler constructed with the context"
            .And(() => getGenresRequestHandler = new GetGenresRequestHandler(context));

            "And a GetGenresRequest".
            And(() => getGenreRequest = new GetGenresRequest());

            "After handling the GetGenresRequest"
            .When(() => genresResponse = getGenresRequestHandler.Handle(getGenreRequest));

            "The GenresResponse should be all existing Genres in the database translated".Then(() =>
            {
                var existingGenresTranslated = new WebApiMovieRestInitializer()
                                               .SeedMovies()
                                               .SelectMany(movie => movie.Genres)
                                               .Distinct()
                                               .ToResponse();

                genresResponse.ShouldBeEquivalentTo(
                    existingGenresTranslated,
                    // do not compare ids
                    o => o.Excluding(x => x.PropertyInfo.Name == "Id")
                    );
            });
        }
コード例 #2
0
        public void Should_return_genre_translated_to_a_genres_response_when_genre_is_found(
            IWebApiMovieRestContext context,
            GetGenreRequestHandler getGenreRequestHandler,
            Genre newGenre,
            GetGenreRequest getGenreRequest,
            GenresResponse genresResponse
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a GetGenreRequestHandler constructed with the context"
            .And(() => getGenreRequestHandler = new GetGenreRequestHandler(context));

            "And a new Genre that has been inserted into the database"
            .And(() => newGenre = Db.InsertGenre(new Genre("a new genre")));

            "And a GetGenreRequest containing the id of the newly inserted Genre".
            And(() => getGenreRequest = new GetGenreRequest()
            {
                GenreId = newGenre.Id
            });

            "After handling the GetGenreRequest"
            .When(() => genresResponse = getGenreRequestHandler.Handle(getGenreRequest));

            "The GenresResponse should be the newly inserted Genre translated"
            .Then(() => genresResponse.ShouldBeEquivalentTo(newGenre.Yield().ToResponse()));
        }