Browse Source

CommandHandler => CommandMiddleware.

pull/95/head
Sebastian Stehle 9 years ago
parent
commit
57a6a5088d
  1. 6
      src/Squidex.Domain.Apps.Write/Apps/AppCommandMiddleware.cs
  2. 6
      src/Squidex.Domain.Apps.Write/Assets/AssetCommandMiddleware.cs
  3. 6
      src/Squidex.Domain.Apps.Write/Contents/ContentCommandMiddleware.cs
  4. 6
      src/Squidex.Domain.Apps.Write/Schemas/SchemaCommandMiddleware.cs
  5. 4
      src/Squidex.Infrastructure/CQRS/Commands/CommandingExtensions.cs
  6. 4
      src/Squidex.Infrastructure/CQRS/Commands/EnrichWithTimestampCommandMiddleware.cs
  7. 4
      src/Squidex.Infrastructure/CQRS/Commands/ICommandHandler.cs
  8. 6
      src/Squidex.Infrastructure/CQRS/Commands/InMemoryCommandBus.cs
  9. 4
      src/Squidex.Infrastructure/CQRS/Commands/LogCommandMiddleware.cs
  10. 40
      src/Squidex/Config/Domain/WriteModule.cs
  11. 8
      src/Squidex/Pipeline/CommandHandlers/ETagCommandMiddleware.cs
  12. 8
      src/Squidex/Pipeline/CommandHandlers/EnrichWithActorCommandMiddleware.cs
  13. 6
      src/Squidex/Pipeline/CommandHandlers/EnrichWithAppIdCommandMiddleware.cs
  14. 6
      src/Squidex/Pipeline/CommandHandlers/EnrichWithSchemaIdCommandMiddleware.cs
  15. 10
      tests/Squidex.Domain.Apps.Write.Tests/Apps/AppCommandHandlerTests.cs
  16. 10
      tests/Squidex.Domain.Apps.Write.Tests/Assets/AssetCommandHandlerTests.cs
  17. 10
      tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentCommandHandlerTests.cs
  18. 10
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaCommandHandlerTests.cs
  19. 4
      tests/Squidex.Infrastructure.Tests/CQRS/Commands/EnrichWithTimestampCommandHandlerTests.cs
  20. 14
      tests/Squidex.Infrastructure.Tests/CQRS/Commands/InMemoryCommandBusTests.cs
  21. 4
      tests/Squidex.Infrastructure.Tests/CQRS/Commands/LogCommandHandlerTests.cs

