Exemplo n.º 1
0
        public void WithExponentialBackoffOn()
        {
            var defaultBackOff = new ClientConfig.Builder()
            {
                Hostname                 = ClientConfig.Environments.Sandbox,
                ConsumerKey              = "key",
                ConsumerSecret           = "secret",
                ExponentialBackoffConfig = new ExponentialBackoffConfig.On(5, 500, (res, t) => {
                    Console.WriteLine("RETRYING");
                })
            };
            var client = new Client.Impl.HttpClient(defaultBackOff, "http", "localhost", port, ServiceUnavailableMockModule.BasePath);

            var task1 = client.sendAsyncRequestWithResult(HttpMethod.Post, "first", "");

            task1.Wait();
            Assert.AreEqual("first", task1.Result);

            var task2 = client.sendAsyncRequestWithResult(HttpMethod.Post, "second", "");

            task2.Wait();
            Assert.AreEqual("second", task2.Result);

            var task3 = client.sendAsyncRequestWithResult(HttpMethod.Post, "third", "");

            task3.Wait();
            Assert.AreEqual("third", task3.Result);
        }
        public void ClientCredentialHandlerFetchingToken()
        {
            ClientConfig config = new ClientConfig.Builder()
            {
                Environment    = Environment,
                ConsumerKey    = ConsumerKeyValue,
                ConsumerSecret = ConsumerSecretValue
            };

            ClientFactory.Create(config);
        }
Exemplo n.º 3
0
        public void InitializationWithToken()
        {
            var otherConfig =
                new ClientConfig.Builder()
            {
                Hostname = ClientConfig.Environments.Sandbox,
                Token    = "token"
            };
            var client = new Client.Impl.HttpClient(otherConfig, "http", "localhost", port, SucceedAPIsMockModule.BasePath);
            var task   = client.sendAsyncRequestWithResult(HttpMethod.Post, "tokencheck");

            task.Wait();
            Assert.AreEqual("Bearer token", task.Result);
        }
Exemplo n.º 4
0
        public void ByDefaultNoExponentialBackoff()
        {
            var defaultBackOff = new ClientConfig.Builder()
            {
                Hostname       = ClientConfig.Environments.Sandbox,
                ConsumerKey    = "key",
                ConsumerSecret = "secret"
            };
            var client = new Client.Impl.HttpClient(defaultBackOff, "http", "localhost", port, ServiceUnavailableMockModule.BasePath);

            Assert.That(() => client.sendAsyncRequestWithResult(HttpMethod.Post, "first", "").Wait(),
                        Throws.TypeOf <AggregateException>()
                        .With.InnerException.TypeOf <InvalidOperationException>()
                        .With.InnerException.Message.EqualTo("status code: ServiceUnavailable, message service out"));
        }
        public void ConfigBuilderDefaulConfig()
        {
            ClientConfig config = new ClientConfig.Builder()
            {
                Environment    = ClientConfig.Environments.Sandbox,
                ConsumerKey    = "CK",
                ConsumerSecret = "CS"
            };

            Assert.AreEqual(config.Environment, ClientConfig.Environments.Sandbox);
            Assert.AreEqual(config.ConsumerKey, "CK");
            Assert.AreEqual(config.ConsumerSecret, "CS");
            Assert.AreEqual(config.ClientTimeout, ClientConfig.Builder.DefaultTimeout);
            Assert.AreEqual(config.MaxResponseContentBufferSize, ClientConfig.Builder.DefaultMaxResponseCcontentBufferSize);
        }
