Skip to content

Commit e544b76

Browse files
authored
Merge pull request #896 from eventflow/allow-no-source-ids
Do not enforce previous source IDs
2 parents 25b3019 + 612cc4b commit e544b76

4 files changed

Lines changed: 50 additions & 25 deletions

File tree

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
```csharp
55
eventFlowOptions.UseHangfireJobScheduler(o => o.UseQueueName("myqueue"))
66
```
7+
* Fixed: Do not throw `MetadataKeyNotFoundException` if there is no meta data on
8+
`previous_source_ids` in snapshots
79

810
### New in 0.82.4684 (released 2021-08-31)
911

Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2222
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323

24+
using System.Linq;
25+
using EventFlow.Core;
2426
using EventFlow.Snapshots;
2527
using EventFlow.TestHelpers;
2628
using EventFlow.TestHelpers.Extensions;
@@ -44,6 +46,7 @@ public void DeserializesCorrectly()
4446
aggregate_sequence_number = "42",
4547
snapshot_name = "thingy",
4648
snapshot_version = "84",
49+
previous_source_ids = "cool,magic,"
4750
}.ToJson();
4851

4952
// Act
@@ -55,6 +58,7 @@ public void DeserializesCorrectly()
5558
snapshotMetadata.AggregateSequenceNumber.Should().Be(42);
5659
snapshotMetadata.SnapshotName.Should().Be("thingy");
5760
snapshotMetadata.SnapshotVersion.Should().Be(84);
61+
snapshotMetadata.PreviousSourceIds.Select(s => s.Value).Should().BeEquivalentTo("cool", "magic");
5862
}
5963

6064
[Test]
@@ -68,6 +72,11 @@ public void GettersAndSettersWork()
6872
AggregateSequenceNumber = 42,
6973
SnapshotName = "thingy",
7074
SnapshotVersion = 84,
75+
PreviousSourceIds = new []
76+
{
77+
new SourceId("cool"),
78+
new SourceId("magic")
79+
}
7180
};
7281

7382
// Act
@@ -80,6 +89,20 @@ public void GettersAndSettersWork()
8089
deserializedSnapshotMetadata.AggregateSequenceNumber.Should().Be(42);
8190
deserializedSnapshotMetadata.SnapshotName.Should().Be("thingy");
8291
deserializedSnapshotMetadata.SnapshotVersion.Should().Be(84);
92+
deserializedSnapshotMetadata.PreviousSourceIds.Select(s => s.Value).Should().BeEquivalentTo("cool", "magic");
93+
}
94+
95+
[Test]
96+
public void PreviousSourceIdsIsAllowedToBeEmpty()
97+
{
98+
// Arrange
99+
var snapshotMetadata = new SnapshotMetadata();
100+
101+
// Act
102+
var previousSourceIds = snapshotMetadata.PreviousSourceIds;
103+
104+
// Assert
105+
previousSourceIds.Should().BeEmpty();
83106
}
84107
}
85108
}

Source/EventFlow/Snapshots/SnapshotMetadata.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,55 +56,55 @@ public SnapshotMetadata(params KeyValuePair<string, string>[] keyValuePairs)
5656
[JsonIgnore]
5757
public string AggregateId
5858
{
59-
get { return GetMetadataValue(SnapshotMetadataKeys.AggregateId); }
60-
set { Add(SnapshotMetadataKeys.AggregateId, value); }
59+
get => GetMetadataValue(SnapshotMetadataKeys.AggregateId);
60+
set => Add(SnapshotMetadataKeys.AggregateId, value);
6161
}
6262

6363
[JsonIgnore]
6464
public string AggregateName
6565
{
66-
get { return GetMetadataValue(SnapshotMetadataKeys.AggregateName); }
67-
set { Add(SnapshotMetadataKeys.AggregateName, value); }
66+
get => GetMetadataValue(SnapshotMetadataKeys.AggregateName);
67+
set => Add(SnapshotMetadataKeys.AggregateName, value);
6868
}
6969

7070
[JsonIgnore]
7171
public int AggregateSequenceNumber
7272
{
73-
get { return GetMetadataValue(SnapshotMetadataKeys.AggregateSequenceNumber, int.Parse); }
74-
set { Add(SnapshotMetadataKeys.AggregateSequenceNumber, value.ToString(CultureInfo.InvariantCulture)); }
73+
get => GetMetadataValue(SnapshotMetadataKeys.AggregateSequenceNumber, int.Parse);
74+
set => Add(SnapshotMetadataKeys.AggregateSequenceNumber, value.ToString(CultureInfo.InvariantCulture));
7575
}
7676

7777
[JsonIgnore]
7878
public string SnapshotName
7979
{
80-
get { return GetMetadataValue(SnapshotMetadataKeys.SnapshotName); }
81-
set { Add(SnapshotMetadataKeys.SnapshotName, value); }
80+
get => GetMetadataValue(SnapshotMetadataKeys.SnapshotName);
81+
set => Add(SnapshotMetadataKeys.SnapshotName, value);
8282
}
8383

8484
[JsonIgnore]
8585
public int SnapshotVersion
8686
{
87-
get { return GetMetadataValue(SnapshotMetadataKeys.SnapshotVersion, int.Parse); }
88-
set { Add(SnapshotMetadataKeys.SnapshotVersion, value.ToString(CultureInfo.InvariantCulture)); }
87+
get => GetMetadataValue(SnapshotMetadataKeys.SnapshotVersion, int.Parse);
88+
set => Add(SnapshotMetadataKeys.SnapshotVersion, value.ToString(CultureInfo.InvariantCulture));
8989
}
9090

9191
[JsonIgnore]
9292
public IReadOnlyCollection<ISourceId> PreviousSourceIds
9393
{
9494
get
9595
{
96-
return GetMetadataValue(SnapshotMetadataKeys.PreviousSourceIds, (json) =>
97-
string.IsNullOrWhiteSpace(json) ?
98-
Empty :
99-
json
100-
.Split(SourceIdSeparators, StringSplitOptions.RemoveEmptyEntries)
101-
.Select(sourceId => new SourceId(sourceId))
102-
.ToList().AsReadOnly());
96+
if (!TryGetValue(SnapshotMetadataKeys.PreviousSourceIds, out var ids) ||
97+
string.IsNullOrEmpty(ids))
98+
{
99+
return Empty;
100+
}
101+
102+
return ids
103+
.Split(SourceIdSeparators, StringSplitOptions.RemoveEmptyEntries)
104+
.Select(sourceId => new SourceId(sourceId))
105+
.ToArray();
103106
}
104-
set { Add(SnapshotMetadataKeys.PreviousSourceIds, string.Join(",", value.Select(x => x.Value)));}
107+
set => Add(SnapshotMetadataKeys.PreviousSourceIds, string.Join(",", value.Select(x => x.Value)));
105108
}
106-
107-
108-
109109
}
110-
}
110+
}

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ services:
3030
- mssql2017
3131
- postgresql101
3232

33-
on_success:
34-
- choco install codecov
35-
- codecov -f "Build\\Reports\\opencover-results.xml"
33+
#on_success:
34+
#- choco install codecov
35+
#- codecov -f "Build\\Reports\\opencover-results.xml"
3636

3737
nuget:
3838
account_feed: false

0 commit comments

Comments
 (0)