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.
 
 
 
 
 

62 lines
1.9 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Threading.Tasks;
using FakeItEasy;
using Microsoft.Extensions.Options;
using Squidex.Infrastructure.Tasks;
using Xunit;
namespace Squidex.Infrastructure.Commands
{
public class ReadonlyCommandMiddlewareTests
{
private readonly ICommand command = A.Dummy<ICommand>();
private readonly ICommandBus commandBus = A.Dummy<ICommandBus>();
private readonly ReadonlyOptions options = new ReadonlyOptions();
private readonly ReadonlyCommandMiddleware sut;
public ReadonlyCommandMiddlewareTests()
{
sut = new ReadonlyCommandMiddleware(Options.Create(options));
}
[Fact]
public async Task Should_throw_exception_if_readonly()
{
var context = new CommandContext(command, commandBus);
options.IsReadonly = true;
await Assert.ThrowsAsync<DomainException>(() => MakeCallAsync(context));
Assert.False(context.IsCompleted);
}
[Fact]
public async Task Should_not_throw_exception_if_not_readonly()
{
var context = new CommandContext(command, commandBus);
options.IsReadonly = false;
await MakeCallAsync(context);
Assert.True(context.IsCompleted);
}
private async Task MakeCallAsync(CommandContext context)
{
await sut.HandleAsync(context, c =>
{
context.Complete(true);
return TaskHelper.Done;
});
}
}
}