示例#1
0
        public async Task Store()
        {
            var random = new Random();
            var data   = new byte[64];

            random.NextBytes(data);
            var relPath     = Guid.NewGuid().ToString();
            var contentType = Guid.NewGuid().ToString();

            var item = Substitute.For <IStorageItem>();

            item.RelativePath.Returns(relPath);
            item.Data.Returns(data);
            item.ContentType.Returns(contentType);
            item.LoadMD5();
            item.Load();

            var container = Substitute.For <IContainer>();

            container.Save(relPath, data, contentType);
            container.Exists(relPath).Returns(Task.FromResult(false));

            var w = new BlobWriter(container);
            await w.Store(new[] { item });

            var x = item.Received().RelativePath;
            var y = item.Received().Data;
            var z = item.Received().ContentType;

            item.Received().LoadMD5();
            item.Received().Load();
            container.Received().Save(relPath, data, contentType);
            container.Received().Exists(relPath);
        }
示例#2
0
        public async Task StoreForwardSlash()
        {
            var containerName = 'a' + Guid.NewGuid().ToString().Replace("-", string.Empty);
            var to            = new Container(containerName, ConnectionString);
            await to.CreateIfNotExists();

            var file = string.Format("{0}/{0}/{0}.bin", Guid.NewGuid());

            var random = new Random();
            var bytes  = new byte[8];

            random.NextBytes(bytes);

            var item = Substitute.For <IStorageItem>();

            item.LoadMD5();
            item.Load();
            item.Data.Returns(bytes);
            item.RelativePath.Returns(file);

            var writer = new BlobWriter(to);
            await writer.Store(new[] { item });

            var result = await to.Get(file.Replace("\\", "/"));

            Assert.AreEqual(bytes, result);

            await to.Delete();
        }
示例#3
0
        public async Task StoreCacheControl()
        {
            var random        = new Random();
            var cache         = random.Next(1, int.MaxValue - 1);
            var containerName = 'a' + Guid.NewGuid().ToString().Replace("-", string.Empty);
            var to            = new Container(containerName, ConnectionString);
            await to.CreateIfNotExists();

            var file = string.Format("{0}.bin", Guid.NewGuid());

            var bytes = new byte[8];

            random.NextBytes(bytes);

            var item = Substitute.For <IStorageItem>();

            item.LoadMD5();
            item.Load();
            item.Data.Returns(bytes);
            item.RelativePath.Returns(file);

            var writer = new BlobWriter(to, false, cache);
            await writer.Store(new[] { item });

            var result = await to.Properties(file);

            Assert.AreEqual("public, max-age=" + cache, result.CacheControl);

            await to.Delete();
        }
示例#4
0
        public async Task StoreSameMd5()
        {
            var random = new Random();
            var data   = new byte[64];

            random.NextBytes(data);
            var relPath     = Guid.NewGuid().ToString();
            var contentType = Guid.NewGuid().ToString();

            var p = new BlobProperties()
            {
                ContentType = Guid.NewGuid().ToString(),
                ContentMD5  = Guid.NewGuid().ToString(),
            };

            var item = Substitute.For <IStorageItem>();

            item.RelativePath.Returns(relPath);
            item.MD5.Returns(p.ContentMD5);
            item.LoadMD5();

            var container = Substitute.For <IContainer>();

            container.Save(relPath, data, contentType);
            container.Exists(relPath).Returns(Task.FromResult(true));
            container.Snapshot(relPath);
            container.Properties(relPath).Returns(Task.FromResult(p));

            var w = new BlobWriter(container, true);
            await w.Store(new[] { item });

            var u = item.Received().MD5;
            var x = item.Received().RelativePath;
            var y = item.Received(0).Data;

            item.Received().LoadMD5();
            item.Received(0).Load();
            container.Received().Save(relPath, data, contentType);
            container.Received().Exists(relPath);
            container.Received().Snapshot(relPath);
            container.Received().Properties(relPath);
        }
示例#5
0
        public async Task StoreCreateSnapshot()
        {
            var random = new Random();
            var data = new byte[64];
            random.NextBytes(data);
            var relPath = Guid.NewGuid().ToString();
            var contentType = Guid.NewGuid().ToString();

            var p = new BlobProperties()
            {
                ContentType = Guid.NewGuid().ToString(),
                ContentMD5 = Guid.NewGuid().ToString(),
            };

            var item = Substitute.For<IStorageItem>();
            item.RelativePath.Returns(relPath);
            item.Data.Returns(data);
            item.ContentType.Returns(contentType);
            item.LoadMD5();
            item.Load();

            var container = Substitute.For<IContainer>();
            container.Save(relPath, data, contentType);
            container.Exists(relPath).Returns(Task.FromResult(true));
            container.Snapshot(relPath);
            container.Properties(relPath).Returns(Task.FromResult(p));

            var w = new BlobWriter(container, true);
            await w.Store(new[] { item });

            var x = item.Received().RelativePath;
            var y = item.Received().Data;
            var z = item.Received().ContentType;
            item.Received().LoadMD5();
            item.Received().Load();
            container.Received().Save(relPath, data, contentType);
            container.Received().Exists(relPath);
            container.Received().Snapshot(relPath);
            container.Received().Properties(relPath);
        }