Beispiel #1
0
        public async Task EbayRestClient_Should_ThrowEbayException()
        {
            var moqAuth = Substitute.For <IOAuth2Authenticator>();

            moqAuth.GetTokenAsync().Returns(new Token
            {
                AccessToken = "randomtoken"
            });

            var restClient = new EbayRestClient
            {
                OAuth2Authenticator = moqAuth
            };

            IFlurlRequest flurl = "/some/path"
                                  .AppendPathSegment($"to", fullyEncode: true)
                                  .WithHeader("header", "value");

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith("Resource Not Found", 404);

                await Assert.ThrowsAsync <EbayException>(async() => await restClient.Request <object>(flurl));
            }
        }
Beispiel #2
0
        // /item/{item_id}
        public async Task <ItemModel> GetItem(string itemId)
        {
            var item = await _ebayRestClient.Request <ItemModel>(
                _itemUrl
                .AppendPathSegment($"v1|{itemId}|0", fullyEncode : true)
                .WithHeaders(
                    new
            {
                Content_Type        = "application/json",
                X_EBAY_C_ENDUSERCTX = "contextualLocation=country=<2_character_country_code>,zip=<zip_code>,affiliateCampaignId=<ePNCampaignId>,affiliateReferenceId=<referenceId>"
            }, replaceUnderscoreWithHyphen : true)
                )
                       .ConfigureAwait(false);

            return(item);
        }
Beispiel #3
0
        public async Task <ItemSummaryCollectionModel> Search(string search, int limit = 50)
        {
            var item = await _ebayRestClient.Request <ItemSummaryCollectionModel>(
                _itemSummaryUrl
                .AppendPathSegment($"?q={search}&limit={limit}", fullyEncode : true)
                .WithHeaders(
                    new
            {
                Content_Type        = "application/json",
                X_EBAY_C_ENDUSERCTX = "contextualLocation=country=<2_character_country_code>,zip=<zip_code>,affiliateCampaignId=<ePNCampaignId>,affiliateReferenceId=<referenceId>"
            }, replaceUnderscoreWithHyphen : true)
                )
                       .ConfigureAwait(false);

            return(item);
        }
Beispiel #4
0
        public async Task EbayRestClient_ShouldCorrectlyAdd_AuthTokenToRequest()
        {
            var moqAuth = Substitute.For <IOAuth2Authenticator>();

            moqAuth.GetTokenAsync().Returns(new Token
            {
                AccessToken = "randomtoken"
            });

            var restClient = new EbayRestClient
            {
                OAuth2Authenticator = moqAuth
            };

            IFlurlRequest flurl = "/some/path"
                                  .AppendPathSegment($"to", fullyEncode: true)
                                  .AppendPathSegment($"ebay", fullyEncode: true)
                                  .WithHeader("header", "value")
                                  .WithHeaders(
                new
            {
                Content_Type = "application/json",
            }, replaceUnderscoreWithHyphen: true);

            using (var httpTest = new HttpTest())
            {
                var response = await restClient.Request <object>(flurl);

                httpTest
                .ShouldHaveCalled("https://api.ebay.com/some/path/to/ebay")
                .WithContentType("application/json")
                .WithHeader("Authorization", "Bearer randomtoken")
                .WithHeader("header", "value")
                .Times(1);
            }
        }