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
        public async Task GetLegacyItem_ShouldResolve_UrlCorrectly()
        {
            var moqAuth = Substitute.For <IOAuth2Authenticator>();

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

            var restClient = new EbayRestClient
            {
                OAuth2Authenticator = moqAuth
            };

            var item = new Item(restClient);

            using (var httpTest = new HttpTest())
            {
                var itemModel = await item.GetItemByLegacyId("123");

                httpTest
                .ShouldHaveCalled("https://api.ebay.com/buy/browse/v1/item/get_item_by_legacy_id/%3Flegacy_item_id%3D123")
                .WithContentType("application/json")
                .WithHeader("Authorization", "Bearer randomtoken")
                .WithHeader("X-EBAY-C-ENDUSERCTX", "*")
                .Times(1);
            }
        }
Beispiel #3
0
        public async Task GetItem_ShouldResolve_UrlCorrectly_Sandbox()
        {
            var moqAuth = Substitute.For <IOAuth2Authenticator>();

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

            var restClient = new EbayRestClient
            {
                OAuth2Authenticator = moqAuth,
                UrlService          = new UrlService(EbayNet.Environment.Sandbox)
            };

            var item = new Item(restClient);

            using (var httpTest = new HttpTest())
            {
                var itemModel = await item.GetItem("123");

                httpTest
                .ShouldHaveCalled("https://api.sandbox.ebay.com/buy/browse/v1/item/v1%7C123%7C0")
                .WithContentType("application/json")
                .WithHeader("Authorization", "Bearer randomtoken")
                .WithHeader("X-EBAY-C-ENDUSERCTX", "*")
                .Times(1);
            }
        }
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);
            }
        }
Beispiel #5
0
        public void EbayRestClient_ShouldHave_CorrectDefaultUrlService()
        {
            var restClient = new EbayRestClient();

            restClient.UrlService.Environment.Should().Be(EbayNet.Environment.Production);
        }
Beispiel #6
0
 public ItemSummary(EbayRestClient ebayRestClient)
 {
     _ebayRestClient = ebayRestClient;
 }
Beispiel #7
0
 public Item(EbayRestClient ebayRestClient)
 {
     _ebayRestClient = ebayRestClient;
 }
Beispiel #8
0
 public BrowseAPI(EbayRestClient ebayRestClient)
 {
     Item        = new Item(ebayRestClient);
     ItemSummary = new ItemSummary(ebayRestClient);
 }