public void RelativePathNoForwardSlash() { var container = Substitute.For<IContainer>(); var bi = new BlobItem(container, "file.txt"); Assert.AreEqual("file.txt", bi.RelativePath); }
public void Path() { var container = Substitute.For<IContainer>(); container.Name.Returns("container"); var bi = new BlobItem(container, "/file.txt"); Assert.AreEqual("container/file.txt", bi.Path); var z = container.Received().Name; }
/// <summary> /// Store Items /// </summary> /// <param name="items">Items</param> public virtual async Task Store(IEnumerable <IStorageItem> items) { foreach (var item in items) { var path = item.RelativePath.Replace("\\", "/"); var exists = await this.container.Exists(path); if (exists) { await item.LoadMD5(); var existing = new BlobItem(container, path); await existing.LoadMD5(); if (item.MD5 == existing.MD5) { Trace.TraceInformation("Synchronization avoided: '{0}'.", item.Path); continue; } if (this.createSnapshot) { await this.container.Snapshot(path); } } await item.LoadMD5(); await item.Load(); Trace.TraceInformation("Uploading to blob: '{0}'.", path); await this.container.Save(path, item.Data, item.ContentType); if (0 < this.cacheControlDuration) { await this.container.SetCacheControl(path, this.cacheControlDuration); } } }
public async Task LoadMD5() { var random = new Random(); var bytes = new byte[64]; random.NextBytes(bytes); var p = new BlobProperties() { ContentType = Guid.NewGuid().ToString(), ContentMD5 = Guid.NewGuid().ToString(), }; var container = Substitute.For<IContainer>(); container.Properties("file.txt").Returns(Task.FromResult(p)); var bi = new BlobItem(container, "/file.txt"); await bi.LoadMD5(); Assert.AreEqual(p.ContentType, bi.ContentType); Assert.AreEqual(p.ContentMD5, bi.MD5); container.Received().Properties("file.txt"); }
public async Task Delete() { var container = Substitute.For<IContainer>(); container.Delete("file.txt"); var bi = new BlobItem(container, "/file.txt"); await bi.Delete(); container.Received().Delete("file.txt"); }