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 SetFile(string file, CancellationToken token) { file.VerifyNotEmpty(nameof(file)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(SetFile), File = file }); _logger.LogInformation($"Pushing {file} to directory service"); IPropertyResolver resolver = new PropertyResolver(new KeyValuePair <string, string> [0]); IReadOnlyList <string> includeFiles = ConfigurationTools.GetJsonFiles(file, resolver) .Where(x => x != file) .ToList(); List <DirectoryEntry> list = new(); foreach (string includeFile in includeFiles) { _logger.LogInformation($"Processing {includeFile}"); string json = File.ReadAllText(includeFile); IList <DirectoryEntry> readList = Json.Default.Deserialize <IList <DirectoryEntry> >(json) .VerifyNotNull($"Cannot read json file {includeFile}"); list.AddRange(readList); } foreach (DirectoryEntry entry in list) { await _directoryClient.Set(entry, token); _logger.LogInformation($"Writing Id {entry.DirectoryId}"); if (entry.ClassType == ClassTypeName.User) { await CreateIdentity(entry, token); } } _logger.LogInformation($"Completed writing {list.Count} entries from {file} to directory"); }
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(); }
internal async Task DeleteProperty(string documentId, string[] properties, CancellationToken token) { documentId.VerifyNotEmpty(nameof(documentId)); properties.VerifyNotNull(nameof(properties)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(DeleteEntry), DirectoryId = documentId }); var id = new DocumentId(documentId); DirectoryEntry entry = (await _directoryClient.Get(id)) .VerifyNotNull($"{documentId} does not exist"); foreach (var key in properties) { entry.Properties.Remove(key); } await _directoryClient.Set(entry, token); _logger.LogInformation($"Removed properties {properties.Join(", ")} from {documentId}"); }