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); }
public static async Task WriteObjectAsync( IStateStore stateStore, VisualObject obj, CancellationToken cancellationToken) { try { await stateStore.WriteAsync(obj, cancellationToken); } catch (Exception e) { Console.WriteLine($"Error in writing the object. {e.ToString()}"); } }
public async Task WriteAsync() { try { var newEtag = Guid.NewGuid().ToString(); await store.WriteAsync(key, State, etag, newEtag); etag = newEtag; } finally { written(); } }
protected async Task WriteStateAsync() { if (!_uncommitedEvents.Any()) { return; } await _eventStore.WriteAsync(_key, _uncommitedEvents.Select(ToStorableEvent)); await PublishUnpublishedEventsAsync(_uncommitedEvents); if (Version >= SaveStateStep && Version % SaveStateStep - _uncommitedEvents.Count < 0) { await _stateStore.WriteAsync(_key, new StorableState(Version, State.GetType().Name, _dataSerializer.Serialize(State))); } _uncommitedEvents.Clear(); }