public async Task UploadFileAsync(string fileName, string yandexDiskTarget) { IDiskApi diskApi = new DiskHttpApi("AgAAAABQNcSVAADLW8Rn_gQcNkrhlIhLGyzFvWM"); var targetPath = Path.TrimEndingDirectorySeparator(yandexDiskTarget) + "/" + Path.GetFileName(fileName); await diskApi.Files.UploadFileAsync(targetPath, false, fileName, CancellationToken.None); }
public async Task RestoreFromTrashTest() { var httpClientTest = new TestHttpClient( methodName: "PUT", url: TestHttpClient.BaseUrl + "trash/resources?path=/foo&name=baz&overwrite=false", httpStatusCode: HttpStatusCode.OK, result: @" { ""href"": ""https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fselfie.png"", ""method"": ""GET"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.Commands.RestoreFromTrashAsync(new RestoreFromTrashRequest { Path = "/foo", Name = "baz" }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fselfie.png", result.Href); Assert.AreEqual("GET", result.Method); Assert.AreEqual(false, result.Templated); }
public async Task GetUploadLinkTest() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + "resources/upload?path=/&overwrite=true", httpStatusCode: HttpStatusCode.OK, result: @" { ""href"": ""https://uploader1d.dst.yandex.net:443/upload-target/..."", ""method"": ""PUT"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.Files.GetUploadLinkAsync("/", true, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("https://uploader1d.dst.yandex.net:443/upload-target/...", result.Href); Assert.AreEqual("PUT", result.Method); Assert.AreEqual(false, result.Templated); }
public async Task GetOperationStatusTest_InProgress() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + "operations/d80c269ce4eb16c0207f0a15t4a31415313452f9e950cd9576f36b1146ee0e42", httpStatusCode: HttpStatusCode.OK, result: @" { ""status"":""in-progress"" } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Operation result = await diskClient.Commands.GetOperationStatus(new Link { Href = TestHttpClient.BaseUrl + "operations/d80c269ce4eb16c0207f0a15t4a31415313452f9e950cd9576f36b1146ee0e42", Method = "GET" }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual(OperationStatus.InProgress, result.Status); }
public async Task GetDiskInfoTest() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + "", httpStatusCode: HttpStatusCode.OK, result: @" { ""trash_size"": 4631577437, ""total_space"": 319975063552, ""used_space"": 26157681270, ""system_folders"": { ""applications"": ""disk:/Приложения"", ""downloads"": ""disk:/Загрузки/"" } } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Disk result = await diskClient.MetaInfo.GetDiskInfoAsync(CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual(319975063552L, result.TotalSpace); Assert.AreEqual(4631577437L, result.TrashSize); Assert.AreEqual(26157681270L, result.UsedSpace); Assert.NotNull(result.SystemFolders); Assert.AreEqual("disk:/Приложения", result.SystemFolders.Applications); Assert.AreEqual("disk:/Загрузки/", result.SystemFolders.Downloads); }
public async Task UnpublishFolderTestAsync() { var httpClientTest = new TestHttpClient( methodName: "PUT", url: TestHttpClient.BaseUrl + Url.EscapePath(@"resources/unpublish?path=/foo"), httpStatusCode: HttpStatusCode.OK, result: @" { ""href"": ""https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png"", ""method"": ""GET"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.MetaInfo.UnpublishFolderAsync("/foo", cancellationToken : CancellationToken.None); Assert.NotNull(result); Assert.AreEqual("https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png", result.Href); Assert.AreEqual("GET", result.Method); Assert.AreEqual(false, result.Templated); }
public async Task DownloadTest() { var link = new Link { Href = "https://downloader.dst.yandex.ru/disk/", Method = "GET", Templated = false }; var httpClientTest = new TestHttpClient( methodName: link.Method, url: link.Href, httpStatusCode: HttpStatusCode.Created, result: @"Test file content"); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Stream stream = await diskClient.Files.DownloadAsync(link, CancellationToken.None).ConfigureAwait(false); var content = new StreamReader(stream).ReadToEnd(); Assert.AreEqual(@"Test file content", content); }
public async Task GetDownloadLinkTest() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + "resources/download?path=/file.txt", httpStatusCode: HttpStatusCode.OK, result: @" { ""href"": ""https://downloader.dst.yandex.ru/disk/..."", ""method"": ""GET"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.Files.GetDownloadLinkAsync("/file.txt", CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("https://downloader.dst.yandex.ru/disk/...", result.Href); Assert.AreEqual("GET", result.Method); Assert.AreEqual(false, result.Templated); }
public async Task MoveTest() { var httpClientTest = new TestHttpClient( methodName: "POST", url: TestHttpClient.BaseUrl + "resources/move?from=/foo&path=/baz&overwrite=true", httpStatusCode: HttpStatusCode.Accepted, result: @" { ""href"": ""https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe"", ""method"": ""GET"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.Commands.MoveAsync(new MoveFileRequest { From = "/foo", Path = "/baz", Overwrite = true }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe", result.Href); Assert.AreEqual("GET", result.Method); Assert.AreEqual(false, result.Templated); }
public async Task EmptyTrashTest() { var httpClientTest = new TestHttpClient( methodName: "DELETE", url: TestHttpClient.BaseUrl + "trash/resources?path=/foo", httpStatusCode: HttpStatusCode.Accepted, result: @" { ""href"": ""https://cloud-api.yandex.net/v1/disk/operations?id=d80c269ce4eb16c0207f0a15t4a31415313452f9e950cd9576f36b1146ee0e42"", ""method"": ""GET"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.Commands.EmptyTrashAsync(path : "/foo", cancellationToken : CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("https://cloud-api.yandex.net/v1/disk/operations?id=d80c269ce4eb16c0207f0a15t4a31415313452f9e950cd9576f36b1146ee0e42", result.Href); Assert.AreEqual("GET", result.Method); Assert.AreEqual(false, result.Templated); }
public async Task CreateDictionaryTest() { var httpClientTest = new TestHttpClient( methodName: "PUT", url: TestHttpClient.BaseUrl + "resources?path=/foo", httpStatusCode: HttpStatusCode.OK, result: @" { ""href"": ""https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2FMusic"", ""method"": ""GET"", ""templated"": false } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Link result = await diskClient.Commands.CreateDictionaryAsync("/foo", CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2FMusic", result.Href); Assert.AreEqual("GET", result.Method); Assert.AreEqual(false, result.Templated); }
static async Task Main(string[] args) { string oauthToken = "<token>"; IDiskApi diskApi = new DiskHttpApi(oauthToken); await DownloadAllFilesInFolder(diskApi); }
public async Task Upload(Stream file) { var oauthToken = _configuration.OauthToken; var diskApi = new DiskHttpApi(oauthToken); var uploadUrl = await diskApi.Files.GetUploadLinkAsync("/Files/faults1.xlsx", true, CancellationToken.None); await diskApi.Files.UploadAsync(uploadUrl, file); }
public IDiskApi Authorize() { try { IDiskApi TestdiskApi = new DiskHttpApi(Settings.Default.token); logger.Trace("Получение токена"); if (TestdiskApi != null) { Disk result = TestdiskApi.MetaInfo.GetDiskInfoAsync().Result; logger.Trace("Успешное получение токена"); return(TestdiskApi); } else { logger.Error("Ошибка создания экземпляра класса DiskApi"); logger.Fatal("Приложение будет закрыто."); Environment.Exit(-1); } } catch (Exception ex) { logger.Warn("Ошибка получения токена: " + ex.Message); logger.Trace("Попытка получения токена: Инциализация диалогового окна регистраци приложения Яндекс.Диска"); YandexAuthWindow yaDlg = new YandexAuthWindow(); yaDlg.Owner = this; if (yaDlg.ShowDialog() == true) { IDiskApi TestdiskApi = new DiskHttpApi(Settings.Default.token); logger.Trace("Получение токена"); if (TestdiskApi != null) { Disk result = TestdiskApi.MetaInfo.GetDiskInfoAsync().Result; logger.Trace("Успешное получение токена"); return(TestdiskApi); } else { logger.Error("Ошибка создания экземпляра класса DiskApi"); logger.Fatal("Приложение будет закрыто."); Environment.Exit(-1); } } else { logger.Error("Ошибка инициализации диалогового окна регистраци приложения Яндекс.Диска: " + ex.Message); logger.Fatal("Приложение будет закрыто."); Environment.Exit(-1); } } return(null); }
static void Main(string[] args) { //токен для доступа к диску пользователя string token; Console.WriteLine($"client_id = 610e7cb79020423a8b684603d726fb53"); token = InputProcessing("Введите token, например - AgAAAAAUHmUAAAbupw7Sl7yYN0diolNAqPExgJk : "); //имя папки на диске в которую будем заливать файлы string folderName; folderName = InputProcessing("Введите имя папки в которую хотите загрузить файлы: "); //путь откуда берем файлы для загрузки на диск string pathFolder; pathFolder = InputProcessing("Введите путь к папки в которой находятся файлы например - C:\\TestFolder : "); Task.Run(async() => { //ловим ошибки try { var api = new DiskHttpApi(token); //берем все элементы из корневой папки диска var rootFolderData = await api.MetaInfo.GetInfoAsync(new ResourceRequest { //указываем откуда брать все файлы Path = "/" }); //Проверяем есть ли такая папка на диске (если тип равен директория то смотрим имя этой директории) if (!rootFolderData.Embedded.Items.Any(i => i.Type == ResourceType.Dir && i.Name.Equals(folderName))) { //создаем директорию await api.Commands.CreateDictionaryAsync("/" + folderName); } //собираем массив string (пути к файлом в этой дериктории с расширением jpg) var files = Directory.GetFiles(pathFolder); Console.WriteLine("Идет загрузка файлов "); foreach (var file in files) { //GetFileName забирает имя файла из ссылки string fileName = Path.GetFileName(file); //формируем ссылку по которому будем заливать файл. overwrite индикатор перезаписи файлов var link = await api.Files.GetUploadLinkAsync("/" + folderName + "/" + fileName, overwrite: false); using (var fileStream = File.OpenRead(file)) { //загружаем файлы на диск await api.Files.UploadAsync(link, fileStream); } Console.WriteLine($"{fileName} загрузился"); } Console.WriteLine("Загрузка завершена."); } //если поймали ошибку то выводим ее в консоль catch (Exception ex) { Console.WriteLine("Ошибка: " + ex.Message); } }); Console.ReadLine(); }
async Task DownloadJson() { //if (!String.IsNullOrEmpty(oauthToken)) //{ IDiskApi diskApi = new DiskHttpApi(oauthToken); //Upload file from local await diskApi.Files.DownloadFileAsync(path : "foo/data.json", localFile : jsonPath + "/" + "Data.json", cancellationToken : CancellationToken.None); //} //else //{ //} }
async Task UploadSample() { //You should have oauth token from Yandex Passport. //See https://tech.yandex.ru/oauth/ // Create a client instance IDiskApi diskApi = new DiskHttpApi(oauthToken); //Upload file from local await diskApi.Files.UploadFileAsync(path : "/foo/myfile.txt", overwrite : false, localFile : @"C:\[WORK]\myfile.txt", cancellationToken : CancellationToken.None); }
private string GetFileLink(string file) { //You should have oauth token from Yandex Passport. //See https://tech.yandex.ru/oauth/ string oauthToken = "AQAAAABAdszkAAcfhoC3M71Vzkl5pDTQ7p19Nz0"; // Create a client instance IDiskApi diskApi = new DiskHttpApi(oauthToken); //Upload file from local string URL = diskApi.Files.GetDownloadLinkAsync("Project Folder/" + file, cancellationToken: CancellationToken.None).Result.Href; return(URL); }
public async Task GetTrashInfoTest() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + Url.EscapePath("trash/resources?path=/foo/cat.png&limit=30&offset=50"), httpStatusCode: HttpStatusCode.OK, result: @" { ""preview"": ""https://downloader.disk.yandex.ru/preview/..."", ""name"": ""cat.png"", ""created"": ""2014-07-16T13:07:45+04:00"", ""custom_properties"": {""foo"":""1"", ""bar"":""2""}, ""origin_path"": ""disk:/foo/cat.png"", ""modified"": ""2014-07-16T13:07:45+04:00"", ""path"": ""trash:/cat.png"", ""md5"": ""02bab05c02537e53dedd408261e0aadf"", ""type"": ""file"", ""mime_type"": ""image/png"", ""size"": 903337 }, "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Resource result = await diskClient.MetaInfo.GetTrashInfoAsync(new ResourceRequest { Path = "/foo/cat.png", Limit = 30, Offset = 50 }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("cat.png", result.Name); Assert.AreEqual("trash:/cat.png", result.Path); Assert.AreEqual("https://downloader.disk.yandex.ru/preview/...", result.Preview); //Assert.AreEqual("custom_properties", result.CustomProperties); Assert.AreEqual("disk:/foo/cat.png", result.OriginPath); Assert.AreEqual(ResourceType.File, result.Type); Assert.AreEqual("02bab05c02537e53dedd408261e0aadf", result.Md5); Assert.AreEqual("image/png", result.MimeType); Assert.AreEqual(903337, result.Size); Assert.AreEqual(new DateTime(2014, 07, 16, 9, 07, 45), result.Created); Assert.AreEqual(new DateTime(2014, 07, 16, 9, 07, 45), result.Modified); }
private async Task UpdateJson(JsonGoalList goalList, bool islocal, bool isWeb) { goalList.UpdateDate = DateTime.Now; if (islocal) { byte[] bytes = Encoding.Default.GetBytes(JsonConvert.SerializeObject(goalList)); await File.WriteAllBytesAsync(jsonFullName, bytes); } if (isWeb) { IDiskApi diskApi = new DiskHttpApi(oauthToken); await diskApi.Files.UploadFileAsync(path : "/foo/Data.json", overwrite : false, localFile : jsonFullName, cancellationToken : CancellationToken.None); } }
public static async Task Main(string[] args) { GetDirectoryPaths(out UploadDetails options); GetFindFiles(out List <FileDetails> filesList, in options); GetAuthorization(out string oauthToken); IDiskApi diskApi = new DiskHttpApi(oauthToken); await CreateDirectoryAsync(diskApi, options); GetShowMessage("Файл", "Статус"); foreach (FileDetails file in filesList) { await GetStartAsync(options, diskApi, file); } }
static void Main(string[] args) { Console.WriteLine("Start project"); Console.WriteLine(args.Length); var token = "AgAAAAAbypL7AADLWxjV5uI3qkwihLVZSj2-iLE"; // OAuth-token var testPath = args[0]; var destDirectory = args[1]; IDiskApi diskApi = new DiskHttpApi(token); string[] allFiles = Directory.GetFiles(testPath); Task[] tasks = new Task[allFiles.Length]; int i = 0; foreach (var file in allFiles) { try { tasks[i] = UploadFileAsynk(file, diskApi, destDirectory); } catch (Exception e) { Console.WriteLine("Exception with file " + file); Console.WriteLine(e); tasks[i] = null; } finally { i++; } } foreach (var task in tasks) { if (null != task) { task.Wait(); } } Console.WriteLine("Files Uploaded"); }
public async Task UploadTest() { var link = new Link { Href = "https://uploader1d.dst.yandex.net/upload-target/", Method = "PUT", Templated = false }; var httpClientTest = new TestHttpClient( methodName: link.Method, url: link.Href, httpStatusCode: HttpStatusCode.Created, result: @""); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); await diskClient.Files.UploadAsync(link, new MemoryStream(), CancellationToken.None).ConfigureAwait(false); }
public Download(DiskHttpApi diskClient) { DiskClient = diskClient; }
static void Main(string[] args) { Task.Run(async() => { try { //http://localhost:12345/callback#access_token=****************&token_type=bearer&expires_in=31536000 var api = new DiskHttpApi("****************"); var rootFolderData = await api.MetaInfo.GetInfoAsync(new ResourceRequest { Path = "/" }); foreach (var item in rootFolderData.Embedded.Items) { write($"{item.Name}\t{item.Type}\t{item.MimeType}"); } const string folderName = "TestFolder"; if (!rootFolderData.Embedded.Items.Any(i => i.Type == ResourceType.Dir && i.Name.Equals(folderName))) { await api.Commands.CreateDictionaryAsync("/" + folderName); } var files = Directory.GetFiles(Environment.CurrentDirectory, "*.jpg"); foreach (var file in files) { try { var link = await api.Files.GetUploadLinkAsync("/" + folderName + "/" + Path.GetFileName(file), overwrite: false); using (var fs = File.OpenRead(file)) { await api.Files.UploadAsync(link, fs); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } var testFolderData = await api.MetaInfo.GetInfoAsync(new ResourceRequest { Path = "/" + folderName }); foreach (var item in testFolderData.Embedded.Items) { write($"{item.Name}\t{item.Type}\t{item.MimeType}"); } var destDir = Path.Combine(Environment.CurrentDirectory, "Download"); if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } foreach (var item in testFolderData.Embedded.Items) { await api.Files.DownloadFileAsync(path: item.Path, Path.Combine(destDir, item.Name)); var lnk = await api.Files.GetDownloadLinkAsync(item.Path); write(item.Name + "\t" + lnk.Href); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }); Console.WriteLine("Нажмите кнопку"); Console.ReadKey(); }
public Upload(DiskHttpApi diskClient) { DiskClient = diskClient; }
public async Task GetLastUploadedInfoTest() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + Url.EscapePath(@"resources/last-uploaded?media_type=audio,executable&limit=20"), httpStatusCode: HttpStatusCode.OK, result: @" { ""items"": [ { ""name"": ""photo2.png"", ""preview"": ""https://downloader.disk.yandex.ru/preview/..."", ""created"": ""2014-04-22T14:57:13+04:00"", ""modified"": ""2014-04-22T14:57:14+04:00"", ""path"": ""disk:/foo/photo2.png"", ""md5"": ""53f4dc6379c8f95ddf11b9508cfea271"", ""type"": ""file"", ""mime_type"": ""image/png"", ""size"": 54321 }, { ""name"": ""photo1.png"", ""preview"": ""https://downloader.disk.yandex.ru/preview/..."", ""created"": ""2014-04-21T14:57:13+04:00"", ""modified"": ""2014-04-21T14:57:14+04:00"", ""path"": ""disk:/foo/photo1.png"", ""md5"": ""4334dc6379c8f95ddf11b9508cfea271"", ""type"": ""file"", ""mime_type"": ""image/png"", ""size"": 34567 } ], ""limit"": 20, } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); LastUploadedResourceList result = await diskClient.MetaInfo.GetLastUploadedInfoAsync(new LastUploadedResourceRequest { Limit = 20, MediaType = new[] { MediaType.Audio, MediaType.Executable } }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual(20, result.Limit); Assert.IsNotEmpty(result.Items); Assert.AreEqual(2, result.Items.Count); var firstItem = result.Items[0]; Assert.AreEqual("photo2.png", firstItem.Name); Assert.AreEqual("https://downloader.disk.yandex.ru/preview/...", firstItem.Preview); Assert.AreEqual("disk:/foo/photo2.png", firstItem.Path); Assert.AreEqual(ResourceType.File, firstItem.Type); Assert.AreEqual("53f4dc6379c8f95ddf11b9508cfea271", firstItem.Md5); Assert.AreEqual("image/png", firstItem.MimeType); Assert.AreEqual(54321, firstItem.Size); Assert.AreEqual(new DateTime(2014, 04, 22, 10, 57, 13), firstItem.Created); Assert.AreEqual(new DateTime(2014, 04, 22, 10, 57, 14), firstItem.Modified); var secondItem = result.Items[1]; Assert.AreEqual("photo1.png", secondItem.Name); Assert.AreEqual("https://downloader.disk.yandex.ru/preview/...", secondItem.Preview); Assert.AreEqual("disk:/foo/photo1.png", secondItem.Path); Assert.AreEqual(ResourceType.File, secondItem.Type); Assert.AreEqual("4334dc6379c8f95ddf11b9508cfea271", secondItem.Md5); Assert.AreEqual("image/png", secondItem.MimeType); Assert.AreEqual(34567, secondItem.Size); Assert.AreEqual(new DateTime(2014, 04, 21, 10, 57, 13), secondItem.Created); Assert.AreEqual(new DateTime(2014, 04, 21, 10, 57, 14), secondItem.Modified); }
public async Task AppendCustomPropertiesTest() { var httpClientTest = new TestHttpClient( methodName: "PATCH", url: TestHttpClient.BaseUrl + Url.EscapePath(@"resources?path=/foo"), httpStatusCode: HttpStatusCode.OK, request: @"{""custom_properties"":{""foo"":""1"",""bar"":""2""}}", result: @" { ""public_key"": ""HQsmHLoeyBlJf8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8="", ""_embedded"": { ""sort"": """", ""path"": ""disk:/foo"", ""items"": [ { ""path"": ""disk:/foo/bar"", ""type"": ""dir"", ""name"": ""bar"", ""modified"": ""2014-04-22T10:32:49+04:00"", ""created"": ""2014-04-22T10:32:49+04:00"" }, { ""name"": ""photo.png"", ""preview"": ""https://downloader.disk.yandex.ru/preview/..."", ""created"": ""2014-04-21T14:57:13+04:00"", ""modified"": ""2014-04-21T14:57:14+04:00"", ""path"": ""disk:/foo/photo.png"", ""md5"": ""4334dc6379c8f95ddf11b9508cfea271"", ""type"": ""file"", ""mime_type"": ""image/png"", ""size"": 34567 } ], ""limit"": 20, ""offset"": 0 }, ""name"": ""foo"", ""created"": ""2014-04-21T14:54:42+04:00"", ""custom_properties"": {""foo"":""1"", ""bar"":""2""}, ""public_url"": ""https://yadi.sk/d/2AEJCiNTZGiYX"", ""modified"": ""2014-04-22T10:32:49+04:00"", ""path"": ""disk:/foo"", ""type"": ""dir"" } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Resource result = await diskClient.MetaInfo.AppendCustomProperties("/foo", new Dictionary <string, string> { { "foo", "1" }, { "bar", "2" } }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.IsNotEmpty(result.CustomProperties); Assert.AreEqual("1", result.CustomProperties["foo"]); Assert.AreEqual("2", result.CustomProperties["bar"]); }
public async Task GetInfoTest() { var httpClientTest = new TestHttpClient( methodName: "GET", url: TestHttpClient.BaseUrl + Url.EscapePath("resources?sort=name&path=/&limit=20&offset=0"), httpStatusCode: HttpStatusCode.OK, result: @" { ""public_key"": ""HQsmHLoeyBlJf8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8="", ""_embedded"": { ""sort"": """", ""path"": ""disk:/foo"", ""items"": [ { ""path"": ""disk:/foo/bar"", ""type"": ""dir"", ""name"": ""bar"", ""modified"": ""2014-04-22T10:32:49+04:00"", ""created"": ""2014-04-22T10:32:49+04:00"" }, { ""name"": ""photo.png"", ""preview"": ""https://downloader.disk.yandex.ru/preview/..."", ""created"": ""2014-04-21T14:57:13+04:00"", ""modified"": ""2014-04-21T14:57:14+04:00"", ""path"": ""disk:/foo/photo.png"", ""md5"": ""4334dc6379c8f95ddf11b9508cfea271"", ""type"": ""file"", ""mime_type"": ""image/png"", ""size"": 34567 } ], ""limit"": 20, ""offset"": 0 }, ""name"": ""foo"", ""created"": ""2014-04-21T14:54:42+04:00"", ""custom_properties"": {""foo"":""1"", ""bar"":""2""}, ""public_url"": ""https://yadi.sk/d/2AEJCiNTZGiYX"", ""modified"": ""2014-04-22T10:32:49+04:00"", ""path"": ""disk:/foo"", ""type"": ""dir"" } "); var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl, TestHttpClient.ApiKey, logSaver: null, httpClient: httpClientTest); Resource result = await diskClient.MetaInfo.GetInfoAsync(new ResourceRequest { Path = "/", Limit = 20, Offset = 0, Sort = "name" }, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(result); Assert.AreEqual("HQsmHLoeyBlJf8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8=", result.PublicKey); Assert.AreEqual("disk:/foo", result.Path); Assert.NotNull(result.Embedded); Assert.AreEqual("", result.Embedded.Sort); Assert.AreEqual("disk:/foo", result.Embedded.Path); Assert.IsNotEmpty(result.Embedded.Items); Assert.AreEqual(2, result.Embedded.Items.Count); Resource firstItem = result.Embedded.Items[0]; Assert.NotNull(firstItem); Assert.AreEqual("disk:/foo/bar", firstItem.Path); Assert.AreEqual(ResourceType.Dir, firstItem.Type); Assert.AreEqual("bar", firstItem.Name); Assert.AreEqual(new DateTime(2014, 04, 22, 6, 32, 49), firstItem.Created); Assert.AreEqual(new DateTime(2014, 04, 22, 6, 32, 49), firstItem.Modified); Resource secondItem = result.Embedded.Items[1]; Assert.NotNull(secondItem); Assert.AreEqual("photo.png", secondItem.Name); Assert.AreEqual("disk:/foo/photo.png", secondItem.Path); Assert.AreEqual("https://downloader.disk.yandex.ru/preview/...", secondItem.Preview); Assert.AreEqual(ResourceType.File, secondItem.Type); Assert.AreEqual("4334dc6379c8f95ddf11b9508cfea271", secondItem.Md5); Assert.AreEqual("image/png", secondItem.MimeType); Assert.AreEqual(34567, secondItem.Size); Assert.AreEqual(new DateTime(2014, 04, 21, 10, 57, 13), secondItem.Created.ToUniversalTime()); Assert.AreEqual(new DateTime(2014, 04, 21, 10, 57, 14), secondItem.Modified.ToUniversalTime()); Assert.AreEqual("foo", result.Name); //Assert.AreEqual("custom_properties", result.CustomProperties); Assert.AreEqual(new DateTime(2014, 04, 21, 10, 54, 42), result.Created.ToUniversalTime()); Assert.AreEqual(new DateTime(2014, 04, 22, 6, 32, 49), result.Modified.ToUniversalTime()); Assert.AreEqual("disk:/foo", result.Path); Assert.AreEqual(ResourceType.Dir, result.Type); //ToDo: Check undefined properties }