Ejemplo n.º 1
0
        public void Scrobble_should_return_list_of_TraktShow_with_user_details_hideWatched()
        {
            //Setup
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 153021,\"imdb_id\": \"tt1520211\",\"title\": \"The Walking Dead\",\"year\": 2010,\"season\": 1,\"episode\": 1,\"duration\": 60,\"progress\": 25,\"plugin_version\": \"1.0\",\"media_center_version\": \"10.0\",\"media_center_date\": \"Dec 17 2010\"}";

            var jsonResult = "{\"status\": \"success\",\"message\": \"scrobbled The Walking Dead 1x01\"}";
            var expectedUrl = String.Format("{0}{1}", Url.ShowScrobble, Constants.ApiKey);

            var episodeInfo = new EpisodeInfo
                                  {
                                      Title = "The Walking Dead",
                                      Year = 2010,
                                      TvdbId = 153021,
                                      ImdbId = "tt1520211",
                                      Season = 1,
                                      Episode = 1
                                  };

            var mediaCenterInfo = new MediaCenterInfo
                                      {
                                          PluginVersion = "1.0",
                                          MediaCenterVersion = "10.0",
                                          MediaCenterDate = "Dec 17 2010"
                                      };

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl, It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<ShowProvider>().Scrobble(Constants.ApiKey, "username", "sha1hash", episodeInfo, 60, 25, mediaCenterInfo);

            //Assert
            result.Should().NotBeNull();;
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("scrobbled The Walking Dead 1x01");
        }
Ejemplo n.º 2
0
        public virtual SimpleStatusResult Scrobble(string apiKey, string username, string passwordHash, EpisodeInfo episodeInfo, int duration, int progress, MediaCenterInfo mediaCenterInfo)
        {
            string url = String.Format("{0}{1}", Url.ShowScrobble, apiKey);

            var postJson = new JObject();
            postJson.Add(new JProperty("username", username));
            postJson.Add(new JProperty("password", passwordHash));

            if (episodeInfo.TvdbId != 0)
                postJson.Add(new JProperty("tvdb_id", episodeInfo.TvdbId));

            if (episodeInfo.ImdbId != null)
                postJson.Add(new JProperty("imdb_id", episodeInfo.ImdbId));

            if (episodeInfo.Title != null)
                postJson.Add(new JProperty("title", episodeInfo.Title));

            if (episodeInfo.Year != 0)
                postJson.Add(new JProperty("year", episodeInfo.Year));

            postJson.Add(new JProperty("season", episodeInfo.Season));
            postJson.Add(new JProperty("episode", episodeInfo.Episode));
            postJson.Add(new JProperty("duration", duration));
            postJson.Add(new JProperty("progress", progress));

            postJson.Add(new JProperty("plugin_version", mediaCenterInfo.PluginVersion));
            postJson.Add(new JProperty("media_center_version", mediaCenterInfo.MediaCenterVersion));
            postJson.Add(new JProperty("media_center_date", mediaCenterInfo.MediaCenterDate));

            var responseJson = _httpProvider.DownloadString(url, postJson.ToString());

            if (String.IsNullOrWhiteSpace(responseJson))
                return new SimpleStatusResult { Status = ResultStatusType.Failure, Message = "Failed to scrobble." };

            return JsonConvert.DeserializeObject<SimpleStatusResult>(responseJson);
        }