6
src/Squidex.Domain.Apps.Write/Apps/AppCommandHandler.cs → src/Squidex.Domain.Apps.Write/Apps/AppCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// AppCommandHandler.cs // AppCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -20,7 +20,7 @@ using Squidex.Shared.Users;
namespace Squidex.Domain.Apps.Write.Apps namespace Squidex.Domain.Apps.Write.Apps
{ {
public class AppCommandHandler : ICommandHandler public class AppCommandMiddleware : ICommandMiddleware
{ {
private readonly IAggregateHandler handler; private readonly IAggregateHandler handler;
private readonly IAppRepository appRepository; private readonly IAppRepository appRepository;
@ -28,7 +28,7 @@ namespace Squidex.Domain.Apps.Write.Apps
private readonly IAppPlanBillingManager appPlansBillingManager; private readonly IAppPlanBillingManager appPlansBillingManager;
private readonly IUserResolver userResolver; private readonly IUserResolver userResolver;
public AppCommandHandler( public AppCommandMiddleware(
IAggregateHandler handler, IAggregateHandler handler,
IAppRepository appRepository, IAppRepository appRepository,
IAppPlansProvider appPlansProvider, IAppPlansProvider appPlansProvider,

6
src/Squidex.Domain.Apps.Write/Assets/AssetCommandHandler.cs → src/Squidex.Domain.Apps.Write/Assets/AssetCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// AssetCommandHandler.cs // AssetCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -16,13 +16,13 @@ using Squidex.Infrastructure.Dispatching;
namespace Squidex.Domain.Apps.Write.Assets namespace Squidex.Domain.Apps.Write.Assets
{ {
public class AssetCommandHandler : ICommandHandler public class AssetCommandMiddleware : ICommandMiddleware
{ {
private readonly IAggregateHandler handler; private readonly IAggregateHandler handler;
private readonly IAssetStore assetStore; private readonly IAssetStore assetStore;
private readonly IAssetThumbnailGenerator assetThumbnailGenerator; private readonly IAssetThumbnailGenerator assetThumbnailGenerator;
public AssetCommandHandler( public AssetCommandMiddleware(
IAggregateHandler handler, IAggregateHandler handler,
IAssetStore assetStore, IAssetStore assetStore,
IAssetThumbnailGenerator assetThumbnailGenerator) IAssetThumbnailGenerator assetThumbnailGenerator)

6
src/Squidex.Domain.Apps.Write/Contents/ContentCommandHandler.cs → src/Squidex.Domain.Apps.Write/Contents/ContentCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ContentCommandHandler.cs // ContentCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -25,7 +25,7 @@ using Squidex.Infrastructure.Dispatching;
namespace Squidex.Domain.Apps.Write.Contents namespace Squidex.Domain.Apps.Write.Contents
{ {
public class ContentCommandHandler : ICommandHandler public class ContentCommandMiddleware : ICommandMiddleware
{ {
private readonly IAggregateHandler handler; private readonly IAggregateHandler handler;
private readonly IAppProvider appProvider; private readonly IAppProvider appProvider;
@ -33,7 +33,7 @@ namespace Squidex.Domain.Apps.Write.Contents
private readonly IContentRepository contentRepository; private readonly IContentRepository contentRepository;
private readonly ISchemaProvider schemas; private readonly ISchemaProvider schemas;
public ContentCommandHandler( public ContentCommandMiddleware(
IAggregateHandler handler, IAggregateHandler handler,
IAppProvider appProvider, IAppProvider appProvider,
IAssetRepository assetRepository, IAssetRepository assetRepository,

6
src/Squidex.Domain.Apps.Write/Schemas/SchemaCommandHandler.cs → src/Squidex.Domain.Apps.Write/Schemas/SchemaCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// SchemaCommandHandler.cs // SchemaCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -17,12 +17,12 @@ using Squidex.Infrastructure.Dispatching;
namespace Squidex.Domain.Apps.Write.Schemas namespace Squidex.Domain.Apps.Write.Schemas
{ {
public class SchemaCommandHandler : ICommandHandler public class SchemaCommandMiddleware : ICommandMiddleware
{ {
private readonly ISchemaProvider schemas; private readonly ISchemaProvider schemas;
private readonly IAggregateHandler handler; private readonly IAggregateHandler handler;
public SchemaCommandHandler(IAggregateHandler handler, ISchemaProvider schemas) public SchemaCommandMiddleware(IAggregateHandler handler, ISchemaProvider schemas)
{ {
Guard.NotNull(handler, nameof(handler)); Guard.NotNull(handler, nameof(handler));
Guard.NotNull(schemas, nameof(schemas)); Guard.NotNull(schemas, nameof(schemas));

4
src/Squidex.Infrastructure/CQRS/Commands/CommandingExtensions.cs

@ -34,9 +34,9 @@ namespace Squidex.Infrastructure.CQRS.Commands
}); });
} }
public static Task HandleAsync(this ICommandHandler commandHandler, CommandContext context) public static Task HandleAsync(this ICommandMiddleware commandMiddleware, CommandContext context)
{ {
return commandHandler.HandleAsync(context, () => TaskHelper.Done); return commandMiddleware.HandleAsync(context, () => TaskHelper.Done);
} }
} }
} }

4
src/Squidex.Infrastructure/CQRS/Commands/EnrichWithTimestampCommandHandler.cs → src/Squidex.Infrastructure/CQRS/Commands/EnrichWithTimestampCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EnrichWithTimestampCommandHandler.cs // EnrichWithTimestampCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -12,7 +12,7 @@ using NodaTime;
namespace Squidex.Infrastructure.CQRS.Commands namespace Squidex.Infrastructure.CQRS.Commands
{ {
public sealed class EnrichWithTimestampHandler : ICommandHandler public sealed class EnrichWithTimestampHandler : ICommandMiddleware
{ {
private readonly IClock clock; private readonly IClock clock;

4
src/Squidex.Infrastructure/CQRS/Commands/ICommandHandler.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ICommandHandler.cs // ICommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace Squidex.Infrastructure.CQRS.Commands namespace Squidex.Infrastructure.CQRS.Commands
{ {
public interface ICommandHandler public interface ICommandMiddleware
{ {
Task HandleAsync(CommandContext context, Func<Task> next); Task HandleAsync(CommandContext context, Func<Task> next);
} }

6
src/Squidex.Infrastructure/CQRS/Commands/InMemoryCommandBus.cs

@ -16,9 +16,9 @@ namespace Squidex.Infrastructure.CQRS.Commands
{ {
public sealed class InMemoryCommandBus : ICommandBus public sealed class InMemoryCommandBus : ICommandBus
{ {
private readonly List<ICommandHandler> handlers; private readonly List<ICommandMiddleware> handlers;
public InMemoryCommandBus(IEnumerable<ICommandHandler> handlers) public InMemoryCommandBus(IEnumerable<ICommandMiddleware> handlers)
{ {
Guard.NotNull(handlers, nameof(handlers)); Guard.NotNull(handlers, nameof(handlers));
@ -43,7 +43,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
return context; return context;
} }
private static Func<Task> Join(ICommandHandler handler, CommandContext context, Func<Task> next) private static Func<Task> Join(ICommandMiddleware handler, CommandContext context, Func<Task> next)
{ {
return () => handler.HandleAsync(context, next); return () => handler.HandleAsync(context, next);
} }

4
src/Squidex.Infrastructure/CQRS/Commands/LogCommandHandler.cs → src/Squidex.Infrastructure/CQRS/Commands/LogCommandMiddleware.cs

@ -12,11 +12,11 @@ using Squidex.Infrastructure.Log;
namespace Squidex.Infrastructure.CQRS.Commands namespace Squidex.Infrastructure.CQRS.Commands
{ {
public sealed class LogCommandHandler : ICommandHandler public sealed class LogCommandMiddleware : ICommandMiddleware
{ {
private readonly ISemanticLog log; private readonly ISemanticLog log;
public LogCommandHandler(ISemanticLog log) public LogCommandMiddleware(ISemanticLog log)
{ {
Guard.NotNull(log, nameof(log)); Guard.NotNull(log, nameof(log));

40
src/Squidex/Config/Domain/WriteModule.cs

@ -14,7 +14,7 @@ using Squidex.Domain.Apps.Write.Assets;
using Squidex.Domain.Apps.Write.Contents; using Squidex.Domain.Apps.Write.Contents;
using Squidex.Domain.Apps.Write.Schemas; using Squidex.Domain.Apps.Write.Schemas;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Pipeline.CommandHandlers; using Squidex.Pipeline.CommandMiddlewares;
// ReSharper disable UnusedAutoPropertyAccessor.Local // ReSharper disable UnusedAutoPropertyAccessor.Local
@ -31,48 +31,48 @@ namespace Squidex.Config.Domain
protected override void Load(ContainerBuilder builder) protected override void Load(ContainerBuilder builder)
{ {
builder.RegisterType<ETagCommandHandler>() builder.RegisterType<ETagCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<EnrichWithTimestampHandler>() builder.RegisterType<EnrichWithTimestampHandler>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<EnrichWithActorCommandHandler>() builder.RegisterType<EnrichWithActorCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<EnrichWithAppIdCommandHandler>() builder.RegisterType<EnrichWithAppIdCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<EnrichWithSchemaIdCommandHandler>() builder.RegisterType<EnrichWithSchemaIdCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<FieldRegistry>() builder.RegisterType<FieldRegistry>()
.AsSelf() .AsSelf()
.SingleInstance(); .SingleInstance();
builder.RegisterType<AppCommandHandler>() builder.RegisterType<AppCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<AssetCommandHandler>() builder.RegisterType<AssetCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<ContentCommandHandler>() builder.RegisterType<ContentCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<SchemaCommandHandler>() builder.RegisterType<SchemaCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<ETagCommandHandler>() builder.RegisterType<ETagCommandMiddleware>()
.As<ICommandHandler>() .As<ICommandMiddleware>()
.SingleInstance(); .SingleInstance();
builder.Register<DomainObjectFactoryFunction<AppDomainObject>>(c => (id => new AppDomainObject(id, -1))) builder.Register<DomainObjectFactoryFunction<AppDomainObject>>(c => (id => new AppDomainObject(id, -1)))

8
src/Squidex/Pipeline/CommandHandlers/ETagCommandHandler.cs → src/Squidex/Pipeline/CommandHandlers/ETagCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ETagCommandHandler.cs // ETagCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -13,13 +13,13 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
namespace Squidex.Pipeline.CommandHandlers namespace Squidex.Pipeline.CommandMiddlewares
{ {
public class ETagCommandHandler : ICommandHandler public class ETagCommandMiddleware : ICommandMiddleware
{ {
private readonly IHttpContextAccessor httpContextAccessor; private readonly IHttpContextAccessor httpContextAccessor;
public ETagCommandHandler(IHttpContextAccessor httpContextAccessor) public ETagCommandMiddleware(IHttpContextAccessor httpContextAccessor)
{ {
this.httpContextAccessor = httpContextAccessor; this.httpContextAccessor = httpContextAccessor;
} }

8
src/Squidex/Pipeline/CommandHandlers/EnrichWithActorCommandHandler.cs → src/Squidex/Pipeline/CommandHandlers/EnrichWithActorCommandMiddleware.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EnrichWithActorCommandHandler.cs // EnrichWithActorCommandMiddleware.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -17,13 +17,13 @@ using Squidex.Infrastructure.Security;
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace Squidex.Pipeline.CommandHandlers namespace Squidex.Pipeline.CommandMiddlewares
{ {
public class EnrichWithActorCommandHandler : ICommandHandler public class EnrichWithActorCommandMiddleware : ICommandMiddleware
{ {
private readonly IHttpContextAccessor httpContextAccessor; private readonly IHttpContextAccessor httpContextAccessor;
public EnrichWithActorCommandHandler(IHttpContextAccessor httpContextAccessor) public EnrichWithActorCommandMiddleware(IHttpContextAccessor httpContextAccessor)
{ {
this.httpContextAccessor = httpContextAccessor; this.httpContextAccessor = httpContextAccessor;
} }

6
src/Squidex/Pipeline/CommandHandlers/EnrichWithAppIdCommandHandler.cs → src/Squidex/Pipeline/CommandHandlers/EnrichWithAppIdCommandMiddleware.cs

@ -15,13 +15,13 @@ using Squidex.Infrastructure.CQRS.Commands;
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace Squidex.Pipeline.CommandHandlers namespace Squidex.Pipeline.CommandMiddlewares
{ {
public sealed class EnrichWithAppIdCommandHandler : ICommandHandler public sealed class EnrichWithAppIdCommandMiddleware : ICommandMiddleware
{ {
private readonly IHttpContextAccessor httpContextAccessor; private readonly IHttpContextAccessor httpContextAccessor;
public EnrichWithAppIdCommandHandler(IHttpContextAccessor httpContextAccessor) public EnrichWithAppIdCommandMiddleware(IHttpContextAccessor httpContextAccessor)
{ {
this.httpContextAccessor = httpContextAccessor; this.httpContextAccessor = httpContextAccessor;
} }

6
src/Squidex/Pipeline/CommandHandlers/EnrichWithSchemaIdCommandHandler.cs → src/Squidex/Pipeline/CommandHandlers/EnrichWithSchemaIdCommandMiddleware.cs

@ -18,14 +18,14 @@ using Squidex.Infrastructure.CQRS.Commands;
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace Squidex.Pipeline.CommandHandlers namespace Squidex.Pipeline.CommandMiddlewares
{ {
public sealed class EnrichWithSchemaIdCommandHandler : ICommandHandler public sealed class EnrichWithSchemaIdCommandMiddleware : ICommandMiddleware
{ {
private readonly ISchemaProvider schemas; private readonly ISchemaProvider schemas;
private readonly IActionContextAccessor actionContextAccessor; private readonly IActionContextAccessor actionContextAccessor;
public EnrichWithSchemaIdCommandHandler(ISchemaProvider schemas, IActionContextAccessor actionContextAccessor) public EnrichWithSchemaIdCommandMiddleware(ISchemaProvider schemas, IActionContextAccessor actionContextAccessor)
{ {
this.schemas = schemas; this.schemas = schemas;

10
tests/Squidex.Domain.Apps.Write.Tests/Apps/AppCommandHandlerTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// AppCommandHandlerTests.cs // AppCommandMiddlewareTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -25,23 +25,23 @@ using Xunit;
namespace Squidex.Domain.Apps.Write.Apps namespace Squidex.Domain.Apps.Write.Apps
{ {
public class AppCommandHandlerTests : HandlerTestBase<AppDomainObject> public class AppCommandMiddlewareTests : HandlerTestBase<AppDomainObject>
{ {
private readonly IAppRepository appRepository = A.Fake<IAppRepository>(); private readonly IAppRepository appRepository = A.Fake<IAppRepository>();
private readonly IAppPlansProvider appPlansProvider = A.Fake<IAppPlansProvider>(); private readonly IAppPlansProvider appPlansProvider = A.Fake<IAppPlansProvider>();
private readonly IAppPlanBillingManager appPlansBillingManager = A.Fake<IAppPlanBillingManager>(); private readonly IAppPlanBillingManager appPlansBillingManager = A.Fake<IAppPlanBillingManager>();
private readonly IUserResolver userResolver = A.Fake<IUserResolver>(); private readonly IUserResolver userResolver = A.Fake<IUserResolver>();
private readonly AppCommandHandler sut; private readonly AppCommandMiddleware sut;
private readonly AppDomainObject app; private readonly AppDomainObject app;
private readonly Language language = Language.DE; private readonly Language language = Language.DE;
private readonly string contributorId = Guid.NewGuid().ToString(); private readonly string contributorId = Guid.NewGuid().ToString();
private readonly string clientName = "client"; private readonly string clientName = "client";
public AppCommandHandlerTests() public AppCommandMiddlewareTests()
{ {
app = new AppDomainObject(AppId, -1); app = new AppDomainObject(AppId, -1);
sut = new AppCommandHandler(Handler, appRepository, appPlansProvider, appPlansBillingManager, userResolver); sut = new AppCommandMiddleware(Handler, appRepository, appPlansProvider, appPlansBillingManager, userResolver);
} }
[Fact] [Fact]

10
tests/Squidex.Domain.Apps.Write.Tests/Assets/AssetCommandHandlerTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// AssetCommandHandlerTests.cs // AssetCommandMiddlewareTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -22,24 +22,24 @@ using Xunit;
namespace Squidex.Domain.Apps.Write.Assets namespace Squidex.Domain.Apps.Write.Assets
{ {
public class AssetCommandHandlerTests : HandlerTestBase<AssetDomainObject> public class AssetCommandMiddlewareTests : HandlerTestBase<AssetDomainObject>
{ {
private readonly IAssetThumbnailGenerator assetThumbnailGenerator = A.Fake<IAssetThumbnailGenerator>(); private readonly IAssetThumbnailGenerator assetThumbnailGenerator = A.Fake<IAssetThumbnailGenerator>();
private readonly IAssetStore assetStore = A.Fake<IAssetStore>(); private readonly IAssetStore assetStore = A.Fake<IAssetStore>();
private readonly AssetCommandHandler sut; private readonly AssetCommandMiddleware sut;
private readonly AssetDomainObject asset; private readonly AssetDomainObject asset;
private readonly Guid assetId = Guid.NewGuid(); private readonly Guid assetId = Guid.NewGuid();
private readonly Stream stream = new MemoryStream(); private readonly Stream stream = new MemoryStream();
private readonly ImageInfo image = new ImageInfo(2048, 2048); private readonly ImageInfo image = new ImageInfo(2048, 2048);
private readonly AssetFile file; private readonly AssetFile file;
public AssetCommandHandlerTests() public AssetCommandMiddlewareTests()
{ {
file = new AssetFile("my-image.png", "image/png", 1024, () => stream); file = new AssetFile("my-image.png", "image/png", 1024, () => stream);
asset = new AssetDomainObject(assetId, -1); asset = new AssetDomainObject(assetId, -1);
sut = new AssetCommandHandler(Handler, assetStore, assetThumbnailGenerator); sut = new AssetCommandMiddleware(Handler, assetStore, assetThumbnailGenerator);
} }
[Fact] [Fact]

10
tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentCommandHandlerTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ContentCommandHandlerTests.cs // ContentCommandMiddlewareTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -28,9 +28,9 @@ using Xunit;
namespace Squidex.Domain.Apps.Write.Contents namespace Squidex.Domain.Apps.Write.Contents
{ {
public class ContentCommandHandlerTests : HandlerTestBase<ContentDomainObject> public class ContentCommandMiddlewareTests : HandlerTestBase<ContentDomainObject>
{ {
private readonly ContentCommandHandler sut; private readonly ContentCommandMiddleware sut;
private readonly ContentDomainObject content; private readonly ContentDomainObject content;
private readonly ISchemaProvider schemaProvider = A.Fake<ISchemaProvider>(); private readonly ISchemaProvider schemaProvider = A.Fake<ISchemaProvider>();
private readonly ISchemaEntity schemaEntity = A.Fake<ISchemaEntity>(); private readonly ISchemaEntity schemaEntity = A.Fake<ISchemaEntity>();
@ -40,7 +40,7 @@ namespace Squidex.Domain.Apps.Write.Contents
private readonly LanguagesConfig languagesConfig = LanguagesConfig.Create(Language.DE); private readonly LanguagesConfig languagesConfig = LanguagesConfig.Create(Language.DE);
private readonly Guid contentId = Guid.NewGuid(); private readonly Guid contentId = Guid.NewGuid();
public ContentCommandHandlerTests() public ContentCommandMiddlewareTests()
{ {
var schema = var schema =
Schema.Create("my-schema", new SchemaProperties()) Schema.Create("my-schema", new SchemaProperties())
@ -49,7 +49,7 @@ namespace Squidex.Domain.Apps.Write.Contents
content = new ContentDomainObject(contentId, -1); content = new ContentDomainObject(contentId, -1);
sut = new ContentCommandHandler(Handler, appProvider, A.Dummy<IAssetRepository>(), schemaProvider, A.Dummy<IContentRepository>()); sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy<IAssetRepository>(), schemaProvider, A.Dummy<IContentRepository>());
A.CallTo(() => appEntity.LanguagesConfig).Returns(languagesConfig); A.CallTo(() => appEntity.LanguagesConfig).Returns(languagesConfig);
A.CallTo(() => appEntity.PartitionResolver).Returns(languagesConfig.ToResolver()); A.CallTo(() => appEntity.PartitionResolver).Returns(languagesConfig.ToResolver());

10
tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaCommandHandlerTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// SchemaCommandHandlerTests.cs // SchemaCommandMiddlewareTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -23,19 +23,19 @@ using Xunit;
namespace Squidex.Domain.Apps.Write.Schemas namespace Squidex.Domain.Apps.Write.Schemas
{ {
public class SchemaCommandHandlerTests : HandlerTestBase<SchemaDomainObject> public class SchemaCommandMiddlewareTests : HandlerTestBase<SchemaDomainObject>
{ {
private readonly ISchemaProvider schemaProvider = A.Fake<ISchemaProvider>(); private readonly ISchemaProvider schemaProvider = A.Fake<ISchemaProvider>();
private readonly SchemaCommandHandler sut; private readonly SchemaCommandMiddleware sut;
private readonly SchemaDomainObject schema; private readonly SchemaDomainObject schema;
private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry()); private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry());
private readonly string fieldName = "age"; private readonly string fieldName = "age";
public SchemaCommandHandlerTests() public SchemaCommandMiddlewareTests()
{ {
schema = new SchemaDomainObject(SchemaId, -1, registry); schema = new SchemaDomainObject(SchemaId, -1, registry);
sut = new SchemaCommandHandler(Handler, schemaProvider); sut = new SchemaCommandMiddleware(Handler, schemaProvider);
} }
[Fact] [Fact]

4
tests/Squidex.Infrastructure.Tests/CQRS/Commands/EnrichWithTimestampCommandHandlerTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EnrichWithTimestampCommandHandlerTests.cs // EnrichWithTimestampCommandMiddlewareTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -13,7 +13,7 @@ using Xunit;
namespace Squidex.Infrastructure.CQRS.Commands namespace Squidex.Infrastructure.CQRS.Commands
{ {
public sealed class EnrichWithTimestampCommandHandlerTests public sealed class EnrichWithTimestampCommandMiddlewareTests
{ {
private sealed class MyTimestampCommand : ITimestampCommand private sealed class MyTimestampCommand : ITimestampCommand
{ {

14
tests/Squidex.Infrastructure.Tests/CQRS/Commands/InMemoryCommandBusTests.cs

@ -18,7 +18,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
{ {
private readonly ICommand command = A.Fake<ICommand>(); private readonly ICommand command = A.Fake<ICommand>();
private sealed class HandledHandler : ICommandHandler private sealed class HandledHandler : ICommandMiddleware
{ {
public ICommand LastCommand; public ICommand LastCommand;
@ -32,7 +32,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
} }
} }
private sealed class NonHandledHandler : ICommandHandler private sealed class NonHandledHandler : ICommandMiddleware
{ {
public ICommand LastCommand; public ICommand LastCommand;
@ -44,7 +44,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
} }
} }
private sealed class ThrowHandledHandler : ICommandHandler private sealed class ThrowHandledHandler : ICommandMiddleware
{ {
public ICommand LastCommand; public ICommand LastCommand;
@ -59,7 +59,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
[Fact] [Fact]
public async Task Should_not_set_handled_if_no_handler_registered() public async Task Should_not_set_handled_if_no_handler_registered()
{ {
var sut = new InMemoryCommandBus(new ICommandHandler[0]); var sut = new InMemoryCommandBus(new ICommandMiddleware[0]);
var ctx = await sut.PublishAsync(command); var ctx = await sut.PublishAsync(command);
Assert.False(ctx.IsCompleted); Assert.False(ctx.IsCompleted);
@ -70,7 +70,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
{ {
var handler = new NonHandledHandler(); var handler = new NonHandledHandler();
var sut = new InMemoryCommandBus(new ICommandHandler[] { handler }); var sut = new InMemoryCommandBus(new ICommandMiddleware[] { handler });
var ctx = await sut.PublishAsync(command); var ctx = await sut.PublishAsync(command);
Assert.Equal(command, handler.LastCommand); Assert.Equal(command, handler.LastCommand);
@ -82,7 +82,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
{ {
var handler = new HandledHandler(); var handler = new HandledHandler();
var sut = new InMemoryCommandBus(new ICommandHandler[] { handler }); var sut = new InMemoryCommandBus(new ICommandMiddleware[] { handler });
var ctx = await sut.PublishAsync(command); var ctx = await sut.PublishAsync(command);
Assert.Equal(command, handler.LastCommand); Assert.Equal(command, handler.LastCommand);
@ -94,7 +94,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
{ {
var handler = new ThrowHandledHandler(); var handler = new ThrowHandledHandler();
var sut = new InMemoryCommandBus(new ICommandHandler[] { handler }); var sut = new InMemoryCommandBus(new ICommandMiddleware[] { handler });
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sut.PublishAsync(command)); await Assert.ThrowsAsync<InvalidOperationException>(async () => await sut.PublishAsync(command));

4
tests/Squidex.Infrastructure.Tests/CQRS/Commands/LogCommandHandlerTests.cs

@ -19,7 +19,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
public class LogExceptionHandlerTests public class LogExceptionHandlerTests
{ {
private readonly MyLog log = new MyLog(); private readonly MyLog log = new MyLog();
private readonly LogCommandHandler sut; private readonly LogCommandMiddleware sut;
private readonly ICommand command = A.Dummy<ICommand>(); private readonly ICommand command = A.Dummy<ICommand>();
private sealed class MyLog : ISemanticLog private sealed class MyLog : ISemanticLog
@ -42,7 +42,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
public LogExceptionHandlerTests() public LogExceptionHandlerTests()
{ {
sut = new LogCommandHandler(log); sut = new LogCommandMiddleware(log);
} }
[Fact] [Fact]

Loading…
Cancel
Save