コード例 #1
0
 public void CreateGenre(GenreDTO genreDTO)
 {
     using (var transaction = GenreRepository.UnitOfWork.BeginTransaction(2))
     {
         GenreRepository.Add(GenreFactory.CreateGenre(genreDTO.Type));
         transaction.Commit();
     }
 }
コード例 #2
0
ファイル: UpdateGenre.aspx.cs プロジェクト: gga1503/BookStore
        private void SendDataToDatabase()
        {
            var genre = GenreFactory.InsertGenre(
                GenreNameInput.Text,
                DescriptionInput.Text
                );

            GenreRepository.InsertGenre(genre);
        }
コード例 #3
0
        public static void insertGenre(string Name, string Description)
        {
            Genre genre = GenreFactory.createGenre(Name, Description);

            Database1Entities db = new Database1Entities();

            db.Genres.Add(genre);
            db.SaveChanges();
        }
コード例 #4
0
        public async Task GetAllAsync_Returns_Known_Genres()
        {
            ApiQueryResponse <IReadOnlyList <Genre> > response = await _api.GetAllAsync();

            ApiResponseUtil.AssertErrorIsNull(response);

            IReadOnlyList <Genre> knownGenres = GenreFactory.GetAll();

            CollectionAssert.AreEquivalent(knownGenres.ToList(), response.Item.ToList());
        }
コード例 #5
0
        public async Task FindMoviesByIdAsync_CanPageResults()
        {
            int genreId = GenreFactory.Comedy().Id;
            // Comedy has upwards of 2k pages.
            const int minimumPageCount         = 5;
            const int minimumTotalResultsCount = 100; // 20 results per page x 5 pages = 100

            await ApiResponseUtil.AssertCanPageSearchResponse(genreId, minimumPageCount, minimumTotalResultsCount,
                                                              (id, page) => _api.FindMoviesByIdAsync(id, page), x => x.Id);
        }
コード例 #6
0
ファイル: GenreService.cs プロジェクト: OrehovP/BookShelf
        public void CreateEditGenre(GenreForm item)
        {
            Genre genre = GenreFactory.Build(item.Id, item.Name);

            if (item.Id != Guid.Empty)
            {
                DbOfWork.Genres.Update(genre);
            }
            else
            {
                DbOfWork.Genres.Create(genre);
            }
            DbOfWork.Save();
        }
コード例 #7
0
        public async Task InvalidPage_PageNotAnInteger_MoviesByGenre()
        {
            const string invalidPage = "One";

            var param = new Dictionary <string, string>
            {
                { "page", invalidPage },
            };

            string command = $"genre/{GenreFactory.Comedy().Id}/movies";

            ApiSearchResponse <MovieInfo> result = await _api.SearchAsync <MovieInfo>(command, param);

            AssertInvalidPage(result);
        }
コード例 #8
0
        public async Task FindMoviesByIdAsync_Returns_ValidResult()
        {
            int genreId = GenreFactory.Comedy().Id;

            ApiSearchResponse <MovieInfo> response = await _api.FindMoviesByIdAsync(genreId);

            ApiResponseUtil.AssertErrorIsNull(response);

            Assert.AreEqual(20, response.Results.Count);

            var expectedGenres = new[] { GenreFactory.Comedy() };

            foreach (MovieInfo info in response.Results)
            {
                CollectionAssert.IsSubsetOf(expectedGenres, info.Genres.ToList());
            }
        }
コード例 #9
0
        public async Task SearchByNameAsync_GameOfThrones_Returns_PopulatedGenres()
        {
            const string query = "Game of Thrones";

            ApiSearchResponse <TVShowInfo> response = await _api.SearchByNameAsync(query);

            ApiResponseUtil.AssertErrorIsNull(response);

            TVShowInfo gameOfThrones = response.Results.Single();

            Genre[] expGenres =
            {
                GenreFactory.SciFiAndFantasy(),
                GenreFactory.ActionAndAdventure(),
                GenreFactory.Drama(),
            };

            CollectionAssert.AreEquivalent(expGenres, gameOfThrones.Genres.ToArray());
        }
