public void ForDefaultEnvironment_GivenCredentialsAreProvided_ThenThrowInvalidOperationException() { // Arrange const string key = "asdfasdf"; const string secret = "89798798"; var apiCredentials = new OdsApiCredential { Key = key, Secret = secret }; // Act void Act() => Run(default(CloudOdsEnvironment), apiCredentials); // Assert Should.Throw <InvalidOperationException>((Action)Act); }
public void ForProductionEnvironment_GivenCredentialsAreProvided_ThenReturnApiConnectionInformation() { // Arrange const string key = "asdfasdf"; const string secret = "89798798"; var apiCredentials = new OdsApiCredential { Key = key, Secret = secret }; // Act var actual = Run(apiCredentials); // Assert actual.ShouldNotBeNull(); actual.ClientKey.ShouldBe(key); actual.ClientSecret.ShouldBe(secret); actual.ApiBaseUrl.ShouldNotBeNullOrWhiteSpace(); actual.OAuthUrl.ShouldNotBeNullOrWhiteSpace(); actual.ApiServerUrl.ShouldBeNullOrWhiteSpace(); }
private static Task <OdsApiConnectionInformation> ConnectionInformationForEnvironment(string apiUrl, OdsApiCredential apiCredentials) { return(Task.FromResult( new OdsApiConnectionInformation("Ods Instance", ApiMode.Sandbox) { ApiServerUrl = $"{apiUrl}", ClientKey = apiCredentials.Key, ClientSecret = apiCredentials.Secret, OAuthUrl = $"{apiUrl}/" })); }
private static OdsApiConnectionInformation ConnectionInformationForEnvironment(string apiUrl, OdsApiCredential apiCredentials, string instanceName, ApiMode apiMode) { var connectionInformation = new OdsApiConnectionInformation(instanceName, apiMode) { ApiServerUrl = $"{apiUrl}", ClientKey = apiCredentials.Key, ClientSecret = apiCredentials.Secret, OAuthUrl = $"{apiUrl}/" }; return(connectionInformation); }
public static OdsApiConnectionInformation GetConnectionInformationForEnvironment(CloudOdsEnvironment environment, OdsApiCredential apiCredentials, string instanceName, ApiMode apiMode) { if (apiCredentials == null) { throw new ArgumentNullException(nameof(apiCredentials)); } if (string.IsNullOrWhiteSpace(apiCredentials.Key)) { throw new ArgumentException($"{nameof(apiCredentials.Key)} in {nameof(apiCredentials)} cannot be null or whitespace"); } if (string.IsNullOrWhiteSpace(apiCredentials.Secret)) { throw new ArgumentException($"{nameof(apiCredentials.Secret)} in {nameof(apiCredentials)} cannot be null or whitespace"); } if (environment == CloudOdsEnvironment.Production) { return(ConnectionInformationForEnvironment(CloudOdsAdminAppSettings.Instance.ProductionApiUrl, apiCredentials, instanceName, apiMode)); } throw new InvalidOperationException($"Cannot provide connection information for '{environment?.DisplayName ?? "null"}' environment"); }
protected OdsApiConnectionInformation Run(OdsApiCredential apiCredentials) { return(CloudOdsApiConnectionInformationProvider.GetConnectionInformationForEnvironment(apiCredentials, "Ods Instance", ApiMode.Sandbox)); }
public static OdsApiConnectionInformation GetConnectionInformationForEnvironment(OdsApiCredential apiCredentials, string instanceName, ApiMode apiMode) { if (apiCredentials == null) { throw new ArgumentNullException(nameof(apiCredentials)); } if (string.IsNullOrWhiteSpace(apiCredentials.Key)) { throw new ArgumentException($"{nameof(apiCredentials.Key)} in {nameof(apiCredentials)} cannot be null or whitespace"); } if (string.IsNullOrWhiteSpace(apiCredentials.Secret)) { throw new ArgumentException($"{nameof(apiCredentials.Secret)} in {nameof(apiCredentials)} cannot be null or whitespace"); } return(ConnectionInformationForEnvironment(CloudOdsAdminAppSettings.Instance.ProductionApiUrl, apiCredentials, instanceName, apiMode)); }