Skip to content

Commit

Permalink
Extending the Tester app with new API call examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MZole committed Jul 16, 2024
1 parent 11eba91 commit d8f8717
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
32 changes: 28 additions & 4 deletions Lombiq.OrchardCoreApiClient.Tester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Lombiq.OrchardCoreApiClient.Models;
using OrchardCore.ContentManagement;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;

namespace Lombiq.OrchardCoreApiClient.Tester;
Expand All @@ -18,18 +20,20 @@ public static class Program
public static async Task Main(string[] arguments)
{
var port = int.TryParse(arguments.FirstOrDefault(), out var customPort) ? customPort : 44335;
using var apiClient = new ApiClient(new ApiClientSettings
var apiClientSettings = new ApiClientSettings
{
ClientId = ClientId,
ClientSecret = ClientSecret,
DefaultTenantUri = new Uri("https://localhost:" + port.ToTechnicalString()),
});
};

using var tenantsApiClient = new TenantsApiClient(apiClientSettings);

// A suffix is used to avoid name clashes on an existing site, as this test doesn't delete tenants.
var suffix = DateTime.Now.Ticks.ToTechnicalString();
var name = "ApiClientTenant" + suffix;

await apiClient.CreateAndSetupTenantAsync(
await tenantsApiClient.CreateAndSetupTenantAsync(
new TenantApiModel
{
Description = "Tenant created by API Client",
Expand Down Expand Up @@ -69,8 +73,28 @@ await apiClient.CreateAndSetupTenantAsync(
};

// Requires Orchard Core 1.6.0 or newer, on a 1.5.0 server this returns a 404 error.
await apiClient.OrchardCoreApi.EditAsync(editModel);
await tenantsApiClient.OrchardCoreApi.EditAsync(editModel);

Console.WriteLine("Editing the tenant succeeded.");

using var contentsApiClient = new ContentsApiClient(apiClientSettings);

var taxonomy = new ContentItem
{
ContentType = "Taxonomy",
DisplayText = "Taxonomy created by API Client",
};

var response = await contentsApiClient.OrchardCoreApi.CreateOrUpdateAsync(taxonomy);
var contentItemIdFromApi = JsonSerializer.Deserialize<ContentItem>(response.Content).ContentItemId;

Console.WriteLine("Creating the taxonomy succeeded.");

taxonomy.ContentItemId = contentItemIdFromApi;
taxonomy.DisplayText = "Taxonomy edited by API Client";

await contentsApiClient.OrchardCoreApi.CreateOrUpdateAsync(taxonomy);

Console.WriteLine("Editing the taxonomy succeeded.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
{
"name": "feature",
"enable": [
"OrchardCore.Contents",
"OrchardCore.ContentTypes",
"OrchardCore.OpenId",
"OrchardCore.OpenId.Management",
"OrchardCore.OpenId.Server",
"OrchardCore.OpenId.Validation",
"OrchardCore.Taxonomies",
"OrchardCore.Tenants"
]
},
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IOrchardCoreApiExtended : IOrchardCoreApi

## Recipes

Lombiq OrchardCore API Client OpenId - Recipe for enabling the Tenants and OpenId features and setting it up for the console tester application. To use this recipe, enable the Deployment feature and import this as a deployment package.
Lombiq OrchardCore API Client OpenId - Recipe for enabling the Content Types, Tenants and OpenId features and setting it up for the console tester application. To use this recipe, enable the Deployment feature and import this as a deployment package.

## Contributing and support

Expand Down

0 comments on commit d8f8717

Please sign in to comment.