Browse Source

Fix loaders.

pull/523/head
Sebastian 6 years ago
parent
commit
a1bf4aba7e
  1. 9
      backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetLoader.cs
  2. 9
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentLoader.cs
  3. 11
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetLoaderTests.cs
  4. 11
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentLoaderTests.cs

9
backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetLoader.cs

@ -28,16 +28,17 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
{ {
using (Profiler.TraceMethod<AssetLoader>()) using (Profiler.TraceMethod<AssetLoader>())
{ {
var grain = grainFactory.GetGrain<IAssetGrain>(id); var assetGrain = grainFactory.GetGrain<IAssetGrain>(id);
var assetState = await assetGrain.GetStateAsync(version);
var content = await grain.GetStateAsync(version); var asset = assetState.Value;
if (content.Value == null || content.Value.Version != version) if (asset == null || asset.Version <= EtagVersion.Empty || (version > EtagVersion.Any && asset.Version != version))
{ {
throw new DomainObjectNotFoundException(id.ToString(), typeof(IAssetEntity)); throw new DomainObjectNotFoundException(id.ToString(), typeof(IAssetEntity));
} }
return content.Value; return asset;
} }
} }
} }

9
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentLoader.cs

@ -28,16 +28,17 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
{ {
using (Profiler.TraceMethod<ContentLoader>()) using (Profiler.TraceMethod<ContentLoader>())
{ {
var grain = grainFactory.GetGrain<IContentGrain>(id); var contentGrain = grainFactory.GetGrain<IContentGrain>(id);
var contentState = await contentGrain.GetStateAsync(version);
var content = await grain.GetStateAsync(version); var content = contentState.Value;
if (content.Value == null || (version > EtagVersion.Any && content.Value.Version != version)) if (content == null || content.Version <= EtagVersion.Empty || (version > EtagVersion.Any && content.Version != version))
{ {
throw new DomainObjectNotFoundException(id.ToString(), typeof(IContentEntity)); throw new DomainObjectNotFoundException(id.ToString(), typeof(IContentEntity));
} }
return content.Value; return content;
} }
} }
} }

11
backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetLoaderTests.cs

@ -39,6 +39,17 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.GetAsync(id, 10)); await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.GetAsync(id, 10));
} }
[Fact]
public async Task Should_throw_exception_if_state_empty()
{
var content = new AssetEntity { Version = EtagVersion.Empty };
A.CallTo(() => grain.GetStateAsync(10))
.Returns(J.Of<IAssetEntity>(content));
await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.GetAsync(id, 10));
}
[Fact] [Fact]
public async Task Should_throw_exception_if_state_has_other_version() public async Task Should_throw_exception_if_state_has_other_version()
{ {

11
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentLoaderTests.cs

@ -39,6 +39,17 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.GetAsync(id, 10)); await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.GetAsync(id, 10));
} }
[Fact]
public async Task Should_throw_exception_if_state_empty()
{
var content = new ContentEntity { Version = EtagVersion.Empty };
A.CallTo(() => grain.GetStateAsync(10))
.Returns(J.Of<IContentEntity>(content));
await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.GetAsync(id, 10));
}
[Fact] [Fact]
public async Task Should_throw_exception_if_state_has_other_version() public async Task Should_throw_exception_if_state_has_other_version()
{ {

Loading…
Cancel
Save