コード例 #1
0
 public void SearchMovieTest()
 {
     OmdbService service = OmdbService.Service;
     string title = "Ant man";
     SearchResult expected = new SearchResult();
     expected.Title.Add("Ant-Man");
     expected.Year.Add("2015");
     SearchResult actual = service.SearchMovie(title);
     Assert.AreNotEqual(expected, actual);
 }
コード例 #2
0
 public void SearchMovieTest2()
 {
     OmdbService service = OmdbService.Service;
     string title = "Armageddon";
     string year = "1998";
     SearchResult expected = new SearchResult();
     expected.Title.Add("Armageddon");
     expected.Title.Add("Countdown to Armageddon");
     expected.Title.Add("Armageddon: Target Earth");
     expected.Title.Add("Armageddon: Biblical Prophecy");
     expected.Year.Add("1998");
     expected.Year.Add("1998");
     expected.Year.Add("1998");
     expected.Year.Add("1998");
     SearchResult actual = service.SearchMovie(title, year);
     Assert.AreNotEqual(expected, actual);
 }
コード例 #3
0
ファイル: TmdbService.cs プロジェクト: kogrego/MovieService
 public SearchResult SearchMovie(string title, string year)
 {
     string url = BaseUrl + "search/movie?api_key=" + ApiKey + "&query=" + title + "&primary_release_year=" + year;
     SearchResult result = new SearchResult();
     using (WebClient wc = new WebClient())
     {
         var json = wc.DownloadString(url);
         JObject search = JObject.Parse(json);
         if ((string)search["total_results"] != "0")
         {
             JArray jArray = new JArray();
             jArray = (JArray)search["results"];
             foreach (var token in jArray)
             {
                 result.Title.Add((string)token["original_title"]);
                 result.Year.Add((string)token["release_date"]);
             }
         }
     }
     return result;
 }
コード例 #4
0
ファイル: OmdbService.cs プロジェクト: kogrego/MovieService
 public SearchResult SearchMovie(string title, string year)
 {
     string url = baseUrl + "s=" + title + "&y=" + year;
     SearchResult result = new SearchResult();
     XDocument xDoc = XDocument.Load(url);
     string response = xDoc.Descendants("root").Attributes("response").First().Value;
     if (response == "True")
     {
         var moviesQuery = from root in xDoc.Root.Descendants("Movie")
                           select new
                           {
                               Title = root.Attribute("Title").Value,
                               Year = root.Attribute("Year").Value
                           };
         var movies = moviesQuery.ToList();
         foreach (var movie in movies)
         {
             result.Title.Add(movie.Title);
             result.Year.Add(movie.Year);
         }
     }
     else
     {
         throw new TitleNotFoundException("The movie was not found!");
     }
     return result;
 }