Browse Source

Fix command result.

pull/664/head
Sebastian 5 years ago
parent
commit
542ace7a87
  1. 2
      backend/src/Squidex.Domain.Apps.Entities/Comments/DomainObject/CommentsGrain.cs
  2. 4
      backend/src/Squidex.Infrastructure/Commands/CommandResult.cs
  3. 2
      backend/src/Squidex.Infrastructure/None.cs
  4. 2
      backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppContributorsJsonTests.cs
  5. 2
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/DomainObject/CommentsCommandMiddlewareTests.cs
  6. 6
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/DomainObject/CommentsGrainTests.cs
  7. 2
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs
  8. 11
      backend/tests/Squidex.Infrastructure.Tests/Commands/CommandRequestTests.cs
  9. 35
      backend/tests/Squidex.Infrastructure.Tests/Commands/CommandResultTests.cs
  10. 12
      backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs
  11. 2
      backend/tests/Squidex.Web.Tests/CommandMiddlewares/ETagCommandMiddlewareTests.cs

2
backend/src/Squidex.Domain.Apps.Entities/Comments/DomainObject/CommentsGrain.cs

@ -126,7 +126,7 @@ namespace Squidex.Domain.Apps.Entities.Comments.DomainObject
events.AddRange(uncommittedEvents);
return new CommandResult(DomainId.Create(Key), Version, previousVersion);
return CommandResult.Empty(DomainId.Create(Key), Version, previousVersion);
}
catch
{

4
backend/src/Squidex.Infrastructure/Commands/CommandResult.cs

@ -15,9 +15,9 @@ namespace Squidex.Infrastructure.Commands
public bool IsChanged => OldVersion != NewVersion;
public CommandResult(DomainId id, long newVersion, long oldVersion)
: this(id, newVersion, oldVersion, None.Value)
public static CommandResult Empty(DomainId id, long newVersion, long oldVersion)
{
return new CommandResult(id, newVersion, oldVersion, None.Value);
}
}
}

2
backend/src/Squidex.Infrastructure/None.cs

