예제 #1
0
        public void when_listing_tax_categories()
        {
            var stubHttp = HttpMockRepository.At("http://localhost:9191");

            stubHttp.Stub(x => x.Get("/v2/categories"))
            .Return(TaxjarFixture.GetJSON("categories.json"))
            .OK();

            var categories = client.Categories();

            Assert.AreEqual(7, categories.Count);
            Assert.AreEqual("Digital Goods", categories[0].Name);
            Assert.AreEqual("31000", categories[0].ProductTaxCode);
            Assert.AreEqual("Digital products transferred electronically, meaning obtained by the purchaser by means other than tangible storage media.", categories[0].Description);
        }
예제 #2
0
        public void returns_exception_with_invalid_api_token()
        {
            this.client = new TaxjarApi("foo123", new { apiUrl = "http://localhost:9191/v2/" });

            var stubHttp = HttpMockRepository.At("http://localhost:9191");

            stubHttp.Stub(x => x.Get("/v2/categories"))
            .Return("{\"error\":\"Unauthorized\",\"detail\":\"Not authorized for route 'GET /v2/categories'\",\"status\":401}")
            .WithStatus(HttpStatusCode.Unauthorized);

            var taxjarException = Assert.Throws <TaxjarException>(() => client.Categories());

            Assert.AreEqual(HttpStatusCode.Unauthorized, taxjarException.HttpStatusCode);
            Assert.AreEqual("Unauthorized", taxjarException.TaxjarError.Error);
            Assert.AreEqual("Not authorized for route 'GET /v2/categories'", taxjarException.TaxjarError.Detail);
            Assert.AreEqual("401", taxjarException.TaxjarError.StatusCode);
        }