Ejemplo n.º 1
0
        public async Task with_restart()
        {
            var memory = new MemoryStorageDriver();
            var cache  = new Testing.InMemoryCache();
            var ew     = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory,
                new [] { new CheckSequence.Projection() },
                cache
                );
            await ew.AppendEventsAsync(new[] { new TstEvent(1) });

            await ew.AppendEventsAsync(new[] { new TstEvent(2) });

            await ew.AppendEventsAsync(new[] { new TstEvent(3) });

            await ew.TrySaveAsync();

            await ew.AppendEventsAsync(new[] { new TstEvent(4) });

            await ew.AppendEventsAsync(new[] { new TstEvent(5) });

            Assert.Equal(5u, ew.Current.LastEvt);

            // try to read:
            var ew2 = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory, new[] { new CheckSequence.Projection() },
                cache);

            await ew2.InitializeAsync();

            Assert.Equal(5u, ew2.Current.LastEvt);
        }
Ejemplo n.º 2
0
        public async Task without_restart()
        {
            var memory = new MemoryStorageDriver();
            var ew     = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory,
                new [] { new CheckSequence.Projection() }, null
                );
            await ew.AppendEventsAsync(new[] { new TstEvent(1) });

            await ew.AppendEventsAsync(new[] { new TstEvent(2) });

            await ew.AppendEventsAsync(new[] { new TstEvent(3) });

            Assert.Equal(3u, ew.Current.LastEvt);

            // try to read:
            var ew2 = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory, new[] { new CheckSequence.Projection() }, null);

            await ew2.InitializeAsync();

            Assert.Equal(3u, ew2.Current.LastEvt);
        }
Ejemplo n.º 3
0
 /// <summary> Append events, constructed from the state, to the stream. </summary>
 /// <remarks>
 /// Builder returns array of events to be appended. It may be called more than
 /// once.
 /// </remarks>
 public Task <AppendResult> AppendEventsAsync(
     Func <TState, Append <TEvent> > builder,
     CancellationToken cancel)
 =>
 EnqueueAction(c => Wrapper.AppendEventsAsync(builder, c), cancel);