示例#1
0
        public async Task Checkpoint_is_notified_but_not_stored_on_project()
        {
            var expected = new AllStreamPosition(10);

            AllStreamPosition projected = AllStreamPosition.None;
            AllStreamPosition notified  = AllStreamPosition.None;

            using (var cpStore = Util.BuildCheckpointStore())
                using (var sut = new CheckpointProjection(
                           Util.Projection(m => projected = m.Checkpoint),
                           cpStore,
                           p => notified = p))
                {
                    await sut.Project(new Envelope(expected, null));

                    projected.ShouldBe(expected);
                    notified.ShouldBe(expected);
                    cpStore.Read().ShouldBeNull();
                }
        }
        public async Task Only_first_messages_before_error_are_processed()
        {
            var expected = new AllStreamPosition(3);
            AllStreamPosition lastCheckpoint = AllStreamPosition.None;

            using (var sut = new SuspendableProjection(
                       Util.Projection(m =>
            {
                lastCheckpoint = m.Checkpoint;
                if (m.Checkpoint == expected)
                {
                    throw new Exception("test");
                }
            })))
            {
                for (int i = 1; i < 5; i++)
                {
                    await sut.Project(new Envelope(new AllStreamPosition(i), null));
                }
            }
            lastCheckpoint.ShouldBe(expected);
        }
        public async Task Commit_happens_only_after_nth_attempt(int n)
        {
            AllStreamPosition projected = AllStreamPosition.None;
            bool committed = false;

            using (var sut = new CommitNthProjection(
                       Util.Projection(m => projected = m.Checkpoint, () => committed = true),
                       n))
            {
                for (int i = 0; i < n; i++)
                {
                    var expected = new AllStreamPosition(i);
                    await sut.Project(new Envelope(expected, null));

                    projected.ShouldBe(expected);
                    if (i < n - 1)
                    {
                        committed.ShouldBeFalse();
                    }
                }
            }
            committed.ShouldBeTrue();
        }