public void Library_should_return_success() { //Setup var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"movies\": [{\"imdb_id\": \"tt0114746\",\"tmdb_id\": null,\"title\": \"Twelve Monkeys\",\"year\": 1995}]}"; var jsonResult = "{\"status\": \"success\",\"inserted\": 1,\"already_exist\": 0,\"already_exist_movies\": [],\"skipped\": 0,\"skipped_movies\": []}"; var movie = new TraktMovieSearch { ImdbId = "tt0114746", Title = "Twelve Monkeys", Year = 1995, Plays = 1, LastPlayed = new DateTime(2009, 10, 19, 1, 56, 18) }; var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult); //Act var result = mocker.Resolve<MovieProvider>().Library(Constants.ApiKey, "username", "sha1hash", new List<TraktMovieSearch> { movie }); //Assert result.Should().NotBeNull(); result.Status.Should().Be(ResultStatusType.Success); result.Inserted.Should().Be(1); result.Already_Exist.Should().Be(0); result.Already_Exist_Movies.Should().BeEmpty(); result.Skipped.Should().Be(0); result.Skipped_Movies.Should().BeEmpty(); }
public virtual SimpleStatusResult Scrobble(string apiKey, string username, string passwordHash, TraktMovieSearch movie) { var url = String.Format("{0}{1}", Url.MovieScrobble, apiKey); var postJson = new JObject(); postJson.Add(new JProperty("username", username)); postJson.Add(new JProperty("password", passwordHash)); postJson.Add(new JProperty("imdb_id", movie.ImdbId)); postJson.Add(new JProperty("tmdb_id", movie.TmdbId)); postJson.Add(new JProperty("title", movie.Title)); postJson.Add(new JProperty("year", movie.Year)); postJson.Add(new JProperty("duration", movie.Duration)); postJson.Add(new JProperty("progress", movie.Progress)); postJson.Add(new JProperty("plugin_version", movie.PluginVersion)); postJson.Add(new JProperty("media_center_version", movie.MediaCenterVersion)); postJson.Add(new JProperty("media_center_date", movie.MediaCenterDate)); var responseJson = _httpProvider.DownloadString(url, postJson.ToString()); if (String.IsNullOrWhiteSpace(responseJson)) return null; return JsonConvert.DeserializeObject<SimpleStatusResult>(responseJson); }
public void Scrobble_should_return_success() { //Setup var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"imdb_id\": \"tt0372784\",\"tmdb_id\": null,\"title\": \"Batman Begins\",\"year\": 2005,\"duration\": 141,\"progress\": 25,\"plugin_version\": \"1.0\",\"media_center_version\": \"10.0\",\"media_center_date\": \"Dec 17 2010\"}"; var jsonResult = "{\"status\":\"success\",\"message\":\"scrobbled Batman Begins (2005)\"}"; var movie = new TraktMovieSearch { ImdbId = "tt0372784", Title = "Batman Begins", Year = 2005, Duration = 141, Progress = 25, PluginVersion = "1.0", MediaCenterVersion = "10.0", MediaCenterDate = "Dec 17 2010" }; var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult); //Act var result = mocker.Resolve<MovieProvider>().Scrobble(Constants.ApiKey, "username", "sha1hash", movie); //Assert result.Should().NotBeNull(); result.Status.Should().Be(ResultStatusType.Success); result.Message.Should().Be("scrobbled Batman Begins (2005)"); }