From 0f6ec1224487d2becacb65cba241fe641b575ecb Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 14 Jan 2024 23:43:54 +0100 Subject: [PATCH] Update NSwag and OpenAPI. (#1064) * Update NSwag and OpenAPI. * Update Tests --- .../StackdriverExceptionHandler.cs | 2 +- .../Squidex.Extensions.csproj | 8 +-- backend/src/Migrations/Migrations.csproj | 2 +- .../Contents/RichTextMark.cs | 2 +- .../Squidex.Domain.Apps.Core.Model.csproj | 2 +- .../GenerateJsonSchema/JsonTypeVisitor.cs | 2 +- ...Squidex.Domain.Apps.Core.Operations.csproj | 4 +- .../Contents/Operations/QueryReferences.cs | 8 +-- ...quidex.Domain.Apps.Entities.MongoDb.csproj | 2 +- .../Assets/AssetsJintExtension.cs | 7 +- .../Squidex.Domain.Apps.Entities.csproj | 4 +- .../Squidex.Domain.Apps.Events.csproj | 2 +- .../Squidex.Domain.Users.MongoDb.csproj | 2 +- .../DefaultUserService.cs | 7 +- .../InMemory/ImmutableApplication.cs | 14 +++- .../InMemory/InMemoryApplicationStore.cs | 39 +++++++++- .../Squidex.Domain.Users.csproj | 6 +- ...quidex.Infrastructure.GetEventStore.csproj | 4 +- .../Squidex.Infrastructure.MongoDb.csproj | 2 +- .../Squidex.Infrastructure.csproj | 6 +- .../src/Squidex.Shared/Squidex.Shared.csproj | 2 +- backend/src/Squidex.Web/Squidex.Web.csproj | 2 +- .../Api/Config/OpenApi/CommonProcessor.cs | 2 +- .../Api/Config/OpenApi/OpenApiServices.cs | 13 ++-- .../Api/Config/OpenApi/ReflectionServices.cs | 2 +- .../Config/OpenApi/RequiredSchemaProcessor.cs | 3 +- .../Api/Config/OpenApi/ScopesProcessor.cs | 2 +- .../Assets/AssetContentController.cs | 9 +-- .../Assets/Models/AssetFoldersDto.cs | 5 +- .../Generator/SchemasOpenApiGenerator.cs | 22 +++--- .../Config/DynamicApplicationStore.cs | 4 +- .../Config/TokenStoreInitializer.cs | 6 +- .../Controllers/Account/AccountController.cs | 8 +-- .../Controllers/Setup/SetupController.cs | 2 +- .../Squidex/Config/Domain/StoreServices.cs | 2 +- backend/src/Squidex/Squidex.csproj | 22 +++--- .../Model/Contents/RichTextTests.cs | 2 +- .../Model/Schemas/SchemaTests.cs | 8 +-- .../ConvertContent/FieldConvertersTests.cs | 8 +-- .../ReferenceExtractionTests.cs | 24 +++---- .../GenerateJsonSchema/JsonSchemaTests.cs | 2 +- .../EventJsonSchemaGeneratorTests.cs | 8 +-- .../Validators/AssetsValidatorTests.cs | 8 +-- .../Squidex.Domain.Apps.Core.Tests.csproj | 8 +-- .../Assets/AssetChangedTriggerHandlerTests.cs | 17 ++--- .../Assets/AssetUsageTrackerTests.cs | 25 ++----- .../Assets/AssetsFluidExtensionTests.cs | 11 +-- .../Assets/AssetsJintExtensionTests.cs | 11 +-- .../Assets/DefaultAssetFileStoreTests.cs | 24 +++---- .../MongoDb/AssetsQueryIntegrationTests.cs | 12 ++-- .../ContentChangedTriggerHandlerTests.cs | 20 +++--- .../Guards/GuardSchemaFieldTests.cs | 23 +++--- .../SchemaChangedTriggerHandlerTests.cs | 18 ++--- .../Squidex.Domain.Apps.Entities.Tests.csproj | 12 ++-- .../TestHelpers/GivenContext.cs | 2 +- .../Squidex.Domain.Users.Tests.csproj | 8 +-- .../HashExtensionsTests.cs | 20 ++---- .../Objects/JsonValuesSerializationTests.cs | 8 +-- .../NamedIdTests.cs | 8 +-- .../Queries/QueryFromJsonTests.cs | 71 ++++++++++++------- .../Squidex.Infrastructure.Tests.csproj | 8 +-- .../Squidex.Web.Tests.csproj | 8 +-- .../TestSuite.ApiTests.csproj | 6 +- .../TestSuite.LoadTests/ReadingBenchmarks.cs | 10 ++- .../ReadingContentBenchmarks.cs | 10 ++- .../TestSuite.LoadTests.csproj | 2 +- .../TestSuite.LoadTests/WritingBenchmarks.cs | 10 ++- .../TestSuite.Shared/TestSuite.Shared.csproj | 8 +-- 68 files changed, 336 insertions(+), 315 deletions(-) diff --git a/backend/extensions/Squidex.Extensions/APM/Stackdriver/StackdriverExceptionHandler.cs b/backend/extensions/Squidex.Extensions/APM/Stackdriver/StackdriverExceptionHandler.cs index 5accd2b44..237f601ab 100644 --- a/backend/extensions/Squidex.Extensions/APM/Stackdriver/StackdriverExceptionHandler.cs +++ b/backend/extensions/Squidex.Extensions/APM/Stackdriver/StackdriverExceptionHandler.cs @@ -39,7 +39,7 @@ internal sealed class StackdriverExceptionHandler : ILogAppender public string GetUserAgent() { - return httpContextAccessor.HttpContext?.Request?.Headers["User-Agent"].ToString() ?? string.Empty; + return httpContextAccessor.HttpContext?.Request?.Headers.UserAgent.ToString() ?? string.Empty; } } diff --git a/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj b/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj index 3862c499e..589ac42a1 100644 --- a/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj +++ b/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj @@ -18,17 +18,17 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/backend/src/Migrations/Migrations.csproj b/backend/src/Migrations/Migrations.csproj index ef2dcff54..0aa67e8c4 100644 --- a/backend/src/Migrations/Migrations.csproj +++ b/backend/src/Migrations/Migrations.csproj @@ -6,7 +6,7 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Contents/RichTextMark.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Contents/RichTextMark.cs index db23edc5a..7935ba1c0 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Contents/RichTextMark.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Contents/RichTextMark.cs @@ -10,7 +10,7 @@ using Squidex.Text.RichText.Model; namespace Squidex.Domain.Apps.Core.Contents; -internal class RichTextMark : IMark +internal sealed class RichTextMark : IMark { private JsonObject? attrs; diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj b/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj index 8064a4efd..045bf75bd 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj @@ -12,7 +12,7 @@ True - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/JsonTypeVisitor.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/JsonTypeVisitor.cs index cc6442847..6eb2f2cfe 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/JsonTypeVisitor.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/JsonTypeVisitor.cs @@ -199,7 +199,7 @@ internal sealed class JsonTypeVisitor : IFieldVisitor + property.ExtensionData = new Dictionary { ["schemaIds"] = field.Properties.SchemaIds ?? [] }; diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index b4504a959..8076bb0a5 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -21,12 +21,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs index c91d9b208..0e394f769 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs @@ -42,12 +42,8 @@ internal sealed class QueryReferences : OperationBase .Find(Filter.Eq(x => x.DocumentId, DomainId.Combine(app.Id, q.Referencing))) .Project(Projection.Include(x => x.ReferencedIds)); - var contentEntity = await find.FirstOrDefaultAsync(ct); - - if (contentEntity == null) - { - throw new DomainObjectNotFoundException(q.Referencing.ToString()); - } + var contentEntity = await find.FirstOrDefaultAsync(ct) + ?? throw new DomainObjectNotFoundException(q.Referencing.ToString()); if (contentEntity.ReferencedIds is not { Count: > 0 }) { diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj index e8d135dae..13f03783e 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsJintExtension.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsJintExtension.cs index 09f43b730..8dfc74c5c 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsJintExtension.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsJintExtension.cs @@ -323,12 +323,7 @@ public sealed class AssetsJintExtension : IJintExtension, IScriptDescriptor var app = await appProvider.GetAppAsync(appId, false, ct); - if (app == null) - { - throw new JavaScriptException("App does not exist."); - } - - return app; + return app ?? throw new JavaScriptException("App does not exist."); } public void Describe(AddDescription describe, ScriptScope scope) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj b/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj index dd0782544..e39c63017 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj +++ b/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj @@ -27,14 +27,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj b/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj index ff839be26..94df9efa4 100644 --- a/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj +++ b/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj b/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj index 4e7f37c60..57afab6ad 100644 --- a/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj +++ b/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Users/DefaultUserService.cs b/backend/src/Squidex.Domain.Users/DefaultUserService.cs index 191f6bfe3..c66b8ecdc 100644 --- a/backend/src/Squidex.Domain.Users/DefaultUserService.cs +++ b/backend/src/Squidex.Domain.Users/DefaultUserService.cs @@ -365,12 +365,7 @@ public sealed class DefaultUserService : IUserService var user = await userManager.FindByIdAsync(id); - if (user == null) - { - throw new DomainObjectNotFoundException(id); - } - - return user; + return user ?? throw new DomainObjectNotFoundException(id); } private Task ResolveAsync(IEnumerable users) diff --git a/backend/src/Squidex.Domain.Users/InMemory/ImmutableApplication.cs b/backend/src/Squidex.Domain.Users/InMemory/ImmutableApplication.cs index 3ce0cdcad..12d471336 100644 --- a/backend/src/Squidex.Domain.Users/InMemory/ImmutableApplication.cs +++ b/backend/src/Squidex.Domain.Users/InMemory/ImmutableApplication.cs @@ -8,6 +8,7 @@ using System.Collections.Immutable; using System.Globalization; using System.Text.Json; +using Microsoft.IdentityModel.Tokens; using OpenIddict.Abstractions; namespace Squidex.Domain.Users.InMemory; @@ -20,11 +21,15 @@ public sealed class ImmutableApplication public string? ClientSecret { get; } + public string? ClientType { get; } + public string? ConsentType { get; } public string? DisplayName { get; } - public string? Type { get; } + public string? ApplicationType { get; } + + public JsonWebKeySet? JsonWebKeySet { get; } public ImmutableDictionary DisplayNames { get; } @@ -38,19 +43,24 @@ public sealed class ImmutableApplication public ImmutableDictionary Properties { get; } + public ImmutableDictionary Settings { get; } + public ImmutableApplication(string id, OpenIddictApplicationDescriptor descriptor) { Id = id; + ApplicationType = descriptor.ApplicationType; ClientId = descriptor.ClientId; ClientSecret = descriptor.ClientSecret; + ClientType = descriptor.ClientType; ConsentType = descriptor.ConsentType; DisplayName = descriptor.DisplayName; DisplayNames = descriptor.DisplayNames.ToImmutableDictionary(); + JsonWebKeySet = descriptor.JsonWebKeySet; Permissions = descriptor.Permissions.ToImmutableArray(); PostLogoutRedirectUris = descriptor.PostLogoutRedirectUris.Select(x => x.ToString()).ToImmutableArray(); Properties = descriptor.Properties.ToImmutableDictionary(); RedirectUris = descriptor.RedirectUris.Select(x => x.ToString()).ToImmutableArray(); Requirements = descriptor.Requirements.ToImmutableArray(); - Type = descriptor.Type; + Settings = descriptor.Settings.ToImmutableDictionary(); } } diff --git a/backend/src/Squidex.Domain.Users/InMemory/InMemoryApplicationStore.cs b/backend/src/Squidex.Domain.Users/InMemory/InMemoryApplicationStore.cs index 9d68e96bb..e6963c26b 100644 --- a/backend/src/Squidex.Domain.Users/InMemory/InMemoryApplicationStore.cs +++ b/backend/src/Squidex.Domain.Users/InMemory/InMemoryApplicationStore.cs @@ -9,6 +9,7 @@ using System.Collections.Immutable; using System.Globalization; using System.Runtime.CompilerServices; using System.Text.Json; +using Microsoft.IdentityModel.Tokens; using OpenIddict.Abstractions; namespace Squidex.Domain.Users.InMemory; @@ -128,7 +129,7 @@ public class InMemoryApplicationStore : IOpenIddictApplicationStore GetClientTypeAsync(ImmutableApplication application, CancellationToken cancellationToken) { - return application.Type.AsValueTask(); + return application.ClientType.AsValueTask(); } public virtual ValueTask GetConsentTypeAsync(ImmutableApplication application, @@ -179,6 +180,24 @@ public class InMemoryApplicationStore : IOpenIddictApplicationStore GetApplicationTypeAsync(ImmutableApplication application, + CancellationToken cancellationToken) + { + return application.ApplicationType.AsValueTask(); + } + + public ValueTask GetJsonWebKeySetAsync(ImmutableApplication application, + CancellationToken cancellationToken) + { + return application.JsonWebKeySet.AsValueTask(); + } + + public ValueTask> GetSettingsAsync(ImmutableApplication application, + CancellationToken cancellationToken) + { + return application.Settings.AsValueTask(); + } + public virtual ValueTask CreateAsync(ImmutableApplication application, CancellationToken cancellationToken) { @@ -268,4 +287,22 @@ public class InMemoryApplicationStore : IOpenIddictApplicationStore settings, + CancellationToken cancellationToken) + { + throw new NotSupportedException(); + } } diff --git a/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj b/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj index 4c0a06689..9a46e7159 100644 --- a/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj +++ b/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj @@ -18,13 +18,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj b/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj index 2b307a722..fff161085 100644 --- a/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj +++ b/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj @@ -14,8 +14,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj b/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj index e823506f1..74e2f746d 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj +++ b/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj b/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj index b2db70321..5baa41f1e 100644 --- a/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj +++ b/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj @@ -13,15 +13,15 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/backend/src/Squidex.Shared/Squidex.Shared.csproj b/backend/src/Squidex.Shared/Squidex.Shared.csproj index 92175590e..bea431aff 100644 --- a/backend/src/Squidex.Shared/Squidex.Shared.csproj +++ b/backend/src/Squidex.Shared/Squidex.Shared.csproj @@ -10,7 +10,7 @@ True - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Web/Squidex.Web.csproj b/backend/src/Squidex.Web/Squidex.Web.csproj index 25b6679d3..d021bb69f 100644 --- a/backend/src/Squidex.Web/Squidex.Web.csproj +++ b/backend/src/Squidex.Web/Squidex.Web.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/CommonProcessor.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/CommonProcessor.cs index c40f9867c..312a5490f 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/CommonProcessor.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/CommonProcessor.cs @@ -33,7 +33,7 @@ public sealed class CommonProcessor : IDocumentProcessor { context.Document.Info.Title = "Squidex API"; context.Document.Info.Version = version; - context.Document.Info.ExtensionData = new Dictionary + context.Document.Info.ExtensionData = new Dictionary { ["x-logo"] = new { diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs index 737fe5e45..695941d98 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs @@ -55,9 +55,9 @@ public static class OpenApiServices services.AddSingletonAs() .AsSelf(); - services.AddSingleton(c => + services.AddSingleton(c => { - var settings = new JsonSchemaGeneratorSettings(); + var settings = new SystemTextJsonSchemaGeneratorSettings(); ConfigureSchemaSettings(settings, c.GetRequiredService(), true); @@ -68,13 +68,10 @@ public static class OpenApiServices { var settings = new OpenApiDocumentGeneratorSettings { - SerializerSettings = new JsonSerializerSettings - { - ContractResolver = new CamelCasePropertyNamesContractResolver() - } + SchemaSettings = new SystemTextJsonSchemaGeneratorSettings() }; - ConfigureSchemaSettings(settings, c.GetRequiredService(), true); + ConfigureSchemaSettings(settings.SchemaSettings, c.GetRequiredService(), true); foreach (var processor in c.GetRequiredService>()) { @@ -86,7 +83,7 @@ public static class OpenApiServices services.AddOpenApiDocument((settings, services) => { - ConfigureSchemaSettings(settings, services.GetRequiredService(), false); + ConfigureSchemaSettings(settings.SchemaSettings, services.GetRequiredService(), false); }); } diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs index 8d0125441..56e88db26 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs @@ -11,7 +11,7 @@ using Squidex.Infrastructure.Collections; namespace Squidex.Areas.Api.Config.OpenApi; -public class ReflectionServices : DefaultReflectionService +public class ReflectionServices : SystemTextJsonReflectionService { protected override bool IsArrayType(ContextualType contextualType) { diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/RequiredSchemaProcessor.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/RequiredSchemaProcessor.cs index 2a20a8dfc..50d2449cc 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/RequiredSchemaProcessor.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/RequiredSchemaProcessor.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Generation; using Squidex.Web; @@ -15,7 +16,7 @@ public sealed class RequiredSchemaProcessor : ISchemaProcessor { public void Process(SchemaProcessorContext context) { - if (context.ContextualType.GetAttribute() != null) + if (context.ContextualType.GetAttribute(true) != null) { FixRequest(context); } diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/ScopesProcessor.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/ScopesProcessor.cs index 6b719e97c..ff79cf7cf 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/ScopesProcessor.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/ScopesProcessor.cs @@ -36,7 +36,7 @@ public sealed class ScopesProcessor : IOperationProcessor context.MethodInfo.DeclaringType!.GetCustomAttributes(true)) .ToArray(); - if (authorizeAttributes.Any()) + if (authorizeAttributes.Length != 0) { var scopes = authorizeAttributes.Where(a => a.Roles != null).SelectMany(a => a.Roles!.Split(',')).Distinct().ToList(); diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs index 90fa75cf6..1f785e148 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs @@ -68,12 +68,9 @@ public sealed class AssetContentController : ApiController { var requestContext = Context.Clone(b => b.WithNoAssetEnrichment()); - var asset = await assetQuery.FindAsync(requestContext, DomainId.Create(idOrSlug), request.Deleted, ct: HttpContext.RequestAborted); - - if (asset == null) - { - asset = await assetQuery.FindBySlugAsync(requestContext, idOrSlug, request.Deleted, HttpContext.RequestAborted); - } + var asset = + await assetQuery.FindAsync(requestContext, DomainId.Create(idOrSlug), request.Deleted, ct: HttpContext.RequestAborted) ?? + await assetQuery.FindBySlugAsync(requestContext, idOrSlug, request.Deleted, HttpContext.RequestAborted); return await DeliverAssetAsync(requestContext, asset, request); } diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetFoldersDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetFoldersDto.cs index 805b9bb59..1ab2c18f1 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetFoldersDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetFoldersDto.cs @@ -33,11 +33,10 @@ public sealed class AssetFoldersDto : Resource var result = new AssetFoldersDto { Total = assetFolders.Total, - Items = assetFolders.Select(x => AssetFolderDto.FromDomain(x, resources)).ToArray() + Items = assetFolders.Select(x => AssetFolderDto.FromDomain(x, resources)).ToArray(), + Path = path.Select(x => AssetFolderDto.FromDomain(x, resources)).ToArray() }; - result.Path = path.Select(x => AssetFolderDto.FromDomain(x, resources)).ToArray(); - return result.CreateLinks(resources); } diff --git a/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs b/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs index 57ed3ef12..c1f697d0d 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs @@ -24,22 +24,22 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator; public sealed class SchemasOpenApiGenerator { private readonly IAppProvider appProvider; - private readonly OpenApiDocumentGeneratorSettings schemaSettings; - private readonly OpenApiSchemaGenerator schemaGenerator; + private readonly OpenApiDocumentGeneratorSettings openApiSettings; + private readonly OpenApiSchemaGenerator openApiGenerator; private readonly IRequestUrlGenerator urlGenerator; private readonly IRequestCache requestCache; public SchemasOpenApiGenerator( IAppProvider appProvider, - OpenApiDocumentGeneratorSettings schemaSettings, - OpenApiSchemaGenerator schemaGenerator, + OpenApiDocumentGeneratorSettings openApiSettings, + OpenApiSchemaGenerator openApiGenerator, IRequestUrlGenerator urlGenerator, IRequestCache requestCache) { this.appProvider = appProvider; this.urlGenerator = urlGenerator; - this.schemaSettings = schemaSettings; - this.schemaGenerator = schemaGenerator; + this.openApiSettings = openApiSettings; + this.openApiGenerator = openApiGenerator; this.requestCache = requestCache; } @@ -47,7 +47,7 @@ public sealed class SchemasOpenApiGenerator { var document = CreateApiDocument(httpContext, app); - var schemaResolver = new OpenApiSchemaResolver(document, schemaSettings); + var schemaResolver = new OpenApiSchemaResolver(document, openApiSettings.SchemaSettings); requestCache.AddDependency(app.UniqueId, app.Version); @@ -56,7 +56,7 @@ public sealed class SchemasOpenApiGenerator requestCache.AddDependency(schema.UniqueId, schema.Version); } - var builder = new Builder(app, document, schemaResolver, schemaGenerator); + var builder = new Builder(app, document, schemaResolver, openApiGenerator); var partitionResolver = app.PartitionResolver(); @@ -77,10 +77,10 @@ public sealed class SchemasOpenApiGenerator Enumerable.Empty(), Enumerable.Empty(), schemaResolver, - schemaGenerator, - schemaSettings); + openApiGenerator, + openApiSettings); - foreach (var processor in schemaSettings.DocumentProcessors) + foreach (var processor in openApiSettings.DocumentProcessors) { processor.Process(context); } diff --git a/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs b/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs index 441c553b3..1ec836acb 100644 --- a/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs +++ b/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs @@ -168,7 +168,7 @@ public class DynamicApplicationStore : InMemoryApplicationStore Permissions.Prefixes.Scope + Constants.ScopeApi, Permissions.Prefixes.Scope + Constants.ScopePermissions }, - Type = ClientTypes.Public + ClientType = ClientTypes.Public }); var internalClientId = Constants.ClientInternalId; @@ -197,7 +197,7 @@ public class DynamicApplicationStore : InMemoryApplicationStore Permissions.Prefixes.Scope + Constants.ScopeApi, Permissions.Prefixes.Scope + Constants.ScopePermissions }, - Type = ClientTypes.Public + ClientType = ClientTypes.Public }); var identityOptions = serviceProvider.GetRequiredService>().Value; diff --git a/backend/src/Squidex/Areas/IdentityServer/Config/TokenStoreInitializer.cs b/backend/src/Squidex/Areas/IdentityServer/Config/TokenStoreInitializer.cs index b5ebb2d56..1614ec7f1 100644 --- a/backend/src/Squidex/Areas/IdentityServer/Config/TokenStoreInitializer.cs +++ b/backend/src/Squidex/Areas/IdentityServer/Config/TokenStoreInitializer.cs @@ -65,11 +65,11 @@ public sealed class TokenStoreInitializer : IInitializable, IBackgroundProcess { var database = await scope.ServiceProvider.GetRequiredService().GetDatabaseAsync(ct); - var collection = database.GetCollection>(options.TokensCollectionName); + var collection = database.GetCollection(options.TokensCollectionName); await collection.Indexes.CreateOneAsync( - new CreateIndexModel>( - Builders>.IndexKeys + new CreateIndexModel( + Builders.IndexKeys .Ascending(x => x.ReferenceId)), cancellationToken: ct); } diff --git a/backend/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs b/backend/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs index c7bc86a78..1ad3f98bf 100644 --- a/backend/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs +++ b/backend/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs @@ -96,13 +96,9 @@ public sealed class AccountController : IdentityServerController return View(vm); } - var user = await userService.GetAsync(User, HttpContext.RequestAborted); - // There is almost no case where this could have happened. - if (user == null) - { - throw new DomainException(T.Get("users.userNotFound")); - } + var user = await userService.GetAsync(User, HttpContext.RequestAborted) + ?? throw new DomainException(T.Get("users.userNotFound")); var update = new UserValues { diff --git a/backend/src/Squidex/Areas/IdentityServer/Controllers/Setup/SetupController.cs b/backend/src/Squidex/Areas/IdentityServer/Controllers/Setup/SetupController.cs index 72359170b..3e9219b91 100644 --- a/backend/src/Squidex/Areas/IdentityServer/Controllers/Setup/SetupController.cs +++ b/backend/src/Squidex/Areas/IdentityServer/Controllers/Setup/SetupController.cs @@ -108,7 +108,7 @@ public class SetupController : IdentityServerController IsValidHttps = HttpContext.Request.IsHttps, IsAssetStoreFile = assetStore is FolderAssetStore, IsAssetStoreFtp = assetStore is FTPAssetStore, - HasExternalLogin = externalProviders.Any(), + HasExternalLogin = externalProviders.Count != 0, HasPasswordAuth = identityOptions.AllowPasswordAuth }; diff --git a/backend/src/Squidex/Config/Domain/StoreServices.cs b/backend/src/Squidex/Config/Domain/StoreServices.cs index de5ebfb43..b1796cbb4 100644 --- a/backend/src/Squidex/Config/Domain/StoreServices.cs +++ b/backend/src/Squidex/Config/Domain/StoreServices.cs @@ -173,7 +173,7 @@ public static class StoreServices services.AddOpenIddict() .AddCore(builder => { - builder.UseMongoDb() + builder.UseMongoDb() .SetScopesCollectionName("Identity_Scopes") .SetTokensCollectionName("Identity_Tokens"); diff --git a/backend/src/Squidex/Squidex.csproj b/backend/src/Squidex/Squidex.csproj index abb0d4a20..93b153fea 100644 --- a/backend/src/Squidex/Squidex.csproj +++ b/backend/src/Squidex/Squidex.csproj @@ -37,27 +37,27 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + - + - + - + @@ -71,11 +71,11 @@ - + - + diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Contents/RichTextTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Contents/RichTextTests.cs index 726ff8bb7..306279cfe 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Contents/RichTextTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Contents/RichTextTests.cs @@ -56,6 +56,6 @@ public class RichTextTests private static string Sanitize(string source) { - return source.Replace("\r\n", "\n").Trim(); + return source.Replace("\r\n", "\n", StringComparison.Ordinal).Trim(); } } diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs index eab248358..6fbfa38ed 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs @@ -17,13 +17,11 @@ public class SchemaTests { private readonly Schema schema_0 = new Schema { Name = "my-schema" }; - public static IEnumerable FieldProperyTypes() - { - return typeof(Schema).Assembly.GetTypes().Where(x => x.BaseType == typeof(FieldProperties)).Select(x => new object[] { x }); - } + public static readonly TheoryData FieldPropertyTypes = + new TheoryData(typeof(Schema).Assembly.GetTypes().Where(x => x.BaseType == typeof(FieldProperties))); [Theory] - [MemberData(nameof(FieldProperyTypes))] + [MemberData(nameof(FieldPropertyTypes))] public void Should_make_deep_equal_test(Type type) { var lhs = (FieldProperties)Activator.CreateInstance(type)!; diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ConvertContent/FieldConvertersTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ConvertContent/FieldConvertersTests.cs index ad88914b8..3fd39f2b7 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ConvertContent/FieldConvertersTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ConvertContent/FieldConvertersTests.cs @@ -19,11 +19,11 @@ public class FieldConvertersTests { private readonly LanguagesConfig languages = LanguagesConfig.English.Set(Language.DE); - public static IEnumerable InvalidValues() + public static readonly TheoryData InvalidValues = new TheoryData { - yield return new object?[] { JsonValue.Null }; - yield return new object?[] { JsonValue.Create(false) }; // Undefined - } + { JsonValue.Null }, + { JsonValue.Create(false) }, + }; [Fact] public void Should_not_change_data_if_all_field_values_have_correct_type() diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ExtractReferenceIds/ReferenceExtractionTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ExtractReferenceIds/ReferenceExtractionTests.cs index 90b46baad..c92698f84 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ExtractReferenceIds/ReferenceExtractionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ExtractReferenceIds/ReferenceExtractionTests.cs @@ -19,6 +19,18 @@ public class ReferenceExtractionTests private readonly Schema schema; private readonly ResolvedComponents components; + public static readonly TheoryData ReferencingNestedFields = new TheoryData + { + { Fields.References(1, "myRefs") }, + { Fields.Assets(1, "myAssets") }, + }; + + public static readonly TheoryData ReferencingFields = new TheoryData + { + { Fields.References(1, "myRefs", Partitioning.Invariant) }, + { Fields.Assets(1, "myAssets", Partitioning.Invariant) }, + }; + public ReferenceExtractionTests() { schema = @@ -299,18 +311,6 @@ public class ReferenceExtractionTests Assert.Equal(CreateValue(id1), actual); } - public static IEnumerable ReferencingNestedFields() - { - yield return new object[] { Fields.References(1, "myRefs") }; - yield return new object[] { Fields.Assets(1, "myAssets") }; - } - - public static IEnumerable ReferencingFields() - { - yield return new object[] { Fields.References(1, "myRefs", Partitioning.Invariant) }; - yield return new object[] { Fields.Assets(1, "myAssets", Partitioning.Invariant) }; - } - private static HashSet RandomIds() { return HashSet.Of(DomainId.NewGuid()); diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/GenerateJsonSchema/JsonSchemaTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/GenerateJsonSchema/JsonSchemaTests.cs index 7447e98e6..38f49740a 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/GenerateJsonSchema/JsonSchemaTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/GenerateJsonSchema/JsonSchemaTests.cs @@ -86,7 +86,7 @@ public class JsonSchemaTests { var actual = new HashSet(); - void AddProperties(JsonSchema current) + void AddProperties(JsonSchema? current) { if (current == null) { diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/EventJsonSchemaGeneratorTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/EventJsonSchemaGeneratorTests.cs index 90cb75604..945db9c33 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/EventJsonSchemaGeneratorTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/EventJsonSchemaGeneratorTests.cs @@ -19,7 +19,7 @@ public class EventJsonSchemaGeneratorTests { var jsonSchemaGenerator = new JsonSchemaGenerator( - new JsonSchemaGeneratorSettings()); + new SystemTextJsonSchemaGeneratorSettings()); sut = new EventJsonSchemaGenerator(jsonSchemaGenerator); } @@ -34,10 +34,8 @@ public class EventJsonSchemaGeneratorTests yield return nameof(EnrichedUsageExceededEvent); } - public static IEnumerable AllTypesData() - { - return AllTypes().Select(x => new object[] { x }); - } + public static readonly TheoryData AllTypesData = + new TheoryData(AllTypes()); [Fact] public void Should_return_null_for_unknown_type_name() diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AssetsValidatorTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AssetsValidatorTests.cs index 3dbb52acf..25a72fca8 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AssetsValidatorTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AssetsValidatorTests.cs @@ -24,11 +24,11 @@ public class AssetsValidatorTests : IClassFixture private static readonly Asset ImageSvg = TestAssets.Svg(DomainId.NewGuid()); private static readonly Asset Video = TestAssets.Video(DomainId.NewGuid()); - public static IEnumerable AssetsWithDimensions() + public static readonly TheoryData AssetsWithDimensions = new TheoryData { - yield return new object[] { Image1.Id }; - yield return new object[] { Video.Id }; - } + { Image1.Id }, + { Video.Id } + }; [Fact] public async Task Should_not_add_error_if_assets_are_valid() diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj b/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj index b7a354fc9..bb0e6a79b 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj @@ -14,9 +14,9 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -27,8 +27,8 @@ - - + + all runtime; build; native; contentfiles; analyzers diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetChangedTriggerHandlerTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetChangedTriggerHandlerTests.cs index 34426279c..2078e8be7 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetChangedTriggerHandlerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetChangedTriggerHandlerTests.cs @@ -18,6 +18,7 @@ using Squidex.Domain.Apps.Events; using Squidex.Domain.Apps.Events.Assets; using Squidex.Domain.Apps.Events.Contents; using Squidex.Infrastructure.EventSourcing; +using Xunit; namespace Squidex.Domain.Apps.Entities.Assets; @@ -28,6 +29,14 @@ public class AssetChangedTriggerHandlerTests : GivenContext private readonly IAssetRepository assetRepository = A.Fake(); private readonly IRuleTriggerHandler sut; + public static readonly TheoryData TestEvents = new TheoryData + { + { TestUtils.CreateEvent(), EnrichedAssetEventType.Created }, + { TestUtils.CreateEvent(), EnrichedAssetEventType.Updated }, + { TestUtils.CreateEvent(), EnrichedAssetEventType.Annotated }, + { TestUtils.CreateEvent(), EnrichedAssetEventType.Deleted } + }; + public AssetChangedTriggerHandlerTests() { A.CallTo(() => scriptEngine.Evaluate(A._, "true", default)) @@ -39,14 +48,6 @@ public class AssetChangedTriggerHandlerTests : GivenContext sut = new AssetChangedTriggerHandler(scriptEngine, assetLoader, assetRepository); } - public static IEnumerable TestEvents() - { - yield return new object[] { TestUtils.CreateEvent(), EnrichedAssetEventType.Created }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedAssetEventType.Updated }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedAssetEventType.Annotated }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedAssetEventType.Deleted }; - } - [Fact] public void Should_return_true_if_asking_for_snapshot_support() { diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetUsageTrackerTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetUsageTrackerTests.cs index 6578adf27..6b35e68fa 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetUsageTrackerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetUsageTrackerTests.cs @@ -25,6 +25,13 @@ public class AssetUsageTrackerTests : GivenContext private readonly DomainId assetKey; private readonly AssetUsageTracker sut; + public static readonly TheoryData EventData = new TheoryData + { + { new AssetCreated { FileSize = 128 }, 128, 1 }, + { new AssetUpdated { FileSize = 512 }, 512, 0 }, + { new AssetDeleted { DeletedSize = 512 }, -512, -1 } + }; + public AssetUsageTrackerTests() { assetKey = DomainId.Combine(AppId, assetId); @@ -56,24 +63,6 @@ public class AssetUsageTrackerTests : GivenContext Assert.True(sut.BatchSize > 1); } - public static IEnumerable EventData() - { - yield return new object[] - { - new AssetCreated { FileSize = 128 }, 128, 1 - }; - - yield return new object[] - { - new AssetUpdated { FileSize = 512 }, 512, 0 - }; - - yield return new object[] - { - new AssetDeleted { DeletedSize = 512 }, -512, -1 - }; - } - [Theory] [MemberData(nameof(EventData))] public async Task Should_increase_usage_if_for_event(AssetEvent @event, long sizeDiff, long countDiff) diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs index ca3dda864..0896a9500 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs @@ -26,6 +26,9 @@ public class AssetsFluidExtensionTests : GivenContext private readonly IAssetThumbnailGenerator assetGenerator = A.Fake(); private readonly FluidTemplateEngine sut; + public static readonly TheoryData Encodings = + new TheoryData("ascii", "unicode", "utf8", "base64"); + public AssetsFluidExtensionTests() { var serviceProvider = @@ -45,14 +48,6 @@ public class AssetsFluidExtensionTests : GivenContext sut = new FluidTemplateEngine(extensions); } - public static IEnumerable Encodings() - { - yield return new object[] { "ascii" }; - yield return new object[] { "unicode" }; - yield return new object[] { "utf8" }; - yield return new object[] { "base64" }; - } - public static byte[] Encode(string encoding, string text) { switch (encoding) diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs index ab33045f2..ce4ff0fa0 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs @@ -32,6 +32,9 @@ public class AssetsJintExtensionTests : GivenContext, IClassFixture(); private readonly JintScriptEngine sut; + public static readonly TheoryData Encodings = + new TheoryData("ascii", "unicode", "utf8", "base64"); + public AssetsJintExtensionTests() { var serviceProvider = @@ -57,14 +60,6 @@ public class AssetsJintExtensionTests : GivenContext, IClassFixture Encodings() - { - yield return new object[] { "ascii" }; - yield return new object[] { "unicode" }; - yield return new object[] { "utf8" }; - yield return new object[] { "base64" }; - } - public static byte[] Encode(string encoding, string text) { switch (encoding) diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DefaultAssetFileStoreTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DefaultAssetFileStoreTests.cs index bbbdc0578..21e433d6b 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DefaultAssetFileStoreTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DefaultAssetFileStoreTests.cs @@ -23,23 +23,23 @@ public class DefaultAssetFileStoreTests : GivenContext private readonly AssetOptions options = new AssetOptions(); private readonly DefaultAssetFileStore sut; - public DefaultAssetFileStoreTests() + public static readonly TheoryData PathCases = new TheoryData { - sut = new DefaultAssetFileStore(assetStore, assetRepository, Options.Create(options)); - } + { true, "resize=100", "{appId}/{assetId}_{assetFileVersion}_resize=100" }, + { true, string.Empty, "{appId}/{assetId}_{assetFileVersion}" }, + { false, "resize=100", "{appId}_{assetId}_{assetFileVersion}_resize=100" }, + { false, string.Empty, "{appId}_{assetId}_{assetFileVersion}" } + }; - public static IEnumerable PathCases() + public static readonly TheoryData PathCasesOld = new TheoryData { - yield return new object[] { true, "resize=100", "{appId}/{assetId}_{assetFileVersion}_resize=100" }; - yield return new object[] { true, string.Empty, "{appId}/{assetId}_{assetFileVersion}" }; - yield return new object[] { false, "resize=100", "{appId}_{assetId}_{assetFileVersion}_resize=100" }; - yield return new object[] { false, string.Empty, "{appId}_{assetId}_{assetFileVersion}" }; - } + { "resize=100", "{assetId}_{assetFileVersion}_resize=100" }, + { string.Empty, "{assetId}_{assetFileVersion}" } + }; - public static IEnumerable PathCasesOld() + public DefaultAssetFileStoreTests() { - yield return new object?[] { "resize=100", "{assetId}_{assetFileVersion}_resize=100" }; - yield return new object?[] { string.Empty, "{assetId}_{assetFileVersion}" }; + sut = new DefaultAssetFileStore(assetStore, assetRepository, Options.Create(options)); } [Theory] diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/MongoDb/AssetsQueryIntegrationTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/MongoDb/AssetsQueryIntegrationTests.cs index 629825360..de15c7fba 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/MongoDb/AssetsQueryIntegrationTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/MongoDb/AssetsQueryIntegrationTests.cs @@ -20,6 +20,12 @@ public class AssetsQueryIntegrationTests : IClassFixture, IA { private readonly ProfilerCollection profiler; + public static readonly TheoryData ParentIds = new TheoryData + { + { null }, + { DomainId.Empty } + }; + public AssetsQueryFixture _ { get; } public AssetsQueryIntegrationTests(AssetsQueryFixture fixture) @@ -172,12 +178,6 @@ public class AssetsQueryIntegrationTests : IClassFixture, IA Assert.NotEmpty(assets); } - public static IEnumerable ParentIds() - { - yield return new object?[] { null }; - yield return new object?[] { DomainId.Empty }; - } - private async Task> QueryAsync(DomainId? parentId, ClrQuery clrQuery, int top = 1000, int skip = 100) diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentChangedTriggerHandlerTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentChangedTriggerHandlerTests.cs index 231d0ddb6..87a5abb76 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentChangedTriggerHandlerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentChangedTriggerHandlerTests.cs @@ -33,6 +33,16 @@ public class ContentChangedTriggerHandlerTests : GivenContext private readonly NamedId schemaNotMatching = NamedId.Of(DomainId.NewGuid(), "my-schema2"); private readonly IRuleTriggerHandler sut; + public static readonly TheoryData TestEvents = new TheoryData() + { + { TestUtils.CreateEvent(), EnrichedContentEventType.Created }, + { TestUtils.CreateEvent(), EnrichedContentEventType.Updated }, + { TestUtils.CreateEvent(), EnrichedContentEventType.Deleted }, + { TestUtils.CreateEvent(x => x.Change = StatusChange.Change), EnrichedContentEventType.StatusChanged }, + { TestUtils.CreateEvent(x => x.Change = StatusChange.Published), EnrichedContentEventType.Published }, + { TestUtils.CreateEvent(x => x.Change = StatusChange.Unpublished), EnrichedContentEventType.Unpublished } + }; + public ContentChangedTriggerHandlerTests() { A.CallTo(() => scriptEngine.Evaluate(A._, "true", default)) @@ -44,16 +54,6 @@ public class ContentChangedTriggerHandlerTests : GivenContext sut = new ContentChangedTriggerHandler(scriptEngine, contentLoader, contentRepository); } - public static IEnumerable TestEvents() - { - yield return new object[] { TestUtils.CreateEvent(), EnrichedContentEventType.Created }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedContentEventType.Updated }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedContentEventType.Deleted }; - yield return new object[] { TestUtils.CreateEvent(x => x.Change = StatusChange.Change), EnrichedContentEventType.StatusChanged }; - yield return new object[] { TestUtils.CreateEvent(x => x.Change = StatusChange.Published), EnrichedContentEventType.Published }; - yield return new object[] { TestUtils.CreateEvent(x => x.Change = StatusChange.Unpublished), EnrichedContentEventType.Unpublished }; - } - [Fact] public void Should_return_true_if_asking_for_snapshot_support() { diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs index dcd437ccf..76436edee 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs @@ -11,6 +11,7 @@ using Squidex.Domain.Apps.Core.TestHelpers; using Squidex.Domain.Apps.Entities.Schemas.Commands; using Squidex.Domain.Apps.Entities.TestHelpers; using Squidex.Infrastructure; +using Squidex.Infrastructure.Translations; using Squidex.Infrastructure.Validation; #pragma warning disable SA1310 // Field names must not contain underscore @@ -22,6 +23,17 @@ public class GuardSchemaFieldTests : GivenContext, IClassFixture FieldCommandData() + { + yield return new object[] { A(GuardSchemaField.CanEnable) }; + yield return new object[] { A(GuardSchemaField.CanDelete) }; + yield return new object[] { A(GuardSchemaField.CanDisable) }; + yield return new object[] { A(GuardSchemaField.CanHide) }; + yield return new object[] { A(GuardSchemaField.CanLock) }; + yield return new object[] { A(GuardSchemaField.CanShow) }; + yield return new object[] { A(GuardSchemaField.CanUpdate) }; + } + public GuardSchemaFieldTests() { Schema = Schema @@ -37,17 +49,6 @@ public class GuardSchemaFieldTests : GivenContext, IClassFixture FieldCommandData() - { - yield return new object[] { A(GuardSchemaField.CanEnable) }; - yield return new object[] { A(GuardSchemaField.CanDelete) }; - yield return new object[] { A(GuardSchemaField.CanDisable) }; - yield return new object[] { A(GuardSchemaField.CanHide) }; - yield return new object[] { A(GuardSchemaField.CanLock) }; - yield return new object[] { A(GuardSchemaField.CanShow) }; - yield return new object[] { A(GuardSchemaField.CanUpdate) }; - } - [Theory] [MemberData(nameof(FieldCommandData))] public void Commands_should_throw_exception_if_field_not_found(Action action) where T : FieldCommand, new() diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaChangedTriggerHandlerTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaChangedTriggerHandlerTests.cs index ba6d2961f..7c7d54bd6 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaChangedTriggerHandlerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaChangedTriggerHandlerTests.cs @@ -24,6 +24,15 @@ public class SchemaChangedTriggerHandlerTests : GivenContext private readonly IScriptEngine scriptEngine = A.Fake(); private readonly IRuleTriggerHandler sut; + public static readonly TheoryData TestEvents = new () + { + { TestUtils.CreateEvent(), EnrichedSchemaEventType.Created }, + { TestUtils.CreateEvent(), EnrichedSchemaEventType.Updated }, + { TestUtils.CreateEvent(), EnrichedSchemaEventType.Deleted }, + { TestUtils.CreateEvent(), EnrichedSchemaEventType.Published }, + { TestUtils.CreateEvent(), EnrichedSchemaEventType.Unpublished }, + }; + public SchemaChangedTriggerHandlerTests() { A.CallTo(() => scriptEngine.Evaluate(A._, "true", default)) @@ -35,15 +44,6 @@ public class SchemaChangedTriggerHandlerTests : GivenContext sut = new SchemaChangedTriggerHandler(scriptEngine); } - public static IEnumerable TestEvents() - { - yield return new object[] { TestUtils.CreateEvent(), EnrichedSchemaEventType.Created }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedSchemaEventType.Updated }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedSchemaEventType.Deleted }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedSchemaEventType.Published }; - yield return new object[] { TestUtils.CreateEvent(), EnrichedSchemaEventType.Unpublished }; - } - [Fact] public void Should_return_false_if_asking_for_snapshot_support() { diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj index 5f1ba3820..e42b41b98 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj @@ -22,26 +22,26 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - + + + all runtime; build; native; contentfiles; analyzers diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/GivenContext.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/GivenContext.cs index ca1d99475..7be67ff2f 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/GivenContext.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/GivenContext.cs @@ -115,7 +115,7 @@ public abstract class GivenContext }; } - public Instant Timestamp() + public static Instant Timestamp() { return SystemClock.Instance.GetCurrentInstant(); } diff --git a/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj b/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj index 978740af9..55e81b401 100644 --- a/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj +++ b/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj @@ -14,17 +14,17 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers diff --git a/backend/tests/Squidex.Infrastructure.Tests/HashExtensionsTests.cs b/backend/tests/Squidex.Infrastructure.Tests/HashExtensionsTests.cs index 571e8b79d..a3b378024 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/HashExtensionsTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/HashExtensionsTests.cs @@ -12,13 +12,8 @@ namespace Squidex.Infrastructure; public class HashExtensionsTests { - public static IEnumerable InputLengths() - { - yield return new object[] { 1 }; - yield return new object[] { 20 }; - yield return new object[] { 50 }; - yield return new object[] { 500 }; - } + public static readonly TheoryData InputLengths = + new TheoryData(1, 20, 50, 500); [Fact] public void Should_calculate_hex_code_from_empty_array() @@ -197,14 +192,11 @@ public class HashExtensionsTests private static string WebhookHash(string value) { - using (var sha = SHA256.Create()) - { - var bytesArray = Encoding.UTF8.GetBytes(value); - var bytesHash = sha.ComputeHash(bytesArray); + var bytesArray = Encoding.UTF8.GetBytes(value); + var bytesHash = SHA256.HashData(bytesArray); - var result = Convert.ToBase64String(bytesHash); + var result = Convert.ToBase64String(bytesHash); - return result; - } + return result; } } diff --git a/backend/tests/Squidex.Infrastructure.Tests/Json/Objects/JsonValuesSerializationTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Json/Objects/JsonValuesSerializationTests.cs index f531a6452..c02224d97 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Json/Objects/JsonValuesSerializationTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Json/Objects/JsonValuesSerializationTests.cs @@ -18,11 +18,11 @@ public class JsonValuesSerializationTests Bson } - public static IEnumerable Serializers() + public static readonly TheoryData Serializers = new TheoryData { - yield return new object[] { SerializerMode.Json }; - yield return new object[] { SerializerMode.Bson }; - } + { SerializerMode.Json }, + { SerializerMode.Bson } + }; private static T Serialize(T input, SerializerMode mode) { diff --git a/backend/tests/Squidex.Infrastructure.Tests/NamedIdTests.cs b/backend/tests/Squidex.Infrastructure.Tests/NamedIdTests.cs index 7a193627b..8f2f492fd 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/NamedIdTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/NamedIdTests.cs @@ -20,11 +20,11 @@ public class NamedIdTests public NamedId Value { get; set; } } - public static IEnumerable Serializers() + public static readonly TheoryData Serializers = new TheoryData { - yield return new object[] { SerializerMode.Json }; - yield return new object[] { SerializerMode.Bson }; - } + { SerializerMode.Json }, + { SerializerMode.Bson } + }; private static T Serialize(T input, SerializerMode mode) { diff --git a/backend/tests/Squidex.Infrastructure.Tests/Queries/QueryFromJsonTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Queries/QueryFromJsonTests.cs index 8592f7a1f..3c9f9b845 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Queries/QueryFromJsonTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Queries/QueryFromJsonTests.cs @@ -9,6 +9,7 @@ using Squidex.Infrastructure.Collections; using Squidex.Infrastructure.Json.Objects; using Squidex.Infrastructure.Queries.Json; using Squidex.Infrastructure.TestHelpers; +using Squidex.Infrastructure.Translations; using Squidex.Infrastructure.Validation; namespace Squidex.Infrastructure.Queries; @@ -71,7 +72,7 @@ public sealed class QueryFromJsonTests public class DateTime { - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { const string value = "2012-11-10T09:08:07Z"; @@ -122,7 +123,7 @@ public sealed class QueryFromJsonTests public class Guid { - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { const string value = "bf57d32c-d4dd-4217-8c16-6dcb16975cf3"; @@ -173,14 +174,14 @@ public sealed class QueryFromJsonTests public class String { - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { const string value = "Hello"; return BuildTests("string", x => true, value, $"'{value}'"); } - public static IEnumerable ValidInTests() + public static TheoryData ValidInTests() { const string value = "Hello"; @@ -253,18 +254,18 @@ public sealed class QueryFromJsonTests return op is "lt" or "exists"; } - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { var value = new { longitude = 10, latitude = 20, distance = 30 }; - return BuildFlatTests("geo", ValidOperator, value, $"Radius({value.longitude}, {value.latitude}, {value.distance})"); + return BuildFlatTests("geo", ValidOperator, value, $"Radius({value.longitude}, {value.latitude}, {value.distance})"); } - public static IEnumerable InvalidTests() + public static TheoryData InvalidTests() { var value = new { longitude = 10, latitude = 20, distance = 30 }; - return BuildInvalidOperatorTests("geo", ValidOperator, value); + return BuildInvalidOperatorTests("geo", ValidOperator, value); } [Theory] @@ -309,21 +310,21 @@ public sealed class QueryFromJsonTests return op.Length == 2 || op == "exists"; } - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { const int value = 12; return BuildTests("number", ValidOperator, value, $"{value}"); } - public static IEnumerable InvalidTests() + public static TheoryData InvalidTests() { const int value = 12; - return BuildInvalidOperatorTests("number", ValidOperator, $"{value}"); + return BuildInvalidOperatorTests("number", ValidOperator, value); } - public static IEnumerable ValidInTests() + public static TheoryData ValidInTests() { const int value = 12; @@ -389,21 +390,21 @@ public sealed class QueryFromJsonTests return op is "eq" or "ne" or "exists"; } - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { const bool value = true; return BuildTests("boolean", ValidOperator, value, $"{value}"); } - public static IEnumerable InvalidTests() + public static TheoryData InvalidTests() { const bool value = true; return BuildInvalidOperatorTests("boolean", ValidOperator, value); } - public static IEnumerable ValidInTests() + public static TheoryData ValidInTests() { const bool value = true; @@ -469,14 +470,14 @@ public sealed class QueryFromJsonTests return op is "eq" or "ne" or "empty" or "exists"; } - public static IEnumerable ValidTests() + public static TheoryData ValidTests() { const string value = "Hello"; return BuildTests("stringArray", ValidOperator, value, $"'{value}'"); } - public static IEnumerable ValidInTests() + public static TheoryData ValidInTests() { const string value = "Hello"; @@ -694,13 +695,15 @@ public sealed class QueryFromJsonTests return jsonFilter.ToString(); } - public static IEnumerable BuildFlatTests(string field, Predicate opFilter, object value, string valueString) + public static TheoryData BuildFlatTests(string field, Predicate opFilter, T value, string valueString) { var fields = new[] { $"{field}" }; + var data = new TheoryData(); + foreach (var fieldName in fields) { foreach (var (_, op, output) in AllOps.Where(x => opFilter(x.Operator))) @@ -710,12 +713,14 @@ public sealed class QueryFromJsonTests .Replace("$FIELD", fieldName, StringComparison.Ordinal) .Replace("$VALUE", valueString, StringComparison.Ordinal); - yield return new[] { fieldName, op, value, expected }; + data.Add(fieldName, op, value, expected); } } + + return data; } - public static IEnumerable BuildTests(string field, Predicate opFilter, object value, string valueString) + public static TheoryData BuildTests(string field, Predicate opFilter, T value, string valueString) { var fields = new[] { @@ -724,6 +729,8 @@ public sealed class QueryFromJsonTests $"json.nested.{field}" }; + var data = new TheoryData(); + foreach (var fieldName in fields) { foreach (var (_, op, output) in AllOps.Where(x => opFilter(x.Operator))) @@ -733,12 +740,14 @@ public sealed class QueryFromJsonTests .Replace("$FIELD", fieldName, StringComparison.Ordinal) .Replace("$VALUE", valueString, StringComparison.Ordinal); - yield return new[] { fieldName, op, value, expected }; + data.Add(fieldName, op, value, expected); } } + + return data; } - public static IEnumerable BuildInTests(string field, object value, string valueString) + public static TheoryData BuildInTests(string field, T value, string valueString) { var fields = new[] { @@ -747,19 +756,27 @@ public sealed class QueryFromJsonTests $"json.nested.{field}" }; - foreach (var f in fields) + var data = new TheoryData(); + + foreach (var fieldName in fields) { - var expected = $"{f} in [{valueString}]"; + var expected = $"{fieldName} in [{valueString}]"; - yield return new[] { f, value, expected }; + data.Add(fieldName, value, expected); } + + return data; } - public static IEnumerable BuildInvalidOperatorTests(string field, Predicate opFilter, object value) + public static TheoryData BuildInvalidOperatorTests(string field, Predicate opFilter, T value) { + var data = new TheoryData(); + foreach (var (name, op, _) in AllOps.Where(x => !opFilter(x.Operator))) { - yield return new[] { field, op, value, name }; + data.Add(field, op, value, name); } + + return data; } } diff --git a/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj b/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj index b7dc10159..ffa155ca1 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj +++ b/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj @@ -14,9 +14,9 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -28,8 +28,8 @@ - - + + all runtime; build; native; contentfiles; analyzers diff --git a/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj b/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj index b49b1fa01..a6b8b7419 100644 --- a/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj +++ b/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj @@ -14,16 +14,16 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers diff --git a/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj b/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj index 0c877f87f..84c63b3c7 100644 --- a/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj +++ b/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj @@ -11,16 +11,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + all diff --git a/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs b/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs index d70685284..89a05075e 100644 --- a/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs +++ b/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs @@ -27,7 +27,7 @@ public class ReadingBenchmarks : IClassFixture _ = fixture; } - public static IEnumerable Loads() + public static TheoryData Loads() { int[] users = { @@ -50,15 +50,19 @@ public class ReadingBenchmarks : IClassFixture 1000 }; + var data = new TheoryData(); + foreach (var user in users) { foreach (var load in loads) { - yield return new object[] { user, load }; + data.Add(user, load); } } - yield return new object[] { 1, 20000 }; + data.Add(1, 20_0000); + + return data; } [Theory] diff --git a/tools/TestSuite/TestSuite.LoadTests/ReadingContentBenchmarks.cs b/tools/TestSuite/TestSuite.LoadTests/ReadingContentBenchmarks.cs index 45f24b908..5c32806e3 100644 --- a/tools/TestSuite/TestSuite.LoadTests/ReadingContentBenchmarks.cs +++ b/tools/TestSuite/TestSuite.LoadTests/ReadingContentBenchmarks.cs @@ -21,7 +21,7 @@ public class ReadingContentBenchmarks : IClassFixture _ = fixture; } - public static IEnumerable Loads() + public static TheoryData Loads() { int[] users = { @@ -44,15 +44,19 @@ public class ReadingContentBenchmarks : IClassFixture 1000 }; + var data = new TheoryData(); + foreach (var user in users) { foreach (var load in loads) { - yield return new object[] { user, load }; + data.Add(user, load); } } - yield return new object[] { 1, 20000 }; + data.Add(1, 20000); + + return data; } [Theory] diff --git a/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj b/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj index 2527384c8..412659eff 100644 --- a/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj +++ b/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj @@ -7,7 +7,7 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tools/TestSuite/TestSuite.LoadTests/WritingBenchmarks.cs b/tools/TestSuite/TestSuite.LoadTests/WritingBenchmarks.cs index 7e6559c94..5284ca0d1 100644 --- a/tools/TestSuite/TestSuite.LoadTests/WritingBenchmarks.cs +++ b/tools/TestSuite/TestSuite.LoadTests/WritingBenchmarks.cs @@ -22,7 +22,7 @@ public class WritingBenchmarks : IClassFixture _ = fixture; } - public static IEnumerable Loads() + public static TheoryData Loads() { int[] users = { @@ -43,15 +43,19 @@ public class WritingBenchmarks : IClassFixture 100 }; + var data = new TheoryData(); + foreach (var user in users) { foreach (var load in loads) { - yield return new object[] { user, load }; + data.Add(user, load); } } - yield return new object[] { 1, 50000 }; + data.Add(1, 50_0000); + + return data; } [Theory] diff --git a/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj b/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj index 29d559d58..98df56bdb 100644 --- a/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj +++ b/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj @@ -7,7 +7,7 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -18,10 +18,10 @@ - - + + - +