From 160a853b8c7dcb7c309f925448ac7664a850dfa9 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Wed, 22 Mar 2023 15:50:36 +0100 Subject: [PATCH] Update client library. (#979) * Update client library. * Fix tests. * Another fix. --- .../TestSuite.ApiTests/AdminUsersTests.cs | 16 +-- .../TestSuite.ApiTests/AnonymousTests.cs | 42 ++---- .../TestSuite.ApiTests/AppClientsTests.cs | 31 ++-- .../AppContributorsTests.cs | 35 ++--- .../TestSuite.ApiTests/AppCreationTests.cs | 54 +++---- .../TestSuite.ApiTests/AppLanguagesTests.cs | 59 ++++---- .../TestSuite.ApiTests/AppRolesTests.cs | 22 +-- .../TestSuite/TestSuite.ApiTests/AppTests.cs | 18 +-- .../TestSuite.ApiTests/AppWorkflowsTests.cs | 31 ++-- .../TestSuite.ApiTests/AssetFormatTests.cs | 38 ++--- .../TestSuite.ApiTests/AssetTests.cs | 116 +++++++-------- .../TestSuite.ApiTests/BackupTests.cs | 52 +++---- .../TestSuite/TestSuite.ApiTests/CDNTests.cs | 12 +- .../TestSuite.ApiTests/CommentsTests.cs | 18 +-- .../TestSuite.ApiTests/ContentCleanupTests.cs | 10 +- .../ContentLanguageTests.cs | 6 +- .../TestSuite.ApiTests/ContentQueryTests.cs | 22 ++- .../ContentScriptingTests.cs | 20 +-- .../TestSuite.ApiTests/ContentUpdateTests.cs | 35 ++--- .../TestSuite.ApiTests/DiagnosticsTests.cs | 2 +- .../TestSuite.ApiTests/FrontendTests.cs | 2 +- .../TestSuite.ApiTests/GraphQLFixture.cs | 20 ++- .../GraphQLSubscriptionTests.cs | 6 +- .../TestSuite.ApiTests/GraphQLTests.cs | 18 +-- .../TestSuite.ApiTests/HistoryTests.cs | 2 +- .../TestSuite.ApiTests/LanguagesTests.cs | 2 +- .../TestSuite.ApiTests/OpenApiTests.cs | 6 +- .../TestSuite/TestSuite.ApiTests/PingTests.cs | 6 +- .../TestSuite.ApiTests/PlansTests.cs | 2 +- .../TestSuite.ApiTests/RuleRunnerTests.cs | 96 ++++++------- .../TestSuite/TestSuite.ApiTests/RuleTests.cs | 34 ++--- .../TestSuite.ApiTests/SchemaTests.cs | 38 +++-- .../TestSuite.ApiTests/SearchTests.cs | 12 +- .../TestSuite.ApiTests.csproj | 12 +- ...Should_get_content_by_version.verified.txt | 25 +++- .../TestSuite.LoadTests/ReadingBenchmarks.cs | 3 +- .../TestSuite.LoadTests.csproj | 4 +- .../TestSuite.Shared/ClientExtensions.cs | 34 ++--- ...ientManagerWrapper.cs => ClientWrapper.cs} | 13 +- .../Fixtures/ClientCloudFixture.cs | 12 +- .../Fixtures/ClientFixture.cs | 134 ++++++------------ .../Fixtures/CreatedAppFixture.cs | 33 ++--- .../Fixtures/TestSchemaFixtureBase.cs | 4 +- .../TestSchemaWithReferencesFixtureBase.cs | 4 +- .../TestSuite.Shared/Model/TestEntity.cs | 4 +- .../Model/TestEntityWithReferences.cs | 4 +- .../TestSuite/TestSuite.Shared/Strategies.cs | 16 +-- .../TestSuite.Shared/TestSuite.Shared.csproj | 8 +- 48 files changed, 530 insertions(+), 663 deletions(-) rename tools/TestSuite/TestSuite.Shared/{ClientManagerWrapper.cs => ClientWrapper.cs} (87%) diff --git a/tools/TestSuite/TestSuite.ApiTests/AdminUsersTests.cs b/tools/TestSuite/TestSuite.ApiTests/AdminUsersTests.cs index 433559686..e00587365 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AdminUsersTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AdminUsersTests.cs @@ -35,14 +35,14 @@ public sealed class AdminUsersTests : IClassFixture // STEP 2: Get user by ID. - var userById = await _.UserManagement.GetUserAsync(user_0.Id); + var userById = await _.Client.UserManagement.GetUserAsync(user_0.Id); Assert.Equal(email, userById.Email); Assert.Equal(email, userById.DisplayName); // STEP 2: Get users by email. - var usersByEmail = await _.UserManagement.GetUsersAsync(user_0.Email); + var usersByEmail = await _.Client.UserManagement.GetUsersAsync(user_0.Email); Assert.Equal(email, usersByEmail.Items.First().Email); Assert.Equal(email, usersByEmail.Items.First().DisplayName); @@ -63,7 +63,7 @@ public sealed class AdminUsersTests : IClassFixture Email = email, }; - var user_1 = await _.UserManagement.PutUserAsync(user_0.Id, updateRequest); + var user_1 = await _.Client.UserManagement.PutUserAsync(user_0.Id, updateRequest); Assert.Equal(updateRequest.DisplayName, user_1.DisplayName); } @@ -76,13 +76,13 @@ public sealed class AdminUsersTests : IClassFixture // STEP 1: Lock user. - var user_1 = await _.UserManagement.LockUserAsync(user_0.Id); + var user_1 = await _.Client.UserManagement.LockUserAsync(user_0.Id); Assert.True(user_1.IsLocked); // STEP 2: Unlock user. - var user_2 = await _.UserManagement.UnlockUserAsync(user_0.Id); + var user_2 = await _.Client.UserManagement.UnlockUserAsync(user_0.Id); Assert.False(user_2.IsLocked); } @@ -98,11 +98,11 @@ public sealed class AdminUsersTests : IClassFixture // STEP 1: Delete user - await _.UserManagement.DeleteUserAsync(user_0.Id); + await _.Client.UserManagement.DeleteUserAsync(user_0.Id); // STEP 2: Get user by email. - var usersByEmail = await _.UserManagement.GetUsersAsync(user_0.Email); + var usersByEmail = await _.Client.UserManagement.GetUsersAsync(user_0.Email); Assert.Empty(usersByEmail.Items); } @@ -118,6 +118,6 @@ public sealed class AdminUsersTests : IClassFixture DisplayName = email, }; - return await _.UserManagement.PostUserAsync(createRequest); + return await _.Client.UserManagement.PostUserAsync(createRequest); } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs b/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs index b94d46e5e..9ec5f7927 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs @@ -17,6 +17,8 @@ namespace TestSuite.ApiTests; [UsesVerify] public class AnonymousTests : IClassFixture { + private readonly string appName = Guid.NewGuid().ToString(); + public ClientFixture _ { get; } public AnonymousTests(ClientFixture fixture) @@ -27,18 +29,11 @@ public class AnonymousTests : IClassFixture [Fact] public async Task Should_create_app_with_anonymous_read_access() { - var appName = Guid.NewGuid().ToString(); - - // STEP 1: Create app - var createRequest = new CreateAppDto - { - Name = appName - }; - - var app = await _.Apps.PostAppAsync(createRequest); + // STEP 1: Create app. + var (app, dto) = await _.PostAppAsync(appName); // Should return create app with correct name. - Assert.Equal(appName, app.Name); + Assert.Equal(appName, app.Options.AppName); // STEP 2: Make the client anonymous. @@ -47,11 +42,11 @@ public class AnonymousTests : IClassFixture AllowAnonymous = true }; - await _.Apps.PutClientAsync(appName, "default", clientRequest); + await app.Apps.PutClientAsync("default", clientRequest); // STEP 3: Check anonymous permission - var url = $"{_.ClientManager.Options.Url}api/apps/{appName}/settings"; + var url = $"{_.Client.Options.Url}api/apps/{appName}/settings"; using (var httpClient = new HttpClient()) { @@ -60,24 +55,17 @@ public class AnonymousTests : IClassFixture Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - await Verify(app); + await Verify(dto); } [Fact] public async Task Should_create_app_with_anonymous_write_access() { - var appName = Guid.NewGuid().ToString(); - - // STEP 1: Create app - var createRequest = new CreateAppDto - { - Name = appName - }; - - var app = await _.Apps.PostAppAsync(createRequest); + // STEP 1: Create app. + var (app, dto) = await _.PostAppAsync(appName); // Should return create app with correct name. - Assert.Equal(appName, app.Name); + Assert.Equal(appName, app.Options.AppName); // STEP 2: Make the client anonymous. @@ -86,7 +74,7 @@ public class AnonymousTests : IClassFixture AllowAnonymous = true }; - await _.Apps.PutClientAsync(appName, "default", clientRequest); + await app.Apps.PutClientAsync("default", clientRequest); // STEP 3: Create schema @@ -97,11 +85,11 @@ public class AnonymousTests : IClassFixture IsPublished = true }; - await _.Schemas.PostSchemaAsync(appName, schemaRequest); + await app.Schemas.PostSchemaAsync(schemaRequest); // STEP 3: Create a content. - var url = $"{_.ClientManager.Options.Url}api/content/{appName}/my-content"; + var url = $"{_.Client.Options.Url}api/content/{appName}/my-content"; using (var httpClient = new HttpClient()) { @@ -110,6 +98,6 @@ public class AnonymousTests : IClassFixture Assert.Equal(HttpStatusCode.Created, response.StatusCode); } - await Verify(app); + await Verify(dto); } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs index 1def631c4..90e7b9ea2 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Squidex.ClientLibrary; using Squidex.ClientLibrary.Management; using TestSuite.Fixtures; @@ -32,11 +33,11 @@ public sealed class AppClientsTests : IClassFixture public async Task Should_create_client() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Create client. - var client = await CreateAsync(); + var client = await CreateAsync(app); // Should return client with correct name and id. Assert.Equal(clientRole, client.Role); @@ -50,11 +51,11 @@ public sealed class AppClientsTests : IClassFixture public async Task Should_update_client() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 0: Create client. - var client = await CreateAsync(); + var client = await CreateAsync(app); // STEP 1: Update client name. @@ -67,7 +68,7 @@ public sealed class AppClientsTests : IClassFixture Role = "Owner" }; - var clients_2 = await _.Apps.PutClientAsync(appName, client.Id, updateNameRequest); + var clients_2 = await app.Apps.PutClientAsync(client.Id, updateNameRequest); var client_2 = clients_2.Items.Find(x => x.Id == client.Id); // Should update client name. @@ -85,15 +86,15 @@ public sealed class AppClientsTests : IClassFixture public async Task Should_delete_client() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 0: Create client. - var client = await CreateAsync(); + var client = await CreateAsync(app); // STEP 1: Delete client - var clients_2 = await _.Apps.DeleteClientAsync(appName, client.Id); + var clients_2 = await app.Apps.DeleteClientAsync(client.Id); // Should not return deleted client. Assert.DoesNotContain(clients_2.Items, x => x.Id == client.Id); @@ -102,26 +103,16 @@ public sealed class AppClientsTests : IClassFixture .IgnoreMember(x => x.Secret); } - private async Task CreateAsync() + private async Task CreateAsync(ISquidexClient app) { var createRequest = new CreateClientDto { Id = id }; - var clients = await _.Apps.PostClientAsync(appName, createRequest); + var clients = await app.Apps.PostClientAsync(createRequest); var client = clients.Items.Find(x => x.Id == id); return client; } - - private async Task CreateAppAsync() - { - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); - } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs index bbd7af44f..efdfb6882 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Squidex.ClientLibrary; using Squidex.ClientLibrary.Management; using TestSuite.Fixtures; @@ -30,7 +31,7 @@ public sealed class AppContributorsTests : IClassFixture public async Task Should_not_invite_contributor_if_flag_is_false() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Do not invite contributors when flag is false. @@ -41,7 +42,7 @@ public sealed class AppContributorsTests : IClassFixture var ex = await Assert.ThrowsAnyAsync(() => { - return _.Apps.PostContributorAsync(appName, createRequest); + return app.Apps.PostContributorAsync(createRequest); }); Assert.Equal(404, ex.StatusCode); @@ -51,11 +52,11 @@ public sealed class AppContributorsTests : IClassFixture public async Task Should_invite_contributor() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Assign contributor. - ContributorDto contributor_1 = await InviteAsync(); + ContributorDto contributor_1 = await InviteAsync(app); Assert.Equal("Developer", contributor_1?.Role); @@ -69,11 +70,11 @@ public sealed class AppContributorsTests : IClassFixture public async Task Should_update_contributor() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Assign contributor. - var contributor = await InviteAsync(); + var contributor = await InviteAsync(app); // STEP 1: Update contributor role. @@ -84,7 +85,7 @@ public sealed class AppContributorsTests : IClassFixture Role = "Owner" }; - var contributors_2 = await _.Apps.PostContributorAsync(appName, updateRequest); + var contributors_2 = await app.Apps.PostContributorAsync(updateRequest); var contributor_2 = contributors_2.Items.Find(x => x.ContributorId == contributor.ContributorId); Assert.Equal(updateRequest.Role, contributor_2?.Role); @@ -94,22 +95,22 @@ public sealed class AppContributorsTests : IClassFixture public async Task Should_remove_contributor() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Assign contributor. - var contributor = await InviteAsync(); + var contributor = await InviteAsync(app); // STEP 1: Remove contributor. - var contributors_2 = await _.Apps.DeleteContributorAsync(appName, contributor.ContributorId); + var contributors_2 = await app.Apps.DeleteContributorAsync(contributor.ContributorId); Assert.DoesNotContain(contributors_2.Items, x => x.ContributorId == contributor.ContributorId); await Verify(contributors_2); } - private async Task InviteAsync() + private async Task InviteAsync(ISquidexClient app) { var createInviteRequest = new AssignContributorDto { @@ -118,19 +119,9 @@ public sealed class AppContributorsTests : IClassFixture Invite = true }; - var contributors = await _.Apps.PostContributorAsync(appName, createInviteRequest); + var contributors = await app.Apps.PostContributorAsync(createInviteRequest); var contributor = contributors.Items.Find(x => x.ContributorName == email); return contributor; } - - private async Task CreateAppAsync() - { - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); - } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs index a2529231a..674f94ddf 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs @@ -29,56 +29,46 @@ public class AppCreationTests : IClassFixture public async Task Should_create_app() { // STEP 1: Create app - var createRequest = new CreateAppDto - { - Name = appName - }; - - var app = await _.Apps.PostAppAsync(createRequest); + var (app, dto) = await _.PostAppAsync(appName); // Should return created app with correct name. - Assert.Equal(appName, app.Name); + Assert.Equal(appName, app.Options.AppName); // STEP 2: Get all apps - var apps = await _.Apps.GetAppsAsync(); + var apps = await app.Apps.GetAppsAsync(); // Should provide new app when apps are queried. Assert.Contains(apps, x => x.Name == appName); // STEP 3: Check contributors - var contributors = await _.Apps.GetContributorsAsync(appName); + var contributors = await app.Apps.GetContributorsAsync(); // Should not add client itself as a contributor. Assert.Empty(contributors.Items); // STEP 4: Check clients - var clients = await _.Apps.GetClientsAsync(appName); + var clients = await app.Apps.GetClientsAsync(); // Should create default client. Assert.Contains(clients.Items, x => x.Id == "default"); - await Verify(app); + await Verify(dto); } [Fact] public async Task Should_not_allow_creation_if_name_used() { // STEP 1: Create app - await CreateAppAsync(); + await _.PostAppAsync(appName); // STEP 2: Create again and fail - var createRequest = new CreateAppDto - { - Name = appName - }; - var ex = await Assert.ThrowsAnyAsync(() => { - return _.Apps.PostAppAsync(createRequest); + return _.PostAppAsync(appName); }); Assert.Equal(400, ex.StatusCode); @@ -88,13 +78,13 @@ public class AppCreationTests : IClassFixture public async Task Should_archive_app() { // STEP 1: Create app - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 2: Archive app - await _.Apps.DeleteAppAsync(appName); + await app.Apps.DeleteAppAsync(); - var apps = await _.Apps.GetAppsAsync(); + var apps = await app.Apps.GetAppsAsync(); // Should not provide deleted app when apps are queried. Assert.DoesNotContain(apps, x => x.Name == appName); @@ -104,11 +94,11 @@ public class AppCreationTests : IClassFixture public async Task Should_recreate_after_archived() { // STEP 1: Create app - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 2: Archive app - await _.Apps.DeleteAppAsync(appName); + await app.Apps.DeleteAppAsync(); // STEP 3: Create app again @@ -117,14 +107,14 @@ public class AppCreationTests : IClassFixture Name = appName }; - await _.Apps.PostAppAsync(createRequest); + await _.PostAppAsync(createRequest); } [Fact] public async Task Should_create_app_from_templates() { // STEP 1: Get template. - var templates = await _.Templates.GetTemplatesAsync(); + var templates = await _.Client.Templates.GetTemplatesAsync(); var template = templates.Items.First(x => x.IsStarter); @@ -137,24 +127,14 @@ public class AppCreationTests : IClassFixture Template = template.Name }; - await _.Apps.PostAppAsync(createRequest); + var (app, _) = await _.PostAppAsync(createRequest); // STEP 3: Get schemas - var schemas = await _.Schemas.GetSchemasAsync(appName); + var schemas = await app.Schemas.GetSchemasAsync(); Assert.NotEmpty(schemas.Items); await Verify(schemas); } - - private async Task CreateAppAsync() - { - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); - } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs index 67d293651..7ab8c08b3 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Squidex.ClientLibrary; using Squidex.ClientLibrary.Management; using TestSuite.Fixtures; @@ -29,14 +30,14 @@ public sealed class AppLanguagesTests : IClassFixture public async Task Should_add_language() { // STEP 0: Add app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Add languages. - await AddLanguageAsync("de"); - await AddLanguageAsync("it"); + await AddLanguageAsync(app, "de"); + await AddLanguageAsync(app, "it"); - var languages_1 = await _.Apps.GetLanguagesAsync(appName); + var languages_1 = await app.Apps.GetLanguagesAsync(); Assert.Equal(new string[] { "en", "de", "it" }, languages_1.Items.Select(x => x.Iso2Code).ToArray()); @@ -47,14 +48,14 @@ public sealed class AppLanguagesTests : IClassFixture public async Task Should_add_custom_language() { // STEP 0: Add app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Add languages. - await AddLanguageAsync("abc"); - await AddLanguageAsync("xyz"); + await AddLanguageAsync(app, "abc"); + await AddLanguageAsync(app, "xyz"); - var languages_1 = await _.Apps.GetLanguagesAsync(appName); + var languages_1 = await app.Apps.GetLanguagesAsync(); Assert.Equal(new string[] { "en", "abc", "xyz" }, languages_1.Items.Select(x => x.Iso2Code).ToArray()); @@ -65,12 +66,12 @@ public sealed class AppLanguagesTests : IClassFixture public async Task Should_update_language() { // STEP 0: Add app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Add languages. - await AddLanguageAsync("de"); - await AddLanguageAsync("it"); + await AddLanguageAsync(app, "de"); + await AddLanguageAsync(app, "it"); // STEP 3: Update German language. @@ -83,7 +84,7 @@ public sealed class AppLanguagesTests : IClassFixture IsOptional = true }; - var languages_2 = await _.Apps.PutLanguageAsync(appName, "de", updateRequest); + var languages_2 = await app.Apps.PutLanguageAsync("de", updateRequest); var language_2_DE = languages_2.Items.Find(x => x.Iso2Code == "de"); Assert.Equal(updateRequest.Fallback, language_2_DE.Fallback); @@ -96,12 +97,12 @@ public sealed class AppLanguagesTests : IClassFixture public async Task Should_update_master_language() { // STEP 0: Add app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Add languages. - await AddLanguageAsync("de"); - await AddLanguageAsync("it"); + await AddLanguageAsync(app, "de"); + await AddLanguageAsync(app, "it"); // STEP 2: Update Italian language. @@ -114,7 +115,7 @@ public sealed class AppLanguagesTests : IClassFixture IsOptional = true }; - await _.Apps.PutLanguageAsync(appName, "it", updateRequest); + await app.Apps.PutLanguageAsync("it", updateRequest); // STEP 3: Change master language to Italian. @@ -123,7 +124,7 @@ public sealed class AppLanguagesTests : IClassFixture IsMaster = true }; - var languages_4 = await _.Apps.PutLanguageAsync(appName, "it", masterRequest); + var languages_4 = await app.Apps.PutLanguageAsync("it", masterRequest); var language_4_IT = languages_4.Items.Find(x => x.Iso2Code == "it"); var language_4_EN = languages_4.Items.Find(x => x.Iso2Code == "en"); @@ -145,12 +146,12 @@ public sealed class AppLanguagesTests : IClassFixture public async Task Should_delete_language() { // STEP 0: Add app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Add languages. - await AddLanguageAsync("de"); - await AddLanguageAsync("it"); + await AddLanguageAsync(app, "de"); + await AddLanguageAsync(app, "it"); // STEP 2: Update Italian language. @@ -163,11 +164,11 @@ public sealed class AppLanguagesTests : IClassFixture IsOptional = true }; - await _.Apps.PutLanguageAsync(appName, "it", updateRequest); + await app.Apps.PutLanguageAsync("it", updateRequest); // STEP 3: Remove language. - var languages_2 = await _.Apps.DeleteLanguageAsync(appName, "de"); + var languages_2 = await app.Apps.DeleteLanguageAsync("de"); var language_2_IT = languages_2.Items.Find(x => x.Iso2Code == "it"); // Fallback language must be removed. @@ -178,23 +179,13 @@ public sealed class AppLanguagesTests : IClassFixture await Verify(languages_2); } - private async Task CreateAppAsync() - { - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); - } - - private async Task AddLanguageAsync(string code) + private async Task AddLanguageAsync(ISquidexClient app, string code) { var createRequest = new AddLanguageDto { Language = code }; - await _.Apps.PostLanguageAsync(appName, createRequest); + await app.Apps.PostLanguageAsync(createRequest); } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs index 5e8b6f3a7..7e556a526 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs @@ -66,7 +66,7 @@ public sealed class AppRolesTests : IClassFixture Permissions = new List { "a", "b" } }; - var roles_2 = await _.Apps.PutRoleAsync(_.AppName, roleName, updateRequest); + var roles_2 = await _.Client.Apps.PutRoleAsync(roleName, updateRequest); var role_2 = roles_2.Items.Find(x => x.Name == roleName); // Should return role with correct name. @@ -89,11 +89,11 @@ public sealed class AppRolesTests : IClassFixture Id = client }; - await _.Apps.PostClientAsync(_.AppName, createClientRequest); + await _.Client.Apps.PostClientAsync(createClientRequest); await AssignClient(roleName); - var roles_2 = await _.Apps.GetRolesAsync(_.AppName); + var roles_2 = await _.Client.Apps.GetRolesAsync(); var role_2 = roles_2.Items.Find(x => x.Name == roleName); // Should return role with correct number of users and clients. @@ -104,7 +104,7 @@ public sealed class AppRolesTests : IClassFixture // STEP 4: Try to delete role. var ex = await Assert.ThrowsAnyAsync(() => { - return _.Apps.DeleteRoleAsync(_.AppName, roleName); + return _.Client.Apps.DeleteRoleAsync(roleName); }); Assert.Equal(400, ex.StatusCode); @@ -113,7 +113,7 @@ public sealed class AppRolesTests : IClassFixture // STEP 5: AssignClient client. await AssignClient("Developer"); - var roles_3 = await _.Apps.DeleteRoleAsync(_.AppName, roleName); + var roles_3 = await _.Client.Apps.DeleteRoleAsync(roleName); Assert.DoesNotContain(roles_3.Items, x => x.Name == roleName); } @@ -128,7 +128,7 @@ public sealed class AppRolesTests : IClassFixture // STEP 2 Assign contributor. await AssignContributor(roleName); - var roles_2 = await _.Apps.GetRolesAsync(_.AppName); + var roles_2 = await _.Client.Apps.GetRolesAsync(); var role_2 = roles_2.Items.Find(x => x.Name == roleName); // Should return role with correct number of users and clients. @@ -139,7 +139,7 @@ public sealed class AppRolesTests : IClassFixture // STEP 4: Try to delete role. var ex = await Assert.ThrowsAnyAsync(() => { - return _.Apps.DeleteRoleAsync(_.AppName, roleName); + return _.Client.Apps.DeleteRoleAsync(roleName); }); Assert.Equal(400, ex.StatusCode); @@ -148,7 +148,7 @@ public sealed class AppRolesTests : IClassFixture // STEP 5: Remove role after contributor removed. await AssignContributor("Developer"); - var roles_3 = await _.Apps.DeleteRoleAsync(_.AppName, roleName); + var roles_3 = await _.Client.Apps.DeleteRoleAsync(roleName); Assert.DoesNotContain(roles_3.Items, x => x.Name == roleName); } @@ -164,7 +164,7 @@ public sealed class AppRolesTests : IClassFixture Invite = true }; - await _.Apps.PostContributorAsync(_.AppName, assignRequest); + await _.Client.Apps.PostContributorAsync(assignRequest); } private async Task AssignClient(string role = null) @@ -174,7 +174,7 @@ public sealed class AppRolesTests : IClassFixture Role = role }; - await _.Apps.PutClientAsync(_.AppName, client, updateRequest); + await _.Client.Apps.PutClientAsync(client, updateRequest); } private async Task CreateRoleAsync(string name) @@ -184,7 +184,7 @@ public sealed class AppRolesTests : IClassFixture Name = name }; - var roles = await _.Apps.PostRoleAsync(_.AppName, createRequest); + var roles = await _.Client.Apps.PostRoleAsync(createRequest); var role = roles.Items.Find(x => x.Name == name); return role; diff --git a/tools/TestSuite/TestSuite.ApiTests/AppTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppTests.cs index 8b55cba19..580b60cb2 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppTests.cs @@ -27,7 +27,7 @@ public sealed class AppTests : IClassFixture public async Task Should_get_app() { // STEP 1: Get app. - var app = await _.Apps.GetAppAsync(_.AppName); + var app = await _.Client.Apps.GetAppAsync(); Assert.Equal(_.AppName, app.Name); } @@ -41,7 +41,7 @@ public sealed class AppTests : IClassFixture Label = Guid.NewGuid().ToString() }; - var app_1 = await _.Apps.PutAppAsync(_.AppName, updateRequest); + var app_1 = await _.Client.Apps.PutAppAsync(updateRequest); Assert.Equal(updateRequest.Label, app_1.Label); } @@ -55,7 +55,7 @@ public sealed class AppTests : IClassFixture Description = Guid.NewGuid().ToString() }; - var app_1 = await _.Apps.PutAppAsync(_.AppName, updateRequest); + var app_1 = await _.Client.Apps.PutAppAsync(updateRequest); Assert.Equal(updateRequest.Description, app_1.Description); } @@ -68,7 +68,7 @@ public sealed class AppTests : IClassFixture { var file = new FileParameter(stream, "logo-squared.png", "image/png"); - var app_1 = await _.Apps.UploadImageAsync(_.AppName, file); + var app_1 = await _.Client.Apps.UploadImageAsync(file); // Should contain image link. Assert.True(app_1._links.ContainsKey("image")); @@ -82,7 +82,7 @@ public sealed class AppTests : IClassFixture var downloaded = new MemoryStream(); - using (var imageStream = await _.Apps.GetImageAsync(_.AppName)) + using (var imageStream = await _.Client.Apps.GetImageAsync()) { await imageStream.Stream.CopyToAsync(downloaded); } @@ -100,7 +100,7 @@ public sealed class AppTests : IClassFixture { var file = new FileParameter(stream, "logo-squared.png", "image/png"); - var app_1 = await _.Apps.UploadImageAsync(_.AppName, file); + var app_1 = await _.Client.Apps.UploadImageAsync(file); // Should contain image link. Assert.True(app_1._links.ContainsKey("image")); @@ -108,7 +108,7 @@ public sealed class AppTests : IClassFixture // STEP 2: Delete Image. - var app_2 = await _.Apps.DeleteImageAsync(_.AppName); + var app_2 = await _.Client.Apps.DeleteImageAsync(); // Should contain image link. Assert.False(app_2._links.ContainsKey("image")); @@ -118,7 +118,7 @@ public sealed class AppTests : IClassFixture public async Task Should_get_settings() { // STEP 1: Get initial settings. - var settings_0 = await _.Apps.GetSettingsAsync(_.AppName); + var settings_0 = await _.Client.Apps.GetSettingsAsync(); Assert.NotEmpty(settings_0.Patterns); } @@ -139,7 +139,7 @@ public sealed class AppTests : IClassFixture } }; - var settings_1 = await _.Apps.PutSettingsAsync(_.AppName, updateRequest); + var settings_1 = await _.Client.Apps.PutSettingsAsync(updateRequest); Assert.NotEmpty(settings_1.Patterns); Assert.NotEmpty(settings_1.Editors); diff --git a/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs index 3959dc3c0..716003649 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Squidex.ClientLibrary; using Squidex.ClientLibrary.Management; using TestSuite.Fixtures; @@ -30,11 +31,11 @@ public sealed class AppWorkflowsTests : IClassFixture public async Task Should_create_workflow() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Create workflow. - var workflow = await CreateAsync(); + var workflow = await CreateAsync(app); Assert.NotNull(workflow); Assert.NotNull(workflow.Name); @@ -47,11 +48,11 @@ public sealed class AppWorkflowsTests : IClassFixture public async Task Should_update_workflow() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 0: Create workflow. - var workflow = await CreateAsync(); + var workflow = await CreateAsync(app); // STEP 1: Update workflow. @@ -72,7 +73,7 @@ public sealed class AppWorkflowsTests : IClassFixture Name = name }; - var workflows_2 = await _.Apps.PutWorkflowAsync(appName, workflow.Id, updateRequest); + var workflows_2 = await app.Apps.PutWorkflowAsync(workflow.Id, updateRequest); var workflow_2 = workflows_2.Items.Find(x => x.Name == name); Assert.NotNull(workflow_2); @@ -86,41 +87,31 @@ public sealed class AppWorkflowsTests : IClassFixture public async Task Should_delete_workflow() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 0: Create workflow. - var workflow = await CreateAsync(); + var workflow = await CreateAsync(app); // STEP 1: Delete workflow. - var workflows_2 = await _.Apps.DeleteWorkflowAsync(appName, workflow.Id); + var workflows_2 = await app.Apps.DeleteWorkflowAsync(workflow.Id); Assert.DoesNotContain(workflows_2.Items, x => x.Name == name); await Verify(workflows_2); } - private async Task CreateAsync() + private async Task CreateAsync(ISquidexClient app) { var createRequest = new AddWorkflowDto { Name = name }; - var workflows = await _.Apps.PostWorkflowAsync(appName, createRequest); + var workflows = await app.Apps.PostWorkflowAsync(createRequest); var workflow = workflows.Items.Find(x => x.Name == name); return workflow; } - - private async Task CreateAppAsync() - { - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); - } } diff --git a/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs b/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs index 333c7ec7d..0efd1974a 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs @@ -26,7 +26,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_gif_without_extension() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_150kb.gif", "image/gif", Guid.NewGuid().ToString()); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_150kb.gif", "image/gif", Guid.NewGuid().ToString()); // Should parse image metadata. Assert.True(asset.IsImage); @@ -45,7 +45,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_gif_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_150kb.gif", "image/gif"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_150kb.gif", "image/gif"); await AssertImageAsync(asset); } @@ -53,7 +53,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_png_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_400kb.png", "image/png"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_400kb.png", "image/png"); await AssertImageAsync(asset); } @@ -61,7 +61,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_jpg_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_62kb.jpg", "image/jpg"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_62kb.jpg", "image/jpg"); await AssertImageAsync(asset); @@ -71,7 +71,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_webp_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_100kb.webp", "image/jpg"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_100kb.webp", "image/jpg"); await AssertImageAsync(asset); } @@ -79,7 +79,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_tiff_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_400kb.tiff", "image/jpg"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_400kb.tiff", "image/jpg"); await AssertImageAsync(asset); } @@ -87,7 +87,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_tga_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_600kb.tga", "image/x-tga"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_600kb.tga", "image/x-tga"); await AssertImageAsync(asset); } @@ -95,7 +95,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_bmp_and_resize() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_700kb.bmp", "image/bmp"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_700kb.bmp", "image/bmp"); await AssertImageAsync(asset); } @@ -103,7 +103,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_image_bmp_and_encode_to_webp() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleImage_700kb.bmp", "image/bmp"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleImage_700kb.bmp", "image/bmp"); var (size, type) = await GetReformattedLength(asset.Id, "WEBP"); @@ -133,7 +133,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_fix_orientation() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-wide-rotated.jpg", "image/jpg"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/logo-wide-rotated.jpg", "image/jpg"); // Should parse image metadata and fix orientation. Assert.True(asset.IsImage); @@ -150,7 +150,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_audio_mp3() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleAudio_0.4mb.mp3", "audio/mp3"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleAudio_0.4mb.mp3", "audio/mp3"); // Should parse audio metadata. Assert.False(asset.IsImage); @@ -166,7 +166,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_video_mp4() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleVideo_1280x720_1mb.mp4", "audio/mp4"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleVideo_1280x720_1mb.mp4", "audio/mp4"); // Should parse video metadata. Assert.False(asset.IsImage); @@ -184,7 +184,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_video_mkv() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleVideo_1280x720_1mb.flv", "audio/webm"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleVideo_1280x720_1mb.flv", "audio/webm"); // Should not parse yet. Assert.Equal(AssetType.Unknown, asset.Type); @@ -195,7 +195,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_video_flv() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleVideo_1280x720_1mb.flv", "audio/x-flv"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleVideo_1280x720_1mb.flv", "audio/x-flv"); // Should not parse yet. Assert.Equal(AssetType.Unknown, asset.Type); @@ -206,7 +206,7 @@ public class AssetFormatTests : IClassFixture [Fact] public async Task Should_upload_video_3gp() { - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/SampleVideo_176x144_1mb.3gp", "audio/3gpp"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/SampleVideo_176x144_1mb.3gp", "audio/3gpp"); // Should not parse yet. Assert.Equal(AssetType.Unknown, asset.Type); @@ -216,9 +216,9 @@ public class AssetFormatTests : IClassFixture private async Task GetResizedLengthAsync(string imageId, int width, int height) { - var url = $"{_.ClientManager.GenerateImageUrl(imageId)}?width={width}&height={height}"; + var url = $"{_.Client.GenerateImageUrl(imageId)}?width={width}&height={height}"; - var httpClient = _.ClientManager.CreateHttpClient(); + var httpClient = _.Client.CreateHttpClient(); var response = await httpClient.GetAsync(url); @@ -234,9 +234,9 @@ public class AssetFormatTests : IClassFixture private async Task<(long, string)> GetReformattedLength(string imageId, string format) { - var url = $"{_.ClientManager.GenerateImageUrl(imageId)}?format={format}"; + var url = $"{_.Client.GenerateImageUrl(imageId)}?format={format}"; - var httpClient = _.ClientManager.CreateHttpClient(); + var httpClient = _.Client.CreateHttpClient(); var response = await httpClient.GetAsync(url); diff --git a/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs b/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs index 079410f12..d4505b2a4 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs @@ -31,7 +31,7 @@ public class AssetTests : IClassFixture public async Task Should_upload_asset() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); await using (var stream = new FileStream("Assets/logo-squared.png", FileMode.Open)) { @@ -52,7 +52,7 @@ public class AssetTests : IClassFixture await using (fileParameter.Data) { - await _.Assets.UploadAssetAsync(_.AppName, fileParameter, progress.AsOptions()); + await _.Client.Assets.UploadAssetAsync(fileParameter, progress.AsOptions()); } Assert.Null(progress.Exception); @@ -101,7 +101,7 @@ public class AssetTests : IClassFixture var id = Guid.NewGuid().ToString(); // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png", id: id); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png", id: id); Assert.Equal(id, asset_1.Id); @@ -116,7 +116,7 @@ public class AssetTests : IClassFixture // STEP 1: Create asset var fileParameter = FileParameter.FromPath("Assets/logo-squared.png"); - await _.Assets.UploadAssetAsync(_.AppName, fileParameter, progress.AsOptions(id)); + await _.Client.Assets.UploadAssetAsync(fileParameter, progress.AsOptions(id)); Assert.Equal(id, progress.Asset?.Id); } @@ -127,13 +127,13 @@ public class AssetTests : IClassFixture var id = Guid.NewGuid().ToString(); // STEP 1: Create asset - await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png", id: id); + await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png", id: id); // STEP 2: Create a new item with a custom id. var ex = await Assert.ThrowsAnyAsync(() => { - return _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png", id: id); + return _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png", id: id); }); Assert.Equal(409, ex.StatusCode); @@ -143,13 +143,13 @@ public class AssetTests : IClassFixture public async Task Should_not_create_very_big_asset() { // STEP 1: Create small asset - await _.Assets.UploadRandomFileAsync(_.AppName, 1_000_000); + await _.Client.Assets.UploadRandomFileAsync(1_000_000); // STEP 2: Create big asset var ex = await Assert.ThrowsAnyAsync(() => { - return _.Assets.UploadRandomFileAsync(_.AppName, 10_000_000); + return _.Client.Assets.UploadRandomFileAsync(10_000_000); }); // Client library cannot catch this exception properly. @@ -160,11 +160,11 @@ public class AssetTests : IClassFixture public async Task Should_replace_asset() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Reupload asset - var asset_2 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-wide.png", asset_1); + var asset_2 = await _.Client.Assets.UploadFileAsync("Assets/logo-wide.png", asset_1); await using (var stream = new FileStream("Assets/logo-wide.png", FileMode.Open)) { @@ -181,7 +181,7 @@ public class AssetTests : IClassFixture public async Task Should_replace_asset_using_tus() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Reupload asset @@ -189,7 +189,7 @@ public class AssetTests : IClassFixture await using (fileParameter.Data) { - await _.Assets.UploadAssetAsync(_.AppName, fileParameter, progress.AsOptions(asset_1.Id)); + await _.Client.Assets.UploadAssetAsync(fileParameter, progress.AsOptions(asset_1.Id)); } Assert.Null(progress.Exception); @@ -211,7 +211,7 @@ public class AssetTests : IClassFixture for (var i = 0; i < 1; i++) { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Reupload asset @@ -240,7 +240,7 @@ public class AssetTests : IClassFixture public async Task Should_annote_asset_file_name() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Annotate file name. @@ -249,7 +249,7 @@ public class AssetTests : IClassFixture FileName = "My Image" }; - var asset_2 = await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, fileNameRequest); + var asset_2 = await _.Client.Assets.PutAssetAsync(asset_1.Id, fileNameRequest); // Should provide updated file name. Assert.Equal(fileNameRequest.FileName, asset_2.FileName); @@ -261,7 +261,7 @@ public class AssetTests : IClassFixture public async Task Should_annote_asset_metadata() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Annotate metadata. @@ -274,7 +274,7 @@ public class AssetTests : IClassFixture } }; - var asset_2 = await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, metadataRequest); + var asset_2 = await _.Client.Assets.PutAssetAsync(asset_1.Id, metadataRequest); // Should provide metadata. Assert.Equal(metadataRequest.Metadata, asset_2.Metadata); @@ -286,7 +286,7 @@ public class AssetTests : IClassFixture public async Task Should_annote_asset_slug() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Annotate slug. @@ -295,7 +295,7 @@ public class AssetTests : IClassFixture Slug = "my-image" }; - var asset_2 = await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, slugRequest); + var asset_2 = await _.Client.Assets.PutAssetAsync(asset_1.Id, slugRequest); // Should provide updated slug. Assert.Equal(slugRequest.Slug, asset_2.Slug); @@ -307,7 +307,7 @@ public class AssetTests : IClassFixture public async Task Should_annote_asset_tags() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Annotate tags. @@ -320,7 +320,7 @@ public class AssetTests : IClassFixture } }; - var asset_2 = await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, tagsRequest); + var asset_2 = await _.Client.Assets.PutAssetAsync(asset_1.Id, tagsRequest); // Should provide updated tags. Assert.Equal(tagsRequest.Tags, asset_2.Tags); @@ -332,7 +332,7 @@ public class AssetTests : IClassFixture public async Task Should_annotate_asset_in_parallel() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 3: Make parallel upserts. @@ -352,7 +352,7 @@ public class AssetTests : IClassFixture } }; - await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, randomMetadataRequest); + await _.Client.Assets.PutAssetAsync(asset_1.Id, randomMetadataRequest); } catch (SquidexManagementException ex) when (ex.StatusCode is 409 or 412) { @@ -374,11 +374,11 @@ public class AssetTests : IClassFixture } }; - var asset_2 = await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, metadataRequest); + var asset_2 = await _.Client.Assets.PutAssetAsync(asset_1.Id, metadataRequest); // STEP 4: Check tags - var tags = await _.Assets.WaitForTagsAsync(_.AppName, tag1, TimeSpan.FromMinutes(2)); + var tags = await _.Client.Assets.WaitForTagsAsync(tag1, TimeSpan.FromMinutes(2)); Assert.Contains(tag1, tags); Assert.Contains(tag2, tags); @@ -394,7 +394,7 @@ public class AssetTests : IClassFixture public async Task Should_protect_asset() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Download asset @@ -413,7 +413,7 @@ public class AssetTests : IClassFixture IsProtected = true }; - var asset_2 = await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, protectRequest); + var asset_2 = await _.Client.Assets.PutAssetAsync(asset_1.Id, protectRequest); // STEP 5: Download asset with authentication. @@ -421,7 +421,7 @@ public class AssetTests : IClassFixture { var downloaded = new MemoryStream(); - using (var assetStream = await _.Assets.GetAssetContentBySlugAsync(_.AppName, asset_2.Id, string.Empty)) + using (var assetStream = await _.Client.Assets.GetAssetContentBySlugAsync(asset_2.Id, string.Empty)) { await assetStream.Stream.CopyToAsync(downloaded); } @@ -470,7 +470,7 @@ public class AssetTests : IClassFixture Name = appName }; - await _.Apps.PostAppAsync(appRequest); + await _.PostAppAsync(appRequest); // STEP 1: Create folder. @@ -479,11 +479,11 @@ public class AssetTests : IClassFixture FolderName = "folder" }; - var folder = await _.Assets.PostAssetFolderAsync(appName, folderRequest); + var folder = await _.Client.Assets.PostAssetFolderAsync(folderRequest); // STEP 2: Create asset - var asset_1 = await _.Assets.UploadFileAsync(appName, "Assets/logo-squared.png", "image/png", parentId: folder.Id); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png", parentId: folder.Id); // STEP 3: Download asset @@ -505,7 +505,7 @@ public class AssetTests : IClassFixture }}" }; - await _.Apps.PutAssetScriptsAsync(appName, scriptsRequest); + await _.Client.Apps.PutAssetScriptsAsync(scriptsRequest); // STEP 5: Download asset. @@ -527,11 +527,11 @@ public class AssetTests : IClassFixture public async Task Should_query_asset_by_metadata() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Query asset by pixel width. - var assets_1 = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery + var assets_1 = await _.Client.Assets.GetAssetsAsync(new AssetQuery { Filter = "metadata/pixelWidth eq 600" }); @@ -542,14 +542,14 @@ public class AssetTests : IClassFixture // STEP 3: Add custom metadata. asset_1.Metadata["custom"] = "foo"; - await _.Assets.PutAssetAsync(_.AppName, asset_1.Id, new AnnotateAssetDto + await _.Client.Assets.PutAssetAsync(asset_1.Id, new AnnotateAssetDto { Metadata = asset_1.Metadata }); // STEP 4: Query asset by custom metadata - var assets_2 = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery + var assets_2 = await _.Client.Assets.GetAssetsAsync(new AssetQuery { Filter = "metadata/custom eq 'foo'" }); @@ -561,11 +561,11 @@ public class AssetTests : IClassFixture public async Task Should_query_asset_by_root_folder() { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Query asset by root folder. - var assets_1 = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery + var assets_1 = await _.Client.Assets.GetAssetsAsync(new AssetQuery { ParentId = Guid.Empty.ToString() }); @@ -582,15 +582,15 @@ public class AssetTests : IClassFixture FolderName = "sub" }; - var folder = await _.Assets.PostAssetFolderAsync(_.AppName, folderRequest); + var folder = await _.Client.Assets.PostAssetFolderAsync(folderRequest); // STEP 1: Create asset in folder - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png", parentId: folder.Id); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png", parentId: folder.Id); // STEP 2: Query asset by root folder. - var assets_1 = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery + var assets_1 = await _.Client.Assets.GetAssetsAsync(new AssetQuery { ParentId = folder.Id }); @@ -607,7 +607,7 @@ public class AssetTests : IClassFixture FolderName = "folder1" }; - var folder_1 = await _.Assets.PostAssetFolderAsync(_.AppName, createRequest1); + var folder_1 = await _.Client.Assets.PostAssetFolderAsync(createRequest1); // STEP 2: Create nested asset folder @@ -618,25 +618,25 @@ public class AssetTests : IClassFixture ParentId = folder_1.Id }; - var folder_2 = await _.Assets.PostAssetFolderAsync(_.AppName, createRequest2); + var folder_2 = await _.Client.Assets.PostAssetFolderAsync(createRequest2); // STEP 3: Create asset in folder - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png", null, folder_2.Id); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png", null, folder_2.Id); // STEP 4: Create asset outside folder - var asset_2 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_2 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 5: Delete folder. - await _.Assets.DeleteAssetFolderAsync(_.AppName, folder_1.Id); + await _.Client.Assets.DeleteAssetFolderAsync(folder_1.Id); // Ensure that asset in folder is deleted. - Assert.True(await _.Assets.WaitForDeletionAsync(_.AppName, asset_1.Id, TimeSpan.FromSeconds(30))); + Assert.True(await _.Client.Assets.WaitForDeletionAsync(asset_1.Id, TimeSpan.FromSeconds(30))); // Ensure that other asset is not deleted. - Assert.NotNull(await _.Assets.GetAssetAsync(_.AppName, asset_2.Id)); + Assert.NotNull(await _.Client.Assets.GetAssetAsync(asset_2.Id)); } [Theory] @@ -645,29 +645,29 @@ public class AssetTests : IClassFixture public async Task Should_delete_asset(bool permanent) { // STEP 1: Create asset - var asset = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Delete asset - await _.Assets.DeleteAssetAsync(_.AppName, asset.Id, permanent: permanent); + await _.Client.Assets.DeleteAssetAsync(asset.Id, permanent: permanent); // Should return 404 when asset deleted. var ex = await Assert.ThrowsAnyAsync(() => { - return _.Assets.GetAssetAsync(_.AppName, asset.Id); + return _.Client.Assets.GetAssetAsync(asset.Id); }); Assert.Equal(404, ex.StatusCode); // STEP 3: Retrieve all items and ensure that the deleted item does not exist. - var updated = await _.Assets.GetAssetsAsync(_.AppName, (AssetQuery)null); + var updated = await _.Client.Assets.GetAssetsAsync((AssetQuery)null); Assert.DoesNotContain(updated.Items, x => x.Id == asset.Id); // STEP 4: Retrieve all deleted items and check if found. - var deleted = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery + var deleted = await _.Client.Assets.GetAssetsAsync(new AssetQuery { Filter = "isDeleted eq true" }); @@ -681,15 +681,15 @@ public class AssetTests : IClassFixture public async Task Should_recreate_deleted_asset(bool permanent) { // STEP 1: Create asset - var asset_1 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-squared.png", "image/png"); + var asset_1 = await _.Client.Assets.UploadFileAsync("Assets/logo-squared.png", "image/png"); // STEP 2: Delete asset - await _.Assets.DeleteAssetAsync(_.AppName, asset_1.Id, permanent: permanent); + await _.Client.Assets.DeleteAssetAsync(asset_1.Id, permanent: permanent); // STEP 3: Recreate asset - var asset_2 = await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-wide.png", "image/png"); + var asset_2 = await _.Client.Assets.UploadFileAsync("Assets/logo-wide.png", "image/png"); Assert.NotEqual(asset_1.FileSize, asset_2.FileSize); } @@ -710,7 +710,7 @@ public class AssetTests : IClassFixture { pausingStream.Reset(); - await _.Assets.UploadAssetAsync(_.AppName, pausingFile, progress.AsOptions(id), cts.Token); + await _.Client.Assets.UploadAssetAsync(pausingFile, progress.AsOptions(id), cts.Token); progress.Uploaded(); } } @@ -824,7 +824,7 @@ public class AssetTests : IClassFixture if (remaining < buffer.Length) { - buffer = buffer[.. (int)remaining]; + buffer = buffer[..(int)remaining]; } var bytesRead = await base.ReadAsync(buffer, cancellationToken); diff --git a/tools/TestSuite/TestSuite.ApiTests/BackupTests.cs b/tools/TestSuite/TestSuite.ApiTests/BackupTests.cs index 6a89c1e44..d93ebadf4 100644 --- a/tools/TestSuite/TestSuite.ApiTests/BackupTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/BackupTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Squidex.ClientLibrary; using Squidex.ClientLibrary.Management; using TestSuite.Fixtures; using TestSuite.Model; @@ -18,6 +19,7 @@ namespace TestSuite.ApiTests; public class BackupTests : IClassFixture { private readonly string appName = Guid.NewGuid().ToString(); + private readonly string appNameRestore = $"{Guid.NewGuid()}-restore"; private readonly string schemaName = $"schema-{Guid.NewGuid()}"; public ClientFixture _ { get; } @@ -33,25 +35,18 @@ public class BackupTests : IClassFixture // Load the backup from another URL, because the public URL is might not be accessible for the server. var backupUrl = TestHelpers.GetAndPrintValue("config:backupUrl", _.Url); - var appNameRestore = $"{appName}-restore"; - // STEP 1: Create app - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); + var (app, _) = await _.PostAppAsync(appName); // STEP 2: Prepare app. - await PrepareAppAsync(appName); + await PrepareAppAsync(app); // STEP 3: Create backup - await _.Backups.PostBackupAsync(appName); + await app.Backups.PostBackupAsync(); - var backups = await _.Backups.WaitForBackupsAsync(appName, x => x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); + var backups = await app.Backups.WaitForBackupsAsync(x => x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); var backup = backups.FirstOrDefault(x => x.Status is JobStatus.Completed or JobStatus.Failed); Assert.Equal(JobStatus.Completed, backup?.Status); @@ -67,11 +62,11 @@ public class BackupTests : IClassFixture Name = appNameRestore }; - await _.Backups.PostRestoreJobAsync(restoreRequest); + await _.Client.Backups.PostRestoreJobAsync(restoreRequest); // STEP 5: Wait for the backup. - var restore = await _.Backups.WaitForRestoreAsync(x => x.Url == uri && x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); + var restore = await app.Backups.WaitForRestoreAsync(x => x.Url == uri && x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); Assert.Equal(JobStatus.Completed, restore?.Status); } @@ -83,29 +78,24 @@ public class BackupTests : IClassFixture var backupUrl = TestHelpers.GetAndPrintValue("config:backupUrl", _.Url); // STEP 1: Create app - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); + var (app, _) = await _.PostAppAsync(appNameRestore); // STEP 2: Prepare app. - await PrepareAppAsync(appName); + await PrepareAppAsync(app); // STEP 3: Create backup - await _.Backups.PostBackupAsync(appName); + await app.Backups.PostBackupAsync(); - var backups = await _.Backups.WaitForBackupsAsync(appName, x => x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); + var backups = await app.Backups.WaitForBackupsAsync(x => x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); var backup = backups.FirstOrDefault(x => x.Status is JobStatus.Completed or JobStatus.Failed); Assert.Equal(JobStatus.Completed, backup?.Status); // STEP 4: Delete app - await _.Apps.DeleteAppAsync(appName); + await app.Apps.DeleteAppAsync(); // STEP 5: Restore backup @@ -118,21 +108,21 @@ public class BackupTests : IClassFixture Name = appName }; - await _.Backups.PostRestoreJobAsync(restoreRequest); + await app.Backups.PostRestoreJobAsync(restoreRequest); // STEP 6: Wait for the backup. - var restore = await _.Backups.WaitForRestoreAsync(x => x.Url == uri && x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); + var restore = await app.Backups.WaitForRestoreAsync(x => x.Url == uri && x.Status is JobStatus.Completed or JobStatus.Failed, TimeSpan.FromMinutes(2)); Assert.Equal(JobStatus.Completed, restore?.Status); } - private async Task PrepareAppAsync(string appName) + private async Task PrepareAppAsync(ISquidexClient app) { // Create a test schema. - await TestEntity.CreateSchemaAsync(_.Schemas, appName, schemaName); + await TestEntity.CreateSchemaAsync(app.Schemas, schemaName); - var contents = _.ClientManager.CreateContentsClient(appName, schemaName); + var contents = app.Contents(schemaName); await contents.CreateAsync(new TestEntityData { @@ -147,7 +137,7 @@ public class BackupTests : IClassFixture { var upload = new FileParameter(stream, fileInfo.Name, "image/png"); - await _.Assets.PostAssetAsync(appName, file: upload); + await app.Assets.PostAssetAsync(file: upload); } @@ -157,7 +147,7 @@ public class BackupTests : IClassFixture Name = appName }; - await _.Apps.PostWorkflowAsync(appName, workflowRequest); + await app.Apps.PostWorkflowAsync(workflowRequest); // Create a language @@ -166,6 +156,6 @@ public class BackupTests : IClassFixture Language = "de" }; - await _.Apps.PostLanguageAsync(appName, languageRequest); + await app.Apps.PostLanguageAsync(languageRequest); } } diff --git a/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs b/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs index f41e5c044..d2db5c0e6 100644 --- a/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs @@ -27,7 +27,7 @@ public class CDNTests : IClassFixture { var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb"; - var url = _.CDNClientManager.GenerateImageUrl(id); + var url = _.CDNClient.GenerateImageUrl(id); Assert.StartsWith("https://assets.squidex.io/", url, StringComparison.Ordinal); } @@ -37,7 +37,7 @@ public class CDNTests : IClassFixture { var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb"; - var url = _.CDNClientManager.GenerateImageUrl(id); + var url = _.CDNClient.GenerateImageUrl(id); await DownloadAsync(url); } @@ -47,7 +47,7 @@ public class CDNTests : IClassFixture { var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb"; - var url = _.ClientManager.GenerateImageUrl(id); + var url = _.CloudClient.GenerateImageUrl(id); Assert.StartsWith("https://cloud.squidex.io/", url, StringComparison.Ordinal); } @@ -57,7 +57,7 @@ public class CDNTests : IClassFixture { var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb"; - var url = _.ClientManager.GenerateImageUrl(id); + var url = _.CloudClient.GenerateImageUrl(id); await DownloadAsync(url); } @@ -65,7 +65,7 @@ public class CDNTests : IClassFixture [Fact] public async Task Should_get_blog_items_from_cdn() { - var client = _.CDNClientManager.CreateContentsClient("blog"); + var client = _.CDNClient.Contents("blog"); var result = await client.GetAsync(); @@ -75,7 +75,7 @@ public class CDNTests : IClassFixture [Fact] public async Task Should_get_blog_items_from_cloud_when_cdn_not_configured() { - var client = _.ClientManager.CreateContentsClient("blog"); + var client = _.CloudClient.Contents("blog"); var result = await client.GetAsync(); diff --git a/tools/TestSuite/TestSuite.ApiTests/CommentsTests.cs b/tools/TestSuite/TestSuite.ApiTests/CommentsTests.cs index 4f6300d21..fd28a2c4a 100644 --- a/tools/TestSuite/TestSuite.ApiTests/CommentsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/CommentsTests.cs @@ -28,7 +28,7 @@ public class CommentsTests : IClassFixture [Fact] public async Task Should_make_watch_request() { - var result = await _.Comments.GetWatchingUsersAsync(_.AppName, resource); + var result = await _.Client.Comments.GetWatchingUsersAsync(resource); Assert.NotNull(result); } @@ -42,11 +42,11 @@ public class CommentsTests : IClassFixture Text = resource }; - await _.Comments.PostCommentAsync(_.AppName, resource, createRequest); + await _.Client.Comments.PostCommentAsync(resource, createRequest); // STEP 2: Get comments - var comments = await _.Comments.GetCommentsAsync(_.AppName, resource); + var comments = await _.Client.Comments.GetCommentsAsync(resource); Assert.Contains(comments.CreatedComments, x => x.Text == createRequest.Text); @@ -63,7 +63,7 @@ public class CommentsTests : IClassFixture Text = resource }; - var comment = await _.Comments.PostCommentAsync(_.AppName, resource, createRequest); + var comment = await _.Client.Comments.PostCommentAsync(resource, createRequest); // STEP 2: Update comment. @@ -72,11 +72,11 @@ public class CommentsTests : IClassFixture Text = $"{resource}_Update" }; - await _.Comments.PutCommentAsync(_.AppName, resource, comment.Id, updateRequest); + await _.Client.Comments.PutCommentAsync(resource, comment.Id, updateRequest); // STEP 3: Get comments since create. - var comments = await _.Comments.GetCommentsAsync(_.AppName, resource, 0); + var comments = await _.Client.Comments.GetCommentsAsync(resource, 0); Assert.Contains(comments.UpdatedComments, x => x.Text == updateRequest.Text); @@ -93,15 +93,15 @@ public class CommentsTests : IClassFixture Text = resource }; - var comment = await _.Comments.PostCommentAsync(_.AppName, resource, createRequest); + var comment = await _.Client.Comments.PostCommentAsync(resource, createRequest); // STEP 2: Delete comment. - await _.Comments.DeleteCommentAsync(_.AppName, resource, comment.Id); + await _.Client.Comments.DeleteCommentAsync(resource, comment.Id); // STEP 3: Get comments since create. - var comments = await _.Comments.GetCommentsAsync(_.AppName, resource, 0); + var comments = await _.Client.Comments.GetCommentsAsync(resource, 0); Assert.Contains(comment.Id, comments.DeletedComments); diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentCleanupTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentCleanupTests.cs index f28832a40..3aef06b76 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentCleanupTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentCleanupTests.cs @@ -29,9 +29,9 @@ public class ContentCleanupTests : IClassFixture public async Task Should_cleanup_old_data_from_update_response() { // STEP 1: Create a schema. - var schema = await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName); + var schema = await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName); - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); // STEP 2: Create a content for this schema. @@ -44,7 +44,7 @@ public class ContentCleanupTests : IClassFixture // STEP 3: Delete a field from schema. - await _.Schemas.DeleteFieldAsync(_.AppName, schema.Name, schema.Fields.First(x => x.Name == TestEntityData.StringField).FieldId); + await _.Client.Schemas.DeleteFieldAsync(schema.Name, schema.Fields.First(x => x.Name == TestEntityData.StringField).FieldId); // STEP 4: Make any update. @@ -61,9 +61,9 @@ public class ContentCleanupTests : IClassFixture public async Task Should_cleanup_old_references() { // STEP 1: Create a schema. - await TestEntityWithReferences.CreateSchemaAsync(_.Schemas, _.AppName, schemaName); + await TestEntityWithReferences.CreateSchemaAsync(_.Client.Schemas, schemaName); - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); // STEP 2: Create a referenced content. diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentLanguageTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentLanguageTests.cs index 57113d688..e516a2ad7 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentLanguageTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentLanguageTests.cs @@ -58,7 +58,7 @@ public class ContentLanguageTests : IClassFixture // STEP 2: Get content. - var contents = _.ClientManager.CreateDynamicContentsClient(_.Contents.SchemaName); + var contents = _.Client.DynamicContents(_.Contents.SchemaName); var contentFlatten = await contents.GetAsync(content.Id, QueryContext.Default.Flatten().WithLanguages(code)); @@ -113,9 +113,9 @@ public class ContentLanguageTests : IClassFixture private async Task<(string, string)> GetEtagAsync(string id, Dictionary headers) { - var url = $"{_.ClientManager.Options.Url}api/content/{_.AppName}/{_.SchemaName}/{id}"; + var url = $"{_.Client.Options.Url}api/content/{_.AppName}/{_.SchemaName}/{id}"; - var httpClient = _.ClientManager.CreateHttpClient(); + var httpClient = _.Client.CreateHttpClient(); foreach (var (key, value) in headers) { diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs index 46f4988aa..45ab1d5b7 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs @@ -31,9 +31,9 @@ public class ContentQueryTests : IClassFixture { var schemaName = $"schema-{Guid.NewGuid()}"; - await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName); + await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName); - var contentClient = _.ClientManager.CreateContentsClient(schemaName); + var contentClient = _.Client.Contents(schemaName); var contentItems = await contentClient.GetAsync(); Assert.Equal(0, contentItems.Total); @@ -55,7 +55,6 @@ public class ContentQueryTests : IClassFixture foreach (var item in items_1.Items) { - Assert.Equal(_.AppName, item.AppName); Assert.Equal(_.SchemaName, item.SchemaName); } } @@ -68,14 +67,13 @@ public class ContentQueryTests : IClassFixture var items_0 = await _.Contents.GetAsync(q); var itemsIds = items_0.Items.Take(3).Select(x => x.Id).ToHashSet(); - var items_1 = await _.SharedContents.GetAsync(itemsIds); + var items_1 = await _.Client.SharedDynamicContents.GetAsync(itemsIds); Assert.Equal(3, items_1.Items.Count); Assert.Equal(3, items_1.Total); foreach (var item in items_1.Items) { - Assert.Equal(_.AppName, item.AppName); Assert.Equal(_.SchemaName, item.SchemaName); } } @@ -528,7 +526,7 @@ public class ContentQueryTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var value = result["createMyReadsContent"]["data"]["number"]["iv"].Value(); @@ -563,7 +561,7 @@ public class ContentQueryTests : IClassFixture } }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var value = result["createMyReadsContent"]["data"]["number"]["iv"].Value(); @@ -611,7 +609,7 @@ public class ContentQueryTests : IClassFixture } }; - var results = await _.SharedContents.GraphQlAsync(new[] { query1, query2 }); + var results = await _.Client.SharedDynamicContents.GraphQlAsync(new[] { query1, query2 }); var items1 = results.ElementAt(0).Data.Items; var items2 = results.ElementAt(1).Data.Items; @@ -642,7 +640,7 @@ public class ContentQueryTests : IClassFixture } }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var items = result.Items; Assert.Equal(items.Select(x => x.Data.Number).ToArray(), new[] { 4, 5, 6 }); @@ -670,7 +668,7 @@ public class ContentQueryTests : IClassFixture } }; - var result = await _.SharedContents.GraphQlGetAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlGetAsync(query); var items = result.Items; Assert.Equal(items.Select(x => x.Data.Number).ToArray(), new[] { 4, 5, 6 }); @@ -694,7 +692,7 @@ public class ContentQueryTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var items = result["queryMyReadsContents"]; Assert.Equal(items.Select(x => x["data"]["number"]["iv"].Value()).ToArray(), new[] { 4, 5, 6 }); @@ -722,7 +720,7 @@ public class ContentQueryTests : IClassFixture } }; - await _.SharedContents.GraphQlAsync(query); + await _.Client.SharedDynamicContents.GraphQlAsync(query); } private sealed class QueryResult diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentScriptingTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentScriptingTests.cs index 9604bb377..bc96637dd 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentScriptingTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentScriptingTests.cs @@ -37,11 +37,11 @@ public class ContentScriptingTests : IClassFixture }; // STEP 1: Create a schema. - await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName, scripts); + await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName, scripts); // STEP 2: Create content - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); var content = await contents.CreateAsync(new TestEntityData { @@ -62,11 +62,11 @@ public class ContentScriptingTests : IClassFixture }; // STEP 1: Create a schema. - await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName, scripts); + await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName, scripts); // STEP 2: Create content - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); var content = await contents.CreateAsync(new TestEntityData { @@ -89,11 +89,11 @@ public class ContentScriptingTests : IClassFixture }; // STEP 1: Create a schema. - await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName, scripts); + await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName, scripts); // STEP 2: Create content - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); var content = await contents.CreateAsync(new TestEntityData { @@ -114,11 +114,11 @@ public class ContentScriptingTests : IClassFixture replace()" }; - await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName, scripts); + await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName, scripts); // STEP 2: Create content with a value that triggers the schema. - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); var results = await contents.BulkUpdateAsync(new BulkUpdate { @@ -162,11 +162,11 @@ public class ContentScriptingTests : IClassFixture replace()" }; - await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName, scripts); + await TestEntity.CreateSchemaAsync(_.Client.Schemas, schemaName, scripts); // STEP 1: Create content with a value that triggers the schema. - var contents = _.ClientManager.CreateContentsClient(schemaName); + var contents = _.Client.Contents(schemaName); var results = await contents.BulkUpdateAsync(new BulkUpdate { diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index b6418bdf2..f5f3d556a 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq; using Squidex.ClientLibrary; +using Squidex.ClientLibrary.EnrichedEvents; using Squidex.ClientLibrary.Management; using TestSuite.Model; @@ -347,7 +348,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Update with selected strategy. - await _.ClientManager.UpdateAsync(content, new TestEntityData + await _.Client.UpdateAsync(content, new TestEntityData { Number = 200 }, strategy); @@ -377,7 +378,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Update with selected strategy. - await _.ClientManager.UpdateAsync(content, new TestEntityData + await _.Client.UpdateAsync(content, new TestEntityData { String = null }, strategy); @@ -404,7 +405,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Patch with selected strategy. - await _.ClientManager.PatchAsync(content, new TestEntityData + await _.Client.PatchAsync(content, new TestEntityData { Number = 200 }, strategy); @@ -434,7 +435,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Patch with selected strategy. - await _.ClientManager.PatchAsync(content, new TestEntityData + await _.Client.PatchAsync(content, new TestEntityData { Id = "id2" }, strategy); @@ -461,7 +462,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Patch with selected strategy. - await _.ClientManager.PatchAsync(content, new + await _.Client.PatchAsync(content, new { @string = new { iv = (string)null } }, strategy); @@ -486,7 +487,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Delete with selected strategy. - await _.ClientManager.DeleteAsync(content, strategy); + await _.Client.DeleteAsync(content, strategy); // STEP 3: Retrieve all items and ensure that the deleted item does not exist. @@ -524,7 +525,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Delete with selected strategy. - await _.ClientManager.DeleteAsync(content, strategy); + await _.Client.DeleteAsync(content, strategy); // STEP 3: Retrieve all items and ensure that the deleted item does not exist. @@ -548,7 +549,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Delete with selected strategy. - await _.ClientManager.DeleteAsync(content_1, strategy); + await _.Client.DeleteAsync(content_1, strategy); // STEP 3: Recreate the item with the same id. @@ -585,7 +586,7 @@ public class ContentUpdateTests : IClassFixture // STEP 2: Delete with selected strategy. - await _.ClientManager.DeleteAsync(content_1, strategy); + await _.Client.DeleteAsync(content_1, strategy); // STEP 3: Recreate the item with the same id. @@ -629,7 +630,7 @@ public class ContentUpdateTests : IClassFixture // STEP 3: Permanently delete content with custom id again. - await _.ClientManager.DeleteAsync(content_2, strategy); + await _.Client.DeleteAsync(content_2, strategy); } [Fact] @@ -653,10 +654,10 @@ public class ContentUpdateTests : IClassFixture } }; - await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + await _.Client.Schemas.PostSchemaAsync(createRequest); - var client = _.ClientManager.CreateDynamicContentsClient(schemaName); + var client = _.Client.DynamicContents(schemaName); // STEP 2: Get content. var content_1 = await client.GetAsync("_schemaId_"); @@ -702,17 +703,17 @@ public class ContentUpdateTests : IClassFixture // STEP 4: Get current version. - var data_2 = await _.Contents.GetDataAsync(content.Id, content.Version); + var content_2 = await _.Contents.GetAsync(content.Id, content.Version); - Assert.Equal(2, data_2.Number); + Assert.Equal(2, content_2.Data.Number); // STEP 4: Get previous version - var data_1 = await _.Contents.GetDataAsync(content.Id, content.Version - 1); + var content_1 = await _.Contents.GetAsync(content.Id, content.Version - 1); - Assert.Equal(1, data_1.Number); + Assert.Equal(1, content_1.Data.Number); - await Verify(data_1); + await Verify(content_1); } [Fact] diff --git a/tools/TestSuite/TestSuite.ApiTests/DiagnosticsTests.cs b/tools/TestSuite/TestSuite.ApiTests/DiagnosticsTests.cs index 7f3646880..326c264e5 100644 --- a/tools/TestSuite/TestSuite.ApiTests/DiagnosticsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/DiagnosticsTests.cs @@ -23,6 +23,6 @@ public class DiagnosticsTests : IClassFixture [Fact] public async Task Should_create_gc_dump() { - await _.Diagnostics.GetGCDumpAsync(); + await _.Client.Diagnostics.GetGCDumpAsync(); } } diff --git a/tools/TestSuite/TestSuite.ApiTests/FrontendTests.cs b/tools/TestSuite/TestSuite.ApiTests/FrontendTests.cs index 09ca646fb..0c1d964ea 100644 --- a/tools/TestSuite/TestSuite.ApiTests/FrontendTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/FrontendTests.cs @@ -50,7 +50,7 @@ public sealed class FrontendTests : IClassFixture await using var page = await browser.NewPageAsync(); - await page.GoToAsync(_.ClientManager.Options.Url + url + "?skip-setup"); + await page.GoToAsync(_.Client.Options.Url + url + "?skip-setup"); await page.ScreenshotAsync($"__{name}.jpg"); var diff = ImageSharpCompare.CalcDiff($"__{name}.jpg", $"Assets/{name}.jpg"); diff --git a/tools/TestSuite/TestSuite.ApiTests/GraphQLFixture.cs b/tools/TestSuite/TestSuite.ApiTests/GraphQLFixture.cs index 0e6eb1a88..7f621aca7 100644 --- a/tools/TestSuite/TestSuite.ApiTests/GraphQLFixture.cs +++ b/tools/TestSuite/TestSuite.ApiTests/GraphQLFixture.cs @@ -32,7 +32,7 @@ public sealed class GraphQLFixture : ContentFixture { try { - var response = await Schemas.PostSchemaAsync(AppName, request); + var response = await Client.Schemas.PostSchemaAsync(request); return response.Id; } @@ -43,7 +43,7 @@ public sealed class GraphQLFixture : ContentFixture throw; } - var schema = await Schemas.GetSchemaAsync(AppName, request.Name); + var schema = await Client.Schemas.GetSchemaAsync(request.Name); return schema.Id; } @@ -121,7 +121,7 @@ public sealed class GraphQLFixture : ContentFixture private async Task CreateContentsAsync() { - var countriesClient = ClientManager.CreateContentsClient("countries"); + var countriesClient = Client.Contents("countries"); var countriesResponse = await countriesClient.GetAsync(); if (countriesResponse.Total > 0) @@ -139,11 +139,10 @@ public sealed class GraphQLFixture : ContentFixture } }; - var citiesClient = ClientManager.CreateContentsClient("cities"); + var citiesClient = Client.Contents("cities"); + var cityResponse = await citiesClient.CreateAsync(citySAData, ContentCreateOptions.AsPublish); - var city = await citiesClient.CreateAsync(citySAData, ContentCreateOptions.AsPublish); - - return city.Id; + return cityResponse.Id; } async Task CreateStateAsync(string name, string cityId) @@ -160,11 +159,10 @@ public sealed class GraphQLFixture : ContentFixture } }; - var statesClient = ClientManager.CreateContentsClient("states"); - - var state = await statesClient.CreateAsync(citySAData, ContentCreateOptions.AsPublish); + var statesClient = Client.Contents("states"); + var stateResponse = await statesClient.CreateAsync(citySAData, ContentCreateOptions.AsPublish); - return state.Id; + return stateResponse.Id; } // STEP 1: Create state 1 diff --git a/tools/TestSuite/TestSuite.ApiTests/GraphQLSubscriptionTests.cs b/tools/TestSuite/TestSuite.ApiTests/GraphQLSubscriptionTests.cs index d8556a9b7..95442e197 100644 --- a/tools/TestSuite/TestSuite.ApiTests/GraphQLSubscriptionTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/GraphQLSubscriptionTests.cs @@ -117,7 +117,7 @@ public class GraphQLSubscriptionTests : IClassFixture await using (fileParameter.Data) { - await _.Assets.UploadAssetAsync(_.AppName, fileParameter, new AssetUploadOptions { Id = assetId }); + await _.Client.Assets.UploadAssetAsync(fileParameter, new AssetUploadOptions { Id = assetId }); } // STEP 3: Wait for publication. @@ -128,11 +128,11 @@ public class GraphQLSubscriptionTests : IClassFixture private async Task CreateClient() { - var accessToken = await _.ClientManager.Options.Authenticator.GetBearerTokenAsync(_.AppName, default); + var accessToken = await _.Client.Options.Authenticator.GetBearerTokenAsync(_.AppName, default); var options = new GraphQLHttpClientOptions { - EndPoint = new Uri(_.ClientManager.GenerateUrl($"/api/content/{_.AppName}/graphql?access_token={accessToken}")) + EndPoint = new Uri(_.Client.GenerateUrl($"/api/content/{_.AppName}/graphql?access_token={accessToken}")) }; var client = new GraphQLHttpClient(options, new NewtonsoftJsonSerializer()); diff --git a/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs b/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs index c4f0645c0..d66abccfa 100644 --- a/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs @@ -55,7 +55,7 @@ public sealed class GraphQLTests : IClassFixture }".Replace("", content_0.Id, StringComparison.Ordinal) }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); Assert.Equal(1, result["findMyWritesContent"]["flatData"]["json"]["value"].Value()); Assert.Equal(2, result["findMyWritesContent"]["flatData"]["json"]["obj"]["value"].Value()); @@ -86,7 +86,7 @@ public sealed class GraphQLTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var cityNames = result["countries"].ToObject>()[0].Data.States @@ -122,7 +122,7 @@ public sealed class GraphQLTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var cityNames = result["countries"] @@ -159,7 +159,7 @@ public sealed class GraphQLTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var cityNames = result["countries"] @@ -188,7 +188,7 @@ public sealed class GraphQLTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var stateNames = result["cities"] @@ -216,7 +216,7 @@ public sealed class GraphQLTests : IClassFixture }" }; - var result = await _.SharedContents.GraphQlAsync(query); + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var stateNames = result["cities"] @@ -240,10 +240,10 @@ public sealed class GraphQLTests : IClassFixture }" }; - var httpClient = _.ClientManager.CreateHttpClient(); + var httpClient = _.Client.CreateHttpClient(); // Create the request manually to check the content type. - var response = await httpClient.PostAsync(_.ClientManager.GenerateUrl($"api/content/{_.AppName}/graphql/batch"), query.ToContent()); + var response = await httpClient.PostAsync(_.Client.GenerateUrl($"api/content/{_.AppName}/graphql/batch"), query.ToContent()); Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType); } @@ -261,7 +261,7 @@ public sealed class GraphQLTests : IClassFixture }" }; - var httpClient = _.ClientManager.CreateHttpClient(); + var httpClient = _.Client.CreateHttpClient(); // Create the request manually to check the headers. var response = await httpClient.PostAsJsonAsync($"api/content/{_.AppName}/graphql", query); diff --git a/tools/TestSuite/TestSuite.ApiTests/HistoryTests.cs b/tools/TestSuite/TestSuite.ApiTests/HistoryTests.cs index 57de1e0e8..cc435fbcd 100644 --- a/tools/TestSuite/TestSuite.ApiTests/HistoryTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/HistoryTests.cs @@ -23,7 +23,7 @@ public class HistoryTests : IClassFixture [Fact] public async Task Should_get_history() { - var history = await _.History.WaitForHistoryAsync(_.AppName, null, x => true, TimeSpan.FromSeconds(30)); + var history = await _.Client.History.WaitForHistoryAsync(null, x => true, TimeSpan.FromSeconds(30)); Assert.NotEmpty(history); } diff --git a/tools/TestSuite/TestSuite.ApiTests/LanguagesTests.cs b/tools/TestSuite/TestSuite.ApiTests/LanguagesTests.cs index a9e2cd7d9..56bd23abf 100644 --- a/tools/TestSuite/TestSuite.ApiTests/LanguagesTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/LanguagesTests.cs @@ -23,7 +23,7 @@ public class LanguagesTests : IClassFixture [Fact] public async Task Should_provide_languages() { - var languages = await _.Languages.GetLanguagesAsync(); + var languages = await _.Client.Languages.GetLanguagesAsync(); Assert.True(languages.Count > 100); } diff --git a/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs b/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs index 2431ace8a..5f230c7dd 100644 --- a/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs @@ -23,7 +23,7 @@ public class OpenApiTests : IClassFixture [Fact] public async Task Should_provide_general_spec() { - var url = $"{_.ClientManager.Options.Url}api/swagger/v1/swagger.json"; + var url = $"{_.Client.Options.Url}api/swagger/v1/swagger.json"; var document = await OpenApiDocument.FromUrlAsync(url); @@ -33,7 +33,7 @@ public class OpenApiTests : IClassFixture [Fact] public async Task Should_provide_content_spec() { - var url = $"{_.ClientManager.Options.Url}api/content/{_.AppName}/swagger/v1/swagger.json"; + var url = $"{_.Client.Options.Url}api/content/{_.AppName}/swagger/v1/swagger.json"; var document = await OpenApiDocument.FromUrlAsync(url); @@ -43,7 +43,7 @@ public class OpenApiTests : IClassFixture [Fact] public async Task Should_provide_flat_content_spec() { - var url = $"{_.ClientManager.Options.Url}api/content/{_.AppName}/flat/swagger/v1/swagger.json"; + var url = $"{_.Client.Options.Url}api/content/{_.AppName}/flat/swagger/v1/swagger.json"; var document = await OpenApiDocument.FromUrlAsync(url); diff --git a/tools/TestSuite/TestSuite.ApiTests/PingTests.cs b/tools/TestSuite/TestSuite.ApiTests/PingTests.cs index 4847d5a73..4f3fb75c8 100644 --- a/tools/TestSuite/TestSuite.ApiTests/PingTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/PingTests.cs @@ -23,19 +23,19 @@ public class PingTests : IClassFixture [Fact] public async Task Should_ping_service() { - await _.Ping.GetPingAsync(); + await _.Client.Ping.GetPingAsync(); } [Fact] public async Task Should_ping_app() { - await _.Ping.GetAppPingAsync(_.AppName); + await _.Client.Ping.GetAppPingAsync(); } [Fact] public async Task Should_get_info() { - var infos = await _.Ping.GetInfoAsync(); + var infos = await _.Client.Ping.GetInfoAsync(); Assert.NotNull(infos); } diff --git a/tools/TestSuite/TestSuite.ApiTests/PlansTests.cs b/tools/TestSuite/TestSuite.ApiTests/PlansTests.cs index 3f9af1a96..9ffc66bae 100644 --- a/tools/TestSuite/TestSuite.ApiTests/PlansTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/PlansTests.cs @@ -23,7 +23,7 @@ public class PlansTests : IClassFixture [Fact] public async Task Should_get_plans() { - var plans = await _.Plans.GetPlansAsync(_.AppName); + var plans = await _.Client.Plans.GetPlansAsync(); Assert.NotNull(plans); } diff --git a/tools/TestSuite/TestSuite.ApiTests/RuleRunnerTests.cs b/tools/TestSuite/TestSuite.ApiTests/RuleRunnerTests.cs index 1e05bf3b9..56d13b5b2 100644 --- a/tools/TestSuite/TestSuite.ApiTests/RuleRunnerTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/RuleRunnerTests.cs @@ -37,7 +37,7 @@ public class RuleRunnerTests : IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture(appName, schemaName); + var referencedContents = app.Contents(schemaName); var referencedContent = await referencedContents.CreateAsync(new TestEntityData { String = contentString }); - var parentSchema = await TestEntityWithReferences.CreateSchemaAsync(_.Schemas, appName, schemaNameRef); + var parentSchema = await TestEntityWithReferences.CreateSchemaAsync(app.Schemas, schemaNameRef); // Create a test content that references the other schema. - var parentContents = _.ClientManager.CreateContentsClient(appName, schemaNameRef); + var parentContents = app.Contents(schemaNameRef); await parentContents.CreateAsync(new TestEntityWithReferencesData { @@ -157,7 +157,7 @@ public class RuleRunnerTests : IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture, IClassFixture x.Method == "POST" && x.Content.Contains(schemaName, StringComparison.OrdinalIgnoreCase)); } - private async Task CreateContentAsync() + private async Task CreateContentAsync(ISquidexClient app) { - await TestEntity.CreateSchemaAsync(_.Schemas, appName, schemaName); + await TestEntity.CreateSchemaAsync(app.Schemas, schemaName); // Create a test content. - var contents = _.ClientManager.CreateContentsClient(appName, schemaName); + var contents = app.Contents(schemaName); await contents.CreateAsync(new TestEntityData { @@ -437,7 +437,7 @@ public class RuleRunnerTests : IClassFixture, IClassFixture, IClassFixture public async Task Should_create_rule() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Create rule @@ -49,7 +49,7 @@ public class RuleTests : IClassFixture } }; - var rule = await _.Rules.PostRuleAsync(appName, createRule); + var rule = await app.Rules.PostRuleAsync(createRule); Assert.IsType(rule.Action); @@ -60,7 +60,7 @@ public class RuleTests : IClassFixture public async Task Should_update_rule() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Create rule @@ -79,7 +79,7 @@ public class RuleTests : IClassFixture } }; - var rule_0 = await _.Rules.PostRuleAsync(appName, createRequest); + var rule_0 = await app.Rules.PostRuleAsync(createRequest); // STEP 2: Update rule @@ -88,7 +88,7 @@ public class RuleTests : IClassFixture Name = ruleName }; - var rule_1 = await _.Rules.PutRuleAsync(appName, rule_0.Id, updateRequest); + var rule_1 = await app.Rules.PutRuleAsync(rule_0.Id, updateRequest); Assert.Equal(ruleName, rule_1.Name); @@ -99,7 +99,7 @@ public class RuleTests : IClassFixture public async Task Should_delete_rule() { // STEP 0: Create app. - await CreateAppAsync(); + var (app, _) = await _.PostAppAsync(appName); // STEP 1: Create rule @@ -118,13 +118,13 @@ public class RuleTests : IClassFixture } }; - var rule = await _.Rules.PostRuleAsync(appName, createRequest); + var rule = await app.Rules.PostRuleAsync(createRequest); // STEP 2: Delete rule - await _.Rules.DeleteRuleAsync(appName, rule.Id); + await app.Rules.DeleteRuleAsync(rule.Id); - var rules = await _.Rules.GetRulesAsync(appName); + var rules = await app.Rules.GetRulesAsync(); Assert.DoesNotContain(rules.Items, x => x.Id == rule.Id); } @@ -132,7 +132,7 @@ public class RuleTests : IClassFixture [Fact] public async Task Should_get_actions() { - var actions = await _.Rules.GetActionsAsync(); + var actions = await _.Client.Rules.GetActionsAsync(); Assert.NotEmpty(actions); } @@ -140,7 +140,7 @@ public class RuleTests : IClassFixture [Fact] public async Task Should_get_event_schemas() { - var schema = await _.Rules.GetEventSchemaAsync("EnrichedContentEvent"); + var schema = await _.Client.Rules.GetEventSchemaAsync("EnrichedContentEvent"); Assert.NotNull(schema); } @@ -148,18 +148,8 @@ public class RuleTests : IClassFixture [Fact] public async Task Should_get_event_types() { - var eventTypes = await _.Rules.GetEventTypesAsync(); + var eventTypes = await _.Client.Rules.GetEventTypesAsync(); Assert.NotEmpty(eventTypes); } - - private async Task CreateAppAsync() - { - var createRequest = new CreateAppDto - { - Name = appName - }; - - await _.Apps.PostAppAsync(createRequest); - } } diff --git a/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs b/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs index a4913a51c..992f06cbb 100644 --- a/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs @@ -35,14 +35,14 @@ public class SchemaTests : IClassFixture Name = schemaName }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // Should return created schemas with correct name. Assert.Equal(schemaName, schema.Name); // STEP 2: Get all schemas - var schemas = await _.Schemas.GetSchemasAsync(_.AppName); + var schemas = await _.Client.Schemas.GetSchemasAsync(); // Should provide new schema when apps are schemas. Assert.Contains(schemas.Items, x => x.Name == schemaName); @@ -57,13 +57,13 @@ public class SchemaTests : IClassFixture Name = schemaName }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // STEP 2: Create again and fail var ex = await Assert.ThrowsAnyAsync(() => { - return _.Schemas.PostSchemaAsync(_.AppName, createRequest); + return _.Client.Schemas.PostSchemaAsync(createRequest); }); Assert.Equal(400, ex.StatusCode); @@ -82,7 +82,7 @@ public class SchemaTests : IClassFixture IsPublished = true }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // Should return created schemas with correct name. Assert.Equal(schemaName, schema.Name); @@ -92,16 +92,14 @@ public class SchemaTests : IClassFixture // STEP 2: Get all schemas - var schemas = await _.Schemas.GetSchemasAsync(_.AppName); + var schemas = await _.Client.Schemas.GetSchemasAsync(); // Should provide new schema when apps are schemas. Assert.Contains(schemas.Items, x => x.Name == schemaName); // STEP 3: Get singleton content - var client = _.ClientManager.CreateDynamicContentsClient(schemaName); - - var content = await client.GetAsync(schema.Id); + var content = await _.Client.DynamicContents(schemaName).GetAsync(schema.Id); Assert.NotNull(content); } @@ -119,7 +117,7 @@ public class SchemaTests : IClassFixture IsPublished = true }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // Should return created schemas with correct name. Assert.Equal(schemaName, schema.Name); @@ -129,16 +127,14 @@ public class SchemaTests : IClassFixture // STEP 2: Get all schemas - var schemas = await _.Schemas.GetSchemasAsync(_.AppName); + var schemas = await _.Client.Schemas.GetSchemasAsync(); // Should provide new schema when apps are schemas. Assert.Contains(schemas.Items, x => x.Name == schemaName); // STEP 3: Get singleton content - var client = _.ClientManager.CreateDynamicContentsClient(schemaName); - - var content = await client.GetAsync(schema.Id); + var content = await _.Client.DynamicContents(schemaName).GetAsync(schema.Id); Assert.NotNull(content); } @@ -174,7 +170,7 @@ public class SchemaTests : IClassFixture } }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // Should return created schemas with correct name. Assert.Equal(schemaName, schema.Name); @@ -189,16 +185,16 @@ public class SchemaTests : IClassFixture Name = schemaName }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // Should return created schemas with correct name. Assert.Equal(schemaName, schema.Name); // STEP 2: Delete schema - await _.Schemas.DeleteSchemaAsync(_.AppName, schemaName); + await _.Client.Schemas.DeleteSchemaAsync(schemaName); - var schemas = await _.Schemas.GetSchemasAsync(_.AppName); + var schemas = await _.Client.Schemas.GetSchemasAsync(); // Should not provide deleted schema when schema are queried. Assert.DoesNotContain(schemas.Items, x => x.Name == schemaName); @@ -213,17 +209,17 @@ public class SchemaTests : IClassFixture Name = schemaName }; - var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + var schema = await _.Client.Schemas.PostSchemaAsync(createRequest); // Should return created schemas with correct name. Assert.Equal(schemaName, schema.Name); // STEP 2: Delete schema. - await _.Schemas.DeleteSchemaAsync(_.AppName, schemaName); + await _.Client.Schemas.DeleteSchemaAsync(schemaName); // STEP 3: Create app again - await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + await _.Client.Schemas.PostSchemaAsync(createRequest); } } diff --git a/tools/TestSuite/TestSuite.ApiTests/SearchTests.cs b/tools/TestSuite/TestSuite.ApiTests/SearchTests.cs index 0d1edb7cf..a8d9ae91f 100644 --- a/tools/TestSuite/TestSuite.ApiTests/SearchTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/SearchTests.cs @@ -27,11 +27,11 @@ public class SearchTests : IClassFixture public async Task Should_search_asset() { // STEP 1: Create asset - await _.Assets.UploadFileAsync(_.AppName, "Assets/logo-wide.png", "image/png"); + await _.Client.Assets.UploadFileAsync("Assets/logo-wide.png", "image/png"); // STEP 2: Search for schema. - var result = await _.Search.GetSearchResultsAsync(_.AppName, "logo"); + var result = await _.Client.Search.GetSearchResultsAsync("logo"); Assert.Contains(result, x => x.Type == SearchResultType.Asset); } @@ -47,11 +47,11 @@ public class SearchTests : IClassFixture Name = schemaName }; - await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + await _.Client.Schemas.PostSchemaAsync(createRequest); // STEP 2: Search for schema. - var result = await _.Search.WaitForSearchAsync(_.AppName, schemaName, x => x.Type == SearchResultType.Content, TimeSpan.FromSeconds(30)); + var result = await _.Client.Search.WaitForSearchAsync(schemaName, x => x.Type == SearchResultType.Content, TimeSpan.FromSeconds(30)); Assert.NotEmpty(result); } @@ -71,7 +71,7 @@ public class SearchTests : IClassFixture // STEP 2: Search for schema. - var result = await _.Search.WaitForSearchAsync(_.AppName, contentString, x => x.Type == SearchResultType.Content, TimeSpan.FromSeconds(30)); + var result = await _.Client.Search.WaitForSearchAsync(contentString, x => x.Type == SearchResultType.Content, TimeSpan.FromSeconds(30)); Assert.NotEmpty(result); } @@ -90,7 +90,7 @@ public class SearchTests : IClassFixture [InlineData(SearchResultType.Setting, "Workflows")] public async Task Should_search_for_dashboard_pages(SearchResultType expectedType, string query) { - var result = await _.Search.GetSearchResultsAsync(_.AppName, query); + var result = await _.Client.Search.GetSearchResultsAsync(query); Assert.Contains(result, x => x.Type == expectedType); } diff --git a/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj b/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj index f54abf47c..6c0f56945 100644 --- a/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj +++ b/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj @@ -14,16 +14,16 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/tools/TestSuite/TestSuite.ApiTests/Verify/ContentUpdateTests.Should_get_content_by_version.verified.txt b/tools/TestSuite/TestSuite.ApiTests/Verify/ContentUpdateTests.Should_get_content_by_version.verified.txt index a0e9c12f9..adcf205a9 100644 --- a/tools/TestSuite/TestSuite.ApiTests/Verify/ContentUpdateTests.Should_get_content_by_version.verified.txt +++ b/tools/TestSuite/TestSuite.ApiTests/Verify/ContentUpdateTests.Should_get_content_by_version.verified.txt @@ -1,5 +1,26 @@ { - Number: { - iv: 1 + Data: { + Number: { + iv: 1 + } + }, + NewStatus: , + Status: Published, + EditingStatus: Published, + Id: Guid_1, + Version: 1, + _links: { + delete: { + Method: DELETE + }, + draft/create: { + Method: POST + }, + previous: { + Method: GET + }, + self: { + Method: GET + } } } \ No newline at end of file diff --git a/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs b/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs index 9ac653e5e..d70685284 100644 --- a/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs +++ b/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs @@ -10,6 +10,7 @@ using Xunit; using Xunit.Abstractions; #pragma warning disable SA1300 // Element should begin with upper-case letter +#pragma warning disable xUnit1033 // Test classes decorated with 'Xunit.IClassFixture' or 'Xunit.ICollectionFixture' should add a constructor argument of type TFixture namespace TestSuite.LoadTests; @@ -66,7 +67,7 @@ public class ReadingBenchmarks : IClassFixture { await Run.Parallel(numUsers, numIterationsPerUser, async () => { - await _.Apps.GetClientsAsync(_.AppName); + await _.Client.Apps.GetClientsAsync(); }, 100, testOutput); } } diff --git a/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj b/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj index bdc1ec5e7..7ce949426 100644 --- a/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj +++ b/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj @@ -6,11 +6,11 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tools/TestSuite/TestSuite.Shared/ClientExtensions.cs b/tools/TestSuite/TestSuite.Shared/ClientExtensions.cs index 6da647582..ff43a34bf 100644 --- a/tools/TestSuite/TestSuite.Shared/ClientExtensions.cs +++ b/tools/TestSuite/TestSuite.Shared/ClientExtensions.cs @@ -13,7 +13,7 @@ namespace TestSuite; public static class ClientExtensions { - public static async Task WaitForDeletionAsync(this IAssetsClient assetsClient, string app, string id, TimeSpan timeout) + public static async Task WaitForDeletionAsync(this IAssetsClient assetsClient, string id, TimeSpan timeout) { try { @@ -23,7 +23,7 @@ public static class ClientExtensions { try { - await assetsClient.GetAssetAsync(app, id, cts.Token); + await assetsClient.GetAssetAsync(id, cts.Token); } catch (SquidexManagementException ex) when (ex.StatusCode == 404) { @@ -65,7 +65,7 @@ public static class ClientExtensions return new ContentsResult(); } - public static async Task> WaitForSearchAsync(this ISearchClient searchClient, string app, string query, Func predicate, TimeSpan timeout) + public static async Task> WaitForSearchAsync(this ISearchClient searchClient, string query, Func predicate, TimeSpan timeout) { try { @@ -73,7 +73,7 @@ public static class ClientExtensions while (!cts.IsCancellationRequested) { - var result = await searchClient.GetSearchResultsAsync(app, query, cts.Token); + var result = await searchClient.GetSearchResultsAsync(query, cts.Token); if (result.Any(predicate)) { @@ -90,7 +90,7 @@ public static class ClientExtensions return new List(); } - public static async Task> WaitForHistoryAsync(this IHistoryClient historyClient, string app, string channel, Func predicate, TimeSpan timeout) + public static async Task> WaitForHistoryAsync(this IHistoryClient historyClient, string channel, Func predicate, TimeSpan timeout) { try { @@ -98,7 +98,7 @@ public static class ClientExtensions while (!cts.IsCancellationRequested) { - var result = await historyClient.GetAppHistoryAsync(app, channel, cts.Token); + var result = await historyClient.GetAppHistoryAsync(channel, cts.Token); if (result.Any(predicate)) { @@ -115,7 +115,7 @@ public static class ClientExtensions return new List(); } - public static async Task> WaitForTagsAsync(this IAssetsClient assetsClient, string app, string id, TimeSpan timeout) + public static async Task> WaitForTagsAsync(this IAssetsClient assetsClient, string id, TimeSpan timeout) { try { @@ -123,7 +123,7 @@ public static class ClientExtensions while (!cts.IsCancellationRequested) { - var result = await assetsClient.GetTagsAsync(app, cts.Token); + var result = await assetsClient.GetTagsAsync(cts.Token); if (result.TryGetValue(id, out var count) && count > 0) { @@ -137,10 +137,10 @@ public static class ClientExtensions { } - return await assetsClient.GetTagsAsync(app); + return await assetsClient.GetTagsAsync(); } - public static async Task> WaitForBackupsAsync(this IBackupsClient backupsClient, string app, Func predicate, TimeSpan timeout) + public static async Task> WaitForBackupsAsync(this IBackupsClient backupsClient, Func predicate, TimeSpan timeout) { try { @@ -148,7 +148,7 @@ public static class ClientExtensions while (!cts.IsCancellationRequested) { - var result = await backupsClient.GetBackupsAsync(app, cts.Token); + var result = await backupsClient.GetBackupsAsync(cts.Token); if (result.Items.Any(predicate)) { @@ -219,7 +219,7 @@ public static class ClientExtensions return temp; } - public static async Task UploadFileAsync(this IAssetsClient assetsClients, string app, string path, AssetDto asset, string fileName = null) + public static async Task UploadFileAsync(this IAssetsClient assetsClients, string path, AssetDto asset, string fileName = null) { var fileInfo = new FileInfo(path); @@ -227,11 +227,11 @@ public static class ClientExtensions { var upload = new FileParameter(stream, fileName ?? fileInfo.Name, asset.MimeType); - return await assetsClients.PutAssetContentAsync(app, asset.Id, upload); + return await assetsClients.PutAssetContentAsync(asset.Id, upload); } } - public static async Task UploadFileAsync(this IAssetsClient assetsClients, string app, string path, string fileType, string fileName = null, string parentId = null, string id = null) + public static async Task UploadFileAsync(this IAssetsClient assetsClients, string path, string fileType, string fileName = null, string parentId = null, string id = null) { var fileInfo = new FileInfo(path); @@ -239,17 +239,17 @@ public static class ClientExtensions { var upload = new FileParameter(stream, fileName ?? fileInfo.Name, fileType); - return await assetsClients.PostAssetAsync(app, parentId, id, true, upload); + return await assetsClients.PostAssetAsync(parentId, id, true, upload); } } - public static async Task UploadRandomFileAsync(this IAssetsClient assetsClients, string app, int size, string parentId = null, string id = null) + public static async Task UploadRandomFileAsync(this IAssetsClient assetsClients, int size, string parentId = null, string id = null) { using (var stream = RandomAsset(size)) { var upload = new FileParameter(stream, RandomName(".txt"), "text/csv"); - return await assetsClients.PostAssetAsync(app, parentId, id, true, upload); + return await assetsClients.PostAssetAsync(parentId, id, true, upload); } } diff --git a/tools/TestSuite/TestSuite.Shared/ClientManagerWrapper.cs b/tools/TestSuite/TestSuite.Shared/ClientWrapper.cs similarity index 87% rename from tools/TestSuite/TestSuite.Shared/ClientManagerWrapper.cs rename to tools/TestSuite/TestSuite.Shared/ClientWrapper.cs index 48abdb86d..6fb678364 100644 --- a/tools/TestSuite/TestSuite.Shared/ClientManagerWrapper.cs +++ b/tools/TestSuite/TestSuite.Shared/ClientWrapper.cs @@ -12,11 +12,11 @@ using TestSuite.Utils; namespace TestSuite; -public sealed class ClientManagerWrapper +public sealed class ClientWrapper { - public ISquidexClientManager ClientManager { get; } + public ISquidexClient Client { get; } - public ClientManagerWrapper() + public ClientWrapper() { var services = new ServiceCollection() @@ -38,10 +38,10 @@ public sealed class ClientManagerWrapper }).Services .BuildServiceProvider(); - ClientManager = services.GetRequiredService(); + Client = services.GetRequiredService(); } - public async Task ConnectAsync() + public async Task ConnectAsync() { var waitSeconds = TestHelpers.Configuration.GetValue("config:wait"); @@ -49,7 +49,6 @@ public sealed class ClientManagerWrapper { Console.WriteLine("Waiting {0} seconds to access server", waitSeconds); - var pingClient = ClientManager.CreatePingClient(); try { using (var cts = new CancellationTokenSource(waitSeconds * 1000)) @@ -58,7 +57,7 @@ public sealed class ClientManagerWrapper { try { - await pingClient.GetPingAsync(cts.Token); + await Client.Ping.GetPingAsync(cts.Token); break; } catch diff --git a/tools/TestSuite/TestSuite.Shared/Fixtures/ClientCloudFixture.cs b/tools/TestSuite/TestSuite.Shared/Fixtures/ClientCloudFixture.cs index 4eb4347a8..be3a7b75f 100644 --- a/tools/TestSuite/TestSuite.Shared/Fixtures/ClientCloudFixture.cs +++ b/tools/TestSuite/TestSuite.Shared/Fixtures/ClientCloudFixture.cs @@ -12,13 +12,13 @@ namespace TestSuite.Fixtures; public sealed class ClientCloudFixture { - public ISquidexClientManager ClientManager { get; private set; } + public ISquidexClient CloudClient { get; private set; } - public ISquidexClientManager CDNClientManager { get; private set; } + public ISquidexClient CDNClient { get; private set; } public ClientCloudFixture() { - ClientManager = + CloudClient = new ServiceCollection() .AddSquidexClient(options => { @@ -28,9 +28,9 @@ public sealed class ClientCloudFixture options.ReadResponseAsString = true; }) .BuildServiceProvider() - .GetRequiredService(); + .GetRequiredService(); - CDNClientManager = + CDNClient = new ServiceCollection() .AddSquidexClient(options => { @@ -41,6 +41,6 @@ public sealed class ClientCloudFixture options.ContentCDN = "https://contents.squidex.io"; }) .BuildServiceProvider() - .GetRequiredService(); + .GetRequiredService(); } } diff --git a/tools/TestSuite/TestSuite.Shared/Fixtures/ClientFixture.cs b/tools/TestSuite/TestSuite.Shared/Fixtures/ClientFixture.cs index 07d18e8d2..2a78a3761 100644 --- a/tools/TestSuite/TestSuite.Shared/Fixtures/ClientFixture.cs +++ b/tools/TestSuite/TestSuite.Shared/Fixtures/ClientFixture.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Microsoft.Extensions.DependencyInjection; using Squidex.ClientLibrary; using Squidex.ClientLibrary.Management; using Xunit; @@ -13,97 +14,17 @@ namespace TestSuite.Fixtures; public class ClientFixture : IAsyncLifetime { - public ClientManagerWrapper Squidex { get; private set; } + public ClientWrapper Squidex { get; private set; } - public string AppName => ClientManager.Options.AppName; + public string AppName => Client.Options.AppName; - public string ClientId => ClientManager.Options.ClientId; + public string ClientId => Client.Options.ClientId; - public string ClientSecret => ClientManager.Options.ClientSecret; + public string ClientSecret => Client.Options.ClientSecret; - public string Url => ClientManager.Options.Url; + public string Url => Client.Options.Url; - public ISquidexClientManager ClientManager => Squidex.ClientManager; - - public IAppsClient Apps - { - get => ClientManager.CreateAppsClient(); - } - - public IAssetsClient Assets - { - get => ClientManager.CreateAssetsClient(); - } - - public IBackupsClient Backups - { - get => ClientManager.CreateBackupsClient(); - } - - public ICommentsClient Comments - { - get => ClientManager.CreateCommentsClient(); - } - - public IDiagnosticsClient Diagnostics - { - get => ClientManager.CreateDiagnosticsClient(); - } - - public IHistoryClient History - { - get => ClientManager.CreateHistoryClient(); - } - - public ILanguagesClient Languages - { - get => ClientManager.CreateLanguagesClient(); - } - - public IPingClient Ping - { - get => ClientManager.CreatePingClient(); - } - - public IPlansClient Plans - { - get => ClientManager.CreatePlansClient(); - } - - public IRulesClient Rules - { - get => ClientManager.CreateRulesClient(); - } - - public ISchemasClient Schemas - { - get => ClientManager.CreateSchemasClient(); - } - - public ISearchClient Search - { - get => ClientManager.CreateSearchClient(); - } - - public ITemplatesClient Templates - { - get => ClientManager.CreateTemplatesClient(); - } - - public ITranslationsClient Translations - { - get => ClientManager.CreateTranslationsClient(); - } - - public IUserManagementClient UserManagement - { - get => ClientManager.CreateUserManagementClient(); - } - - public IContentsSharedClient SharedContents - { - get => ClientManager.CreateSharedDynamicContentsClient(); - } + public ISquidexClient Client => Squidex.Client; static ClientFixture() { @@ -119,11 +40,48 @@ public class ClientFixture : IAsyncLifetime VerifierSettings.IgnoreMembersWithType(); } + public Task<(ISquidexClient, AppDto)> PostAppAsync(string name) + { + var createRequest = new CreateAppDto + { + Name = name + }; + + return PostAppAsync(createRequest); + } + + public async Task<(ISquidexClient, AppDto)> PostAppAsync(CreateAppDto request) + { + var services = + new ServiceCollection() + .AddSquidexClient(options => + { + options.AppName = request.Name; + options.ClientId = ClientId; + options.ClientSecret = ClientSecret; + options.Url = Client.Options.Url; + options.ReadResponseAsString = true; + }) + .AddSquidexHttpClient() + .ConfigurePrimaryHttpMessageHandler(() => + { + return new HttpClientHandler + { + ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator + }; + }).Services + .BuildServiceProvider(); + + var client = services.GetRequiredService(); + + return (client, await client.Apps.PostAppAsync(request)); + } + public virtual async Task InitializeAsync() { - Squidex = await Factories.CreateAsync(nameof(ClientManagerWrapper), async () => + Squidex = await Factories.CreateAsync(nameof(ClientWrapper), async () => { - var clientManager = new ClientManagerWrapper(); + var clientManager = new ClientWrapper(); await clientManager.ConnectAsync(); diff --git a/tools/TestSuite/TestSuite.Shared/Fixtures/CreatedAppFixture.cs b/tools/TestSuite/TestSuite.Shared/Fixtures/CreatedAppFixture.cs index 9b92f8cf3..b83a0826e 100644 --- a/tools/TestSuite/TestSuite.Shared/Fixtures/CreatedAppFixture.cs +++ b/tools/TestSuite/TestSuite.Shared/Fixtures/CreatedAppFixture.cs @@ -15,29 +15,16 @@ public class CreatedAppFixture : ClientFixture { await base.InitializeAsync(); - await Factories.CreateAsync(AppName, async () => + async Task CreateLanguageAsync(string name) { try { - await Apps.PostAppAsync(new CreateAppDto - { - Name = AppName - }); - } - catch (SquidexManagementException ex) - { - if (ex.StatusCode != 400) + var createRequest = new AddLanguageDto { - throw; - } - } + Language = name + }; - try - { - await Apps.PostLanguageAsync(AppName, new AddLanguageDto - { - Language = "de" - }); + await Client.Apps.PostLanguageAsync(createRequest); } catch (SquidexManagementException ex) { @@ -46,12 +33,15 @@ public class CreatedAppFixture : ClientFixture throw; } } + } + await Factories.CreateAsync(AppName, async () => + { try { - await Apps.PostLanguageAsync(AppName, new AddLanguageDto + await Client.Apps.PostAppAsync(new CreateAppDto { - Language = "custom" + Name = AppName }); } catch (SquidexManagementException ex) @@ -62,6 +52,9 @@ public class CreatedAppFixture : ClientFixture } } + await CreateLanguageAsync("de"); + await CreateLanguageAsync("custom"); + return true; }); } diff --git a/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaFixtureBase.cs b/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaFixtureBase.cs index 80a7d4d9b..f828de363 100644 --- a/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaFixtureBase.cs +++ b/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaFixtureBase.cs @@ -30,7 +30,7 @@ public abstract class TestSchemaFixtureBase : CreatedAppFixture { try { - await TestEntity.CreateSchemaAsync(Schemas, AppName, SchemaName); + await TestEntity.CreateSchemaAsync(Client.Schemas, SchemaName); } catch (SquidexManagementException ex) { @@ -43,6 +43,6 @@ public abstract class TestSchemaFixtureBase : CreatedAppFixture return true; }); - Contents = ClientManager.CreateContentsClient(SchemaName); + Contents = Client.Contents(SchemaName); } } diff --git a/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaWithReferencesFixtureBase.cs b/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaWithReferencesFixtureBase.cs index f3641912d..4ca3a7ac9 100644 --- a/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaWithReferencesFixtureBase.cs +++ b/tools/TestSuite/TestSuite.Shared/Fixtures/TestSchemaWithReferencesFixtureBase.cs @@ -30,7 +30,7 @@ public abstract class TestSchemaWithReferencesFixtureBase : CreatedAppFixture { try { - await TestEntityWithReferences.CreateSchemaAsync(Schemas, AppName, SchemaName); + await TestEntityWithReferences.CreateSchemaAsync(Client.Schemas, SchemaName); } catch (SquidexManagementException ex) { @@ -43,6 +43,6 @@ public abstract class TestSchemaWithReferencesFixtureBase : CreatedAppFixture return true; }); - Contents = ClientManager.CreateContentsClient(SchemaName); + Contents = Client.Contents(SchemaName); } } diff --git a/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs b/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs index 7c5af2b0a..35f92b5ae 100644 --- a/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs +++ b/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs @@ -19,9 +19,9 @@ public sealed class TestEntity : Content { public const int ScriptTrigger = -99; - public static async Task CreateSchemaAsync(ISchemasClient schemas, string appName, string name, SchemaScriptsDto scripts = null) + public static async Task CreateSchemaAsync(ISchemasClient schemas, string name, SchemaScriptsDto scripts = null) { - var schema = await schemas.PostSchemaAsync(appName, new CreateSchemaDto + var schema = await schemas.PostSchemaAsync(new CreateSchemaDto { Name = name, Fields = new List diff --git a/tools/TestSuite/TestSuite.Shared/Model/TestEntityWithReferences.cs b/tools/TestSuite/TestSuite.Shared/Model/TestEntityWithReferences.cs index 07cf0985c..351676aaa 100644 --- a/tools/TestSuite/TestSuite.Shared/Model/TestEntityWithReferences.cs +++ b/tools/TestSuite/TestSuite.Shared/Model/TestEntityWithReferences.cs @@ -15,9 +15,9 @@ namespace TestSuite.Model; public sealed class TestEntityWithReferences : Content { - public static async Task CreateSchemaAsync(ISchemasClient schemas, string appName, string name) + public static async Task CreateSchemaAsync(ISchemasClient schemas, string name) { - var schema = await schemas.PostSchemaAsync(appName, new CreateSchemaDto + var schema = await schemas.PostSchemaAsync(new CreateSchemaDto { Name = name, Fields = new List diff --git a/tools/TestSuite/TestSuite.Shared/Strategies.cs b/tools/TestSuite/TestSuite.Shared/Strategies.cs index 7ac23fc96..1f528aaeb 100644 --- a/tools/TestSuite/TestSuite.Shared/Strategies.cs +++ b/tools/TestSuite/TestSuite.Shared/Strategies.cs @@ -19,11 +19,11 @@ public static class Strategies BulkPermanent } - public static Task DeleteAsync(this ISquidexClientManager clientManager, ContentBase content, Deletion strategy) + public static Task DeleteAsync(this ISquidexClient client, ContentBase content, Deletion strategy) { IContentsClient GetClient() { - return clientManager.CreateContentsClient(content.SchemaName); + return client.Contents(content.SchemaName); } switch (strategy) @@ -73,11 +73,11 @@ public static class Strategies BulkShared } - public static Task UpdateAsync(this ISquidexClientManager clientManager, ContentBase content, object data, Update strategy) + public static Task UpdateAsync(this ISquidexClient client, ContentBase content, object data, Update strategy) { IContentsClient GetClient() { - return clientManager.CreateContentsClient(content.SchemaName); + return client.Contents(content.SchemaName); } switch (strategy) @@ -127,7 +127,7 @@ public static class Strategies } }); case Update.BulkShared: - return clientManager.CreateSharedContentsClient().BulkUpdateAsync(new BulkUpdate + return client.SharedContents().BulkUpdateAsync(new BulkUpdate { Jobs = new List { @@ -155,11 +155,11 @@ public static class Strategies UpsertBulk } - public static Task PatchAsync(this ISquidexClientManager clientManager, ContentBase content, object data, Patch strategy) + public static Task PatchAsync(this ISquidexClient client, ContentBase content, object data, Patch strategy) { IContentsClient GetClient() { - return clientManager.CreateContentsClient(content.SchemaName); + return client.Contents(content.SchemaName); } switch (strategy) @@ -209,7 +209,7 @@ public static class Strategies } }); case Patch.BulkShared: - return clientManager.CreateSharedContentsClient().BulkUpdateAsync(new BulkUpdate + return client.SharedContents().BulkUpdateAsync(new BulkUpdate { Jobs = new List { diff --git a/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj b/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj index aeb542dce..b997b3278 100644 --- a/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj +++ b/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj @@ -6,18 +6,18 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - + +