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.
89 lines
2.8 KiB
89 lines
2.8 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using FakeItEasy;
|
|
using Orleans;
|
|
using Squidex.Domain.Apps.Entities.Contents.DomainObject;
|
|
using Squidex.Infrastructure;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.Queries
|
|
{
|
|
public class ContentLoaderTests
|
|
{
|
|
private readonly IGrainFactory grainFactory = A.Fake<IGrainFactory>();
|
|
private readonly IContentGrain grain = A.Fake<IContentGrain>();
|
|
private readonly DomainId appId = DomainId.NewGuid();
|
|
private readonly DomainId id = DomainId.NewGuid();
|
|
private readonly ContentLoader sut;
|
|
|
|
public ContentLoaderTests()
|
|
{
|
|
var key = DomainId.Combine(appId, id).ToString();
|
|
|
|
A.CallTo(() => grainFactory.GetGrain<IContentGrain>(key, null))
|
|
.Returns(grain);
|
|
|
|
sut = new ContentLoader(grainFactory);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_return_null_if_no_state_returned()
|
|
{
|
|
A.CallTo(() => grain.GetStateAsync(10))
|
|
.Returns(Task.FromResult<IContentEntity>(null!));
|
|
|
|
Assert.Null(await sut.GetAsync(appId, id, 10));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_return_null_if_state_empty()
|
|
{
|
|
var content = new ContentEntity { Version = EtagVersion.Empty };
|
|
|
|
A.CallTo(() => grain.GetStateAsync(10))
|
|
.Returns(content);
|
|
|
|
Assert.Null(await sut.GetAsync(appId, id, 10));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_return_null_if_state_has_other_version()
|
|
{
|
|
var content = new ContentEntity { Version = 5 };
|
|
|
|
A.CallTo(() => grain.GetStateAsync(10))
|
|
.Returns(content);
|
|
|
|
Assert.Null(await sut.GetAsync(appId, id, 10));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_not_return_null_if_state_has_other_version_than_any()
|
|
{
|
|
var content = new ContentEntity { Version = 5 };
|
|
|
|
A.CallTo(() => grain.GetStateAsync(EtagVersion.Any))
|
|
.Returns(content);
|
|
|
|
await sut.GetAsync(appId, id, EtagVersion.Any);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_return_content_from_state()
|
|
{
|
|
var content = new ContentEntity { Version = 10 };
|
|
|
|
A.CallTo(() => grain.GetStateAsync(10))
|
|
.Returns(content);
|
|
|
|
var result = await sut.GetAsync(appId, id, 10);
|
|
|
|
Assert.Same(content, result);
|
|
}
|
|
}
|
|
}
|
|
|