-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Lutando/dev
Fixed ComittedEvent Deserialization
- Loading branch information
Showing
13 changed files
with
103 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Akkatecture.TestHelpers | ||
{ | ||
public static class SerializationHelpers | ||
{ | ||
public static T SerializeDeserialize<T>(this T message) | ||
{ | ||
var json = JsonConvert.SerializeObject(message); | ||
var obj = JsonConvert.DeserializeObject<T>(json); | ||
return obj; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test/Akkatecture.Tests/UnitTests/Serialization/SerializationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using Akkatecture.Aggregates; | ||
using Akkatecture.Core; | ||
using Akkatecture.Extensions; | ||
using Akkatecture.TestHelpers; | ||
using Akkatecture.TestHelpers.Aggregates; | ||
using Akkatecture.TestHelpers.Aggregates.Entities; | ||
using Akkatecture.TestHelpers.Aggregates.Events; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace Akkatecture.Tests.UnitTests.Serialization | ||
{ | ||
public class SerializationTests | ||
{ | ||
private const string Category = "Serialization"; | ||
|
||
[Fact] | ||
[Category(Category)] | ||
public void CommittedEvent_AfterSerialization_IsValidAfterDeserialization() | ||
{ | ||
|
||
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{3}"); | ||
var eventMetadata = new Metadata | ||
{ | ||
Timestamp = now, | ||
AggregateSequenceNumber = 3, | ||
AggregateName = typeof(TestAggregate).GetAggregateName().Value, | ||
AggregateId = aggregateId.Value, | ||
EventId = eventId | ||
}; | ||
var committedEvent = | ||
new CommittedEvent<TestAggregate, TestAggregateId, TestAddedEvent>( | ||
aggregateId, | ||
aggregateEvent, | ||
eventMetadata); | ||
|
||
committedEvent.SerializeDeserialize().Should().BeEquivalentTo(committedEvent); | ||
} | ||
|
||
} | ||
|
||
} |