Exemple #1
0
        public virtual RateResult Movie(string apiKey, RateMovie movie)
        {
            var url = String.Format("{0}{1}", Url.RateMovie, apiKey);
            var postJson = Serializer.SerializeObject(movie);
            var responseJson = _httpProvider.DownloadString(url, postJson);

            if (String.IsNullOrWhiteSpace(responseJson))
                return null;

            return JsonConvert.DeserializeObject<RateResult>(responseJson);
        }
        public void RateMovie_should_return_RateResult_on_success()
        {
            //Setup
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"imdb_id\": \"tt0082971\",\"title\": \"Indiana Jones and the Raiders of the Lost Ark\",\"year\": 1981,\"rating\": \"hate\"}";
            var jsonResult = "{\"status\":\"success\",\"message\":\"rated Indiana Jones and the Raiders of the Lost Ark (1981)\",\"type\":\"movie\",\"rating\":\"hate\",\"ratings\":{\"percentage\":100,\"votes\":15,\"loved\":15,\"hated\":0},\"facebook\":true,\"twitter\":true,\"tumblr\":false}";

            var movie = new RateMovie
            {
                Username = "******",
                Password = "******",
                ImdbId = "tt0082971",
                Title = "Indiana Jones and the Raiders of the Lost Ark",
                Year = 1981,
                Rating = RatingType.Hate
            };

            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>().Movie(Constants.ApiKey, movie);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Rating.Should().Be(RatingType.Hate);
            result.Facebook.Should().BeTrue();
            result.Type.Should().Be(TraktType.Movie);
        }