From ad3882d0cb518b555fabb494efd7ed4c96df03de Mon Sep 17 00:00:00 2001 From: Emanuel Palm Date: Sat, 30 Dec 2023 11:47:19 +0100 Subject: [PATCH] small fixes --- .../AzBobbyTables.Core/AzDataTableService.cs | 34 +++++++++++-------- Tests/Module.Tests.ps1 | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Source/AzBobbyTables.Core/AzDataTableService.cs b/Source/AzBobbyTables.Core/AzDataTableService.cs index 389832a..4ec4c84 100644 --- a/Source/AzBobbyTables.Core/AzDataTableService.cs +++ b/Source/AzBobbyTables.Core/AzDataTableService.cs @@ -11,12 +11,12 @@ namespace PipeHow.AzBobbyTables.Core; public class AzDataTableService { - private TableClient tableClient { get; set; } + private TableClient TableClient { get; set; } /// /// Cancellation token used within the AzDataTableService. /// - private CancellationToken cancellationToken { get; } + private CancellationToken CancellationToken { get; } /// /// List of supported data types for the table. @@ -36,7 +36,7 @@ public class AzDataTableService "string" }; - private AzDataTableService(CancellationToken cancellationToken) => this.cancellationToken = cancellationToken; + private AzDataTableService(CancellationToken cancellationToken) => CancellationToken = cancellationToken; private static void CreateIfNotExists(TableClient client, CancellationToken cancellationToken) { @@ -56,14 +56,14 @@ public static AzDataTableService CreateWithConnectionString(string connectionStr { var dataTableService = new AzDataTableService(cancellationToken); - TableClient client = new TableClient(connectionString, tableName); + TableClient client = new(connectionString, tableName); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - dataTableService.tableClient = client; + dataTableService.TableClient = client; return dataTableService; } catch (Exception ex) @@ -79,14 +79,14 @@ public static AzDataTableService CreateWithStorageKey(string storageAccountName, var bobbyService = new AzDataTableService(cancellationToken); var tableEndpoint = new Uri($"https://{storageAccountName}.table.core.windows.net/{tableName}"); - TableClient client = new TableClient(tableEndpoint, tableName, new TableSharedKeyCredential(storageAccountName, storageAccountKey)); + TableClient client = new(tableEndpoint, tableName, new TableSharedKeyCredential(storageAccountName, storageAccountKey)); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - bobbyService.tableClient = client; + bobbyService.TableClient = client; return bobbyService; } catch (Exception ex) @@ -102,14 +102,14 @@ public static AzDataTableService CreateWithToken(string storageAccountName, stri var bobbyService = new AzDataTableService(cancellationToken); var tableEndpoint = new Uri($"https://{storageAccountName}.table.core.windows.net/{tableName}"); - TableClient client = new TableClient(tableEndpoint, tableName, new ExternalTokenCredential(token, DateTimeOffset.Now.Add(TimeSpan.FromHours(1)))); + TableClient client = new(tableEndpoint, tableName, new ExternalTokenCredential(token, DateTimeOffset.Now.Add(TimeSpan.FromHours(1)))); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - bobbyService.tableClient = client; + bobbyService.TableClient = client; return bobbyService; } catch (Exception ex) @@ -134,14 +134,14 @@ public static AzDataTableService CreateWithSAS(Uri sasUrl, string tableName, boo sasUrl = new Uri($"{urlParts.First()}{tableName}?{urlParts.Last()}"); } - TableClient client = new TableClient(sasUrl, sasCredential); + TableClient client = new(sasUrl, sasCredential); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - dataTableService.tableClient = client; + dataTableService.TableClient = client; return dataTableService; } catch (Exception ex) @@ -154,7 +154,7 @@ public void RemoveTable() { try { - tableClient.Delete(); + TableClient.Delete(); } catch (Exception ex) { @@ -368,7 +368,7 @@ public IEnumerable GetEntitiesFromTable(string query, string[] propert try { // Declare type as IAsyncEnumerable to be able to overwrite it with LINQ results further down - IAsyncEnumerable entities = tableClient.QueryAsync(query, null, properties, cancellationToken); + IAsyncEnumerable entities = TableClient.QueryAsync(query, null, properties, CancellationToken); // If user specified one or more properties to sort list by // This may slow the query down a lot with a lot of results @@ -422,7 +422,7 @@ public void ClearTable() { try { - var entities = tableClient.Query((string)null, null, new[] { "PartitionKey", "RowKey" }); + var entities = TableClient.Query((string)null, null, new[] { "PartitionKey", "RowKey" }); var transactions = new List(); @@ -448,7 +448,11 @@ private void SubmitTransaction(IList transactions) // Loop through each group and submit up to 100 at a time for (int i = 0; i < group.Count(); i += 100) { - tableClient.SubmitTransaction(group.Skip(i).Take(100), cancellationToken); + var response = TableClient.SubmitTransaction(group.Skip(i).Take(100), CancellationToken); + foreach (var transactionResult in response.Value) + { + Console.WriteLine(transactionResult.Content.ToString()); + } } } } diff --git a/Tests/Module.Tests.ps1 b/Tests/Module.Tests.ps1 index d747c82..263aef6 100644 --- a/Tests/Module.Tests.ps1 +++ b/Tests/Module.Tests.ps1 @@ -57,7 +57,7 @@ Describe "$ModuleName" { } It 'has no help file with empty documentation sections' { - Get-ChildItem "$RootDirectory\Docs\Help\*.md" | Select-String '{{|}}' | Should -BeNullOrEmpty + Get-ChildItem "$RootDirectory\Docs\Help\*.md" | Select-String '{{ Fill \w+ Description }}' | Should -BeNullOrEmpty } It 'has command defined in file in the correct directory' -TestCases $CommandTestCases {