コード例 #10
0
        private void AssertRunLolaRun(ApiSearchResponse <MovieInfo> response, string expectedTitle)
        {
            ApiResponseUtil.AssertErrorIsNull(response);

            Assert.AreEqual(1, response.TotalResults);
            Assert.AreEqual(1, response.Results.Count);

            MovieInfo movie = response.Results.Single();

            Assert.AreEqual(104, movie.Id);

            Assert.AreEqual(expectedTitle, movie.Title);

            Assert.AreEqual(new DateTime(1998, 08, 20), movie.ReleaseDate);

            var expectedGenres = new List <Genre>
            {
                GenreFactory.Action(),
                GenreFactory.Drama(),
                GenreFactory.Thriller(),
            };

            CollectionAssert.AreEquivalent(expectedGenres, movie.Genres.ToList());
        }
コード例 #11
0
        public async Task FindByIdAsync_StarWarsTheForceAwakens_Returns_AllValues()
        {
            const int    id                       = 140607;
            const string expectedImdbId           = "tt2488496";
            const string expectedTitle            = "Star Wars: The Force Awakens";
            const string expectedOriginalTitle    = "Star Wars: The Force Awakens";
            const string expectedTagline          = "Every generation has a story.";
            const string expetedOverview          = "Thirty years after defeating the Galactic Empire"; // truncated
            const string expectedOriginalLanguage = "en";
            const string expectedHomepage         = "http://www.starwars.com/films/star-wars-episode-vii";
            const string expectedStatus           = "Released";
            const int    expectedBudget           = 200000000;
            const int    expectedRuntime          = 136;
            var          expectedReleaseDate      = new DateTime(2015, 12, 15);

            ApiQueryResponse <Movie> response = await _api.FindByIdAsync(id);

            ApiResponseUtil.AssertErrorIsNull(response);

            Movie movie = response.Item;

            Assert.AreEqual(id, movie.Id);
            Assert.AreEqual(expectedImdbId, movie.ImdbId);
            Assert.AreEqual(expectedTitle, movie.Title);
            Assert.AreEqual(expectedOriginalTitle, movie.OriginalTitle);
            Assert.AreEqual(expectedTagline, movie.Tagline);
            Assert.AreEqual(expectedOriginalLanguage, movie.OriginalLanguage);
            Assert.AreEqual(expectedHomepage, movie.Homepage);
            Assert.AreEqual(expectedStatus, movie.Status);
            Assert.AreEqual(expectedBudget, movie.Budget);
            Assert.AreEqual(expectedRuntime, movie.Runtime);
            Assert.AreEqual(expectedReleaseDate, movie.ReleaseDate);

            ApiResponseUtil.AssertImagePath(movie.BackdropPath);
            ApiResponseUtil.AssertImagePath(movie.PosterPath);

            Assert.IsTrue(movie.Overview.StartsWith(expetedOverview));
            Assert.IsTrue(movie.Popularity > 7, $"Actual: {movie.Popularity}");
            Assert.IsTrue(movie.VoteAverage > 5);
            Assert.IsTrue(movie.VoteCount > 1500);

            // Spoken Languages
            var languages = new[]
            {
                new Language("en", "English"),
            };

            CollectionAssert.AreEqual(languages, movie.SpokenLanguages.ToArray());

            // Production Companies
            var companies = new[]
            {
                new ProductionCompanyInfo(1, "Lucasfilm"),
                new ProductionCompanyInfo(1634, "Truenorth Productions"),
                new ProductionCompanyInfo(11461, "Bad Robot"),
            };

            CollectionAssert.AreEquivalent(companies, movie.ProductionCompanies.ToArray());

            // Production Countries
            var countries = new[]
            {
                new Country("US", "United States of America"),
            };

            CollectionAssert.AreEqual(countries, movie.ProductionCountries.ToArray());

            // Movie Collection
            Assert.IsNotNull(movie.MovieCollectionInfo);
            Assert.AreEqual(10, movie.MovieCollectionInfo.Id);
            Assert.AreEqual("Star Wars Collection", movie.MovieCollectionInfo.Name);
            ApiResponseUtil.AssertImagePath(movie.MovieCollectionInfo.BackdropPath);
            ApiResponseUtil.AssertImagePath(movie.MovieCollectionInfo.PosterPath);

            // Genres
            var expectedGenres = new List <Genre>
            {
                GenreFactory.Action(),
                GenreFactory.Adventure(),
                GenreFactory.ScienceFiction(),
                GenreFactory.Fantasy(),
            };

            CollectionAssert.AreEquivalent(expectedGenres, movie.Genres.ToList());

            // Keywords
            var expectedKeywords = new List <Keyword>
            {
                new Keyword(803, "android"),
                new Keyword(9831, "spaceship"),
                new Keyword(10527, "jedi"),
                new Keyword(161176, "space opera"),
                new Keyword(209714, "3d"),
                new Keyword(229031, "shot on imax cameras"),
            };

            CollectionAssert.AreEquivalent(expectedKeywords, movie.Keywords.ToList());
        }
