public static Task <bool> Rename(this MailRuCloud cloud, IStoreItem item, string destinationName) { if (null == item) { return(Task.FromResult(false)); } var storeItem = item as MailruStoreItem; if (storeItem != null) { return(cloud.Rename(storeItem.FileInfo, destinationName)); } var storeCollection = item as MailruStoreCollection; if (storeCollection != null) { return(cloud.Rename(storeCollection.DirectoryInfo, destinationName)); } throw new ArgumentException(string.Empty, nameof(item)); }
public void RenameTest() { var api = new MailRuCloud(); api.Account = this.account; var result = api.UploadFileAsync(new FileInfo(@"D:\1.stl"), "/"); if (result.Result) { var file = api.GetItems("/").Files.First(x => x.Name == "1.stl"); api.Rename(file, "rename stl test.stl"); api.CreateFolder("new test folder", "/"); var folder = api.GetItems("/").Folders.First(x => x.Name == "new test folder"); api.Rename(folder, "rename folder test"); var entry = api.GetItems("/"); Assert.IsNotNull(entry.Folders.FirstOrDefault(x => x.Name == "rename folder test")); Assert.IsNotNull(entry.Files.FirstOrDefault(x => x.Name == "rename stl test.stl")); } }