private static async Task<long> GetNewObjectIdAsync(Credentials credentials) { var httpClient = new ExHttpClient(); var cookies = httpClient.GetCookiesAsync(credentials).Result; var url = await httpClient.GetNewObjectUriAsync(cookies); long newId = long.Parse(url.Segments.Last()); await httpClient.SaveObjectAsync(newId, "Test object created", "test content", cookies); Debug.WriteLine("Created object #{0}", newId); return await Task.FromResult(newId); }
public static void WhenMultipleFilesAreCreated_TheySHouldBeDeletedProperly() { var credentials = CredentialsProvider.Instance.GetCredentials(); var httpClient = new ExHttpClient(); var cookies = httpClient.GetCookiesAsync(credentials).Result; var newIdsCollection = new Collection<long>(); for (int i = 0; i < 2; i++) { httpClient.GetNewObjectUriAsync(cookies).ContinueWith(t => { var newId = long.Parse(t.Result.Segments.Last()); newIdsCollection.Add(newId); httpClient.SaveObjectAsync(newId, "Test object #" + i, "Contents #" + i, cookies).Wait(); Debug.WriteLine("Created object #{0}", t.Result); }).Wait(); } var apiClient = new ExClient(); apiClient.FileList(credentials, 0, 100).ContinueWith(t => { t.Result.Items.Select(it => it.Id).Should().Contain(newIdsCollection); }).Wait(); foreach (long id in newIdsCollection) { httpClient.DeleteObjectAsync(id, cookies).Wait(); Debug.WriteLine("Deleted object #{0}", id); } apiClient.FileList(credentials, 0, 100).ContinueWith(t => { t.Result.Items.Select(it => it.Id).Should().NotContain(newIdsCollection); }).Wait(); }