Exemplo n.º 6
0
        public void CompressionEnabledForceTrue()
        {
            var configWithCompression = new ClientConfig.Builder()
            {
                Hostname           = ClientConfig.Environments.Sandbox,
                ConsumerKey        = "key",
                ConsumerSecret     = "secret",
                CompressionEnabled = true
            };

            var client = new Client.Impl.HttpClient(configWithCompression, "http", "localhost", port, SucceedAPIsMockModule.BasePath);
            var task   = client.sendAsyncRequestWithResult(HttpMethod.Post, "compressed", SucceedAPIsMockModule.TestJsonString);

            task.Wait();

            Assert.AreEqual(SucceedAPIsMockModule.TestJsonString, task.Result);
        }
        public void ConfigBuilderAdvanceConfig()
        {
            ClientConfig config = new ClientConfig.Builder()
            {
                Environment    = ClientConfig.Environments.Sandbox,
                ConsumerKey    = "CK",
                ConsumerSecret = "CS",
                ClientTimeout  = 155,
                MaxResponseContentBufferSize = 166
            };

            Assert.AreEqual(config.Environment, ClientConfig.Environments.Sandbox);
            Assert.AreEqual(config.ConsumerKey, "CK");
            Assert.AreEqual(config.ConsumerSecret, "CS");
            Assert.AreEqual(config.ClientTimeout, 155);
            Assert.AreEqual(config.MaxResponseContentBufferSize, 166);
        }
        public void ConfigBuilderDefaulConfigWithClientParameters()
        {
            ClientConfig config = new ClientConfig.Builder()
            {
                Environment    = ClientConfig.Environments.Sandbox,
                ConsumerKey    = "CK",
                ConsumerSecret = "CS",
                ClientTimeout  = 50000,
                MaxResponseContentBufferSize = 1000000
            };

            Assert.AreEqual(config.Environment, ClientConfig.Environments.Sandbox);
            Assert.AreEqual(config.ConsumerKey, "CK");
            Assert.AreEqual(config.ConsumerSecret, "CS");
            Assert.AreEqual(config.ClientTimeout, 50000);
            Assert.AreEqual(config.MaxResponseContentBufferSize, 1000000);
        }
Exemplo n.º 9
0
        public void ConfigBuilderAdvanceConfig()
        {
            ClientConfig config = new ClientConfig.Builder()
            {
                Hostname       = ClientConfig.Environments.Sandbox,
                ConsumerKey    = "CK",
                ConsumerSecret = "CS",
                ClientTimeout  = 155,
                MaxResponseContentBufferSize = 166,
                CompressionEnabled           = true
            };

            Assert.AreEqual(config.Hostname, ClientConfig.Environments.Sandbox);
            Assert.AreEqual(config.ConsumerKey, "CK");
            Assert.AreEqual(config.ConsumerSecret, "CS");
            Assert.AreEqual(config.ClientTimeout, 155);
            Assert.AreEqual(config.MaxResponseContentBufferSize, 166);
            Assert.AreEqual(config.CompressionEnabled, true);
        }
        public void ClientCredentialBadRequestToken(
            string consumerKey,
            string consumerSecret)
        {
            ClientConfig config = new ClientConfig.Builder()
            {
                Environment    = ClientConfig.Environments.Sandbox,
                ConsumerKey    = consumerKey,
                ConsumerSecret = consumerSecret
            };

            Assert.That(() =>
            {
                var client = ClientFactory.Create(config);
                client.Owners.Delete("unknown");
            },
                        Throws.TypeOf <InvalidOperationException>()
                        .With.Message.EqualTo("Error fetching token..."));
        }
Exemplo n.º 11
0
        public void ConfigBuilderAdvanceConfigWrongValues(
            string environment,
            string securityConsumerKey,
            string securityConsumerSecret,
            int clientTimeout,
            long maxResponseContentBufferSize,
            string errorMsg)
        {
            ClientConfig config;

            Assert.That(() => config = new ClientConfig.Builder()
            {
                Hostname       = environment,
                ConsumerKey    = securityConsumerKey,
                ConsumerSecret = securityConsumerSecret,
                ClientTimeout  = clientTimeout,
                MaxResponseContentBufferSize = maxResponseContentBufferSize
            },
                        Throws.TypeOf <ArgumentException>()
                        .With.Message.EqualTo(errorMsg));
        }