public async Task GivenDirectoryEntry_WhenRoundTrip_Success() { DirectoryClient client = TestApplication.GetDirectoryClient(); var documentId = new DocumentId("test/unit-tests/entry1"); var query = new QueryParameter() { Filter = "test/unit-tests", Recursive = false, }; IReadOnlyList <DatalakePathItem> search = (await client.Search(query).ReadNext()).Records; if (search.Any(x => x.Name == (string)documentId)) { await client.Delete(documentId); } var entry = new DirectoryEntryBuilder() .SetDirectoryId(documentId) .SetClassType("test") .AddProperty(new EntryProperty { Name = "property1", Value = "value1" }) .Build(); await client.Set(entry); search = (await client.Search(query).ReadNext()).Records; search.Any(x => x.Name == (string)documentId).Should().BeTrue(); DirectoryEntry?readEntry = await client.Get(documentId); readEntry.Should().NotBeNull(); readEntry !.DirectoryId.Should().Be(entry.DirectoryId); readEntry.ClassType.Should().Be(entry.ClassType); readEntry.ETag.Should().NotBeNull(); readEntry.Properties.Count.Should().Be(1); readEntry.Properties.Values.First().Action(x => { (x == entry.Properties.Values.First()).Should().BeTrue(); }); await client.Delete(documentId); search = (await client.Search(query).ReadNext()).Records; search.Any(x => x.Name == (string)documentId).Should().BeFalse(); }
public async Task GivenDirectoryEntry_WhenRoundTripWithETag_Fail() { DirectoryClient client = TestApplication.GetDirectoryClient(); var documentId = new DocumentId("test/unit-tests/entry1"); var query = new QueryParameter() { Filter = "test", Recursive = false, }; await client.Delete(documentId); var entry = new DirectoryEntryBuilder() .SetDirectoryId(documentId) .SetClassType("test") .AddProperty(new EntryProperty { Name = "property1", Value = "value1" }) .Build(); await client.Set(entry); DirectoryEntry?readEntry = await client.Get(documentId); readEntry.Should().NotBeNull(); readEntry !.ETag.Should().NotBeNull(); readEntry.Properties.Count.Should().Be(1); var updateEntry = new DirectoryEntryBuilder(readEntry) .SetClassType("test-next") .SetETag(new ETag("0xFF9CA90CB9F5120")) .AddProperty(new EntryProperty { Name = "property2", Value = "value2" }) .Build(); bool failed; try { await client.Set(updateEntry); failed = false; } catch (Azure.RequestFailedException) { failed = true; } failed.Should().BeTrue(); await client.Delete(documentId); IReadOnlyList <DatalakePathItem> search = (await client.Search(query).ReadNext()).Records; search.Any(x => x.Name == (string)documentId).Should().BeFalse(); }
public async Task WriteFile(string file, string path, bool recursive, CancellationToken token) { file.VerifyNotEmpty(nameof(file)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(WriteFile), File = file, Path = path, Recursive = recursive }); _logger.LogInformation($"Reading directory at {path}, recursive={recursive}..."); var query = new QueryParameter() { Filter = path, Recursive = recursive, }; BatchSetCursor <DatalakePathItem> batch = _directoryClient.Search(query); var list = new List <DirectoryEntry>(); while (true) { BatchSet <DatalakePathItem> batchSet = await batch.ReadNext(token); if (batchSet.IsEndSignaled) { break; } foreach (var entry in batchSet.Records) { var documentId = new DocumentId(entry.Name); DirectoryEntry?directoryEntry = await _directoryClient.Get(documentId, token); if (directoryEntry == null) { _logger.LogWarning($"Directory entry for {entry.Name} was not found"); continue; } list.Add(directoryEntry); } } string json = Json.Default.SerializeFormat(list); File.WriteAllText(path, json); _logger.LogInformation($"{list.Count} directory entries written to {file}"); }
public async Task List(string path, bool recursive, CancellationToken token) { path.VerifyNotEmpty(nameof(path)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(List), Path = path }); var query = new QueryParameter() { Filter = path, Recursive = recursive, }; BatchSetCursor <DatalakePathItem> batch = _directoryClient.Search(query); int index = 0; var list = new List <string> { $"Listing directory from path {path}, recursive={recursive}...", "", }; while (true) { BatchSet <DatalakePathItem> batchSet = await batch.ReadNext(token); if (batchSet.IsEndSignaled) { break; } batchSet.Records .Where(x => !(x.IsDirectory == true)) .ForEach(x => list.Add($"({index++}) {x.Name}")); } list.Add(""); list.Add($"Completed, {index} listed"); _logger.LogInformation(list.Join(Environment.NewLine)); }