Ejemplo n.º 1
0
        public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema()
        {
            using var session = theStore.LightweightSession();
            var joined = new MembersJoined {
                Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
            };
            var departed = new MembersDeparted {
                Members = new[] { "Thom" }
            };

            var id = "Thirteen";

            session.Events.StartStream <Quest>(id, joined, departed);
            session.SaveChanges();

            var streamEvents = session.Events.FetchStream(id);

            streamEvents.Count().ShouldBe(2);
            streamEvents.ElementAt(0).Data.ShouldBeOfType <MembersJoined>();
            streamEvents.ElementAt(0).Version.ShouldBe(1);
            streamEvents.ElementAt(1).Data.ShouldBeOfType <MembersDeparted>();
            streamEvents.ElementAt(1).Version.ShouldBe(2);
        }
Ejemplo n.º 2
0
        public void should_check_max_event_id_on_append_with_string_identifier()
        {
            UseStreamIdentity(StreamIdentity.AsString);

            var joined = new MembersJoined {
                Members = new string[] { "Rand", "Matt", "Perrin", "Thom" }
            };
            var departed = new MembersDeparted {
                Members = new[] { "Thom" }
            };

            var stream = "First";

            theSession.Events.Append(stream, joined);
            theSession.Events.Append(stream, 2, departed);

            theSession.SaveChanges();

            var state = theSession.Events.FetchStreamState(stream);

            state.Key.ShouldBe(stream);
            state.Version.ShouldBe(2);
        }
Ejemplo n.º 3
0
        public async Task delete_stream_by_guid_id_async()
        {
            var stream1 = Guid.NewGuid();
            var stream2 = Guid.NewGuid();

            using (var session = theStore.LightweightSession())
            {
                var joined = new MembersJoined {
                    Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
                };
                var departed = new MembersDeparted {
                    Members = new[] { "Thom" }
                };

                session.Events.Append(stream1, joined, departed);

                var joined2 = new MembersJoined {
                    Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
                };
                var departed2 = new MembersDeparted {
                    Members = new[] { "Thom" }
                };

                session.Events.Append(stream2, joined2, departed2);

                await session.SaveChangesAsync();
            }

            await theStore.Advanced.Clean.DeleteSingleEventStreamAsync(stream1);

            using (var session = theStore.LightweightSession())
            {
                session.Events.QueryAllRawEvents().ToList().All(x => x.StreamId == stream2)
                .ShouldBeTrue();
            }
        }
Ejemplo n.º 4
0
        public void capture_events_to_an_existing_stream_and_fetch_the_events_back()
        {
            var id      = "Twelth";
            var started = new QuestStarted();

            using (var session = theStore.LightweightSession())
            {
                session.Events.StartStream <Quest>(id, started);
                session.SaveChanges();
            }

            using (var session = theStore.LightweightSession())
            {
                var joined = new MembersJoined {
                    Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
                };
                var departed = new MembersDeparted {
                    Members = new[] { "Thom" }
                };

                session.Events.Append(id, joined);
                session.Events.Append(id, departed);

                session.SaveChanges();

                var streamEvents = session.Events.FetchStream(id);

                streamEvents.Count().ShouldBe(3);
                streamEvents.ElementAt(0).Data.ShouldBeOfType <QuestStarted>();
                streamEvents.ElementAt(0).Version.ShouldBe(1);
                streamEvents.ElementAt(1).Data.ShouldBeOfType <MembersJoined>();
                streamEvents.ElementAt(1).Version.ShouldBe(2);
                streamEvents.ElementAt(2).Data.ShouldBeOfType <MembersDeparted>();
                streamEvents.ElementAt(2).Version.ShouldBe(3);
            }
        }
Ejemplo n.º 5
0
        public void capture_events_to_a_new_stream_and_fetch_the_events_back()
        {
            var joined = new MembersJoined {
                Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
            };
            var departed = new MembersDeparted {
                Members = new[] { "Thom" }
            };

            var id = "First";

            theSession.Events.StartStream <Quest>(id, joined, departed);
            theSession.SaveChanges();

            var streamEvents = theSession.Events.FetchStream(id);

            streamEvents.Count().ShouldBe(2);
            streamEvents.ElementAt(0).Data.ShouldBeOfType <MembersJoined>();
            streamEvents.ElementAt(0).Version.ShouldBe(1);
            streamEvents.ElementAt(1).Data.ShouldBeOfType <MembersDeparted>();
            streamEvents.ElementAt(1).Version.ShouldBe(2);

            streamEvents.Each(e => e.Timestamp.ShouldNotBe(default(DateTimeOffset)));
        }
Ejemplo n.º 6
0
 public void Apply(MembersDeparted departed)
 {
     _members.RemoveAll(x => departed.Members.Contains(x));
 }
Ejemplo n.º 7
0
        public void running_synchronously()
        {
            var logger = new RecordingSessionLogger();

            Guid streamId = Guid.NewGuid();

            using (var session = theStore.OpenSession())
            {
                session.Logger = logger;

                var joined = new MembersJoined {
                    Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
                };
                var departed = new MembersDeparted {
                    Members = new[] { "Thom" }
                };

                session.Events.StartStream <Quest>(streamId, joined, departed);
                session.SaveChanges();

                var events = logger.LastCommit.GetEvents().ToArray();
                events.Select(x => x.Version)
                .ShouldHaveTheSameElementsAs(1, 2);

                events.Each(x => SpecificationExtensions.ShouldBeGreaterThan(x.Sequence, 0L));

                events.Select(x => x.Sequence).Distinct().Count().ShouldBe(2);
            }

            using (var session = theStore.OpenSession())
            {
                session.Logger = logger;

                var joined2 = new MembersJoined {
                    Members = new[] { "Egwene" }
                };
                var departed2 = new MembersDeparted {
                    Members = new[] { "Perrin" }
                };

                session.Events.Append(streamId, joined2, departed2);
                session.SaveChanges();

                logger.LastCommit.GetEvents().Select(x => x.Version)
                .ShouldHaveTheSameElementsAs(3, 4);
            }

            using (var session = theStore.OpenSession())
            {
                session.Logger = logger;

                var joined3 = new MembersJoined {
                    Members = new[] { "Egwene" }
                };
                var departed3 = new MembersDeparted {
                    Members = new[] { "Perrin" }
                };

                session.Events.Append(streamId, joined3, departed3);
                session.SaveChanges();

                logger.LastCommit.GetEvents().Select(x => x.Version)
                .ShouldHaveTheSameElementsAs(5, 6);
            }
        }