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.
 
 
 
 
 

61 lines
1.8 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Squidex.Domain.Apps.Entities.Rules.Repositories;
using Squidex.Domain.Apps.Entities.TestHelpers;
namespace Squidex.Domain.Apps.Entities.Rules.Indexes;
public class RulesIndexTests : GivenContext
{
private readonly IRuleRepository ruleRepository = A.Fake<IRuleRepository>();
private readonly RulesIndex sut;
public RulesIndexTests()
{
sut = new RulesIndex(ruleRepository);
}
[Fact]
public async Task Should_resolve_rules_by_id()
{
var rule = CreateRule();
A.CallTo(() => ruleRepository.QueryAllAsync(AppId.Id, CancellationToken))
.Returns([rule]);
var actual = await sut.GetRulesAsync(AppId.Id, CancellationToken);
Assert.Same(actual[0], rule);
}
[Fact]
public async Task Should_return_empty_rules_if_rule_not_created()
{
var rule = CreateRule() with { Version = -1 };
A.CallTo(() => ruleRepository.QueryAllAsync(AppId.Id, CancellationToken))
.Returns([rule]);
var actual = await sut.GetRulesAsync(AppId.Id, CancellationToken);
Assert.Empty(actual);
}
[Fact]
public async Task Should_return_empty_rules_if_rule_deleted()
{
var rule = CreateRule() with { IsDeleted = true };
A.CallTo(() => ruleRepository.QueryAllAsync(AppId.Id, CancellationToken))
.Returns([rule]);
var actual = await sut.GetRulesAsync(AppId.Id, CancellationToken);
Assert.Empty(actual);
}
}