-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
100 lines (83 loc) · 3.7 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Lombiq.OrchardCoreApiClient.Clients;
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;
public static class Program
{
private const string ClientId = "Console";
private const string ClientSecret = "Password";
[SuppressMessage(
"Design",
"CA1303:Do not pass literals as localized parameters",
Justification = "It is not a localization issue")]
public static async Task Main(string[] arguments)
{
var port = int.TryParse(arguments.FirstOrDefault(), out var customPort) ? customPort : 44335;
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 tenantsApiClient.CreateAndSetupTenantAsync(
new TenantApiModel
{
Description = "Tenant created by API Client",
Name = name,
DatabaseProvider = "Sqlite",
RequestUrlPrefix = "api-client-tenant-" + suffix,
RequestUrlHost = string.Empty,
ConnectionString = string.Empty,
TablePrefix = "apiclienttenant" + suffix, // #spell-check-ignore-line
RecipeName = "Blog",
Category = "API Client Tenants",
},
new TenantSetupApiModel
{
Name = name,
DatabaseProvider = "Sqlite",
ConnectionString = string.Empty,
UserName = "admin",
Email = "[email protected]",
Password = "Password1!",
SiteName = "Api Client Tenant Site",
SiteTimeZone = "Europe/Budapest",
TablePrefix = "apiclienttenant" + suffix, // #spell-check-ignore-line
}
);
Console.WriteLine("Creating and setting up the tenant succeeded.");
var editModel = new TenantApiModel
{
Description = "Tenant edited by API Client",
Name = name,
RequestUrlPrefix = "api-client-tenant-edited-" + suffix,
RequestUrlHost = "https://orcharddojo.net/",
Category = "API Client - Edited Tenants",
};
// Requires Orchard Core 1.6.0 or newer, on a 1.5.0 server this returns a 404 error.
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.");
}
}