-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Configuration from IConfiguration, create Credentials from Con…
…figuration
- Loading branch information
Showing
4 changed files
with
161 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,140 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Configuration; | ||
using Vonage.Cryptography; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit | ||
{ | ||
public class ConfigurationTest | ||
{ | ||
[Fact] | ||
public void FromConfiguration_ShouldLoadEmptyCredentials_GivenConfigurationContainsNoElement() | ||
{ | ||
var credentials = Configuration.FromConfiguration(new ConfigurationBuilder().Build()); | ||
credentials.ApiKey.Should().BeEmpty(); | ||
credentials.ApiSecret.Should().BeEmpty(); | ||
credentials.ApplicationId.Should().BeEmpty(); | ||
credentials.ApplicationKey.Should().BeEmpty(); | ||
credentials.SecuritySecret.Should().BeEmpty(); | ||
credentials.SigningMethod.Should().BeEmpty(); | ||
credentials.UserAgent.Should().BeEmpty(); | ||
credentials.EuropeApiUrl.Should().Be(new Uri("https://api-eu.vonage.com")); | ||
credentials.NexmoApiUrl.Should().Be(new Uri("https://api.nexmo.com")); | ||
credentials.RestApiUrl.Should().Be(new Uri("https://rest.nexmo.com")); | ||
credentials.VideoApiUrl.Should().Be(new Uri("https://video.api.vonage.com")); | ||
} | ||
} | ||
public class ConfigurationTest | ||
{ | ||
[Fact] | ||
public void BuildCredentials_ShouldCreateEmptyCredentials_GivenConfigurationContainsNoElement() | ||
{ | ||
var credentials = Configuration.FromConfiguration(new ConfigurationBuilder().Build()).BuildCredentials(); | ||
credentials.ApiKey.Should().BeEmpty(); | ||
credentials.ApiSecret.Should().BeEmpty(); | ||
credentials.ApplicationId.Should().BeEmpty(); | ||
credentials.ApplicationKey.Should().BeEmpty(); | ||
credentials.SecuritySecret.Should().BeEmpty(); | ||
credentials.Method.Should().Be(SmsSignatureGenerator.Method.md5hash); | ||
} | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationContainsNoElement() | ||
{ | ||
var configuration = Configuration.FromConfiguration(new ConfigurationBuilder().Build()); | ||
configuration.ApiKey.Should().BeEmpty(); | ||
configuration.ApiSecret.Should().BeEmpty(); | ||
configuration.ApplicationId.Should().BeEmpty(); | ||
configuration.ApplicationKey.Should().BeEmpty(); | ||
configuration.SecuritySecret.Should().BeEmpty(); | ||
configuration.SigningMethod.Should().BeEmpty(); | ||
configuration.UserAgent.Should().BeEmpty(); | ||
configuration.EuropeApiUrl.Should().Be(new Uri("https://api-eu.vonage.com")); | ||
configuration.NexmoApiUrl.Should().Be(new Uri("https://api.nexmo.com")); | ||
configuration.RestApiUrl.Should().Be(new Uri("https://rest.nexmo.com")); | ||
configuration.VideoApiUrl.Should().Be(new Uri("https://video.api.vonage.com")); | ||
} | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetApiKey_GivenConfigurationContainsApiKey() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage_key", "RandomValue"}, | ||
}) | ||
.Build()).ApiKey.Should().Be("RandomValue"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetApiKSecret_GivenConfigurationContainsApiSecret() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage_secret", "RandomValue"}, | ||
}) | ||
.Build()).ApiSecret.Should().Be("RandomValue"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetApplicationId_GivenConfigurationContainsApplicationId() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.Application.Id", "RandomValue"}, | ||
}) | ||
.Build()).ApplicationId.Should().Be("RandomValue"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetApplicationKey_GivenConfigurationContainsApplicationKey() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.Application.Key", "RandomValue"}, | ||
}) | ||
.Build()).ApplicationKey.Should().Be("RandomValue"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetEuropeApiUrl_GivenConfigurationContainsEuropeApiUrl() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.Url.Api.Europe", "https://api.vonage.com"}, | ||
}) | ||
.Build()).EuropeApiUrl.Should().Be(new Uri("https://api.vonage.com")); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetNexmoApiUrl_GivenConfigurationContainsNexmoApiUrl() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.Url.Api", "https://api.vonage.com"}, | ||
}) | ||
.Build()).NexmoApiUrl.Should().Be(new Uri("https://api.vonage.com")); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetRestApiUrl_GivenConfigurationContainsRestApiUrl() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.Url.Rest", "https://api.vonage.com"}, | ||
}) | ||
.Build()).RestApiUrl.Should().Be(new Uri("https://api.vonage.com")); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetSecuritySecret_GivenConfigurationContainsSecuritySecret() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.security_secret", "RandomValue"}, | ||
}) | ||
.Build()).SecuritySecret.Should().Be("RandomValue"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetSigningMethod_GivenConfigurationContainsSigningMethod() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.signing_method", "sha512"}, | ||
}) | ||
.Build()).SigningMethod.Should().Be("sha512"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetUserAgent_GivenConfigurationContainsUserAgent() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.UserAgent", "RandomValue"}, | ||
}) | ||
.Build()).UserAgent.Should().Be("RandomValue"); | ||
|
||
[Fact] | ||
public void FromConfiguration_ShouldSetVideoApiUrl_GivenConfigurationContainsVideoApiUrl() => | ||
Configuration.FromConfiguration(new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"appSettings:Vonage.Url.Api.Video", "https://api.vonage.com"}, | ||
}) | ||
.Build()).VideoApiUrl.Should().Be(new Uri("https://api.vonage.com")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters