コード例 #1
0
        public async Task Should_read_from_store()
        {
            A.CallTo(() => store.ReadAsync <int>(key))
            .Returns((123, Guid.NewGuid().ToString()));

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

            Assert.Same(state, actual);
            Assert.NotNull(cache.Get <object>(key));

            Assert.Equal(123, state.State);
        }
コード例 #2
0
        public async Task ReadAsync()
        {
            (State, etag) = await store.ReadAsync <T>(key);

            if (Equals(State, default(T)))
            {
                State = Activator.CreateInstance <T>();
            }
        }
コード例 #3
0
 public static async Task <VisualObject> ReadObjectAsync(
     IStateStore stateStore,
     CancellationToken cancellationToken)
 {
     try
     {
         return(await stateStore.ReadAsync(cancellationToken));
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error in reading the object. {e.ToString()}");
         return(null);
     }
 }
コード例 #4
0
        private async Task ReadStateAsync()
        {
            var storableState = await _stateStore.ReadAsync(_key);

            if (storableState != null)
            {
                Version = storableState.Version;
                State   = _dataSerializer.Deserialize <TState>(storableState.Payload);
            }

            var hasMoreResults = false;

            do
            {
                var slice = await _eventStore.ReadAsync(_key, Version + 1);

                hasMoreResults = slice.HasMoreResults;
                if (slice.Events.Any())
                {
                    ApplyEvents(slice.Events.Select(ToVersionedEvent));
                }
            } while (hasMoreResults);
        }