public virtual RateResult Show(string apiKey, RateShow show) { var url = String.Format("{0}{1}", Url.RateShow, apiKey); var postJson = Serializer.SerializeObject(show); var responseJson = _httpProvider.DownloadString(url, postJson); if (String.IsNullOrWhiteSpace(responseJson)) return null; return JsonConvert.DeserializeObject<RateResult>(responseJson); }
public void RateShow_unrate_should_return_RateResult_on_success() { //Setup var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 213221,\"title\": \"Portlandia\",\"year\": 2011,\"rating\": \"unrate\"}"; var jsonResult = "{\"status\":\"success\",\"message\":\"rated Portlandia 1x01\",\"type\":\"episode\",\"rating\":\"unrate\",\"ratings\":{\"percentage\":100,\"votes\":2,\"loved\":2,\"hated\":0},\"facebook\":true,\"twitter\":true,\"tumblr\":false}"; var show = new RateShow { Username = "******", Password = "******", TvdbId = 213221, Title = "Portlandia", Year = 2011, Rating = RatingType.Unrate }; 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<RateProvider>().Show(Constants.ApiKey, show); //Assert result.Should().NotBeNull(); result.Status.Should().Be(ResultStatusType.Success); result.Rating.Should().Be(RatingType.Unrate); result.Facebook.Should().BeTrue(); result.Type.Should().Be(TraktType.Episode); }