Skip to content

Commit

Permalink
Fix namespace collision for string and CollectionUtils method `IsNull…
Browse files Browse the repository at this point in the history
…OrEmpty` (#2471)

## Why make this change?

- Closes #2469 
- There is a namespace collision for the `IsNullOrEmpty` method in the
`MsSqlQueryBuilder` class between String and CollectionUtils class.

## What is this change?

- `MsSqlQueryBuilder` class had a check in the `Build` method where it
was using `IsNullOrEmpty` for Strings but it was refrencing
CollectionUtils Class instead
- Removed `Collection.Utilities` class from Cli and renamed it in the
Core project to `EnumerableUtilities` to avoid any future namespace
collision.
- Also updated all the references of `IsNullOrEmpty`

## How was this tested?

- [x] manual tests
- [x] current existing tests

Notes:
Work Around shared here:
AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#1722

---------

Co-authored-by: Aaron Burtle <[email protected]>
Co-authored-by: aaronburtle <[email protected]>
  • Loading branch information
3 people committed Nov 28, 2024
1 parent 3dd7df2 commit 84f049a
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Cli.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public static Process ExecuteDabCommand(string command, string flags)
/// <returns></returns>
public static string GenerateConfigWithGivenDepthLimit(string? depthLimitJson = null)
{
string depthLimitSection = depthLimitJson.IsNullOrEmpty() ? string.Empty : ("," + depthLimitJson);
string depthLimitSection = string.IsNullOrEmpty(depthLimitJson) ? string.Empty : ("," + depthLimitJson);

string runtimeSection = $@"
""runtime"": {{
Expand Down
24 changes: 0 additions & 24 deletions src/Cli/CollectionUtilities.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Cli/ConfigGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Azure.DataApiBuilder.Config.Converters;
using Azure.DataApiBuilder.Config.NamingPolicies;
using Azure.DataApiBuilder.Config.ObjectModel;
using Azure.DataApiBuilder.Core;
using Azure.DataApiBuilder.Core.Configurations;
using Azure.DataApiBuilder.Service;
using Cli.Commands;
Expand Down Expand Up @@ -609,7 +610,7 @@ private static bool TryUpdateConfiguredDataSourceOptions(
dbOptions.Add(namingPolicy.ConvertName(nameof(MsSqlOptions.SetSessionContext)), options.DataSourceOptionsSetSessionContext.Value);
}

dbOptions = dbOptions.IsNullOrEmpty() ? null : dbOptions;
dbOptions = EnumerableUtilities.IsNullOrEmpty(dbOptions) ? null : dbOptions;
DataSource dataSource = new(dbType, dataSourceConnectionString, dbOptions);
runtimeConfig = runtimeConfig with { DataSource = dataSource };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ namespace Azure.DataApiBuilder.Core;

/// <summary>
/// A class which contains useful methods for processing collections.
/// Pulled from Microsoft.IdentityModel.JsonWebTokens which changed the
/// helper to be internal.
/// </summary>
/// <seealso cref="https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/dev/src/Microsoft.IdentityModel.Tokens/CollectionUtilities.cs"/>
internal static class CollectionUtilities
public static class EnumerableUtilities
{
/// <summary>
/// Checks whether <paramref name="enumerable"/> is null or empty.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Resolvers/MsSqlQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private string MakeOutputColumns(List<LabelledColumn> columns, string columnPref
/// </summary>
private string Build(LabelledColumn column, string columnPrefix)
{
if (columnPrefix.IsNullOrEmpty())
if (string.IsNullOrEmpty(columnPrefix))
{
return $"{QuoteIdentifier(column.ColumnName)} AS {QuoteIdentifier(column.Label)}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Resolvers/SqlMutationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ private void ProcessMultipleCreateInputField(
queryParameters,
queryExecutor.ExtractResultSetFromDbDataReader,
GetHttpContext(),
exposedColumnNames.IsNullOrEmpty() ? sourceDefinition.Columns.Keys.ToList() : exposedColumnNames,
EnumerableUtilities.IsNullOrEmpty(exposedColumnNames) ? sourceDefinition.Columns.Keys.ToList() : exposedColumnNames,
dataSourceName);

dbResultSetRow = dbResultSet is not null ? (dbResultSet.Rows.FirstOrDefault() ?? new DbResultSetRow()) : null;
Expand Down
4 changes: 2 additions & 2 deletions src/Service.Tests/Configuration/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ public async Task TestSqlMetadataForValidConfigEntities()

configValidator.ValidateRelationshipConfigCorrectness(configProvider.GetConfig());
await configValidator.ValidateEntitiesMetadata(configProvider.GetConfig(), mockLoggerFactory);
Assert.IsTrue(configValidator.ConfigValidationExceptions.IsNullOrEmpty());
Assert.IsTrue(EnumerableUtilities.IsNullOrEmpty(configValidator.ConfigValidationExceptions));
}

/// <summary>
Expand Down Expand Up @@ -1574,7 +1574,7 @@ public async Task TestConfigSchemaIsValid()

JsonSchemaValidationResult result = await jsonSchemaValidator.ValidateJsonConfigWithSchemaAsync(jsonSchema, jsonData);
Assert.IsTrue(result.IsValid);
Assert.IsTrue(result.ValidationErrors.IsNullOrEmpty());
Assert.IsTrue(EnumerableUtilities.IsNullOrEmpty(result.ValidationErrors));
schemaValidatorLogger.Verify(
x => x.Log(
LogLevel.Information,
Expand Down
2 changes: 1 addition & 1 deletion src/Service.Tests/Configuration/TelemetryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public async Task TestNoTelemetryItemsSentWhenDisabled_NonHostedScenario(bool is
List<ITelemetry> telemetryItems = ((CustomTelemetryChannel)telemetryChannel).GetTelemetryItems();

// Assert that we are not sending any Traces/Requests/Exceptions to Telemetry
Assert.IsTrue(telemetryItems.IsNullOrEmpty());
Assert.IsTrue(EnumerableUtilities.IsNullOrEmpty(telemetryItems));
}

/// <summary>
Expand Down

0 comments on commit 84f049a

Please sign in to comment.