public void ToMovie_HasMovieResultWithSomeGenres_ReturnsMovieWithCorrectGenres() { var source = new MovieResult() { Adult = true, GenreIds = new int[] { 1, 2 }, Id = 10, Overview = "Some overview text", Popularity = 8.52D, PosterPath = "another.poster.path", ReleaseDate = "2010/01/01", Title = "Movie title", VoteAverage = 7.43D, VoteCount = 54 }; var genreInfo = new GenreInfo() { Genres = new List <GenreResult>() { new GenreResult() { Id = 2, Name = "Genre 2" } } }; var target = new MovieMapper(); var actual = target.ToMovie(source, genreInfo); Assert.AreEqual(1, actual.Genres.Count); Assert.AreEqual(genreInfo.Genres[0].Id, actual.Genres[0].Id); }
public Movie ToMovie(MovieResult source, GenreInfo genreInfo) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (genreInfo == null) { throw new ArgumentNullException(nameof(genreInfo)); } var genres = GetGenres(source, genreInfo); var result = new Movie() { Id = source.Id, Overview = source.Overview, SmallPosterUri = new Uri($"{PosterBaseUrl}{SmallPosterSize}{source.PosterPath}", UriKind.Absolute), LargePosterUri = new Uri($"{PosterBaseUrl}{LargePosterSize}{source.PosterPath}", UriKind.Absolute), Popularity = source.Popularity, Title = source.Title, VoteAverage = source.VoteAverage, VoteCount = source.VoteCount, Genres = genres, ReleaseDate = ParseDate(source.ReleaseDate) }; return(result); }
private IList <Genre> GetGenres(MovieResult source, GenreInfo genreInfo) { var genreMapper = new GenreMapper(); return(genreInfo .Genres .Where(list => source.GenreIds.Contains(list.Id)) .Select(genre => genreMapper.ToGenre(genre)) .ToList()); }
public void GetUpcomingMovies_SpecificPage_InvokeServiceWithCorrectParameters() { int expectedPage = 2; var expectedLanguage = "en-US"; var pagingInfo = new MoviePagingInfo(); GenreInfo genreInfo = null; var apiClientMock = new Mock <ITmdbApiClient>(); apiClientMock .Setup(x => x.FetchUpcomingMovies( It.IsAny <int>(), It.IsAny <string>())) .Returns(() => Observable.Return(pagingInfo)); apiClientMock .Setup(x => x.FetchMovieGenres( It.IsAny <string>())) .Returns(() => Observable.Return(genreInfo)); var apiServiceMock = new Mock <ITmdbApiService>(); apiServiceMock .Setup(x => x.GetClient()) .Returns(apiClientMock.Object); var cacheMock = new Mock <ICache>(); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <MoviePagingInfo> > >())) .Returns <string, Func <IObservable <MoviePagingInfo> > >((arg, targetMethod) => targetMethod()); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <GenreInfo> > >())) .Returns <string, Func <IObservable <GenreInfo> > >((arg, targetMethod) => targetMethod()); var target = new MovieService( apiServiceMock.Object, cacheMock.Object); target.GetUpcomingMovies(expectedPage).Subscribe(); apiServiceMock.Verify(x => x.GetClient(), Times.Once); apiClientMock.Verify( x => x.FetchUpcomingMovies( It.Is <int>(page => page == expectedPage), It.Is <string>(language => language == expectedLanguage)), Times.Once); apiClientMock.Verify( x => x.FetchMovieGenres( It.Is <string>(language => language == expectedLanguage)), Times.Once); }
public void GetMovies_WhenInvoked_UsesSpecifiedCacheKey() { var expectedQuery = "another query"; int expectedPage = 2; var pagingInfo = new MoviePagingInfo(); GenreInfo genreInfo = null; var apiClientMock = new Mock <ITmdbApiClient>(); apiClientMock .Setup(x => x.FetchMovies( It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>())) .Returns(() => Observable.Return(pagingInfo)); apiClientMock .Setup(x => x.FetchMovieGenres( It.IsAny <string>())) .Returns(() => Observable.Return(genreInfo)); var apiServiceMock = new Mock <ITmdbApiService>(); apiServiceMock .Setup(x => x.GetClient()) .Returns(apiClientMock.Object); var cacheMock = new Mock <ICache>(); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <MoviePagingInfo> > >())) .Returns <string, Func <IObservable <MoviePagingInfo> > >((arg, targetMethod) => targetMethod()); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <GenreInfo> > >())) .Returns <string, Func <IObservable <GenreInfo> > >((arg, targetMethod) => targetMethod()); var target = new MovieService( apiServiceMock.Object, cacheMock.Object); target .GetMovies(expectedQuery, expectedPage) .Subscribe(); cacheMock.Verify( x => x.GetAndFetchLatest( It.Is <string>(cacheKey => cacheKey == $"movies_{expectedQuery}_{expectedPage}"), It.IsAny <Func <IObservable <MoviePagingInfo> > >()), Times.Once); }
public void GetMovies_PagingInfoIsNull_ReturnsEmpty() { string expectedQuery = "a query value"; int expectedPage = 2; MoviePagingInfo pagingInfo = null; GenreInfo genreInfo = null; var apiClientMock = new Mock <ITmdbApiClient>(); apiClientMock .Setup(x => x.FetchMovies( It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>())) .Returns(() => Observable.Return(pagingInfo)); apiClientMock .Setup(x => x.FetchMovieGenres( It.IsAny <string>())) .Returns(() => Observable.Return(genreInfo)); var apiServiceMock = new Mock <ITmdbApiService>(); apiServiceMock .Setup(x => x.GetClient()) .Returns(apiClientMock.Object); var cacheMock = new Mock <ICache>(); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <MoviePagingInfo> > >())) .Returns <string, Func <IObservable <MoviePagingInfo> > >((arg, targetMethod) => targetMethod()); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <GenreInfo> > >())) .Returns <string, Func <IObservable <GenreInfo> > >((arg, targetMethod) => targetMethod()); var target = new MovieService( apiServiceMock.Object, cacheMock.Object); IEnumerable <Movie> resultData = null; Assert.DoesNotThrow( () => target .GetMovies(expectedQuery, expectedPage) .Subscribe(results => resultData = results)); Assert.IsEmpty(resultData); }
public async Task <GenreInfo> GetGenreInfo(string genre) { var genreInfo = new GenreInfo { Genre = genre }; var info = await _redisAccessService.GetAsync(genre); if (info == null) { throw new ItemNotFoundException("GenreInfo"); } var regionsInfo = JsonConvert.DeserializeObject <List <RegionInfo> >(info); genreInfo.RegionsInfo = regionsInfo; return(genreInfo); }
private bool AssignMissingGenreIds(List <GenreInfo> genres, List <GenreMapping> genreMap) { bool retVal = false; List <GenreInfo> checkGenres = new List <GenreInfo>(genres); genres.Clear(); foreach (GenreInfo genre in checkGenres) { if (genre.Id > 0) { if (!genres.Contains(genre)) { genres.Add(genre); } continue; } if (string.IsNullOrEmpty(genre.Name)) { continue; } GenreInfo testGenre = genre; foreach (GenreMapping map in genreMap) { if (map.GenrePattern.Regex.IsMatch(genre.Name)) { testGenre = new GenreInfo { Id = map.GenreId, Name = genre.Name }; retVal = true; break; } } if (!genres.Contains(testGenre)) { genres.Add(testGenre); } } return(retVal); }
public int[] solution(string[] genres, int[] plays) { var album = new List <int>(); var genreInfo = new Dictionary <string, GenreInfo>(); for (int i = 0; i < genres.Length; i++) { if (genreInfo.ContainsKey(genres[i])) { genreInfo[genres[i]].TotalPlay += plays[i]; genreInfo[genres[i]].MusicAndPlayInfo.Add(new KeyValuePair <int, int>(i, plays[i])); } else { var tempGenreInfo = new GenreInfo() { TotalPlay = plays[i], MusicAndPlayInfo = new List <KeyValuePair <int, int> >() }; tempGenreInfo.MusicAndPlayInfo.Add(new KeyValuePair <int, int>(i, plays[i])); genreInfo.Add(genres[i], tempGenreInfo); } } foreach (var item in genreInfo.OrderByDescending(d => d.Value.TotalPlay)) { var musicList = item.Value.MusicAndPlayInfo.OrderByDescending(d => d.Value).ToList(); album.Add(musicList[0].Key); if (musicList.Count > 1) { album.Add(musicList[1].Key); } } return(album.ToArray()); }
public void ToMovie_HasMovieResultWithNoAvailableGenres_ReturnsMovieWithNoGenres() { var smallPosterBaseUrl = "https://image.tmdb.org/t/p/w185"; var largePosterBaseUrl = "https://image.tmdb.org/t/p/w500"; var source = new MovieResult() { Adult = true, GenreIds = new int[] { 1, 2 }, Id = 10, Overview = "Some overview text", Popularity = 8.52D, PosterPath = "/another.poster.path", ReleaseDate = "2010-01-01", Title = "Movie title", VoteAverage = 7.43D, VoteCount = 54 }; var genreInfo = new GenreInfo(); var target = new MovieMapper(); var actual = target.ToMovie(source, genreInfo); Assert.AreEqual($"{smallPosterBaseUrl}{source.PosterPath}", actual.SmallPosterUri.ToString()); Assert.AreEqual($"{largePosterBaseUrl}{source.PosterPath}", actual.LargePosterUri.ToString()); Assert.AreEqual(source.Id, actual.Id); Assert.AreEqual(source.Overview, actual.Overview); Assert.AreEqual(source.Popularity, actual.Popularity); Assert.AreEqual(source.Title, actual.Title); Assert.AreEqual(source.VoteAverage, actual.VoteAverage); Assert.AreEqual(source.VoteCount, actual.VoteCount); Assert.IsEmpty(actual.Genres); Assert.AreEqual(DateTime.Parse( source.ReleaseDate, new CultureInfo("en-US"), DateTimeStyles.AssumeUniversal), actual.ReleaseDate); }
public void GetMovieGenres_WhenInvoked_UsesSpecifiedCacheKey() { var genreInfo = new GenreInfo(); var apiClientMock = new Mock <ITmdbApiClient>(); apiClientMock .Setup(x => x.FetchMovieGenres(It.IsAny <string>())) .Returns(() => Observable.Return(genreInfo)); var apiServiceMock = new Mock <ITmdbApiService>(); apiServiceMock .Setup(x => x.GetClient()) .Returns(apiClientMock.Object); var cacheMock = new Mock <ICache>(); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <GenreInfo> > >())) .Returns <string, Func <IObservable <GenreInfo> > >((arg, targetMethod) => targetMethod()); var target = new MovieService( apiServiceMock.Object, cacheMock.Object); target.GetMovieGenres().Subscribe(); cacheMock.Verify( x => x.GetAndFetchLatest( It.Is <string>(cacheKey => cacheKey == "genres"), It.IsAny <Func <IObservable <GenreInfo> > >()), Times.Once); }
public bool Update(GenreInfo genre) { return(dal.Update(genre)); }
public bool AddInfo(GenreInfo genre) { return(dal.AddInfo(genre)); }
public bool Update(GenreInfo genre) { var sql = string.Format("update WaterService.GenreInfo set GenreName='{0}',Status={1},Modify='{2}',ModifyDate='{3}' where GenreId={4}", genre.GenreName, genre.Status, genre.Modify, genre.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss"), genre.GenreId); return(new MySqlHelper().ExcuteNonQuery(sql) > 0); }
public void GetMovies_MovieHasGenres_MovieWithGenres() { string expectedQuery = "query"; int expectedPage = 2; var pagingInfo = new MoviePagingInfo() { Results = new List <MovieResult>() { new MovieResult() { Id = 1, Title = "Movie 1", GenreIds = new List <int>() { 1, 2, 3 }, ReleaseDate = "2004-01-02" }, new MovieResult() { Id = 2, Title = "Movie 2", GenreIds = new List <int>() { 1, 3 }, ReleaseDate = "2003-10-10" } } }; var genreInfo = new GenreInfo() { Genres = new List <GenreResult>() { new GenreResult() { Id = 1, Name = "Genre 1" }, new GenreResult() { Id = 2, Name = "Genre 2" }, new GenreResult() { Id = 3, Name = "Genre 3" } } }; var apiClientMock = new Mock <ITmdbApiClient>(); apiClientMock .Setup(x => x.FetchMovies( It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>())) .Returns(() => Observable.Return(pagingInfo)); apiClientMock .Setup(x => x.FetchMovieGenres( It.IsAny <string>())) .Returns(() => Observable.Return(genreInfo)); var apiServiceMock = new Mock <ITmdbApiService>(); apiServiceMock .Setup(x => x.GetClient()) .Returns(apiClientMock.Object); var cacheMock = new Mock <ICache>(); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <MoviePagingInfo> > >())) .Returns <string, Func <IObservable <MoviePagingInfo> > >((arg, targetMethod) => targetMethod()); cacheMock .Setup(x => x.GetAndFetchLatest( It.IsAny <string>(), It.IsAny <Func <IObservable <GenreInfo> > >())) .Returns <string, Func <IObservable <GenreInfo> > >((arg, targetMethod) => targetMethod()); IList <Movie> results = null; var target = new MovieService( apiServiceMock.Object, cacheMock.Object); target .GetMovies(expectedQuery, expectedPage) .Subscribe(movies => results = movies.ToList()); Assert.AreEqual(pagingInfo.Results.Count, results.Count()); Assert.AreEqual(pagingInfo.Results[0].GenreIds.Count, results[0].Genres.Count()); Assert.AreEqual(pagingInfo.Results[1].GenreIds.Count, results[1].Genres.Count()); }
public ResultModel AddInfo([FromBody] GenreInfo genre) { genre.Create = User.Identity.GetCurrentUser().UserName; genre.CreateDate = DateTime.Now; return(GenerateResult("", "", bll.AddInfo(genre))); }
public ResultModel Update([FromBody] GenreInfo genre) { genre.Modify = User.Identity.GetCurrentUser().UserName; genre.ModifyDate = DateTime.Now; return(GenerateResult("", "", bll.Update(genre))); }
public bool AddInfo(GenreInfo genre) { var sql = string.Format("insert into WaterService.GenreInfo (GenreName,Status,`Create`) values ('{0}',1,'{1}')", genre.GenreName, genre.Create); return(new MySqlHelper().ExcuteNonQuery(sql) > 0); }