diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.DotNet.verified.txt index ac9d02f5fdf..fc98e247614 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.DotNet.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.DotNet.verified.txt @@ -64,6 +64,7 @@ namespace Akka.Persistence.Query { public static Akka.Persistence.Query.NoOffset Instance { get; } public override int CompareTo(Akka.Persistence.Query.Offset other) { } + public override string ToString() { } } public abstract class Offset : System.IComparable { @@ -72,6 +73,7 @@ namespace Akka.Persistence.Query public static Akka.Persistence.Query.Offset NoOffset() { } public static Akka.Persistence.Query.Offset Sequence(long value) { } public static Akka.Persistence.Query.Offset TimeBasedUuid(System.Guid value) { } + public virtual string ToString() { } } public sealed class PersistenceQuery : Akka.Actor.IExtension { @@ -100,6 +102,7 @@ namespace Akka.Persistence.Query public override int CompareTo(Akka.Persistence.Query.Offset other) { } public override bool Equals(object obj) { } public override int GetHashCode() { } + public override string ToString() { } } public sealed class TimeBasedUuid : Akka.Persistence.Query.Offset, System.IComparable { @@ -109,5 +112,6 @@ namespace Akka.Persistence.Query public override int CompareTo(Akka.Persistence.Query.Offset other) { } public override bool Equals(object obj) { } public override int GetHashCode() { } + public override string ToString() { } } } \ No newline at end of file diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.Net.verified.txt index eb4682f9eaa..e598732f711 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.Net.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApprovePersistenceQuery.Net.verified.txt @@ -64,6 +64,7 @@ namespace Akka.Persistence.Query { public static Akka.Persistence.Query.NoOffset Instance { get; } public override int CompareTo(Akka.Persistence.Query.Offset other) { } + public override string ToString() { } } public abstract class Offset : System.IComparable { @@ -72,6 +73,7 @@ namespace Akka.Persistence.Query public static Akka.Persistence.Query.Offset NoOffset() { } public static Akka.Persistence.Query.Offset Sequence(long value) { } public static Akka.Persistence.Query.Offset TimeBasedUuid(System.Guid value) { } + public virtual string ToString() { } } public sealed class PersistenceQuery : Akka.Actor.IExtension { @@ -100,6 +102,7 @@ namespace Akka.Persistence.Query public override int CompareTo(Akka.Persistence.Query.Offset other) { } public override bool Equals(object obj) { } public override int GetHashCode() { } + public override string ToString() { } } public sealed class TimeBasedUuid : Akka.Persistence.Query.Offset, System.IComparable { @@ -109,5 +112,6 @@ namespace Akka.Persistence.Query public override int CompareTo(Akka.Persistence.Query.Offset other) { } public override bool Equals(object obj) { } public override int GetHashCode() { } + public override string ToString() { } } } \ No newline at end of file diff --git a/src/core/Akka.Persistence.Query.Tests/OffsetSpec.cs b/src/core/Akka.Persistence.Query.Tests/OffsetSpec.cs index 336745ed0f5..1a29a8d5c9c 100644 --- a/src/core/Akka.Persistence.Query.Tests/OffsetSpec.cs +++ b/src/core/Akka.Persistence.Query.Tests/OffsetSpec.cs @@ -38,5 +38,24 @@ public void Sequence_offset_must_be_ordered_correctly() var shuffledSequenceBasedList = sequenceBasedList.OrderBy(_ => Guid.NewGuid()); shuffledSequenceBasedList.Should().BeEquivalentTo(sequenceBasedList); } + + [Fact] + public void Sequence_must_log_value_correctly() + { + Assert.Equal("7", new Sequence(7).ToString()); + } + + [Fact] + public void TimeBasedUuid_must_log_value_correctly() + { + var timeBasedUuid = new TimeBasedUuid(new Guid("49225740-2019-11ea-a6f0-a0a60c2ef4ff")); + Assert.Equal("49225740-2019-11ea-a6f0-a0a60c2ef4ff", timeBasedUuid.ToString()); + } + + [Fact] + public void NoOffset_must_log_zero() + { + Assert.Equal("0", NoOffset.Instance.ToString()); + } } } diff --git a/src/core/Akka.Persistence.Query/Offset.cs b/src/core/Akka.Persistence.Query/Offset.cs index 9f2a1301308..113c1722eb7 100644 --- a/src/core/Akka.Persistence.Query/Offset.cs +++ b/src/core/Akka.Persistence.Query/Offset.cs @@ -37,6 +37,11 @@ public abstract class Offset : IComparable /// /// The other offset to compare. public abstract int CompareTo(Offset other); + + /// + /// Used to log offset's value + /// + public abstract override string ToString(); } /// @@ -83,6 +88,8 @@ public override int CompareTo(Offset other) throw new InvalidOperationException($"Can't compare offset of type {GetType()} to offset of type {other.GetType()}"); } + + public override string ToString() => Value.ToString(); } /// @@ -123,6 +130,8 @@ public override int CompareTo(Offset other) ? CompareTo(seq) : throw new InvalidOperationException($"Can't compare offset of type {GetType()} to offset of type {other.GetType()}"); } + + public override string ToString() => Value.ToString(); } /// @@ -145,5 +154,7 @@ public override int CompareTo(Offset other) throw new InvalidOperationException($"Can't compare offset of type {GetType()} to offset of type {other.GetType()}"); } + + public override string ToString() => "0"; } }