public void ConnectionTimeout_is_optional() { var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .Build(); // Default value (client as DefaultClient).ConnectionTimeout.ShouldBe(20 * 1000); }
public void AuthenticationScheme_is_optional() { var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .Build(); // Defaults to SAuthc1 (client as DefaultClient).AuthenticationScheme.ShouldBe(AuthenticationScheme.SAuthc1); }
public void Throws_for_invalid_API_key() { Assert.Throws <ArgumentException>(() => { this.builder .SetApiKey(FakeApiKey.Create(valid: false)) .Build(); }); }
public void Passing_disabled_cache() { var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .SetCacheProvider(SDK.Cache.Caches.NewDisabledCacheProvider()) .Build(); client.GetCacheProvider().ShouldBeOfType <NullCacheProvider>(); }
public void BaseUrl_is_optional() { var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .Build(); // Default value (client as DefaultClient).BaseUrl.ShouldBe("https://api.stormpath.com/v1"); }
public void Passing_custom_cache() { var fakeCache = Substitute.For <SDK.Cache.ICacheProvider>(); var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .SetCacheProvider(fakeCache) .Build(); client.GetCacheProvider().ShouldBe(fakeCache); }
public void Default_cache_is_InMemoryCache() { var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .Build(); // Default value client.GetCacheProvider().ShouldBeOfType <InMemoryCacheProvider>(); (client.GetCacheProvider() as InMemoryCacheProvider).DefaultTimeToIdle.ShouldBe(TimeSpan.FromHours(1)); (client.GetCacheProvider() as InMemoryCacheProvider).DefaultTimeToLive.ShouldBe(TimeSpan.FromHours(1)); }
public void Passing_custom_HttpClient() { var fakeHttpClient = Substitute.For <Http.IHttpClient>(); var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .SetHttpClient(fakeHttpClient) .Build(); (client as DefaultClient).HttpClient.ShouldBe(fakeHttpClient); (client as DefaultClient).Serializer.ShouldBeOfType <JsonNetSerializer>(); }
public void Looks_for_default_ClientApiKey_if_none_specified() { var fakeKey = FakeApiKey.Create(valid: true); var fakeClientApiKeyBuilder = Substitute.For <IClientApiKeyBuilder>(); fakeClientApiKeyBuilder.Build().Returns(fakeKey); IClientBuilder builder = new DefaultClientBuilder(fakeClientApiKeyBuilder, new FakeUserAgentBuilder()); var client = builder.Build(); (client as DefaultClient).ApiKey.ShouldBe(fakeKey); }
public void Passing_custom_JsonSerializer() { var fakeSerializer = Substitute.For <Serialization.IJsonSerializer>(); var client = this.builder .SetApiKey(FakeApiKey.Create(valid: true)) .SetSerializer(fakeSerializer) .Build(); (client as DefaultClient).HttpClient.ShouldBeOfType <RestSharpClient>(); (client as DefaultClient).Serializer.ShouldBe(fakeSerializer); }
protected void InitializeClientWithCollection(IEnumerable <T> items) { this.FakeHttpClient = new CollectionReturningHttpClient <T>(this.BaseUrl, items); var client = Clients.Builder() .SetApiKey(FakeApiKey.Create(valid: true)) .SetBaseUrl(this.BaseUrl) .SetHttpClient(this.FakeHttpClient) .Build(); this.Queryable = new CollectionResourceQueryable <T>(this.BaseUrl, (client as DefaultClient).DataStore); }
private static IRequestExecutor GetRequestExecutor(IHttpClient client, IBackoffStrategy defaultStrategy = null, IBackoffStrategy throttlingStrategy = null) { var defaultBackoffStrategy = defaultStrategy ?? GetFakeBackoffStrategy(); var throttlingBackoffStrategy = throttlingStrategy ?? GetFakeBackoffStrategy(); return(new DefaultRequestExecutor( client, FakeApiKey.Create(valid: true), AuthenticationScheme.Basic, Substitute.For <ILogger>(), defaultBackoffStrategy, throttlingBackoffStrategy)); }
public async Task Csharp_code_creates_csharp_user_agent() { var fakeHttpClient = new ResourceReturningHttpClient("http://foo.bar", FakeJson.Account); var client = Clients.Builder() .SetApiKey(FakeApiKey.Create(valid: true)) .SetBaseUrl("http://foo.bar/") .SetHttpClient(fakeHttpClient) .SetCacheProvider(Cache.Caches.NewDisabledCacheProvider()) .Build(); var tenant = await client.GetResourceAsync <IAccount>("http://foo.bar/fooAccount"); var userAgent = fakeHttpClient.Calls.Single().Headers.UserAgent; userAgent.Split(' ').Count(x => x.StartsWith("lang")).ShouldBe(1); userAgent.ShouldContain("lang/csharp"); }