diff --git a/Kontent.Ai.Management.Tests/Data/ElementsData.cs b/Kontent.Ai.Management.Tests/Data/ElementsData.cs index 04f2072e..4e467264 100644 --- a/Kontent.Ai.Management.Tests/Data/ElementsData.cs +++ b/Kontent.Ai.Management.Tests/Data/ElementsData.cs @@ -140,7 +140,7 @@ private static dynamic GetRichTextAsDynamic(Guid? elementId, string value, IEnum dynamic element = new ExpandoObject(); element.element = GetElement(elementId.Value.ToString("d")); element.value = value; - element.components = compoments.Select(x => GetRichTextComponentAsDynamic(x)); + element.components = compoments.Select(GetRichTextComponentAsDynamic); return element; } diff --git a/Kontent.Ai.Management.Tests/ManagementClientTests/AssetTests.cs b/Kontent.Ai.Management.Tests/ManagementClientTests/AssetTests.cs index 49b536c8..7a0a16b9 100644 --- a/Kontent.Ai.Management.Tests/ManagementClientTests/AssetTests.cs +++ b/Kontent.Ai.Management.Tests/ManagementClientTests/AssetTests.cs @@ -33,7 +33,7 @@ public async Task ListAssetsAsync_DynamicallyTyped_WithMorePages_ListsAssets() "00000000-0000-0000-0000-000000000000", "10000000-0000-0000-0000-000000000000", "20000000-0000-0000-0000-000000000000" - }.Select(x => GetExpectedDynamicAssetModel(assetId: x)); + }.Select(GetExpectedDynamicAssetModel); var response = await client.ListAssetsAsync().GetAllAsync(); @@ -49,7 +49,7 @@ public async Task ListAssetsAsync_StronglyTyped_WithMorePages_ListsAssets() "00000000-0000-0000-0000-000000000000", "10000000-0000-0000-0000-000000000000", "20000000-0000-0000-0000-000000000000" - }.Select(x => GetExpectedStronglyTypedAssetModel(assetId: x)); + }.Select(GetExpectedStronglyTypedAssetModel); var response = await client.ListAssetsAsync().GetAllAsync(); diff --git a/Kontent.Ai.Management.Tests/Modules/Extensions/PropertyInfoExtensionsTests.cs b/Kontent.Ai.Management.Tests/Modules/Extensions/PropertyInfoExtensionsTests.cs index 5c04d3dd..7d2693f7 100644 --- a/Kontent.Ai.Management.Tests/Modules/Extensions/PropertyInfoExtensionsTests.cs +++ b/Kontent.Ai.Management.Tests/Modules/Extensions/PropertyInfoExtensionsTests.cs @@ -40,7 +40,7 @@ public void GetKontentElementCodename_ThrowsIfNoAttribute() { var property = typeof(PropertyInfoExtensionsTestsSampleClass).GetProperty("Property1"); - Assert.Throws(() => property.GetKontentElementCodename()); + Assert.Throws(property.GetKontentElementCodename); } [Fact] diff --git a/Kontent.Ai.Management/Extensions/ManagementClientExtensions.cs b/Kontent.Ai.Management/Extensions/ManagementClientExtensions.cs index f931d6f5..b9f0bacb 100644 --- a/Kontent.Ai.Management/Extensions/ManagementClientExtensions.cs +++ b/Kontent.Ai.Management/Extensions/ManagementClientExtensions.cs @@ -21,15 +21,9 @@ public static class ManagementClientExtensions /// The instance that represents updated content item. public async static Task UpsertContentItemAsync(this IManagementClient client, Reference identifier, ContentItemModel contentItem) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (contentItem == null) - { - throw new ArgumentNullException(nameof(contentItem)); - } + ArgumentNullException.ThrowIfNull(contentItem); var contentItemUpdateModel = new ContentItemUpsertModel { @@ -52,14 +46,8 @@ public async static Task UpsertContentItemAsync(this IManageme /// Updated values for the asset. public async static Task CreateAssetAsync(this IManagementClient client, FileContentSource fileContent, AssetCreateModel assetCreateModel) { - if (fileContent == null) - { - throw new ArgumentNullException(nameof(fileContent)); - } - if (assetCreateModel == null) - { - throw new ArgumentNullException(nameof(assetCreateModel)); - } + ArgumentNullException.ThrowIfNull(fileContent); + ArgumentNullException.ThrowIfNull(assetCreateModel); var fileResult = await client.UploadFileAsync(fileContent); @@ -78,14 +66,8 @@ public async static Task CreateAssetAsync(this IManagementClient cli /// Updated values for the strongly typed asset. public async static Task> CreateAssetAsync(this IManagementClient client, FileContentSource fileContent, AssetCreateModel assetCreateModel) where T : new() { - if (fileContent == null) - { - throw new ArgumentNullException(nameof(fileContent)); - } - if (assetCreateModel == null) - { - throw new ArgumentNullException(nameof(assetCreateModel)); - } + ArgumentNullException.ThrowIfNull(fileContent); + ArgumentNullException.ThrowIfNull(assetCreateModel); var fileResult = await client.UploadFileAsync(fileContent); @@ -106,20 +88,11 @@ public async static Task CreateAssetAsync(this IManagementClient cli /// The instance that represents created or updated asset. public async static Task UpsertAssetAsync(this IManagementClient client, Reference identifier, FileContentSource fileContent, AssetUpsertModel upsertModel) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (fileContent == null) - { - throw new ArgumentNullException(nameof(fileContent)); - } + ArgumentNullException.ThrowIfNull(fileContent); - if (upsertModel == null) - { - throw new ArgumentNullException(nameof(upsertModel)); - } + ArgumentNullException.ThrowIfNull(upsertModel); var fileResult = await client.UploadFileAsync(fileContent); @@ -140,20 +113,11 @@ public async static Task UpsertAssetAsync(this IManagementClient cli /// The instance that represents created or updated strongly typed asset. public async static Task> UpsertAssetAsync(this IManagementClient client, Reference identifier, FileContentSource fileContent, AssetUpsertModel upsertModel) where T : new() { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (fileContent == null) - { - throw new ArgumentNullException(nameof(fileContent)); - } + ArgumentNullException.ThrowIfNull(fileContent); - if (upsertModel == null) - { - throw new ArgumentNullException(nameof(upsertModel)); - } + ArgumentNullException.ThrowIfNull(upsertModel); var fileResult = await client.UploadFileAsync(fileContent); diff --git a/Kontent.Ai.Management/ManagementClient.Asset.cs b/Kontent.Ai.Management/ManagementClient.Asset.cs index 016da50e..bc3ac8e1 100644 --- a/Kontent.Ai.Management/ManagementClient.Asset.cs +++ b/Kontent.Ai.Management/ManagementClient.Asset.cs @@ -39,10 +39,7 @@ public async Task> ListAssetsAsync() /// public async Task GetAssetAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildAssetsUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -61,15 +58,9 @@ public async Task GetAssetAsync(Reference identifier) /// public async Task UpsertAssetAsync(Reference identifier, AssetUpsertModel asset) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (asset == null) - { - throw new ArgumentNullException(nameof(asset)); - } + ArgumentNullException.ThrowIfNull(asset); var endpointUrl = _urlBuilder.BuildAssetsUrl(identifier); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, asset); @@ -80,10 +71,7 @@ public async Task UpsertAssetAsync(Reference identifier, AssetUpsert /// public async Task> UpsertAssetAsync(Reference identifier, AssetUpsertModel asset) where T : new() { - if (asset == null) - { - throw new ArgumentNullException(nameof(asset)); - } + ArgumentNullException.ThrowIfNull(asset); var result = await UpsertAssetAsync(identifier, _modelProvider.GetAssetUpsertModel(asset)); @@ -93,10 +81,7 @@ public async Task UpsertAssetAsync(Reference identifier, AssetUpsert /// public async Task CreateAssetAsync(AssetCreateModel asset) { - if (asset == null) - { - throw new ArgumentNullException(nameof(asset)); - } + ArgumentNullException.ThrowIfNull(asset); var endpointUrl = _urlBuilder.BuildAssetsUrl(); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, asset); @@ -107,10 +92,7 @@ public async Task CreateAssetAsync(AssetCreateModel asset) /// public async Task> CreateAssetAsync(AssetCreateModel asset) where T : new() { - if (asset == null) - { - throw new ArgumentNullException(nameof(asset)); - } + ArgumentNullException.ThrowIfNull(asset); var result = await CreateAssetAsync(_modelProvider.GetAssetCreateModel(asset)); @@ -120,10 +102,7 @@ public async Task CreateAssetAsync(AssetCreateModel asset) /// public async Task DeleteAssetAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildAssetsUrl(identifier); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Delete); @@ -132,10 +111,7 @@ public async Task DeleteAssetAsync(Reference identifier) /// public async Task UploadFileAsync(FileContentSource fileContent) { - if (fileContent == null) - { - throw new ArgumentNullException(nameof(fileContent)); - } + ArgumentNullException.ThrowIfNull(fileContent); var stream = fileContent.OpenReadStream(); try diff --git a/Kontent.Ai.Management/ManagementClient.AssetFolder.cs b/Kontent.Ai.Management/ManagementClient.AssetFolder.cs index 40d9b7c8..893eccb9 100644 --- a/Kontent.Ai.Management/ManagementClient.AssetFolder.cs +++ b/Kontent.Ai.Management/ManagementClient.AssetFolder.cs @@ -21,10 +21,7 @@ public async Task GetAssetFoldersAsync() /// public async Task CreateAssetFoldersAsync(AssetFolderCreateModel folder) { - if (folder == null) - { - throw new ArgumentNullException(nameof(folder)); - } + ArgumentNullException.ThrowIfNull(folder); var endpointUrl = _urlBuilder.BuildAssetFoldersUrl(); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, folder); @@ -35,10 +32,7 @@ public async Task CreateAssetFoldersAsync(AssetFolderCreateMo /// public async Task ModifyAssetFoldersAsync(IEnumerable changes) { - if (changes == null) - { - throw new ArgumentNullException(nameof(changes)); - } + ArgumentNullException.ThrowIfNull(changes); var endpointUrl = _urlBuilder.BuildAssetFoldersUrl(); var response = await _actionInvoker.InvokeMethodAsync, AssetFoldersModel>(endpointUrl, new HttpMethod("PATCH"), changes); diff --git a/Kontent.Ai.Management/ManagementClient.AssetRendition.cs b/Kontent.Ai.Management/ManagementClient.AssetRendition.cs index 932147af..eea493a3 100644 --- a/Kontent.Ai.Management/ManagementClient.AssetRendition.cs +++ b/Kontent.Ai.Management/ManagementClient.AssetRendition.cs @@ -11,10 +11,7 @@ public partial class ManagementClient /// public async Task> ListAssetRenditionsAsync(Reference assetIdentifier) { - if (assetIdentifier == null) - { - throw new ArgumentNullException(nameof(assetIdentifier)); - } + ArgumentNullException.ThrowIfNull(assetIdentifier); var endpointUrl = _urlBuilder.BuildAssetRenditionsUrl(assetIdentifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -29,10 +26,7 @@ public async Task> ListAssetRendition /// public async Task GetAssetRenditionAsync(AssetRenditionIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildAssetRenditionsUrl(identifier); return await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -41,14 +35,8 @@ public async Task GetAssetRenditionAsync(AssetRenditionIden /// public async Task UpdateAssetRenditionAsync(AssetRenditionIdentifier identifier, AssetRenditionUpdateModel updateModel) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } - if (updateModel == null) - { - throw new ArgumentNullException(nameof(updateModel)); - } + ArgumentNullException.ThrowIfNull(identifier); + ArgumentNullException.ThrowIfNull(updateModel); var endpointUrl = _urlBuilder.BuildAssetRenditionsUrl(identifier); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, updateModel); @@ -57,15 +45,9 @@ public async Task UpdateAssetRenditionAsync(AssetRenditionI /// public async Task CreateAssetRenditionAsync(Reference assetIdentifier, AssetRenditionCreateModel createModel) { - if (assetIdentifier == null) - { - throw new ArgumentNullException(nameof(assetIdentifier)); - } + ArgumentNullException.ThrowIfNull(assetIdentifier); - if (createModel == null) - { - throw new ArgumentNullException(nameof(createModel)); - } + ArgumentNullException.ThrowIfNull(createModel); var endpointUrl = _urlBuilder.BuildAssetRenditionsUrl(assetIdentifier); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, createModel); diff --git a/Kontent.Ai.Management/ManagementClient.Collection.cs b/Kontent.Ai.Management/ManagementClient.Collection.cs index fa93908c..c39a2c87 100644 --- a/Kontent.Ai.Management/ManagementClient.Collection.cs +++ b/Kontent.Ai.Management/ManagementClient.Collection.cs @@ -19,10 +19,7 @@ public async Task ListCollectionsAsync() /// public async Task ModifyCollectionAsync(IEnumerable changes) { - if (changes == null) - { - throw new ArgumentNullException(nameof(changes)); - } + ArgumentNullException.ThrowIfNull(changes); var endpointUrl = _urlBuilder.BuildCollectionsUrl(); return await _actionInvoker.InvokeMethodAsync, CollectionsModel>(endpointUrl, new HttpMethod("PATCH"), changes); diff --git a/Kontent.Ai.Management/ManagementClient.ContentItem.cs b/Kontent.Ai.Management/ManagementClient.ContentItem.cs index 4866e431..185c1db5 100644 --- a/Kontent.Ai.Management/ManagementClient.ContentItem.cs +++ b/Kontent.Ai.Management/ManagementClient.ContentItem.cs @@ -15,7 +15,7 @@ public async Task> ListContentItemsAsync var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Items); @@ -24,10 +24,7 @@ public async Task> ListContentItemsAsync /// public async Task GetContentItemAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildItemUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -38,10 +35,7 @@ public async Task GetContentItemAsync(Reference identifier) /// public async Task CreateContentItemAsync(ContentItemCreateModel contentItem) { - if (contentItem == null) - { - throw new ArgumentNullException(nameof(contentItem)); - } + ArgumentNullException.ThrowIfNull(contentItem); var endpointUrl = _urlBuilder.BuildItemsUrl(); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, contentItem); @@ -52,15 +46,9 @@ public async Task CreateContentItemAsync(ContentItemCreateMode /// public async Task UpsertContentItemAsync(Reference identifier, ContentItemUpsertModel contentItem) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (contentItem == null) - { - throw new ArgumentNullException(nameof(contentItem)); - } + ArgumentNullException.ThrowIfNull(contentItem); var endpointUrl = _urlBuilder.BuildItemUrl(identifier); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, contentItem); @@ -71,10 +59,7 @@ public async Task UpsertContentItemAsync(Reference identifier, /// public async Task DeleteContentItemAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildItemUrl(identifier); diff --git a/Kontent.Ai.Management/ManagementClient.ContentType.cs b/Kontent.Ai.Management/ManagementClient.ContentType.cs index 8e58ae4d..1ab629f4 100644 --- a/Kontent.Ai.Management/ManagementClient.ContentType.cs +++ b/Kontent.Ai.Management/ManagementClient.ContentType.cs @@ -18,7 +18,7 @@ public async Task> ListContentTypesAsync var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Types); @@ -27,10 +27,7 @@ public async Task> ListContentTypesAsync /// public async Task GetContentTypeAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildTypeUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -41,10 +38,7 @@ public async Task GetContentTypeAsync(Reference identifier) /// public async Task CreateContentTypeAsync(ContentTypeCreateModel contentType) { - if (contentType == null) - { - throw new ArgumentNullException(nameof(contentType)); - } + ArgumentNullException.ThrowIfNull(contentType); var endpointUrl = _urlBuilder.BuildTypeUrl(); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, contentType); @@ -55,10 +49,7 @@ public async Task CreateContentTypeAsync(ContentTypeCreateMode /// public async Task DeleteContentTypeAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildTypeUrl(identifier); @@ -68,10 +59,7 @@ public async Task DeleteContentTypeAsync(Reference identifier) /// public async Task ModifyContentTypeAsync(Reference identifier, IEnumerable changes) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); if (changes == null || !changes.Any()) { diff --git a/Kontent.Ai.Management/ManagementClient.ContentTypeSnippet.cs b/Kontent.Ai.Management/ManagementClient.ContentTypeSnippet.cs index 41e2b9c6..a7d7653e 100644 --- a/Kontent.Ai.Management/ManagementClient.ContentTypeSnippet.cs +++ b/Kontent.Ai.Management/ManagementClient.ContentTypeSnippet.cs @@ -18,7 +18,7 @@ public async Task> ListContentTyp var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Snippets); @@ -27,10 +27,7 @@ public async Task> ListContentTyp /// public async Task GetContentTypeSnippetAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildSnippetsUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -41,10 +38,7 @@ public async Task GetContentTypeSnippetAsync(Reference /// public async Task CreateContentTypeSnippetAsync(ContentTypeSnippetCreateModel contentTypeSnippet) { - if (contentTypeSnippet == null) - { - throw new ArgumentNullException(nameof(contentTypeSnippet)); - } + ArgumentNullException.ThrowIfNull(contentTypeSnippet); var endpointUrl = _urlBuilder.BuildSnippetsUrl(); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, contentTypeSnippet); @@ -55,10 +49,7 @@ public async Task CreateContentTypeSnippetAsync(Content /// public async Task DeleteContentTypeSnippetAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildSnippetsUrl(identifier); @@ -68,10 +59,7 @@ public async Task DeleteContentTypeSnippetAsync(Reference identifier) /// public async Task ModifyContentTypeSnippetAsync(Reference identifier, IEnumerable changes) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); if (changes == null || !changes.Any()) { diff --git a/Kontent.Ai.Management/ManagementClient.Environment.cs b/Kontent.Ai.Management/ManagementClient.Environment.cs index d91fcb88..6e75af55 100644 --- a/Kontent.Ai.Management/ManagementClient.Environment.cs +++ b/Kontent.Ai.Management/ManagementClient.Environment.cs @@ -12,10 +12,7 @@ public partial class ManagementClient /// public async Task CloneEnvironmentAsync(EnvironmentCloneModel cloneEnvironmentModel) { - if (cloneEnvironmentModel == null) - { - throw new ArgumentNullException(nameof(cloneEnvironmentModel)); - } + ArgumentNullException.ThrowIfNull(cloneEnvironmentModel); var endpointUrl = _urlBuilder.BuildCloneEnvironmentUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, cloneEnvironmentModel); @@ -38,10 +35,7 @@ public async Task DeleteEnvironmentAsync() /// public async Task MarkEnvironmentAsProductionAsync(MarkAsProductionModel markAsProductionModel) { - if (markAsProductionModel == null) - { - throw new ArgumentNullException(nameof(markAsProductionModel)); - } + ArgumentNullException.ThrowIfNull(markAsProductionModel); var endpointUrl = _urlBuilder.BuildMarkEnvironmentAsProductionUrl(); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, markAsProductionModel); @@ -50,10 +44,7 @@ public async Task MarkEnvironmentAsProductionAsync(MarkAsProductionModel markAsP /// public async Task ModifyEnvironmentAsync(IEnumerable changes) { - if (changes == null) - { - throw new ArgumentNullException(nameof(changes)); - } + ArgumentNullException.ThrowIfNull(changes); var endpointUrl = _urlBuilder.BuildEnvironmentUrl(); return await _actionInvoker.InvokeMethodAsync, EnvironmentModel>(endpointUrl, new HttpMethod("PATCH"), changes); diff --git a/Kontent.Ai.Management/ManagementClient.Language.cs b/Kontent.Ai.Management/ManagementClient.Language.cs index e55b1f6f..573b14be 100644 --- a/Kontent.Ai.Management/ManagementClient.Language.cs +++ b/Kontent.Ai.Management/ManagementClient.Language.cs @@ -16,7 +16,7 @@ public async Task> ListLanguagesAsync() var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Languages); @@ -25,10 +25,7 @@ public async Task> ListLanguagesAsync() /// public async Task GetLanguageAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildLanguagesUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -39,10 +36,7 @@ public async Task GetLanguageAsync(Reference identifier) /// public async Task CreateLanguageAsync(LanguageCreateModel language) { - if (language == null) - { - throw new ArgumentNullException(nameof(language)); - } + ArgumentNullException.ThrowIfNull(language); var endpointUrl = _urlBuilder.BuildLanguagesUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, language); @@ -51,10 +45,7 @@ public async Task CreateLanguageAsync(LanguageCreateModel languag /// public async Task ModifyLanguageAsync(Reference identifier, IEnumerable changes) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildLanguagesUrl(identifier); return await _actionInvoker.InvokeMethodAsync, LanguageModel>(endpointUrl, new HttpMethod("PATCH"), changes); diff --git a/Kontent.Ai.Management/ManagementClient.LanguageVariant.cs b/Kontent.Ai.Management/ManagementClient.LanguageVariant.cs index fb468839..cfc78e54 100644 --- a/Kontent.Ai.Management/ManagementClient.LanguageVariant.cs +++ b/Kontent.Ai.Management/ManagementClient.LanguageVariant.cs @@ -15,10 +15,7 @@ public partial class ManagementClient /// public async Task> ListLanguageVariantsByItemAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildListVariantsByItemUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync>(endpointUrl, HttpMethod.Get); @@ -29,16 +26,13 @@ public async Task> ListLanguageVariantsByItemA /// public async Task> ListLanguageVariantsByTypeAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildListVariantsByTypeUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Variants); @@ -47,16 +41,13 @@ public async Task> ListLanguageVaria /// public async Task>> ListLanguageVariantsByTypeAsync(Reference identifier) where T : new() { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildListVariantsByTypeUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseMappedModel>( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Variants, @@ -66,16 +57,13 @@ public async Task> ListLanguageVaria /// public async Task> ListLanguageVariantsOfContentTypeWithComponentsAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildListVariantsByComponentUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Variants); @@ -84,16 +72,13 @@ public async Task> ListLanguageVaria /// public async Task> ListLanguageVariantsByCollectionAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildListVariantsByCollectionUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Variants); @@ -108,7 +93,7 @@ public async Task> ListLanguageVaria var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Variants); @@ -117,24 +102,18 @@ public async Task> ListLanguageVaria /// public async Task>> ListLanguageVariantsByItemAsync(Reference identifier) where T : new() { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildListVariantsByItemUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync>(endpointUrl, HttpMethod.Get); - return response.Select(x => _modelProvider.GetLanguageVariantModel(x)).ToList(); + return response.Select(_modelProvider.GetLanguageVariantModel).ToList(); } /// public async Task GetLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildVariantsUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -145,10 +124,7 @@ public async Task GetLanguageVariantAsync(LanguageVariantI /// public async Task> GetLanguageVariantAsync(LanguageVariantIdentifier identifier) where T : new() { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildVariantsUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -159,10 +135,7 @@ public async Task GetLanguageVariantAsync(LanguageVariantI /// public async Task GetPublishedLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildPublishedVariantsUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -173,10 +146,7 @@ public async Task GetPublishedLanguageVariantAsync(Languag /// public async Task> GetPublishedLanguageVariantAsync(LanguageVariantIdentifier identifier) where T : new() { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildPublishedVariantsUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -187,15 +157,9 @@ public async Task GetPublishedLanguageVariantAsync(Languag /// public async Task UpsertLanguageVariantAsync(LanguageVariantIdentifier identifier, LanguageVariantUpsertModel languageVariantUpsertModel) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (languageVariantUpsertModel == null) - { - throw new ArgumentNullException(nameof(languageVariantUpsertModel)); - } + ArgumentNullException.ThrowIfNull(languageVariantUpsertModel); var endpointUrl = _urlBuilder.BuildVariantsUrl(identifier); var response = await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, languageVariantUpsertModel); @@ -206,15 +170,9 @@ public async Task UpsertLanguageVariantAsync(LanguageVaria /// public async Task UpsertLanguageVariantAsync(LanguageVariantIdentifier identifier, LanguageVariantModel languageVariant) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (languageVariant == null) - { - throw new ArgumentNullException(nameof(languageVariant)); - } + ArgumentNullException.ThrowIfNull(languageVariant); var languageVariantUpsertModel = new LanguageVariantUpsertModel(languageVariant); @@ -224,10 +182,7 @@ public async Task UpsertLanguageVariantAsync(LanguageVaria /// public async Task> UpsertLanguageVariantAsync(LanguageVariantIdentifier identifier, T variantElements, WorkflowStepIdentifier workflow = null) where T : new() { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); if (variantElements == null) { @@ -244,10 +199,7 @@ public async Task UpsertLanguageVariantAsync(LanguageVaria /// public async Task DeleteLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildVariantsUrl(identifier); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Delete); diff --git a/Kontent.Ai.Management/ManagementClient.LegacyWebhook.cs b/Kontent.Ai.Management/ManagementClient.LegacyWebhook.cs index 3aba1c4b..5c8c78a4 100644 --- a/Kontent.Ai.Management/ManagementClient.LegacyWebhook.cs +++ b/Kontent.Ai.Management/ManagementClient.LegacyWebhook.cs @@ -19,10 +19,7 @@ public async Task> ListLegacyWebhooksAsync() /// public async Task GetLegacyWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildLegacyWebhooksUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -33,10 +30,7 @@ public async Task GetLegacyWebhookAsync(Reference identifier /// public async Task CreateLegacyWebhookAsync(LegacyWebhookCreateModel webhook) { - if (webhook == null) - { - throw new ArgumentNullException(nameof(webhook)); - } + ArgumentNullException.ThrowIfNull(webhook); var endpointUrl = _urlBuilder.BuildLegacyWebhooksUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, webhook); @@ -45,10 +39,7 @@ public async Task CreateLegacyWebhookAsync(LegacyWebhookCrea /// public async Task DeleteLegacyWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildLegacyWebhooksUrl(identifier); @@ -58,10 +49,7 @@ public async Task DeleteLegacyWebhookAsync(Reference identifier) /// public async Task EnableLegacyWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildLegacyWebhooksEnableUrl(identifier); @@ -71,10 +59,7 @@ public async Task EnableLegacyWebhookAsync(Reference identifier) /// public async Task DisableLegacyWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildLegacyWebhooksDisableUrl(identifier); diff --git a/Kontent.Ai.Management/ManagementClient.ProjectRole.cs b/Kontent.Ai.Management/ManagementClient.ProjectRole.cs index 358abd2e..34140818 100644 --- a/Kontent.Ai.Management/ManagementClient.ProjectRole.cs +++ b/Kontent.Ai.Management/ManagementClient.ProjectRole.cs @@ -18,10 +18,7 @@ public async Task ListEnvironmentRolesAsync() /// public async Task GetEnvironmentRoleAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildEnvironmentRoleUrl(identifier); return await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); diff --git a/Kontent.Ai.Management/ManagementClient.ProjectUser.cs b/Kontent.Ai.Management/ManagementClient.ProjectUser.cs index 5fe104c0..ff3951ef 100644 --- a/Kontent.Ai.Management/ManagementClient.ProjectUser.cs +++ b/Kontent.Ai.Management/ManagementClient.ProjectUser.cs @@ -11,10 +11,7 @@ public partial class ManagementClient /// public async Task InviteUserIntoEnvironmentAsync(UserInviteModel invitation) { - if (invitation == null) - { - throw new ArgumentNullException(nameof(invitation)); - } + ArgumentNullException.ThrowIfNull(invitation); var endpointUrl = _urlBuilder.BuildUsersUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, invitation); @@ -23,15 +20,9 @@ public async Task InviteUserIntoEnvironmentAsync(UserInviteModel invi /// public async Task ModifyUsersRolesAsync(UserIdentifier identifier, UserModel user) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (user == null) - { - throw new ArgumentNullException(nameof(user)); - } + ArgumentNullException.ThrowIfNull(user); var endpointUrl = _urlBuilder.BuildModifyUsersRoleUrl(identifier); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, user); diff --git a/Kontent.Ai.Management/ManagementClient.ProjectValidation.cs b/Kontent.Ai.Management/ManagementClient.ProjectValidation.cs index 6ec1d087..cfd927a5 100644 --- a/Kontent.Ai.Management/ManagementClient.ProjectValidation.cs +++ b/Kontent.Ai.Management/ManagementClient.ProjectValidation.cs @@ -38,7 +38,7 @@ public async Task> ListAsyn var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Issues); diff --git a/Kontent.Ai.Management/ManagementClient.Publishing.cs b/Kontent.Ai.Management/ManagementClient.Publishing.cs index 6f3afe3e..c97590dc 100644 --- a/Kontent.Ai.Management/ManagementClient.Publishing.cs +++ b/Kontent.Ai.Management/ManagementClient.Publishing.cs @@ -15,15 +15,9 @@ public sealed partial class ManagementClient /// public async Task ChangeLanguageVariantWorkflowAsync(LanguageVariantIdentifier identifier, WorkflowStepIdentifier workflowStepIdentifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (workflowStepIdentifier == null) - { - throw new ArgumentNullException(nameof(workflowStepIdentifier)); - } + ArgumentNullException.ThrowIfNull(workflowStepIdentifier); var endpointUrl = _urlBuilder.BuildWorkflowChangeUrl(identifier); @@ -33,10 +27,7 @@ public async Task ChangeLanguageVariantWorkflowAsync(LanguageVariantIdentifier i /// public async Task PublishLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildPublishVariantUrl(identifier); @@ -46,15 +37,9 @@ public async Task PublishLanguageVariantAsync(LanguageVariantIdentifier identifi /// public async Task SchedulePublishingOfLanguageVariantAsync(LanguageVariantIdentifier identifier, ScheduleModel scheduleModel) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (scheduleModel == null) - { - throw new ArgumentNullException(nameof(scheduleModel)); - } + ArgumentNullException.ThrowIfNull(scheduleModel); var endpointUrl = _urlBuilder.BuildPublishVariantUrl(identifier); @@ -64,10 +49,7 @@ public async Task SchedulePublishingOfLanguageVariantAsync(LanguageVariantIdenti /// public async Task CancelPublishingOfLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildCancelPublishingVariantUrl(identifier); @@ -77,10 +59,7 @@ public async Task CancelPublishingOfLanguageVariantAsync(LanguageVariantIdentifi /// public async Task UnpublishLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildUnpublishVariantUrl(identifier); @@ -90,10 +69,7 @@ public async Task UnpublishLanguageVariantAsync(LanguageVariantIdentifier identi /// public async Task CancelUnpublishingOfLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildCancelUnpublishingVariantUrl(identifier); @@ -103,15 +79,9 @@ public async Task CancelUnpublishingOfLanguageVariantAsync(LanguageVariantIdenti /// public async Task ScheduleUnpublishingOfLanguageVariantAsync(LanguageVariantIdentifier identifier, ScheduleModel scheduleModel) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (scheduleModel == null) - { - throw new ArgumentNullException(nameof(scheduleModel)); - } + ArgumentNullException.ThrowIfNull(scheduleModel); var endpointUrl = _urlBuilder.BuildUnpublishVariantUrl(identifier); @@ -121,10 +91,7 @@ public async Task ScheduleUnpublishingOfLanguageVariantAsync(LanguageVariantIden /// public async Task CreateNewVersionOfLanguageVariantAsync(LanguageVariantIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildNewVersionVariantUrl(identifier); diff --git a/Kontent.Ai.Management/ManagementClient.Subscription.cs b/Kontent.Ai.Management/ManagementClient.Subscription.cs index e9746a06..0a75a920 100644 --- a/Kontent.Ai.Management/ManagementClient.Subscription.cs +++ b/Kontent.Ai.Management/ManagementClient.Subscription.cs @@ -15,7 +15,7 @@ public async Task> ListSubscript var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Projects); @@ -28,7 +28,7 @@ public async Task> ListSubscription var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Users); @@ -37,10 +37,7 @@ public async Task> ListSubscription /// public async Task GetSubscriptionUserAsync(UserIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildSubscriptionUserUrl(identifier); @@ -50,10 +47,7 @@ public async Task GetSubscriptionUserAsync(UserIdentifier /// public async Task ActivateSubscriptionUserAsync(UserIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildSubscriptionUserActivateUrl(identifier); @@ -63,10 +57,7 @@ public async Task ActivateSubscriptionUserAsync(UserIdentifier identifier) /// public async Task DeactivateSubscriptionUserAsync(UserIdentifier identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildSubscriptionUserDeactivateDisableUrl(identifier); diff --git a/Kontent.Ai.Management/ManagementClient.TaxonomyGroup.cs b/Kontent.Ai.Management/ManagementClient.TaxonomyGroup.cs index a3c7530b..6c3f4ba3 100644 --- a/Kontent.Ai.Management/ManagementClient.TaxonomyGroup.cs +++ b/Kontent.Ai.Management/ManagementClient.TaxonomyGroup.cs @@ -16,7 +16,7 @@ public async Task> ListTaxonomyGroupsA var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); return new ListingResponseModel( - (token, url) => GetNextListingPageAsync(token, url), + GetNextListingPageAsync, response.Pagination?.Token, endpointUrl, response.Taxonomies); @@ -25,10 +25,7 @@ public async Task> ListTaxonomyGroupsA /// public async Task GetTaxonomyGroupAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildTaxonomyUrl(identifier); var response = await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -39,10 +36,7 @@ public async Task GetTaxonomyGroupAsync(Reference identifier /// public async Task CreateTaxonomyGroupAsync(TaxonomyGroupCreateModel taxonomyGroup) { - if (taxonomyGroup == null) - { - throw new ArgumentNullException(nameof(taxonomyGroup)); - } + ArgumentNullException.ThrowIfNull(taxonomyGroup); var endpointUrl = _urlBuilder.BuildTaxonomyUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, taxonomyGroup); @@ -51,10 +45,7 @@ public async Task CreateTaxonomyGroupAsync(TaxonomyGroupCrea /// public async Task ModifyTaxonomyGroupAsync(Reference identifier, IEnumerable changes) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildTaxonomyUrl(identifier); return await _actionInvoker.InvokeMethodAsync, TaxonomyGroupModel>(endpointUrl, new HttpMethod("PATCH"), changes); @@ -63,10 +54,7 @@ public async Task ModifyTaxonomyGroupAsync(Reference identif /// public async Task DeleteTaxonomyGroupAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildTaxonomyUrl(identifier); diff --git a/Kontent.Ai.Management/ManagementClient.Webhook.cs b/Kontent.Ai.Management/ManagementClient.Webhook.cs index 1fa25688..18cd1a14 100644 --- a/Kontent.Ai.Management/ManagementClient.Webhook.cs +++ b/Kontent.Ai.Management/ManagementClient.Webhook.cs @@ -19,10 +19,7 @@ public async Task> ListWebhooksAsync() /// public async Task GetWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildWebhooksUrl(identifier); return await _actionInvoker.InvokeReadOnlyMethodAsync(endpointUrl, HttpMethod.Get); @@ -31,10 +28,7 @@ public async Task GetWebhookAsync(Reference identifier) /// public async Task CreateWebhookAsync(WebhookCreateModel webhook) { - if (webhook == null) - { - throw new ArgumentNullException(nameof(webhook)); - } + ArgumentNullException.ThrowIfNull(webhook); var endpointUrl = _urlBuilder.BuildWebhooksUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, webhook); @@ -43,10 +37,7 @@ public async Task CreateWebhookAsync(WebhookCreateModel webhook) /// public async Task DeleteWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildWebhooksUrl(identifier); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Delete); @@ -55,10 +46,7 @@ public async Task DeleteWebhookAsync(Reference identifier) /// public async Task EnableWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildWebhooksEnableUrl(identifier); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put); @@ -67,10 +55,7 @@ public async Task EnableWebhookAsync(Reference identifier) /// public async Task DisableWebhookAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildWebhooksDisableUrl(identifier); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put); diff --git a/Kontent.Ai.Management/ManagementClient.Workflow.cs b/Kontent.Ai.Management/ManagementClient.Workflow.cs index 901cb872..852f81c1 100644 --- a/Kontent.Ai.Management/ManagementClient.Workflow.cs +++ b/Kontent.Ai.Management/ManagementClient.Workflow.cs @@ -22,10 +22,7 @@ public async Task> ListWorkflowsAsync() /// public async Task CreateWorkflowAsync(WorkflowUpsertModel workflow) { - if (workflow == null) - { - throw new ArgumentNullException(nameof(workflow)); - } + ArgumentNullException.ThrowIfNull(workflow); var endpointUrl = _urlBuilder.BuildWorkflowsUrl(); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Post, workflow); @@ -34,15 +31,9 @@ public async Task CreateWorkflowAsync(WorkflowUpsertModel workflo /// public async Task UpdateWorkflowAsync(Reference identifier, WorkflowUpsertModel workflow) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); - if (workflow == null) - { - throw new ArgumentNullException(nameof(workflow)); - } + ArgumentNullException.ThrowIfNull(workflow); var endpointUrl = _urlBuilder.BuildWorkflowsUrl(identifier); return await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, workflow); @@ -51,10 +42,7 @@ public async Task UpdateWorkflowAsync(Reference identifier, Workf /// public async Task DeleteWorkflowAsync(Reference identifier) { - if (identifier == null) - { - throw new ArgumentNullException(nameof(identifier)); - } + ArgumentNullException.ThrowIfNull(identifier); var endpointUrl = _urlBuilder.BuildWorkflowsUrl(identifier); await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Delete); diff --git a/Kontent.Ai.Management/ManagementClient.cs b/Kontent.Ai.Management/ManagementClient.cs index b72abd25..a7b1e479 100644 --- a/Kontent.Ai.Management/ManagementClient.cs +++ b/Kontent.Ai.Management/ManagementClient.cs @@ -29,10 +29,7 @@ public sealed partial class ManagementClient : IManagementClient /// The settings of the Kontent.ai environment. public ManagementClient(ManagementOptions ManagementOptions) { - if (ManagementOptions == null) - { - throw new ArgumentNullException(nameof(ManagementOptions)); - } + ArgumentNullException.ThrowIfNull(ManagementOptions); if (string.IsNullOrEmpty(ManagementOptions.EnvironmentId)) { diff --git a/Kontent.Ai.Management/Modules/ActionInvoker/ActionInvoker.cs b/Kontent.Ai.Management/Modules/ActionInvoker/ActionInvoker.cs index d4bdc2c5..787b49bc 100644 --- a/Kontent.Ai.Management/Modules/ActionInvoker/ActionInvoker.cs +++ b/Kontent.Ai.Management/Modules/ActionInvoker/ActionInvoker.cs @@ -81,10 +81,7 @@ public async Task InvokeMethodAsync(string endpointUrl, HttpMethod met public async Task UploadFileAsync(string endpointUrl, Stream stream, string contentType) { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } + ArgumentNullException.ThrowIfNull(stream); var content = new StreamContent(stream); diff --git a/Kontent.Ai.Management/Modules/ActionInvoker/DynamicObjectJsonConverter.cs b/Kontent.Ai.Management/Modules/ActionInvoker/DynamicObjectJsonConverter.cs index 727bd992..2ab49738 100644 --- a/Kontent.Ai.Management/Modules/ActionInvoker/DynamicObjectJsonConverter.cs +++ b/Kontent.Ai.Management/Modules/ActionInvoker/DynamicObjectJsonConverter.cs @@ -21,7 +21,7 @@ private static dynamic ConvertToDynamicObject(JObject obj) { if (property.Value is JArray array) { - resultAsDictionary.Add(property.Name, array.Select(arrayObject => ConvertJComplexObject(arrayObject))); + resultAsDictionary.Add(property.Name, array.Select(ConvertJComplexObject)); continue; } @@ -48,7 +48,7 @@ private static dynamic ConvertToDynamicObject(JObject obj) private static object ConvertJComplexObject(object input) => input switch { JObject obj => ConvertToDynamicObject(obj), - JArray array => array.Select(obj => ConvertJComplexObject(obj)), + JArray array => array.Select(ConvertJComplexObject), _ => throw new ArgumentOutOfRangeException(nameof(input), "JSON deserialization did not return either object nor array."), };