@ -9,7 +9,7 @@ using System;
namespace Squidex.Infrastructure
{
public sealed class None
public sealed record None
{
public static readonly Type Type = typeof(None);

2
backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppContributorsJsonTests.cs

@ -15,7 +15,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps
public class AppContributorsJsonTests
{
[Fact]
public void Should_serialize_and_deserialize()
public void #()
{
var contributors = AppContributors.Empty;

2
backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/DomainObject/CommentsCommandMiddlewareTests.cs

@ -48,7 +48,7 @@ namespace Squidex.Domain.Apps.Entities.Comments.DomainObject
.Returns(grain);
A.CallTo(() => grain.ExecuteAsync(A<J<CommentsCommand>>.That.Matches(x => x.Value == command)))
.Returns(new CommandResult(commentsId, 0, 0).AsJ());
.Returns(CommandResult.Empty(commentsId, 0, 0).AsJ());
var isNextCalled = false;

6
backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/DomainObject/CommentsGrainTests.cs

@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Entities.Comments.DomainObject
var result = await sut.ExecuteAsync(CreateCommentsCommand(command));
result.Value.ShouldBeEquivalent(new CommandResult(commentsId, 0, EtagVersion.Empty));
result.Value.ShouldBeEquivalent(CommandResult.Empty(commentsId, 0, EtagVersion.Empty));
sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult
{
@ -86,7 +86,7 @@ namespace Squidex.Domain.Apps.Entities.Comments.DomainObject
var result = await sut.ExecuteAsync(CreateCommentsCommand(updateCommand));
result.Value.ShouldBeEquivalent(new CommandResult(commentsId, 1, 0));
result.Value.ShouldBeEquivalent(CommandResult.Empty(commentsId, 1, 0));
sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult
{
@ -122,7 +122,7 @@ namespace Squidex.Domain.Apps.Entities.Comments.DomainObject
var result = await sut.ExecuteAsync(CreateCommentsCommand(deleteCommand));
result.Value.ShouldBeEquivalent(new CommandResult(commentsId, 2, 1));
result.Value.ShouldBeEquivalent(CommandResult.Empty(commentsId, 2, 1));
sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult
{

2
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs

@ -696,7 +696,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
}
}");
commandContext.Complete(new CommandResult(contentId, 13, 12));
commandContext.Complete(CommandResult.Empty(contentId, 13, 12));
var result = await ExecuteAsync( new ExecutionOptions { Query = query }, Permissions.AppContentsDeleteOwn);

11
backend/tests/Squidex.Infrastructure.Tests/Commands/CommandRequestTests.cs

@ -9,6 +9,7 @@ using System.Globalization;
using System.Threading.Tasks;
using Orleans;
using Orleans.TestingHost;
using Squidex.Infrastructure.TestHelpers;
using Xunit;
#pragma warning disable SA1133 // Do not combine attributes
@ -56,6 +57,16 @@ namespace Squidex.Infrastructure.Commands
Assert.Equal(cultureUI.Name, sut.CultureUI);
}
[Fact]
public void Should_serialize_and_deserialize()
{
var sut = CommandRequest.Create(null!);
var serialized = sut.SerializeAndDeserialize();
Assert.Equal(sut, serialized);
}
[Fact, Trait("Category", "Dependencies")]
public async Task Should_communicate_with_orleans()
{

35
backend/tests/Squidex.Infrastructure.Tests/Commands/CommandResultTests.cs

@ -0,0 +1,35 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Squidex.Infrastructure.TestHelpers;
using Xunit;
namespace Squidex.Infrastructure.Commands
{
public class CommandResultTests
{
[Fact]
public void Should_serialize_and_deserialize()
{
var sut = new CommandResult(DomainId.NewGuid(), 3, 2, "result");
var serialized = sut.SerializeAndDeserialize();
Assert.Equal(sut, serialized);
}
[Fact]
public void Should_serialize_and_deserialize_empty()
{
var sut = CommandResult.Empty(DomainId.NewGuid(), 3, 2);
var serialized = sut.SerializeAndDeserialize();
Assert.Equal(sut, serialized);
}
}
}

12
backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs

@ -50,7 +50,7 @@ namespace Squidex.Infrastructure.Commands
A.CallTo(() => persistence.ReadAsync(A<long>._))
.MustNotHaveHappened();
Assert.Equal(new CommandResult(id, 0, EtagVersion.Empty), result);
Assert.Equal(CommandResult.Empty(id, 0, EtagVersion.Empty), result);
Assert.Empty(sut.GetUncomittedEvents());
AssertSnapshot(sut.Snapshot, 4, 0);
@ -74,7 +74,7 @@ namespace Squidex.Infrastructure.Commands
A.CallTo(() => persistence.ReadAsync(A<long>._))
.MustHaveHappened();
Assert.Equal(new CommandResult(id, 2, 1), result);
Assert.Equal(CommandResult.Empty(id, 2, 1), result);
Assert.Empty(sut.GetUncomittedEvents());
AssertSnapshot(sut.Snapshot, 4, 2);
@ -112,7 +112,7 @@ namespace Squidex.Infrastructure.Commands
A.CallTo(() => persistence.ReadAsync(A<long>._))
.MustHaveHappened();
Assert.Equal(new CommandResult(id, 2, 1), result);
Assert.Equal(CommandResult.Empty(id, 2, 1), result);
Assert.Empty(sut.GetUncomittedEvents());
AssertSnapshot(sut.Snapshot, 4, 2);
@ -148,7 +148,7 @@ namespace Squidex.Infrastructure.Commands
A.CallTo(() => persistence.ReadAsync(A<long>._))
.MustNotHaveHappened();
Assert.Equal(new CommandResult(id, 1, 0), result);
Assert.Equal(CommandResult.Empty(id, 1, 0), result);
Assert.Empty(sut.GetUncomittedEvents());
AssertSnapshot(sut.Snapshot, 8, 1);
@ -168,7 +168,7 @@ namespace Squidex.Infrastructure.Commands
A.CallTo(() => persistence.ReadAsync(A<long>._))
.MustHaveHappenedOnceExactly();
Assert.Equal(new CommandResult(id, 1, 0), result);
Assert.Equal(CommandResult.Empty(id, 1, 0), result);
Assert.Empty(sut.GetUncomittedEvents());
AssertSnapshot(sut.Snapshot, 8, 1);
@ -299,7 +299,7 @@ namespace Squidex.Infrastructure.Commands
var result = await sut.ExecuteAsync(new UpdateAuto { Value = MyDomainState.Unchanged });
Assert.Equal(new CommandResult(id, 0, 0), result);
Assert.Equal(CommandResult.Empty(id, 0, 0), result);
Assert.Empty(sut.GetUncomittedEvents());
AssertSnapshot(sut.Snapshot, 4, 0);

2
backend/tests/Squidex.Web.Tests/CommandMiddlewares/ETagCommandMiddlewareTests.cs

@ -74,7 +74,7 @@ namespace Squidex.Web.CommandMiddlewares
[Fact]
public async Task Should_add_version_from_result_as_etag_to_response()
{
var result = new CommandResult(DomainId.Empty, 17, 16);
var result = CommandResult.Empty(DomainId.Empty, 17, 16);
await HandleAsync(new CreateContent(), result);

Loading…
Cancel
Save