Ejemplo n.º 1
0
        public async Task UpdatesTimeOfLastRead()
        {
            const string knownId = "known id";

            using (var source = new MemoryStream(new byte[0]))
            {
                await _storage.Save(knownId, source);
            }

            var hadLastReadTime = (await _storage.ReadMetadata(knownId)).ContainsKey(MetadataKeys.ReadTime);

            Assert.That(hadLastReadTime, Is.False, "Did not expect the {0} key to be set", MetadataKeys.ReadTime);

            var justSomeTime = new DateTimeOffset(1.January(2016));

            RebusTimeMachine.FakeIt(justSomeTime);

            _storage.Read(knownId).Result.Dispose();

            var metadata = await _storage.ReadMetadata(knownId);

            Assert.That(metadata.ContainsKey(MetadataKeys.ReadTime), Is.True);

            var readTimeMetadata = metadata[MetadataKeys.ReadTime];
            var readTime         = DateTimeOffset.Parse(readTimeMetadata);

            Assert.That(readTime, Is.EqualTo(justSomeTime),
                        $"Expected that the '{MetadataKeys.ReadTime}' metadata value '{readTimeMetadata}' would equal {justSomeTime} when passed to DateTimeOffset.Parse(...)");
        }
        /// <summary>
        /// Opens the data stored under the given ID for reading
        /// </summary>
        public async Task <Stream> Read(string id)
        {
            var metadata = await _innerDataBusStorage.ReadMetadata(id).ConfigureAwait(false);

            if (!metadata.TryGetValue(MetadataKeys.ContentEncoding, out var contentEncoding))
            {
                return(await _innerDataBusStorage.Read(id).ConfigureAwait(false));
            }

            if (!string.Equals(contentEncoding, "gzip", StringComparison.OrdinalIgnoreCase))
            {
                // unknown content encoding - the user must know best how to decode this!
                return(await _innerDataBusStorage.Read(id).ConfigureAwait(false));
            }

            var sourceStream = await _innerDataBusStorage.Read(id).ConfigureAwait(false);

            return(new GZipStream(sourceStream, CompressionMode.Decompress));
        }
        public async Task UpdatesTimeOfLastRead()
        {
            const string knownId = "known id";

            using (var source = new MemoryStream(new byte[0]))
            {
                await _storage.Save(knownId, source);
            }

            var hadLastReadTime = (await _storage.ReadMetadata(knownId)).ContainsKey(MetadataKeys.ReadTime);

            Assert.That(hadLastReadTime, Is.False, "Did not expect the {0} key to be set", MetadataKeys.ReadTime);

            var justSomeTime = new DateTimeOffset(1.January(2016));

            RebusTimeMachine.FakeIt(justSomeTime);

            _storage.Read(knownId).Result.Dispose();

            var metadata = await _storage.ReadMetadata(knownId);

            Assert.That(metadata.ContainsKey(MetadataKeys.ReadTime), Is.True);
            Assert.That(metadata[MetadataKeys.ReadTime], Is.EqualTo(justSomeTime.ToString("O")));
        }
Ejemplo n.º 4
0
        public async Task Metadata_Key_May_Contain_Delimiter()
        {
            // Setup
            var          defaultDelimiter = new AmazonS3DataBusOptions("bucket").MetadataDelimiter;
            const string key      = "SomeKey";
            var          metadata = new Dictionary <string, string>
            {
                [key] = $"Legal{defaultDelimiter}Value"
            };

            // Test
            await using (var source = new MemoryStream(Array.Empty <byte>()))
            {
                await _storage.Save(KnownId, source, metadata);
            }

            // Verify
            var readMetadata = await _storage.ReadMetadata(KnownId);

            Assert.That(readMetadata[key], Is.EqualTo(metadata[key]));
        }
Ejemplo n.º 5
0
 public Task <Dictionary <string, string> > GetMetadata(string dataBusAttachmentId) => _dataBusStorage.ReadMetadata(dataBusAttachmentId);
Ejemplo n.º 6
0
 /// <inheritdoc />
 public async Task <Dictionary <string, string> > GetMetadata(string dataBusAttachmentId)
 {
     return(await _dataBusStorage.ReadMetadata(dataBusAttachmentId).ConfigureAwait(false));
 }