public async Task CleanDestinationSourceItemsNull() { var destination = Substitute.For <IDataLister>(); var e = new Echoer(destination); Assert.That(async() => await e.CleanDestination(null), Throws.TypeOf <ArgumentNullException>()); }
public async Task CleanDestinationNothingToDelete() { var random = new Random(); var count = random.Next(1, 64); var sItems = new List <IStorageItem>(count); var dItems = new List <IStorageItem>(count); for (var i = 0; i < count; i++) { var item = Substitute.For <IStorageItem>(); item.RelativePath.Returns(Guid.NewGuid().ToString()); sItems.Add(item); dItems.Add(item); } var destination = Substitute.For <IDataLister>(); destination.List().Returns(dItems); var e = new Echoer(destination); await e.CleanDestination(sItems); destination.Received().List(); foreach (var di in dItems) { di.Received(0).Delete(); } }
public async Task CleanDestinationSourceItemsEmpty() { var destination = Substitute.For <IDataLister>(); destination.List().Returns(new List <IStorageItem>()); var e = new Echoer(destination); await e.CleanDestination(new List <IStorageItem>()); }
public async Task CleanDestinationDestinationItems() { var sItems = new List <IStorageItem>(); sItems.Add(Substitute.For <IStorageItem>()); var destination = Substitute.For <IDataLister>(); destination.List().Returns((IEnumerable <IStorageItem>)null); var e = new Echoer(destination); await e.CleanDestination(sItems); destination.Received().List(); }
public async Task FolderToBlob() { var random = new Random(); var containerName = 'a' + Guid.NewGuid().ToString().Replace("-", ""); var from = string.Format("{0}\\{1}", Environment.CurrentDirectory, Guid.NewGuid()); Directory.CreateDirectory(from); var to = new Container(containerName, ConnectionString); await to.CreateIfNotExists(); var extraCount = random.Next(1, 25); var extra = new List <Validation>(extraCount); for (var i = 0; i < extraCount; i++) { var v = new Validation { Data = Guid.NewGuid().ToByteArray(), FileName = Guid.NewGuid().ToString(), }; await to.Save(v.FileName, v.Data); extra.Add(v); } var e = new Echoer(new BlobReader(to)); await e.CleanDestination(new FolderReader(from).List()); var items = to.List(); Assert.AreEqual(0, items.Count()); await to.Delete(); Directory.Delete(from, true); }
public async Task BlobToBlob() { var random = new Random(); var containerName = string.Format("a{0}b", random.Next()); var destContainerName = string.Format("c{0}d", random.Next()); var from = new Container(containerName, ConnectionString); await from.CreateIfNotExists(); var to = new Container(destContainerName, ConnectionString); await to.CreateIfNotExists(); var count = random.Next(1, 25); for (var i = 0; i < count; i++) { var v = new Validation { Data = Guid.NewGuid().ToByteArray(), FileName = Guid.NewGuid().ToString(), }; await to.Save(v.FileName, v.Data); } var sourceItems = new BlobReader(from).List(); var e = new Echoer(new BlobReader(to)); await e.CleanDestination(sourceItems); var items = to.List(); Assert.AreEqual(0, items.Count()); //Clean-Up await from.Delete(); await to.Delete(); }
public async Task BlobToFolder() { var random = new Random(); var containerName = 'a' + Guid.NewGuid().ToString().Replace("-", ""); var from = new Container(containerName, ConnectionString); await from.CreateIfNotExists(); var to = string.Format("{0}\\{1}", Environment.CurrentDirectory, Guid.NewGuid()); Directory.CreateDirectory(to); var count = random.Next(1, 25); for (var i = 0; i < count; i++) { var v = new Validation { Data = new byte[64], FileName = string.Format("{0}.{1}", Guid.NewGuid(), i), }; var bytes = new byte[64]; random.NextBytes(v.Data); File.WriteAllBytes(string.Format("{0}\\{1}", to, v.FileName), v.Data); } var e = new Echoer(new FolderReader(to)); await e.CleanDestination(new BlobReader(from).List()); var items = Directory.GetFiles(to); Assert.AreEqual(0, items.Count()); Directory.Delete(to, true); await from.Delete(); }