public async Task GetAuthenticationToken_ReturnsCorrectSignature(Int32 timestamp, String method, String request, String body, String signiture) { // Arrange var clock = Substitute.For <ISystemClock>(); clock.UnixTimestamp.Returns(timestamp); var apiKey = "thisisafakekeythisisafakekey1234"; var apiPassphrase = "thisisafake"; var apiSecret = "thisisafakesecretthisisafakesecretthisisafakesecretthisisafakesecretthisisafakesecret+=="; var applicationName = "test-application"; var credentials = new GdaxCredentials(apiKey, apiPassphrase, apiSecret, applicationName); var handler = new GdaxAuthenticationHandler(credentials, clock) { InnerHandler = new NoopHandler() }; var http = new HttpClient(handler); // Act var response = await http.SendAsync(new HttpRequestMessage { Method = new HttpMethod(method), RequestUri = new Uri("https://test.com" + request), Content = body == null ? null : new StringContent(body) }); // Assert response.RequestMessage.Headers.GetValues("CB-ACCESS-KEY").Single().ShouldBe(apiKey); response.RequestMessage.Headers.GetValues("CB-ACCESS-SIGN").Single().ShouldBe(signiture); response.RequestMessage.Headers.GetValues("CB-ACCESS-TIMESTAMP").Single().ShouldBe(timestamp.ToString(CultureInfo.InvariantCulture)); response.RequestMessage.Headers.GetValues("CB-ACCESS-PASSPHRASE").Single().ShouldBe(apiPassphrase); response.RequestMessage.Headers.GetValues("User-Agent").Single().ShouldBe(applicationName); }
public GdaxApiClient(GdaxAuthenticationHandler authenticationHandler, ISerializer serializer = null, bool sandbox = false) { if (authenticationHandler == null) { throw new ArgumentNullException(nameof(authenticationHandler)); } if (authenticationHandler.InnerHandler == null) { authenticationHandler.InnerHandler = new HttpClientHandler(); } this.Serializer = serializer ?? new Serializer(); this.httpClient = new HttpClient(authenticationHandler); this.hasOwnershipOfHttpClient = true; this.BaseUri = sandbox ? BaseUriSandbox : BaseUriPublic; }