Skip to content

Commit

Permalink
Replace computed property by method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Sep 19, 2023
1 parent b62130b commit 59bae4e
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Vonage.Test.Unit/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public class TestBase
protected readonly string RestUrl = Configuration.Instance.Settings["appSettings:Vonage.Url.Rest"];
protected readonly string ApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "testkey";
protected readonly string ApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_Secret") ?? "testSecret";

protected readonly string AppId = Environment.GetEnvironmentVariable("APPLICATION_ID") ??
"afed99d2-ae38-487c-bb5a-fe2518febd44";

protected readonly string PrivateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY") ??
Environment.GetEnvironmentVariable("Vonage.Test.RsaPrivateKey");

Expand All @@ -43,15 +45,12 @@ protected Credentials BuildCredentialsForBasicAuthentication() =>
protected Credentials BuildCredentialsForBearerAuthentication() =>
Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey);

private static string AssemblyDirectory
private static string GetAssemblyDirectory()
{
get
{
var codeBase = ThisAssembly.CodeBase;
var uri = new UriBuilder(codeBase);
var path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
var codeBase = ThisAssembly.CodeBase;
var uri = new UriBuilder(codeBase);
var path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}

protected void Setup(string uri, string responseContent, string requestContent = null,
Expand Down Expand Up @@ -98,7 +97,7 @@ protected string GetResponseJson([CallerMemberName] string name = null)
if (ns != null)
{
var projectFolder = ns.Substring(TestAssemblyName.Length);
var path = Path.Combine(AssemblyDirectory, projectFolder, "Data", type, $"{name}-response.json");
var path = Path.Combine(GetAssemblyDirectory(), projectFolder, "Data", type, $"{name}-response.json");
if (!File.Exists(path))
{
throw new FileNotFoundException($"File not found at {path}.");
Expand All @@ -112,7 +111,8 @@ protected string GetResponseJson([CallerMemberName] string name = null)
return string.Empty;
}

protected string GetResponseJson(Dictionary<string, string> parameters, [CallerMemberName] string name = null) =>
protected string GetResponseJson(Dictionary<string, string> parameters,
[CallerMemberName] string name = null) =>
TokenReplacementRegEx.Replace(this.GetResponseJson(name), match => parameters[match.Groups[1].Value]);

protected string GetRequestJson([CallerMemberName] string name = null)
Expand All @@ -122,7 +122,7 @@ protected string GetRequestJson([CallerMemberName] string name = null)
if (ns != null)
{
var projectFolder = ns.Substring(TestAssemblyName.Length);
var path = Path.Combine(AssemblyDirectory, projectFolder, "Data", type, $"{name}-request.json");
var path = Path.Combine(GetAssemblyDirectory(), projectFolder, "Data", type, $"{name}-request.json");
if (!File.Exists(path))
{
throw new FileNotFoundException($"File not found at {path}.");
Expand Down

0 comments on commit 59bae4e

Please sign in to comment.