Skip to content

Commit

Permalink
Fix xunit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Oct 8, 2024
1 parent 1f15dc9 commit 15cbce6
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 67 deletions.
112 changes: 56 additions & 56 deletions src/Authress.SDK/Api/ResourcePermissionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,66 @@

namespace Authress.SDK
{
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
internal partial class AuthressClient : IResourcePermissionsApi
{
/// <summary>
/// List resource configurations Permissions can be set globally at a resource level. Lists any resources with a globally set resource policy
/// </summary>
/// <returns>ResourcePermissionCollection</returns>
public async Task<ResourcePermissionCollection> GetResources ()
{
// /// <summary>
// /// Represents a collection of functions to interact with the API endpoints
// /// </summary>
// internal partial class AuthressClient : IResourcePermissionsApi
// {
// /// <summary>
// /// List resource configurations Permissions can be set globally at a resource level. Lists any resources with a globally set resource policy
// /// </summary>
// /// <returns>ResourcePermissionCollection</returns>
// public async Task<ResourcePermissionCollection> GetResources ()
// {

var path = "/v1/resources";
var client = await authressHttpClientProvider.GetHttpClientAsync();
using (var response = await client.GetAsync(path))
{
await response.ThrowIfNotSuccessStatusCode();
return await response.Content.ReadAsAsync<ResourcePermissionCollection>();
}
}
// var path = "/v1/resources";
// var client = await authressHttpClientProvider.GetHttpClientAsync();
// using (var response = await client.GetAsync(path))
// {
// await response.ThrowIfNotSuccessStatusCode();
// return await response.Content.ReadAsAsync<ResourcePermissionCollection>();
// }
// }

/// <summary>
/// Get a resource permissions object. Permissions can be set globally at a resource level. This will apply to all users in an account.
/// </summary>
/// <param name="resourceUri">The uri path of a resource to validate, uri segments are allowed.</param>
/// <returns>ResourcePermission</returns>
public async Task<ResourcePermission> GetResourcePermissions (string resourceUri)
{
// verify the required parameter 'resourceUri' is set
if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'.");
// /// <summary>
// /// Get a resource permissions object. Permissions can be set globally at a resource level. This will apply to all users in an account.
// /// </summary>
// /// <param name="resourceUri">The uri path of a resource to validate, uri segments are allowed.</param>
// /// <returns>ResourcePermission</returns>
// public async Task<ResourcePermission> GetResourcePermissions (string resourceUri)
// {
// // verify the required parameter 'resourceUri' is set
// if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'.");

var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}";
var client = await authressHttpClientProvider.GetHttpClientAsync();
using (var response = await client.GetAsync(path))
{
await response.ThrowIfNotSuccessStatusCode();
return await response.Content.ReadAsAsync<ResourcePermission>();
}
}
// var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}";
// var client = await authressHttpClientProvider.GetHttpClientAsync();
// using (var response = await client.GetAsync(path))
// {
// await response.ThrowIfNotSuccessStatusCode();
// return await response.Content.ReadAsAsync<ResourcePermission>();
// }
// }

/// <summary>
/// Update a resource permissions object. Updates the global permissions on a resource. This applies to all users in an account.
/// </summary>
/// <param name="body">The contents of the permission to set on the resource. Overwrites existing data.</param>
/// <param name="resourceUri">The uri path of a resource to validate, uri segments are allowed.</param>
/// <returns>Object</returns>
public async Task SetResourcePermissions (string resourceUri, ResourcePermission body)
{
// verify the required parameter 'body' is set
if (body == null) throw new ArgumentNullException("Missing required parameter 'body'.");
// verify the required parameter 'resourceUri' is set
if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'.");
// /// <summary>
// /// Update a resource permissions object. Updates the global permissions on a resource. This applies to all users in an account.
// /// </summary>
// /// <param name="body">The contents of the permission to set on the resource. Overwrites existing data.</param>
// /// <param name="resourceUri">The uri path of a resource to validate, uri segments are allowed.</param>
// /// <returns>Object</returns>
// public async Task SetResourcePermissions (string resourceUri, ResourcePermission body)
// {
// // verify the required parameter 'body' is set
// if (body == null) throw new ArgumentNullException("Missing required parameter 'body'.");
// // verify the required parameter 'resourceUri' is set
// if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'.");

var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}";
var client = await authressHttpClientProvider.GetHttpClientAsync();
using (var response = await client.PutAsync(path, body.ToHttpContent()))
{
await response.ThrowIfNotSuccessStatusCode();
}
}
// var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}";
// var client = await authressHttpClientProvider.GetHttpClientAsync();
// using (var response = await client.PutAsync(path, body.ToHttpContent()))
// {
// await response.ThrowIfNotSuccessStatusCode();
// }
// }

}
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TestCase
public string Permission { get; set; }
}

public static TestData<TestCase> TestCases = new TestData<TestCase>
public static TestData<TestCase> TestCases => new TestData<TestCase>
{
{
"Expect cached value to be returned",
Expand Down
20 changes: 10 additions & 10 deletions tests/Authress.SDK/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ namespace Authress.SDK.UnitTests
/// Represents a set of data for a theory. Data can be added to the data set using the collection initializer syntax.
/// </summary>
/// <typeparam name="T"></typeparam>
public class TestData<T> : TheoryData
public class TestData<T> : TheoryData<string, T>
{
/// <summary>
/// Adds a theory to the Test
/// </summary>
/// <param name="testName">Name of the Test</param>
/// <param name="testObject">Data used in the Test</param>
public void Add(string testName, T testObject)
{
AddRow(testName, testObject);
}
// /// <summary>
// /// Adds a theory to the Test
// /// </summary>
// /// <param name="testName">Name of the Test</param>
// /// <param name="testObject">Data used in the Test</param>
// public void Add(string testName, T testObject)
// {
// AddRow(testName, testObject);
// }
}
}
53 changes: 53 additions & 0 deletions testsIntegration/AuthressClientTokenProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using Xunit;
using Authress.SDK;
using Authress.SDK.Client;

namespace Authress.SDK.UnitTests
{
public class AuthressClientTokenProviderTests
{
private const string userId = "unit-test-user-id";

public class TestCase
{
public string AccessKey { get; set; }
}

public static TestData<TestCase> TestCases = new TestData<TestCase>
{
{
"EdDSA",
new TestCase{ AccessKey = "KEY" }
}
};

[Theory, MemberData(nameof(TestCases))]
public async Task GetBearerToken(string testName, TestCase testCase)
{
var tokenProvider = new AuthressClientTokenProvider(testCase.AccessKey);
var token = await tokenProvider.GetBearerToken();
System.Console.WriteLine(token);

tokenProvider.Should().NotBeNull(testName, testCase);

var authressSettings = new AuthressSettings { AuthressApiUrl = "DOMAIN", };
var authressClient = new AuthressClient(tokenProvider, authressSettings);
var result = await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED);
await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED);
await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED);
await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED);
await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED);
await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED);
System.Console.WriteLine(string.Join(", ", result.Resources.Select(s => s.ResourceUri)));

var token2 = await tokenProvider.GetBearerToken();
System.Console.WriteLine(token2);
}
}
}

0 comments on commit 15cbce6

Please sign in to comment.