public void OneTimeSetUp() { _clientId = Environment.GetEnvironmentVariable("AUPHONIC_CLIENT_ID"); _clientSecret = Environment.GetEnvironmentVariable("AUPHONIC_CLIENT_SECRET"); _username = Environment.GetEnvironmentVariable("AUPHONIC_USERNAME"); _password = Environment.GetEnvironmentVariable("AUPHONIC_PASSWORD"); _accessToken = Environment.GetEnvironmentVariable("AUPHONIC_ACCESS_TOKEN"); _productionFilePath = Environment.GetEnvironmentVariable("AUPHONIC_PRODUCTION_FILE_PATH"); _logFilePath = Environment.GetEnvironmentVariable("AUPHONIC_LOG_FILE_PATH"); _hasClientCredentials = !String.IsNullOrWhiteSpace(_clientId) && !String.IsNullOrWhiteSpace(_clientSecret); _hasUserCredentials = !String.IsNullOrWhiteSpace(_username) && !String.IsNullOrWhiteSpace(_password); _hasAccessToken = !String.IsNullOrWhiteSpace(_accessToken); if (_hasClientCredentials) { _auphonic = new Auphonic(_clientId, _clientSecret); if (_hasAccessToken) { _auphonic.Authenticate(_accessToken); if (!String.IsNullOrWhiteSpace(_logFilePath)) { _auphonic.RecieveResponse += Auphonic_RecieveResponse; _auphonic.SendRequest += Auphonic_SendRequest; } } } }
public void Invoke_Authenticate_With_Invalid_Client_Credentials_Throws_AuthenticationException() { HasUserCredentials(); var auphonic = new Auphonic("clientId", "clientSecret"); Assert.That(() => auphonic.Authenticate(_username, _password), Throws .InstanceOf <AuthenticationException>() .And.Property("Message").EqualTo("invalid_client: client_id clientId doesn't exist")); }
public void Invoke_Authenticate_With_Invalid_User_Credentials_Throws_AuthenticationException() { HasClientCredentials(); var auphonic = new Auphonic(_clientId, _clientSecret); Assert.That(() => auphonic.Authenticate("username", "password"), Throws .InstanceOf <AuthenticationException>() .And.Property("Message").EqualTo("invalid_request: User authentication failed.")); }
public void Invoke_Authenticate_With_Invalid_Token_Throws_AuthenticationException() { HasClientCredentials(); var auphonic = new Auphonic(_clientId, _clientSecret); auphonic.Authenticate("24p5w92x9a"); Assert.That(() => auphonic.GetAccountInfo(), Throws .InstanceOf <AuthenticationException>() .And.Property("Message").EqualTo("Token doesn't exist")); }
public void Invoke_Authenticate_Returns_Result() { HasUserCredentials(); OAuthToken token = null; Assert.That(() => token = _auphonic.Authenticate(_username, _password), Throws.Nothing); Assert.That(token, Is.Not.Null); Assert.Multiple(() => { Assert.That(String.IsNullOrWhiteSpace(token.AccessToken), Is.False, "AccessToken is null or whitespace"); Assert.That(token.ExpiresIn, Is.EqualTo(315360000), "ExpiresIn"); Assert.That(token.TokenType, Is.EqualTo("bearer"), "TokenType"); Assert.That(String.IsNullOrWhiteSpace(token.Username), Is.False, "Username is null or whitespace"); Assert.That(String.IsNullOrWhiteSpace(_auphonic.AccessToken), Is.False, "AccessToken is null or whitespace"); Assert.That(_auphonic.AccessToken, Is.EqualTo(token.AccessToken), "AccessToken"); _accessToken = token.AccessToken; }); }
public void Authenticate_With_Null_Parameters_Throws_ArgumentNullException(string username, string password, string expectedParamName) { Assert.That(() => _auphonic.Authenticate(username, password), Throws .InstanceOf <ArgumentNullException>() .And.Property("ParamName").EqualTo(expectedParamName)); }