public async void CanHandleExceptionsThatAreThrown()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            // modify the token to ensure it's bad
            client.Options.ThrowOnFail = true; // throw error if not a success status code
            var previousToken = client.Options.Token;
            client.Options.Token = Guid.NewGuid().ToString("N").ToLower();

            try
            {
                var response = await client.CallbackList(request);
            }
            catch (FreshBooksException ex)
            {
                Assert.AreEqual(HttpStatusCode.Unauthorized, ex.StatusCode);
                Assert.AreEqual("Unauthorized", ex.Message);
                Assert.AreEqual("Authentication failed.", ex.error);
                throw;
            }
            finally
            {
                // reset the token for future tests
                client.Options.Token = previousToken;
                client.Options.ThrowOnFail = false;
            }
        }
        public async void CanHandleExceptionsThatAreThrown()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            // modify the token to ensure it's bad
            client.Options.ThrowOnFail = true; // throw error if not a success status code
            var previousToken = client.Options.Token;

            client.Options.Token = Guid.NewGuid().ToString("N").ToLower();

            try
            {
                var response = await client.CallbackList(request);
            }
            catch (FreshBooksException ex)
            {
                Assert.AreEqual(HttpStatusCode.Unauthorized, ex.StatusCode);
                Assert.AreEqual("Unauthorized", ex.Message);
                Assert.AreEqual("Authentication failed.", ex.error);
                throw;
            }
            finally
            {
                // reset the token for future tests
                client.Options.Token       = previousToken;
                client.Options.ThrowOnFail = false;
            }
        }
        public async void CanHandleSuccess()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            var response = await client.CallbackList(request);

            Assert.AreEqual("ok", response.status);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
        public async void CanHandleSuccess()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            var response = await client.CallbackList(request);

            Assert.AreEqual("ok", response.status);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Exemplo n.º 5
0
        public async void CanListCallbacksAsync()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            var response = await client.CallbackList(request);

            Assert.IsTrue(response.status == "ok");
            if (response.callbacks.pages > 0)
            {
                Assert.IsNotNull(response.callbacks.callback);
                Assert.GreaterOrEqual(response.callbacks.callback.Length, 0);
            } else
            {
                Assert.IsNull(response.callbacks.callback);
            }
        }
        public async void CanHandleExceptionsThatDoNotThrow()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            // modify the token to ensure it's bad
            var previousToken = client.Options.Token;
            client.Options.Token = Guid.NewGuid().ToString("N").ToLower();

            var response = await client.CallbackList(request);

            // reset the token for future tests
            client.Options.Token = previousToken;

            Assert.AreEqual("fail", response.status);
            Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
            Assert.AreEqual("Authentication failed.", response.error);
        }
        public void CanSerializeRequestCorrectly()
        {
            var validRequest = @"
<?xml version=""1.0"" encoding=""utf-8""?>  
<request method=""callback.list"">
  <event>invoice.create</event>
  <uri>http://example.com/webhooks/ready</uri>
</request>".Trim();

            var request = new CallbackList.request();
            request.@event = EventNames.invoice_create;
            request.uri = "http://example.com/webhooks/ready";
            var actual = request.ToXmlString();

            // strip new lines to ensure the same rules apply
            actual = new Regex(@">\s*<").Replace(actual, "><");
            validRequest = new Regex(@">\s*<").Replace(validRequest, "><");

            Assert.AreEqual(validRequest, actual);
        }
Exemplo n.º 8
0
        public async void CanListCallbacksAsync()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            var response = await client.CallbackList(request);

            Assert.IsTrue(response.status == "ok");
            if (response.callbacks.pages > 0)
            {
                Assert.IsNotNull(response.callbacks.callback);
                Assert.GreaterOrEqual(response.callbacks.callback.Length, 0);
            }
            else
            {
                Assert.IsNull(response.callbacks.callback);
            }
        }
        public void CanSerializeRequestCorrectly()
        {
            var validRequest = @"
<?xml version=""1.0"" encoding=""utf-8""?>  
<request method=""callback.list"">
  <event>invoice.create</event>
  <uri>http://example.com/webhooks/ready</uri>
</request>".Trim();

            var request = new CallbackList.request();

            request.@event = EventNames.invoice_create;
            request.uri    = "http://example.com/webhooks/ready";
            var actual = request.ToXmlString();

            // strip new lines to ensure the same rules apply
            actual       = new Regex(@">\s*<").Replace(actual, "><");
            validRequest = new Regex(@">\s*<").Replace(validRequest, "><");

            Assert.AreEqual(validRequest, actual);
        }
        public async void CanHandleExceptionsThatDoNotThrow()
        {
            var request = new CallbackList.request()
            {
                @event = EventNames.invoice_create
            };

            // modify the token to ensure it's bad
            var previousToken = client.Options.Token;

            client.Options.Token = Guid.NewGuid().ToString("N").ToLower();

            var response = await client.CallbackList(request);

            // reset the token for future tests
            client.Options.Token = previousToken;

            Assert.AreEqual("fail", response.status);
            Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
            Assert.AreEqual("Authentication failed.", response.error);
        }