Skip to content

Commit

Permalink
Merge pull request #116 from Lutando/dev
Browse files Browse the repository at this point in the history
Serialization fixes for common message types
  • Loading branch information
Lutando committed May 9, 2019
2 parents 116d797 + e4203bc commit 996cf1d
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build/azure-pipelines-development-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pr: none
variables:
majorVersion: '0'
minorVersion: '4'
patchVersion: '4'
patchVersion: '5'
feedVersion: 'alpha'
dayOfYear: $(DayOfYear)
revision: $(Rev:r)
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipelines-master-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pr: none
variables:
majorVersion: '0'
minorVersion: '4'
patchVersion: '4'
patchVersion: '5'
feedVersion: 'prerelease'
dayOfYear: $(DayOfYear)
revision: $(Rev:r)
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipelines-release-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pr: none
variables:
majorVersion: '0'
minorVersion: '4'
patchVersion: '4'
patchVersion: '5'

name: ${{ format('{0}.{1}.{2}', variables.majorVersion, variables.minorVersion, variables.patchVersion) }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void Handle(
}
else
{
var executionResult = new FailedExecutionResult("aggregate is already created");
var executionResult = new FailedExecutionResult(new List<string>{"aggregate is already created"});
context.Sender.Tell(executionResult);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Akkatecture/Aggregates/DomainEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class DomainEvent<TAggregate, TIdentity, TAggregateEvent> : IDomainEvent<
public TIdentity AggregateIdentity { get; }
public TAggregateEvent AggregateEvent { get; }
public long AggregateSequenceNumber { get; }
public IMetadata Metadata { get; }
public Metadata Metadata { get; }
public DateTimeOffset Timestamp { get; }

public DomainEvent(
TIdentity aggregateIdentity,
TAggregateEvent aggregateEvent,
IMetadata metadata,
Metadata metadata,
DateTimeOffset timestamp,
long aggregateSequenceNumber)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Akkatecture.Aggregates.ExecutionResults
public abstract class ExecutionResult : IExecutionResult
{
private static readonly IExecutionResult SuccessResult = new SuccessExecutionResult();
private static readonly IExecutionResult FailedResult = new FailedExecutionResult();
private static readonly IExecutionResult FailedResult = new FailedExecutionResult(Enumerable.Empty<string>());

public static IExecutionResult Success() => SuccessResult;
public static IExecutionResult Failed() => FailedResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ namespace Akkatecture.Aggregates.ExecutionResults
public class FailedExecutionResult : ExecutionResult
{
public IReadOnlyCollection<string> Errors { get; }

public FailedExecutionResult(
params string[] errors)
: this(errors.ToList())
{
}


public FailedExecutionResult(
IEnumerable<string> errors)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Akkatecture/Aggregates/IDomainEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IDomainEvent
Type IdentityType { get; }
Type EventType { get; }
long AggregateSequenceNumber { get; }
IMetadata Metadata { get; }
Metadata Metadata { get; }
DateTimeOffset Timestamp { get; }

IIdentity GetIdentity();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Akkatecture.Commands;

namespace Akkatecture.TestHelpers.Aggregates.Commands
{
public class TestFailedExecutionResultCommand : Command<TestAggregate, TestAggregateId>
{
public TestFailedExecutionResultCommand(
TestAggregateId aggregateId,
CommandId sourceId)
: base(aggregateId, sourceId)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Akkatecture.Commands;

namespace Akkatecture.TestHelpers.Aggregates.Commands
{
public class TestSuccessExecutionResultCommand : Command<TestAggregate, TestAggregateId>
{
public TestSuccessExecutionResultCommand(
TestAggregateId aggregateId,
CommandId sourceId)
: base(aggregateId, sourceId)
{
}
}
}
14 changes: 13 additions & 1 deletion test/Akkatecture.TestHelpers/Aggregates/TestAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public TestAggregate(TestAggregateId aggregateId)
Command<PoisonTestAggregateCommand>(Execute);
Command<PublishTestStateCommand>(Execute);
Command<TestDomainErrorCommand>(Execute);
Command<TestFailedExecutionResultCommand>(Execute);
Command<TestSuccessExecutionResultCommand>(Execute);

Command<SaveSnapshotSuccess>(SnapshotStatus);

Expand Down Expand Up @@ -158,7 +160,17 @@ private bool Execute(ReceiveTestCommand command)

return true;
}

private bool Execute(TestFailedExecutionResultCommand command)
{
Sender.Tell(ExecutionResult.Failed(), Self);
return true;
}

private bool Execute(TestSuccessExecutionResultCommand command)
{
Sender.Tell(ExecutionResult.Success(), Self);
return true;
}
private bool Execute(TestDistinctCommand command)
{
return true;
Expand Down
26 changes: 25 additions & 1 deletion test/Akkatecture.Tests/UnitTests/Aggregates/AggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,31 @@ public void TestSnapShotting_AfterManyTests_TestStateSignalled()
&& x.AggregateEvent.AggregateState.TestCollection.Count == 10
&& x.AggregateEvent.AggregateState.FromHydration);
}



[Fact]
[Category(Category)]
public async Task InitialState_TestingSuccessCommand_SuccessResultReplied()
{
var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager");
var aggregateId = TestAggregateId.New;
var commandId = CommandId.New;
var command = new TestSuccessExecutionResultCommand(aggregateId, commandId);

var result = await aggregateManager.Ask<SuccessExecutionResult>(command);
}

[Fact]
[Category(Category)]
public async Task InitialState_TestingFailedCommand_SuccessResultReplied()
{
var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager");
var aggregateId = TestAggregateId.New;
var commandId = CommandId.New;
var command = new TestFailedExecutionResultCommand(aggregateId, commandId);

var result = await aggregateManager.Ask<FailedExecutionResult>(command);
}
[Fact]
[Category(Category)]
public void TestDistinctCommand_AfterTwoHandles_CommandFails()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Akkatecture.Aggregates;
using Akkatecture.Aggregates.ExecutionResults;
using Akkatecture.Aggregates.Snapshot;
using Akkatecture.Commands;
using Akkatecture.Core;
Expand Down Expand Up @@ -77,6 +79,38 @@ public void CommittedEvent_AfterSerialization_IsValidAfterDeserialization()
committedEvent.SerializeDeserialize().Should().BeEquivalentTo(committedEvent);
}

[Fact]
[Category(Category)]
public void DomainEvent_AfterSerialization_IsValidAfterDeserialization()
{
var aggregateSequenceNumber = 3;
var aggregateId = TestAggregateId.New;
var entityId = TestId.New;
var entity = new Test(entityId);
var aggregateEvent = new TestAddedEvent(entity);
var now = DateTimeOffset.UtcNow;
var eventId = EventId.NewDeterministic(
GuidFactories.Deterministic.Namespaces.Events,
$"{aggregateId.Value}-v{aggregateSequenceNumber}");
var eventMetadata = new Metadata
{
Timestamp = now,
AggregateSequenceNumber = aggregateSequenceNumber,
AggregateName = typeof(TestAggregate).GetAggregateName().Value,
AggregateId = aggregateId.Value,
EventId = eventId
};
var domainEvent =
new DomainEvent<TestAggregate, TestAggregateId, TestAddedEvent>(
aggregateId,
aggregateEvent,
eventMetadata,
now,
aggregateSequenceNumber);

domainEvent.SerializeDeserialize().Should().BeEquivalentTo(domainEvent);
}

[Fact]
[Category(Category)]
public void CommittedSnapshot_AfterSerialization_IsValidAfterDeserialization()
Expand Down Expand Up @@ -128,6 +162,30 @@ public void AddFourTestsCommand_AfterSerialization_IsValidAfterDeserialization()

command.SerializeDeserialize().Should().BeEquivalentTo(command);
}

[Fact]
[Category(Category)]
public void FailedExecutionResult_AfterSerialization_IsValidAfterDeserialization()
{
var failureString = "this is a failed execution";
var executionResult = new FailedExecutionResult(new List<string>{failureString});

var result = executionResult.SerializeDeserialize();

result.Should().BeEquivalentTo(executionResult);
result.Errors.Should().Equal(failureString);
}

[Fact]
[Category(Category)]
public void SuccessfulExecutionResult_AfterSerialization_IsValidAfterDeserialization()
{
var executionResult = new SuccessExecutionResult();

var result = executionResult.SerializeDeserialize();

result.Should().BeEquivalentTo(executionResult);
}

}

Expand Down

0 comments on commit 996cf1d

Please sign in to comment.