public void Test_NoRateLimiter_TooManyRequest_Error()
        {
            var connector = new CustomerConnector();

            connector.UseRateLimiter = false;

            FortnoxApiException error = null;
            int i;

            for (i = 0; i < 200; i++)
            {
                var searchSettings = new CustomerSearch();
                searchSettings.City = TestUtils.RandomString();
                try
                {
                    connector.Find(searchSettings);
                }
                catch (FortnoxApiException ex)
                {
                    error = ex;
                    break;
                }
            }

            //Assert
            //Assert.IsTrue(failed > 0);
            Console.WriteLine($@"Succesful requests: {i}");
            Assert.IsNotNull(error);
            Console.WriteLine(error.Message);
            Assert.IsTrue(error.Message.Contains("Too Many Requests"));

            Thread.Sleep(5 * 1000); //Sleep to cooldown/recover from "debt" (otherwise following tests will fail with TooManyRequests)
        }
Esempio n. 2
0
    public async Task Test_NoRateLimiter_TooManyRequest_Error()
    {
        var fortnoxClient = new FortnoxClient()
        {
            Authorization  = new StaticTokenAuth(TestCredentials.Access_Token, TestCredentials.Client_Secret),
            UseRateLimiter = false
        };

        var connector = fortnoxClient.CustomerConnector;

        FortnoxApiException error = null;
        int i;

        for (i = 0; i < 200; i++)
        {
            var searchSettings = new CustomerSearch();
            searchSettings.City = TestUtils.RandomString();
            try
            {
                await connector.FindAsync(searchSettings);
            }
            catch (FortnoxApiException ex)
            {
                error = ex;
                break;
            }
        }

        //Assert
        //Assert.IsTrue(failed > 0);
        Console.WriteLine($@"Succesful requests: {i}");
        Assert.IsNotNull(error);
        Console.WriteLine(error.Message);
        Assert.IsTrue(error.Message.Contains("Too Many Requests"));

        Thread.Sleep(5 * 1000); //Sleep to cooldown/recover from "debt" (otherwise following tests will fail with TooManyRequests)
    }