Пример #1
0
        public void Reset_WithData_DeletesData()
        {
            _inMemDataStore.Save("test1", new byte[] { 1, 2, 3 });
            _inMemDataStore.Save("test2", new byte[] { 4, 5, 6 }, new Dictionary <string, string> {
                { "x", "y" }
            });

            Assert.That(_inMemDataStore.SizeBytes, Is.EqualTo(6));
            Assert.That(_inMemDataStore.LoadMetadata("test1"), Is.Empty);
            Assert.That(_inMemDataStore.LoadMetadata("test2")["x"], Is.EqualTo("y"));

            _inMemDataStore.Reset();

            Assert.That(_inMemDataStore.SizeBytes, Is.Zero);
            Assert.That(_inMemDataStore.AttachmentIds, Is.Empty);
            Assert.That(_inMemDataStore.Contains("test1"), Is.False);
            Assert.That(_inMemDataStore.Contains("test2"), Is.False);
            Assert.That(() => _inMemDataStore.Load("test1"), Throws.ArgumentException.With.Message.Contains("test1"));
            Assert.That(() => _inMemDataStore.Load("test2"), Throws.ArgumentException.With.Message.Contains("test2"));
            Assert.That(() => _inMemDataStore.LoadMetadata("test1"), Throws.ArgumentException.With.Message.Contains("test1"));
            Assert.That(() => _inMemDataStore.LoadMetadata("test2"), Throws.ArgumentException.With.Message.Contains("test2"));
        }
Пример #2
0
    public async Task <Stream> Read(string id)
    {
        var now = _rebusTime.Now;

        var metadata = new Dictionary <string, string>
        {
            { MetadataKeys.ReadTime, now.ToString("O") }
        };

        _dataStore.AddMetadata(id, metadata);

        var source = new MemoryStream(_dataStore.Load(id));

        return(source);
    }
Пример #3
0
        public async Task CreateTest()
        {
            var dataStore = new InMemDataStore();
            var fakeBus   = new FakeBus {
                Advanced = new FakeAdvancedApi(dataBus: new FakeDataBus(dataStore))
            };
            var handler = new DataBusAttachmentCreatingHandler(fakeBus);

            await handler.Handle("hej med dig min ven!");

            var sentDataBusAttachments = fakeBus.Events
                                         .OfType <MessageSent <DataBusAttachment> >()
                                         .ToList();

            Assert.That(sentDataBusAttachments.Count, Is.EqualTo(1));

            var attachmentId = sentDataBusAttachments.First().CommandMessage.Id;

            var data     = dataStore.Load(attachmentId);
            var textData = Encoding.UTF8.GetString(data);

            Assert.That(textData, Is.EqualTo("hej med dig min ven!"));
        }