mirror of https://github.com/Squidex/squidex.git
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.
87 lines
2.6 KiB
87 lines
2.6 KiB
// ==========================================================================
|
|
// CompoundEventConsumerTests.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using Squidex.Infrastructure.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Infrastructure.CQRS.Events
|
|
{
|
|
public class CompoundEventConsumerTests
|
|
{
|
|
private readonly Mock<IEventConsumer> consumer1 = new Mock<IEventConsumer>();
|
|
private readonly Mock<IEventConsumer> consumer2 = new Mock<IEventConsumer>();
|
|
|
|
private sealed class MyEvent : IEvent
|
|
{
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_given_name()
|
|
{
|
|
var sut = new CompoundEventConsumer("consumer-name");
|
|
|
|
Assert.Equal("consumer-name", sut.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_first_inner_name()
|
|
{
|
|
const string name = "my-inner-consumer";
|
|
|
|
consumer1.Setup(x => x.Name).Returns(name);
|
|
|
|
var sut = new CompoundEventConsumer(consumer1.Object, consumer2.Object);
|
|
|
|
Assert.Equal(name, sut.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_first_inner_filter()
|
|
{
|
|
const string filter = "my-inner-filter";
|
|
|
|
consumer1.Setup(x => x.EventsFilter).Returns(filter);
|
|
|
|
var sut = new CompoundEventConsumer(consumer1.Object, consumer2.Object);
|
|
|
|
Assert.Equal(filter, sut.EventsFilter);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_clear_all_consumers()
|
|
{
|
|
consumer1.Setup(x => x.ClearAsync()).Returns(TaskHelper.Done).Verifiable();
|
|
consumer2.Setup(x => x.ClearAsync()).Returns(TaskHelper.Done).Verifiable();
|
|
|
|
var sut = new CompoundEventConsumer("consumer-name", consumer1.Object, consumer2.Object);
|
|
|
|
await sut.ClearAsync();
|
|
|
|
consumer1.VerifyAll();
|
|
consumer2.VerifyAll();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_invoke_all_consumers()
|
|
{
|
|
var @event = Envelope.Create(new MyEvent());
|
|
|
|
consumer1.Setup(x => x.On(@event)).Returns(TaskHelper.Done).Verifiable();
|
|
consumer2.Setup(x => x.On(@event)).Returns(TaskHelper.Done).Verifiable();
|
|
|
|
var sut = new CompoundEventConsumer("consumer-name", consumer1.Object, consumer2.Object);
|
|
|
|
await sut.On(@event);
|
|
|
|
consumer1.VerifyAll();
|
|
consumer2.VerifyAll();
|
|
}
|
|
}
|
|
}
|
|
|