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.
76 lines
2.4 KiB
76 lines
2.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using FakeItEasy;
|
|
using Squidex.Domain.Apps.Entities.Rules.Indexes;
|
|
using Squidex.Domain.Apps.Entities.TestHelpers;
|
|
using Squidex.Infrastructure;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Rules.Queries
|
|
{
|
|
public class RuleQueryServiceTests
|
|
{
|
|
private readonly IRulesIndex rulesIndex = A.Fake<IRulesIndex>();
|
|
private readonly IRuleEnricher ruleEnricher = A.Fake<IRuleEnricher>();
|
|
private readonly NamedId<DomainId> appId = NamedId.Of(DomainId.NewGuid(), "my-app");
|
|
private readonly Context requestContext;
|
|
private readonly RuleQueryService sut;
|
|
|
|
public RuleQueryServiceTests()
|
|
{
|
|
requestContext = Context.Anonymous(Mocks.App(appId));
|
|
|
|
sut = new RuleQueryService(rulesIndex, ruleEnricher);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_get_rules_from_index_and_enrich()
|
|
{
|
|
var original = new List<IRuleEntity>
|
|
{
|
|
new RuleEntity()
|
|
};
|
|
|
|
var enriched = new List<IEnrichedRuleEntity>
|
|
{
|
|
new RuleEntity()
|
|
};
|
|
|
|
A.CallTo(() => rulesIndex.GetRulesAsync(appId.Id))
|
|
.Returns(original);
|
|
|
|
A.CallTo(() => ruleEnricher.EnrichAsync(original, requestContext))
|
|
.Returns(enriched);
|
|
|
|
var result = await sut.QueryAsync(requestContext);
|
|
|
|
Assert.Same(enriched, result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_not_get_deleted_rules()
|
|
{
|
|
var original = new List<IRuleEntity>
|
|
{
|
|
new RuleEntity { IsDeleted = true }
|
|
};
|
|
|
|
A.CallTo(() => rulesIndex.GetRulesAsync(appId.Id))
|
|
.Returns(original);
|
|
|
|
var result = await sut.QueryAsync(requestContext);
|
|
|
|
Assert.Empty(result);
|
|
|
|
A.CallTo(() => ruleEnricher.EnrichAsync(A<IEnumerable<IRuleEntity>>._, requestContext))
|
|
.MustNotHaveHappened();
|
|
}
|
|
}
|
|
}
|
|
|