コード例 #1
0
        public async Task Should_write_to_store_with_previous_position()
        {
            InvalidateMessage message = null;

            pubSub.Subscribe <InvalidateMessage>(m =>
            {
                message = m;
            });

            SetupEventStore(3);

            var actualObject = await sut.GetSingleAsync <MyStatefulObject>(key);

            Assert.Same(statefulObject, actualObject);

            await statefulObject.WriteEventsAsync(new MyEvent(), new MyEvent());

            await statefulObject.WriteEventsAsync(new MyEvent(), new MyEvent());

            A.CallTo(() => eventStore.AppendEventsAsync(A <Guid> .Ignored, key, 2, A <ICollection <EventData> > .That.Matches(x => x.Count == 2)))
            .MustHaveHappened();
            A.CallTo(() => eventStore.AppendEventsAsync(A <Guid> .Ignored, key, 4, A <ICollection <EventData> > .That.Matches(x => x.Count == 2)))
            .MustHaveHappened();

            Assert.NotNull(message);
            Assert.Equal(key, message.Key);
        }
コード例 #2
0
        public async Task Should_write_to_store_with_previous_version()
        {
            InvalidateMessage message = null;

            pubSub.Subscribe <InvalidateMessage>(m =>
            {
                message = m;
            });

            A.CallTo(() => snapshotStore.ReadAsync(key))
            .Returns((123, 13));

            var actualObject = await sut.GetSingleAsync <MyStatefulObject, string>(key);

            Assert.Same(statefulObject, actualObject);
            Assert.Equal(123, statefulObject.State);

            statefulObject.SetState(456);

            await statefulObject.WriteStateAsync();

            A.CallTo(() => snapshotStore.WriteAsync(key, 456, 13, 14))
            .MustHaveHappened();

            Assert.NotNull(message);
            Assert.Equal(key, message.Key);
        }
コード例 #3
0
        public async Task Should_write_to_store_with_previous_etag()
        {
            var etag = Guid.NewGuid().ToString();

            InvalidateMessage message = null;

            pubSub.Subscribe <InvalidateMessage>(m =>
            {
                message = m;
            });

            A.CallTo(() => store.ReadAsync <int>(key))
            .Returns((123, etag));

            var actual = await sut.GetAsync <MyStatefulObject, int>(key);

            Assert.Same(state, actual);
            Assert.Equal(123, state.State);

            state.SetState(456);

            await state.WriteStateAsync();

            A.CallTo(() => store.WriteAsync(key, 456, etag, A <string> .That.Matches(x => x != null)))
            .MustHaveHappened();

            Assert.NotNull(message);
            Assert.Equal(key, message.Key);
        }
コード例 #4
0
        public void Should_send_invalidation_message_on_refresh()
        {
            InvalidateMessage message = null;

            pubSub.Subscribe <InvalidateMessage>(m =>
            {
                message = m;
            });

            sut.Synchronize <MyStatefulObject, string>(key);

            Assert.NotNull(message);
            Assert.Equal(key, message.Key);
        }