public async Task ReturnsSortedList()
            {
                var reviews = await ReviewsClient.GetListByUser(
                    ReviewsUserId,
                    sort : SortReviewsList.AverageRating,
                    order : Order.Descending);

                Assert.NotNull(reviews);

                Review previousReview = null;

                foreach (var currentReview in reviews.List)
                {
                    Assert.NotNull(currentReview);
                    Assert.NotNull(currentReview.Book);
                    Assert.NotNull(currentReview.Book.AverageRating);

                    if (previousReview != null)
                    {
                        Assert.True(previousReview.Book.AverageRating >= currentReview.Book.AverageRating);
                    }

                    previousReview = currentReview;
                }
            }
Example #2
0
            public async Task ReturnsSortedList()
            {
                var reviews = await ReviewsClient.GetListByUser(
                    ReviewsUserId,
                    sort : SortReviewsList.AverageRating,
                    order : Order.Descending);

                Assert.NotNull(reviews);

                Review previousReview = null;

                foreach (var currentReview in reviews.List)
                {
                    Assert.NotNull(currentReview);
                    Assert.NotNull(currentReview.Book);
                    Assert.NotNull(currentReview.Book.AverageRating);

                    if (previousReview != null)
                    {
                        // TODO: Goodreads is currently returning sorted lists wrong. Disable this
                        // assertion for now until they hopefully fix it in the future.
                        // Assert.True(previousReview.Book.AverageRating >= currentReview.Book.AverageRating);
                    }

                    previousReview = currentReview;
                }
            }
            public async Task ReturnsReviews()
            {
                var reviews = await ReviewsClient.GetRecentReviewsForAllMembers();

                Assert.NotNull(reviews);
                Assert.True(reviews.Count > 0);
            }
 public static ReviewsClient CreateReviewClientWithUri(this CommerceClients source, string serviceUrl)
 {
     var client = new ReviewsClient(
         new Uri(serviceUrl),
         source.CreateMessageProcessingHandler());
     return client;
 }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GoodreadsClient"/> class.
        /// Use this constructor if you already have OAuth permissions for the user.
        /// </summary>
        /// <param name="apiKey">Your Goodreads API key.</param>
        /// <param name="apiSecret">Your Goodreads API secret.</param>
        /// <param name="accessToken">The user's OAuth access token.</param>
        /// <param name="accessSecret">The user's OAuth access secret.</param>
        public GoodreadsClient(string apiKey, string apiSecret, string accessToken, string accessSecret)
        {
            var client = new RestClient(new Uri(GoodreadsUrl))
            {
                UserAgent = "goodreads-dotnet"
            };

            client.AddDefaultParameter("key", apiKey, ParameterType.QueryString);
            client.AddDefaultParameter("format", "xml", ParameterType.QueryString);

            var apiCredentials = new ApiCredentials(client, apiKey, apiSecret, accessToken, accessSecret);

            // Setup the OAuth authenticator if they have passed on the appropriate tokens
            if (!string.IsNullOrWhiteSpace(accessToken) &&
                !string.IsNullOrWhiteSpace(accessSecret))
            {
                client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                    apiKey, apiSecret, accessToken, accessSecret);
            }

            Connection = new Connection(client, apiCredentials);
            Authors    = new AuthorsClient(Connection);
            Books      = new BooksClient(Connection);
            Shelves    = new ShelvesClient(Connection);
            Users      = new UsersClient(Connection);
            Reviews    = new ReviewsClient(Connection);
            Series     = new SeriesClient(Connection);
        }
            public async Task ReturnsAReview()
            {
                var expectedId = 1690356266;
                var review     = await ReviewsClient.GetById(expectedId);

                Assert.NotNull(review);
                Assert.Equal(review.Id, expectedId);
            }
