public static IEnumerable <object[]> MetadataTestCases()
        {
            var builder = StreamMetadata.Create(
                maxCount: 0xDEAD,
                maxAge: TimeSpan.FromSeconds(0xFAD),
                truncateBefore: 0xBEEF,
                cacheControl: TimeSpan.FromSeconds(0xF00L),
                acl: new StreamAcl(SystemRoles.All, SystemRoles.All, SystemRoles.All, SystemRoles.All,
                                   SystemRoles.All)).Copy()
                          .SetCustomProperty(nameof(String), "f")
                          .SetCustomProperty(nameof(Int32), 1)
                          .SetCustomProperty(nameof(Double), 2.0)
                          .SetCustomProperty(nameof(Int64), int.MaxValue + 1L)
                          .SetCustomProperty(nameof(Boolean), true)
                          .SetCustomProperty(nameof(Nullable), default(int?))
                          .SetCustomPropertyWithValueAsRawJsonString(nameof(JObject), @"{ ""subProperty"": 999 }");

            var createStreams = new[] { true, false };
            var metadatas     = new[] { builder, null };

            foreach (var(expectedVersion, displayName) in ExpectedVersions)
            {
                foreach (var createStream in createStreams)
                {
                    foreach (var metadata in metadatas)
                    {
                        yield return(new object[] { expectedVersion, displayName, createStream, metadata });
                    }
                }
            }
        }
        public void setting_metadata_with_expected_version_any_works()
        {
            const string stream   = "setting_metadata_with_expected_version_any_works";
            var          metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadata(stream, ExpectedVersion.Any, metadata);

            var meta = _connection.GetStreamMetadata(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);

            metadata = StreamMetadata.Create(37, TimeSpan.FromSeconds(0xBEEFDEAD), 24, TimeSpan.FromSeconds(0xDABACABAD));
            _connection.SetStreamMetadata(stream, ExpectedVersion.Any, metadata);

            meta = _connection.GetStreamMetadata(stream);
            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(1, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
示例#3
0
        public async Task for_existing_stream_returns_set_metadata()
        {
            var streamName = GetStreamName();
            var connection = _fixture.Connection;
            var metadata   = StreamMetadata.Create(
                maxCount: 0xDEAD,
                maxAge: TimeSpan.FromSeconds(0xFAD),
                truncateBefore: 0xBEEF,
                cacheControl: TimeSpan.FromSeconds(0xF00L),
                acl: new StreamAcl(SystemRoles.All, SystemRoles.All, SystemRoles.All, SystemRoles.All,
                                   SystemRoles.All));
            await connection.SetStreamMetadataAsync(streamName, ExpectedVersion.NoStream, metadata).WithTimeout();

            var meta = await connection.GetStreamMetadataAsync(streamName).WithTimeout();

            Assert.Equal(streamName, meta.Stream);
            Assert.False(meta.IsStreamDeleted);
            Assert.Equal(0, meta.MetastreamVersion);
            Assert.Equal(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.Equal(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.Equal(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.Equal(metadata.CacheControl, meta.StreamMetadata.CacheControl);
            Assert.Equal(metadata.Acl.ReadRoles, meta.StreamMetadata.Acl.ReadRoles);
            Assert.Equal(metadata.Acl.WriteRoles, meta.StreamMetadata.Acl.WriteRoles);
            Assert.Equal(metadata.Acl.DeleteRoles, meta.StreamMetadata.Acl.DeleteRoles);
            Assert.Equal(metadata.Acl.MetaReadRoles, meta.StreamMetadata.Acl.MetaReadRoles);
            Assert.Equal(metadata.Acl.MetaWriteRoles, meta.StreamMetadata.Acl.MetaWriteRoles);
        }
        public async Task setting_metadata_few_times_returns_last_metadata_info()
        {
            const string stream   = "setting_metadata_few_times_returns_last_metadata_info";
            var          metadata =
                StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));
            await _connection.SetStreamMetadataAsync(stream, ExpectedVersion.NoStream, metadata);

            var meta = await _connection.GetStreamMetadataAsync(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);

            metadata = StreamMetadata.Create(37, TimeSpan.FromSeconds(0xBEEFDEAD), 24,
                                             TimeSpan.FromSeconds(0xDABACABAD));
            await _connection.SetStreamMetadataAsync(stream, 0, metadata);

            meta = await _connection.GetStreamMetadataAsync(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(1, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
        public void setting_metadata_few_times_returns_last_metadata_info()
        {
            const string stream   = "setting_metadata_few_times_returns_last_metadata_info";
            var          metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, metadata);

            var meta = _connection.GetStreamMetadata(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);

            metadata = StreamMetadata.Create(37, TimeSpan.FromSeconds(0xBEEFDEAD), TimeSpan.FromSeconds(0xDABACABAD));
            _connection.SetStreamMetadata(stream, 0, metadata);

            meta = _connection.GetStreamMetadata(stream);
            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(1, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
示例#6
0
        public void setting_metadata_few_times_returns_last_metadata_info()
        {
            var metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadataAsync(_stream, ExpectedVersion.Any, metadata).Wait();

            var meta = _connection.GetStreamMetadataAsync(_stream).Result;

            Assert.AreEqual(_stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);

            metadata = StreamMetadata.Create(37, TimeSpan.FromSeconds(0xBEEFDEAD), 24, TimeSpan.FromSeconds(0xDABACABAD));
            _connection.SetStreamMetadataAsync(_stream, 0, metadata).Wait();

            meta = _connection.GetStreamMetadataAsync(_stream).Result;
            Assert.AreEqual(_stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(1, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
        public void trying_to_set_metadata_with_wrong_expected_version_fails()
        {
            const string stream = "trying_to_set_metadata_with_wrong_expected_version_fails";

            Assert.That(() => _connection.SetStreamMetadata(stream, 2, StreamMetadata.Create()),
                        Throws.Exception.InstanceOf <AggregateException>()
                        .With.InnerException.InstanceOf <WrongExpectedVersionException>());
        }
示例#8
0
        public void setting_empty_metadata_works()
        {
            _connection.SetStreamMetadataAsync(_stream, ExpectedVersion.Any, StreamMetadata.Create()).Wait();

            var meta = _connection.GetStreamMetadataAsRawBytesAsync(_stream).Result;

            Assert.AreEqual(_stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(Helper.UTF8NoBom.GetBytes("{}"), meta.StreamMetadata);
        }
        public void setting_empty_metadata_works()
        {
            const string stream = "setting_empty_metadata_works";

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, StreamMetadata.Create());

            var meta = _connection.GetStreamMetadataAsRawBytes(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(Helper.UTF8NoBom.GetBytes("{}"), meta.StreamMetadata);
        }
示例#10
0
        public void setting_metadata_for_not_existing_stream_works()
        {
            var metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadataAsync(_stream, ExpectedVersion.EmptyStream, metadata).Wait();

            var meta = _connection.GetStreamMetadataAsync(_stream).Result;

            Assert.AreEqual(_stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
        public void setting_metadata_for_not_existing_stream_works()
        {
            const string stream   = "setting_metadata_for_not_existing_stream_works";
            var          metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, metadata);

            var meta = _connection.GetStreamMetadata(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
        public async Task setting_metadata_for_not_existing_stream_works()
        {
            const string stream   = "setting_metadata_for_not_existing_stream_works";
            var          metadata =
                StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));
            await _connection.SetStreamMetadataAsync(stream, ExpectedVersion.NoStream, metadata);

            var meta = await _connection.GetStreamMetadataAsync(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
示例#13
0
        public void getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion()
        {
            var metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadataAsync(_stream, ExpectedVersion.EmptyStream, metadata).Wait();

            _connection.DeleteStreamAsync(_stream, ExpectedVersion.EmptyStream, hardDelete: true).Wait();

            var meta = _connection.GetStreamMetadataAsync(_stream).Result;

            Assert.AreEqual(_stream, meta.Stream);
            Assert.AreEqual(true, meta.IsStreamDeleted);
            Assert.AreEqual(EventNumber.DeletedStream, meta.MetastreamVersion);
            Assert.AreEqual(null, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(null, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(null, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(null, meta.StreamMetadata.CacheControl);
            Assert.AreEqual(null, meta.StreamMetadata.Acl);
        }
        public void getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion()
        {
            const string stream = "getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion";

            var metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, metadata);

            _connection.DeleteStream(stream, ExpectedVersion.EmptyStream);

            var meta = _connection.GetStreamMetadata(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(true, meta.IsStreamDeleted);
            Assert.AreEqual(EventNumber.DeletedStream, meta.MetastreamVersion);
            Assert.AreEqual(null, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(null, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(null, meta.StreamMetadata.CacheControl);
            Assert.AreEqual(null, meta.StreamMetadata.Acl);
        }
示例#15
0
        public void setting_metadata_for_existing_stream_works()
        {
            const string stream = "setting_metadata_for_existing_stream_works";

            _connection.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent()).Wait();

            var metadata =
                StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadataAsync(stream, ExpectedVersion.NoStream, metadata).Wait();

            var meta = _connection.GetStreamMetadataAsync(stream).Result;

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(metadata.MaxCount, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(metadata.MaxAge, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(metadata.TruncateBefore, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(metadata.CacheControl, meta.StreamMetadata.CacheControl);
        }
        public async Task getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion()
        {
            const string stream =
                "getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion";

            var metadata =
                StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));
            await _connection.SetStreamMetadataAsync(stream, ExpectedVersion.NoStream, metadata);

            await _connection.DeleteStreamAsync(stream, ExpectedVersion.NoStream, hardDelete : true);

            var meta = await _connection.GetStreamMetadataAsync(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(true, meta.IsStreamDeleted);
            Assert.AreEqual(EventNumber.DeletedStream, meta.MetastreamVersion);
            Assert.AreEqual(null, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(null, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(null, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(null, meta.StreamMetadata.CacheControl);
            Assert.AreEqual(null, meta.StreamMetadata.Acl);
        }
 public async Task trying_to_set_metadata_with_wrong_expected_version_fails()
 {
     const string stream = "trying_to_set_metadata_with_wrong_expected_version_fails";
     await AssertEx.ThrowsAsync <WrongExpectedVersionException>(() =>
                                                                _connection.SetStreamMetadataAsync(stream, 2, StreamMetadata.Create()));
 }
示例#18
0
        public async Task for_hard_deleted_stream_returns_default_with_stream_deletion()
        {
            var streamName = GetStreamName();
            var connection = _fixture.Connection;
            await connection.SetStreamMetadataAsync(streamName, ExpectedVersion.NoStream, StreamMetadata.Create())
            .WithTimeout();

            await connection.DeleteStreamAsync(streamName, ExpectedVersion.Any, true).WithTimeout();

            var meta = await connection.GetStreamMetadataAsync(streamName).WithTimeout();

            Assert.Equal(streamName, meta.Stream);
            Assert.True(meta.IsStreamDeleted);
            Assert.Equal(long.MaxValue, meta.MetastreamVersion);
            Assert.False(meta.StreamMetadata.MaxCount.HasValue);
            Assert.False(meta.StreamMetadata.MaxAge.HasValue);
            Assert.False(meta.StreamMetadata.TruncateBefore.HasValue);
            Assert.False(meta.StreamMetadata.CacheControl.HasValue);
        }
 public Task <StreamMetadataResult> GetStreamMetadataAsync(string stream, UserCredentials userCredentials = null)
 {
     return(GetStreamMetadataAsRawBytesAsync(stream, userCredentials).ContinueWith(t =>
     {
         if (t.Exception != null)
         {
             throw t.Exception.InnerException;
         }
         var res = t.Result;
         if (res.StreamMetadata == null || res.StreamMetadata.Length == 0)
         {
             return new StreamMetadataResult(res.Stream, res.IsStreamDeleted, res.MetastreamVersion, StreamMetadata.Create());
         }
         var metadata = StreamMetadata.FromJsonBytes(res.StreamMetadata);
         return new StreamMetadataResult(res.Stream, res.IsStreamDeleted, res.MetastreamVersion, metadata);
     }));
 }