-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
StreamStarting.cs
96 lines (71 loc) · 2.51 KB
/
StreamStarting.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
using FluentAssertions;
using Marten.Exceptions;
using Marten.Integration.Tests.TestsInfrastructure;
using Xunit;
namespace Marten.Integration.Tests.EventStore.Stream;
public record IssueCreated(
Guid IssueId,
string Description
);
public record IssueUpdated(
Guid IssueId,
string Description
);
public record Issue(
Guid IssueId,
string Description
);
public class StreamStarting(MartenFixture fixture): MartenTest(fixture.PostgreSqlContainer)
{
[Fact(Skip = "Skipped because of https://github.com/JasperFx/marten/issues/1648")]
public void GivenNoEvents_WhenStreamIsStarting_ThenEventsAreSavedWithoutError()
{
var @event = new IssueCreated(Guid.NewGuid(), "Description");
var streamId = EventStore.StartStream(@event.IssueId);
Session.SaveChanges();
streamId.Should().NotBeNull();
}
[Fact]
public void GivenOneEvent_WhenStreamIsStarting_ThenEventsAreSavedWithoutError()
{
var @event = new IssueCreated(Guid.NewGuid(), "Description");
var streamId = EventStore.StartStream(@event.IssueId, @event);
streamId.Should().NotBeNull();
Session.SaveChanges();
}
[Fact]
public void GivenStartedStream_WhenStartStreamIsBeingCalledAgain_ThenExceptionIsThrown()
{
var @event = new IssueCreated(Guid.NewGuid(), "Description");
var streamId = EventStore.StartStream(@event.IssueId, @event);
Session.SaveChanges();
Assert.Throws<ExistingStreamIdCollisionException>(() =>
{
EventStore.StartStream(@event.IssueId, @event);
Session.SaveChanges();
});
}
[Fact]
public void GivenOneEvent_WhenEventsArePublishedWithStreamId_ThenEventsAreSavedWithoutErrorAndStreamIsStarted()
{
var @event = new IssueCreated(Guid.NewGuid(), "Description");
var streamId = Guid.NewGuid();
EventStore.Append(streamId, @event);
Session.SaveChanges();
var streamState = EventStore.FetchStreamState(streamId);
streamState.Should().NotBeNull();
streamState!.Version.Should().Be(1);
}
[Fact]
public void GivenMoreThenOneEvent_WhenStreamIsStarting_ThenEventsAreSavedWithoutError()
{
var taskId = Guid.NewGuid();
var events = new object[]
{
new IssueCreated(taskId, "Description1"), new IssueUpdated(taskId, "Description2")
};
var streamId = EventStore.StartStream(events);
streamId.Should().NotBeNull();
Session.SaveChanges();
}
}