Example #7
0
        public static ReviewsClient CreateReviewClientWithUri(this CommerceClients source, string serviceUrl)
        {
            var client = new ReviewsClient(
                new Uri(serviceUrl),
                source.CreateMessageProcessingHandler());

            return(client);
        }
            public async Task ReturnsCorrectPageSize()
            {
                var expectedPageSize = 42;
                var reviews          = await ReviewsClient.GetListByUser(ReviewsUserId, pageSize : expectedPageSize);

                Assert.NotNull(reviews);
                Assert.Equal(reviews.Pagination.End, expectedPageSize);
                Assert.Equal(reviews.List.Count, expectedPageSize);
            }
            public async Task CreateAndDeleteAReview()
            {
                var reviewId = await ReviewsClient.Create(10790277);

                Assert.NotNull(reviewId);

                ////var result = await ReviewsClient.Delete(1700138017);
                ////Assert.True(result);
            }
            public async Task ReturnsAReview()
            {
                var expectedBookId = 7235533;
                var review         = await ReviewsClient.GetByUserIdAndBookId(UserId, expectedBookId);

                Assert.NotNull(review);
                Assert.NotNull(review.Book);
                Assert.NotNull(review.User);
                Assert.Equal(review.User.Id, UserId);
                Assert.Equal(review.Book.Id, expectedBookId);
            }
            public async Task ReturnsAReviewOnADifferentEdition()
            {
                var expectedBookId         = 7235533;
                var differentEditionBookId = 10063939;
                var review = await ReviewsClient.GetByUserIdAndBookId(
                    UserId,
                    differentEditionBookId,
                    findReviewOnDifferentEdition : true);

                Assert.NotNull(review);
                Assert.NotNull(review.Book);
                Assert.NotNull(review.User);
                Assert.Equal(review.User.Id, UserId);
                Assert.Equal(review.Book.Id, expectedBookId);
            }
            public async Task EditRatingSucceeds()
            {
                var reviewBeforeEdit = await ReviewsClient.GetById(EditReviewId);

                var ratingBeforeEdit  = reviewBeforeEdit.Rating;
                var expectedNewRating = ratingBeforeEdit == 5 ? 4 : 5;
                var result            = await ReviewsClient.Edit(EditReviewId, rating : expectedNewRating);

                Assert.True(result);

                var reviewAfterEdit = await ReviewsClient.GetById(EditReviewId);

                var actualRatingAfterEdit = reviewAfterEdit.Rating;

                Assert.Equal(expectedNewRating, actualRatingAfterEdit);
            }
        private CommerceService()
        {
            this._listClient      = ClientContext.Clients.CreateListClient();
            this._browseClient    = ClientContext.Clients.CreateBrowseClient();
            this._storeClient     = ClientContext.Clients.CreateStoreClient();
            this._cartClient      = ClientContext.Clients.CreateCartClient();
            this._orderClient     = ClientContext.Clients.CreateOrderClient();
            this._priceClient     = ClientContext.Clients.CreatePriceClient();
            this._marketingClient = ClientContext.Clients.CreateMarketingClient();
            this._themeClient     = ClientContext.Clients.CreateThemeClient();
            this._reviewsClient   = ClientContext.Clients.CreateReviewsClient();

            _themesCacheStoragePath = ConfigurationManager.AppSettings["ThemeCacheFolder"];
            this._viewLocator       = new FileThemeViewLocator(_themesCacheStoragePath);
            this._cartHelper        = new CartHelper(this);
        }
            public async Task EditReadDateSucceeds()
            {
                var reviewBeforeEdit = await ReviewsClient.GetById(EditReviewId);

                var dateBeforeEdit  = reviewBeforeEdit.DateRead;
                var expectedNewDate = dateBeforeEdit.Value.Date >= DateTime.UtcNow.Date ? DateTime.UtcNow.Date.AddDays(-7) : DateTime.UtcNow.Date;

                var result = await ReviewsClient.Edit(EditReviewId, dateRead : expectedNewDate);

                Assert.True(result);

                var reviewAfterEdit = await ReviewsClient.GetById(EditReviewId);

                var actualNewDate = reviewAfterEdit.DateRead;

                Assert.NotNull(actualNewDate);
                Assert.True(dateBeforeEdit.Value.Date != actualNewDate.Value.Date);
            }
            public async Task EditReviewTextSucceeds()
            {
                var reviewBeforeEdit = await ReviewsClient.GetById(EditReviewId);

                var textBeforeEdit  = reviewBeforeEdit.Body.Trim();
                var match           = Regex.Match(textBeforeEdit, @".*(\d+)");
                var testNumber      = int.Parse(match.Groups[1].Value);
                var expectedNewText = textBeforeEdit.Replace(testNumber.ToString(), (testNumber + 1).ToString());

                var result = await ReviewsClient.Edit(EditReviewId, reviewText : expectedNewText);

                Assert.True(result);

                var reviewAfterEdit = await ReviewsClient.GetById(EditReviewId);

                var actualNewText = reviewAfterEdit.Body.Trim();

                Assert.Equal(expectedNewText, actualNewText);
            }
Example #16
0
        public CommerceService()
        {
            this._listClient      = ClientContext.Clients.CreateListClient();
            this._browseClient    = ClientContext.Clients.CreateBrowseClient();
            this._storeClient     = ClientContext.Clients.CreateStoreClient();
            this._cartClient      = ClientContext.Clients.CreateCartClient();
            this._orderClient     = ClientContext.Clients.CreateOrderClient();
            this._securityClient  = ClientContext.Clients.CreateSecurityClient();
            this._priceClient     = ClientContext.Clients.CreatePriceClient();
            this._marketingClient = ClientContext.Clients.CreateMarketingClient();
            this._inventoryClient = ClientContext.Clients.CreateInventoryClient();
            this._themeClient     = ClientContext.Clients.CreateThemeClient();
            this._pageClient      = ClientContext.Clients.CreatePageClient();
            this._reviewsClient   = ClientContext.Clients.CreateReviewsClient();

            _themesCacheStoragePath = ConfigurationManager.AppSettings["ThemeCacheFolder"];
            _pagesCacheStoragePath  = ConfigurationManager.AppSettings["PageCacheFolder"];

            this._viewLocator = new FileThemeViewLocator(HostingEnvironment.MapPath(_themesCacheStoragePath));

            this._cartHelper = new CartHelper(this);
        }
 public static ReviewsClient CreateReviewClient(this CommerceClients source, string serviceUrl, string appId, string secretKey)
 {
     var client = new ReviewsClient(new Uri(serviceUrl), appId, secretKey);
     return client;
 }
            public async Task ReturnsNullIfCannotCreate()
            {
                var reviewId = await ReviewsClient.Create(int.MaxValue);

                Assert.Null(reviewId);
            }
        public static ReviewsClient CreateReviewClient(this CommerceClients source, string serviceUrl, string appId, string secretKey)
        {
            var client = new ReviewsClient(new Uri(serviceUrl), appId, secretKey);

            return(client);
        }
            public async Task ReturnsReviews()
            {
                var reviews = await ReviewsClient.GetListByUser(ReviewsUserId);

                Assert.NotNull(reviews);
            }