-
-
Notifications
You must be signed in to change notification settings - Fork 515
/
StreamLoadingFromExactState.cs
98 lines (76 loc) · 3.32 KB
/
StreamLoadingFromExactState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using FluentAssertions;
using Marten.Integration.Tests.TestsInfrastructure;
using Xunit;
namespace Marten.Integration.Tests.EventStore.Stream;
public class StreamLoadingFromExactState(MartenFixture fixture): MartenTest(fixture.PostgreSqlContainer)
{
public record IssueCreated(
Guid IssueId,
string Description
);
public record IssueUpdated(
Guid IssueId,
string Description
);
[Fact(Skip = "Skipping - AppVeyor for some reason doesn't like it -_-")]
public void GivenSetOfEvents_WithFetchEventsFromDifferentTimes_ThenProperSetsAreLoaded()
{
//Given
var streamId = Guid.NewGuid();
var taskId = Guid.NewGuid();
//When
var beforeCreateTimestamp = DateTime.UtcNow;
EventStore.Append(streamId, new IssueCreated(taskId, "Initial Name"));
Session.SaveChanges();
var createTimestamp = DateTime.UtcNow;
EventStore.Append(streamId, new IssueUpdated(taskId, "Updated name"));
Session.SaveChanges();
var firstUpdateTimestamp = DateTime.UtcNow;
EventStore.Append(streamId, new IssueUpdated(taskId, "Updated again name"),
new IssueUpdated(taskId, "Updated again and again name"));
Session.SaveChanges();
var secondUpdateTimestamp = DateTime.UtcNow;
//Then
var events = EventStore.FetchStream(streamId, timestamp: beforeCreateTimestamp);
events.Count.Should().Be(0);
events = EventStore.FetchStream(streamId, timestamp: createTimestamp);
events.Count.Should().Be(1);
events = EventStore.FetchStream(streamId, timestamp: firstUpdateTimestamp);
events.Count.Should().Be(2);
events = EventStore.FetchStream(streamId, timestamp: secondUpdateTimestamp);
events.Count.Should().Be(4);
}
[Fact]
public void GivenSetOfEvents_WithFetchEventsFromDifferentVersionNumber_ThenProperSetsAreLoaded()
{
//Given
var streamId = Guid.NewGuid();
var taskId = Guid.NewGuid();
//When
EventStore.Append(streamId, new IssueCreated(taskId, "Initial Name"));
Session.SaveChanges();
EventStore.Append(streamId, new IssueUpdated(taskId, "Updated name"));
Session.SaveChanges();
EventStore.Append(streamId, new IssueUpdated(taskId, "Updated again name"),
new IssueUpdated(taskId, "Updated again and again name"));
Session.SaveChanges();
//Then
//version after create
var events = EventStore.FetchStream(streamId, 1);
events.Count.Should().Be(1);
//version after first update
events = EventStore.FetchStream(streamId, 2);
events.Count.Should().Be(2);
//even though 3 and 4 updates were append at the same time version is incremented for both of them
events = EventStore.FetchStream(streamId, 3);
events.Count.Should().Be(3);
events = EventStore.FetchStream(streamId, 4);
events.Count.Should().Be(4);
//fetching with version equal to 0 returns the most recent state
events = EventStore.FetchStream(streamId, 0);
events.Count.Should().Be(4);
//providing bigger version than current doesn't throws exception - returns most recent state
events = EventStore.FetchStream(streamId, 100);
events.Count.Should().Be(4);
}
}