コード例 #12
0
        public async Task FindById_GameOfThrones_ReturnsAllValuesIncludingImages()
        {
            var          expFirstAirDate     = new DateTime(2011, 04, 17);
            const string expHomepage         = "http://www.hbo.com/game-of-thrones";
            const string expName             = "Game of Thrones";
            const string expOriginalLanguage = "en";

            ApiQueryResponse <TVShow> response = await _api.FindByIdAsync(1399, includeImages : true);

            ApiResponseUtil.AssertErrorIsNull(response);

            TVShow show = response.Item;

            TVShowCreator[] expCreatedBy =
            {
                new TVShowCreator(9813,   "David Benioff", "/8CuuNIKMzMUL1NKOPv9AqEwM7og.jpg"),
                new TVShowCreator(228068, "D. B. Weiss",   "/caUAtilEe06OwOjoQY3B7BgpARi.jpg"),
            };

            CollectionAssert.AreEquivalent(expCreatedBy, show.CreatedBy.ToArray());

            var expRunTime = new[] { 60 };

            CollectionAssert.AreEquivalent(expRunTime, show.EpisodeRunTime.ToArray());

            Assert.AreEqual(expFirstAirDate.Date, show.FirstAirDate.Date);

            Genre[] expGenres =
            {
                GenreFactory.SciFiAndFantasy(),
                GenreFactory.ActionAndAdventure(),
                GenreFactory.Drama(),
            };

            CollectionAssert.AreEquivalent(expGenres, show.Genres.ToArray());

            Assert.AreEqual(expHomepage, show.Homepage);

            var expLanguages = new[] { "es", "en", "de" };

            CollectionAssert.AreEquivalent(expLanguages, show.Languages.ToArray());

            Assert.AreEqual(expName, show.Name);

            Network[] expNetworks =
            {
                new Network(49, "HBO")
            };

            CollectionAssert.AreEquivalent(expNetworks, show.Networks.ToArray());

            var expCountryCodes = new[] { "US" };

            CollectionAssert.AreEquivalent(expCountryCodes, show.OriginCountry.ToArray());

            Assert.AreEqual(expOriginalLanguage, show.OriginalLanguage);

            ApiResponseUtil.AssertImagePath(show.BackdropPath);
            ApiResponseUtil.AssertImagePath(show.PosterPath);

            ProductionCompanyInfo[] expProductionCompanies =
            {
                new ProductionCompanyInfo(3268,  "Home Box Office (HBO)"),
                new ProductionCompanyInfo(5820,  "Generator Entertainment"),
                new ProductionCompanyInfo(12525, "Television 360"),
                new ProductionCompanyInfo(12526, "Bighead Littlehead"),
                new ProductionCompanyInfo(76043, "Revolution Sun Studios")
            };
            CollectionAssert.AreEquivalent(expProductionCompanies, show.ProductionCompanies.ToArray());

            Keyword[] expKeywords =
            {
                new Keyword(6091,   "war"),
                new Keyword(818,    "based on novel"),
                new Keyword(4152,   "kingdom"),
                new Keyword(12554,  "dragon"),
                new Keyword(13084,  "king"),
                new Keyword(34038,  "intrigue"),
                new Keyword(170362, "fantasy world"),
            };
            CollectionAssert.AreEquivalent(expKeywords, show.Keywords.ToArray());

            Assert.IsNotNull(show.Backdrops);
            Assert.IsNotNull(show.Posters);

            Assert.AreNotEqual(0, show.Backdrops.Count);
            Assert.AreNotEqual(0, show.Posters);

            var backdrop = show.Backdrops[0];

            Assert.AreNotEqual(0, backdrop.AspectRatio);
            ApiResponseUtil.AssertImagePath(backdrop.FilePath);
            Assert.AreNotEqual(0, backdrop.Height);
            Assert.AreNotEqual(0, backdrop.Width);
        }