<commit_before>﻿using NUnit.Framework;
using Phaxio.Entities;
using Phaxio.Errors.V2;
using Phaxio.Tests.Helpers;
using System;

namespace Phaxio.Tests.UnitTests.V2
{
    [TestFixture]
    public class PhaxioClientTests
    {
        [Test]
        public void UnitTests_V2_NonJsonErrorHandled()
        {
            var requestAsserts = new RequestAsserts()
                .Auth()
                .Get()
                .Resource("account/status")
                .Build();

            var restClient = new RestClientBuilder()
                .WithRequestAsserts(requestAsserts)
                .AsText()
                .Content("There was an error")
                .InternalServerError()
                .Build<Response<AccountStatus>>();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            Assert.Throws(typeof(ServiceException), () => Console.Write(phaxio.Account.Status.Balance));
        }

        [Test]
        public void UnitTests_V2_RateLimitException()
        {
            var requestAsserts = new RequestAsserts()
                .Auth()<commit_msg>Adding test to verify that PlaxioClient.download will throw an exception on error.<commit_after>﻿using NUnit.Framework;
using Phaxio.Entities;
using Phaxio.Errors.V2;
using Phaxio.Resources.V2;
using Phaxio.Tests.Helpers;
using System;

namespace Phaxio.Tests.UnitTests.V2
{
    [TestFixture]
    public class PhaxioClientTests
    {
        [Test]
        public void UnitTests_V2_NonJsonErrorHandled()
        {
            var requestAsserts = new RequestAsserts()
                .Auth()
                .Get()
                .Resource("account/status")
                .Build();

            var restClient = new RestClientBuilder()
                .WithRequestAsserts(requestAsserts)
                .AsText()
                .Content("There was an error")
                .InternalServerError()
                .Build<Response<AccountStatus>>();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            Assert.Throws(typeof(ServiceException), () => Console.Write(phaxio.Account.Status.Balance));
        }

        [Test]
        public void UnitTests_V2_FileDownloadThrowsError()
        {
            var requestAsserts = new RequestAsserts()
                .Auth()
                .Get()
                .Resource("faxes/123456/file")
                .Build();

            var restClient = new RestClientBuilder()
                .WithRequestAsserts(requestAsserts)
                .AsJson()
                .Content(JsonResponseFixtures.FromFile("V2/error_rate_limited"))
                .RateLimited()
                .Build();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var fax = new FaxFile(123456);
            fax.PhaxioClient = phaxio;

            Assert.Throws(typeof(RateLimitException), () => Console.Write(fax.Pdf.Bytes));
        }

        [Test]
        public void UnitTests_V2_RateLimitException()
        {
            var requestAsserts = new RequestAsserts()
                .Auth()
{'fraction_non_alphanumeric': 0.09418713086726764, 'fraction_numerical': 0.007149518184644078, 'mean_word_length': 1.9017132551848512, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5990163', 'n_tokens_mistral': 907, 'n_tokens_neox': 857, 'n_words': 161}