public async Task getting_for_an_existing_stream_and_no_metadata_exists() { var stream = _fixture.GetStreamName(); await _fixture.Client.AppendToStreamAsync(stream, StreamState.NoStream, _fixture.CreateTestEvents()); var actual = await _fixture.Client.GetStreamMetadataAsync(stream); Assert.Equal(StreamMetadataResult.None(stream), actual); }
public async Task <StreamMetadataResult> GetStreamMetadataAsync(string streamName, UserCredentials userCredentials = default, CancellationToken cancellationToken = default) { ResolvedEvent metadata = default; try { metadata = await ReadStreamAsync(Direction.Backwards, SystemStreams.MetastreamOf(streamName), StreamRevision.End, 1, false, userCredentials : userCredentials, cancellationToken : cancellationToken).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } catch (StreamNotFoundException) { return(StreamMetadataResult.None(streamName)); } return(metadata.Event == null ? StreamMetadataResult.None(streamName) : StreamMetadataResult.Create( streamName, metadata.OriginalEventNumber, JsonSerializer.Deserialize <StreamMetadata>(metadata.Event.Data, StreamMetadataJsonSerializerOptions))); }
private async Task <StreamMetadataResult> GetStreamMetadataAsync(string streamName, EventStoreClientOperationOptions operationOptions, UserCredentials?userCredentials = null, CancellationToken cancellationToken = default) { ResolvedEvent metadata; _log.LogDebug("Read stream metadata for {streamName}."); try { metadata = await ReadStreamAsync(Direction.Backwards, SystemStreams.MetastreamOf(streamName), StreamPosition.End, 1, operationOptions, false, userCredentials, cancellationToken) .FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } catch (StreamNotFoundException) { _log.LogWarning("Stream metadata for {streamName} not found."); return(StreamMetadataResult.None(streamName)); } return(metadata.Event == null ? StreamMetadataResult.None(streamName) : StreamMetadataResult.Create(streamName, metadata.OriginalEventNumber, JsonSerializer.Deserialize <StreamMetadata>(metadata.Event.Data.Span, StreamMetadataJsonSerializerOptions))); }