Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

60 lines
2.1 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Threading.Tasks;
using FakeItEasy;
using Squidex.Domain.Apps.Entities.Contents.Commands;
using Squidex.Domain.Apps.Entities.Schemas.Commands;
using Squidex.Infrastructure.Commands;
using Xunit;
namespace Squidex.Domain.Apps.Entities.Contents
{
public class SingletonCommandMiddlewareTests
{
private readonly ICommandBus commandBus = A.Fake<ICommandBus>();
private readonly SingletonCommandMiddleware sut = new SingletonCommandMiddleware();
[Fact]
public async Task Should_create_content_when_singleton_schema_is_created()
{
var context =
new CommandContext(new CreateSchema { Singleton = true, Name = "my-schema" }, commandBus)
.Complete();
await sut.HandleAsync(context);
A.CallTo(() => commandBus.PublishAsync(A<CreateContent>.That.Matches(x => x.Publish == true)))
.MustHaveHappened();
}
[Fact]
public async Task Should_not_create_content_when_non_singleton_schema_is_created()
{
var context =
new CommandContext(new CreateSchema { Singleton = false }, commandBus)
.Complete();
await sut.HandleAsync(context);
A.CallTo(() => commandBus.PublishAsync(A<ICommand>.Ignored))
.MustNotHaveHappened();
}
[Fact]
public async Task Should_not_create_content_when_singleton_schema_not_created()
{
var context =
new CommandContext(new CreateSchema { Singleton = true }, commandBus);
await sut.HandleAsync(context);
A.CallTo(() => commandBus.PublishAsync(A<ICommand>.Ignored))
.MustNotHaveHappened();
}
}
}