Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-867: Addressing analyzer warnings #378

Merged
merged 10 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Lombiq.Tests.UI.Shortcuts.Controllers;
[ApiController]
[Route("api/ApplicationInfo")]
[DevelopmentAndLocalhostOnly]
public class ApplicationInfoController : Controller
public class ApplicationInfoController : ControllerBase
{
private readonly IApplicationContext _applicationContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Lombiq.Tests.UI.Shortcuts.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;

namespace Lombiq.Tests.UI.Shortcuts.Controllers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static async Task<IEnumerable<string>> GetErrorsAsync(this HtmlValidation
{
if (string.IsNullOrEmpty(result.ResultFilePath) || !File.Exists(result.ResultFilePath))
{
return Enumerable.Empty<string>();
return [];
}

var fullOutput = await File.ReadAllTextAsync(result.ResultFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static Task EnableFeatureDirectlyAsync(

var feature = extensionManager.GetFeature(featureId);

return shellFeatureManager.EnableFeaturesAsync(new[] { feature }, force: true);
return shellFeatureManager.EnableFeaturesAsync([feature], force: true);
},
tenant,
activateShell);
Expand All @@ -292,7 +292,7 @@ public static Task DisableFeatureDirectlyAsync(

var feature = extensionManager.GetFeature(featureId);

return shellFeatureManager.DisableFeaturesAsync(new[] { feature }, force: true);
return shellFeatureManager.DisableFeaturesAsync([feature], force: true);
},
tenant,
activateShell);
Expand Down Expand Up @@ -489,7 +489,7 @@ public static Task SetThemeDirectlyAsync(

if (!isEnabled)
{
await shellFeatureManager.EnableFeaturesAsync(new[] { themeFeature }, force: true);
await shellFeatureManager.EnableFeaturesAsync([themeFeature], force: true);
}
},
tenant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static async Task LogsShouldBeEmptyAsync(
CancellationToken cancellationToken = default)
{
if (cancellationToken == default) cancellationToken = CancellationToken.None;
permittedErrorLines ??= Array.Empty<string>();
permittedErrorLines ??= [];

var logOutput = await webApplicationInstance.GetLogOutputAsync(cancellationToken);

Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/Pages/OrchardCoreAdminPage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using Atata;
using Lombiq.Tests.UI.Components;
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.Tests.UI.Pages;

[SuppressMessage(
"Major Code Smell",
"S1144:Unused private types or members should be removed",
Justification = "Atata requires private setters: https://atata.io/examples/page-object-inheritance/.")]
public abstract class OrchardCoreAdminPage<TOwner> : Page<TOwner>
where TOwner : OrchardCoreAdminPage<TOwner>
{
Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/Pages/OrchardCoreContentItemsPage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Atata;
using Atata.Bootstrap;
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.Tests.UI.Pages;

Expand All @@ -8,6 +9,10 @@ namespace Lombiq.Tests.UI.Pages;
using _ = OrchardCoreContentItemsPage;
#pragma warning restore IDE0065 // Misplaced using directive

[SuppressMessage(
"Major Code Smell",
"S1144:Unused private types or members should be removed",
Justification = "Atata requires private setters: https://atata.io/examples/page-object-inheritance/.")]
public class OrchardCoreContentItemsPage : OrchardCoreAdminPage<_>
{
[FindById("new-dropdown")]
Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/Pages/OrchardCoreFeaturesPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Atata;
using Atata.Bootstrap;
using Lombiq.Tests.UI.Components;
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.Tests.UI.Pages;

Expand All @@ -9,6 +10,10 @@ namespace Lombiq.Tests.UI.Pages;
using _ = OrchardCoreFeaturesPage;
#pragma warning restore IDE0065 // Misplaced using directive

[SuppressMessage(
"Major Code Smell",
"S1144:Unused private types or members should be removed",
Justification = "Atata requires private setters: https://atata.io/examples/page-object-inheritance/.")]
public sealed class OrchardCoreFeaturesPage : OrchardCoreAdminPage<_>
{
[FindById]
Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/Pages/OrchardCoreLoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Lombiq.Tests.UI.Components;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Pages;
Expand All @@ -13,6 +14,10 @@ namespace Lombiq.Tests.UI.Pages;

[Url(DefaultUrl)]
[TermFindSettings(Case = TermCase.Pascal, TargetAllChildren = true, TargetAttributeType = typeof(FindByIdAttribute))]
[SuppressMessage(
"Major Code Smell",
"S1144:Unused private types or members should be removed",
Justification = "Atata requires private setters: https://atata.io/examples/page-object-inheritance/.")]
public class OrchardCoreLoginPage : Page<_>
{
private const string DefaultUrl = "Login";
Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/Pages/OrchardCoreRegistrationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Models;
using Lombiq.Tests.UI.Services;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Pages;
Expand All @@ -15,6 +16,10 @@ namespace Lombiq.Tests.UI.Pages;

[Url(DefaultUrl)]
[TermFindSettings(Case = TermCase.Pascal, TargetAllChildren = true, TargetAttributeType = typeof(FindByNameAttribute))]
[SuppressMessage(
"Major Code Smell",
"S1144:Unused private types or members should be removed",
Justification = "Atata requires private setters: https://atata.io/examples/page-object-inheritance/.")]
public class OrchardCoreRegistrationPage : Page<_>
{
public const string DefaultUrl = "Register";
Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/Pages/OrchardCoreSetupPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Pages;
Expand All @@ -19,6 +20,10 @@ namespace Lombiq.Tests.UI.Pages;
Case = TermCase.Pascal,
TargetAllChildren = true,
TargetAttributeTypes = [typeof(FindByIdAttribute), typeof(FindByNameAttribute)])]
[SuppressMessage(
"Major Code Smell",
"S1144:Unused private types or members should be removed",
Justification = "Atata requires private setters: https://atata.io/examples/page-object-inheritance/.")]
public sealed class OrchardCoreSetupPage : Page<_>
{
public const string DefaultPageTitle = "Setup";
Expand Down
8 changes: 2 additions & 6 deletions Lombiq.Tests.UI/SecurityScanning/SecurityScanConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class SecurityScanConfiguration
public bool UnusedDatabaseTechnologiesAreExcluded { get; private set; } = true;

/// <summary>
/// Gets a value indicating whether the security scan should not visit the <see cref="ErrorController"/> to test
/// Gets or sets a value indicating whether the security scan should not visit the <see cref="ErrorController"/> to test
/// for correct error handling. This is achieved by adding the error page URL to the configuration with <see
/// cref="YamlDocumentExtensions.AddRequestor"/>.
/// </summary>
public bool DontScanErrorPage { get; private set; }
public bool DontScanErrorPage { get; set; }

internal SecurityScanConfiguration()
{
Expand Down Expand Up @@ -327,11 +327,7 @@ internal async Task ApplyToPlanAsync(YamlDocument yamlDocument, UITestContext co
// pollPostData: ""
}

// False positive: https://github.com/SonarSource/sonar-dotnet/issues/8510.
#pragma warning disable S3878 // Arrays should not be created for params parameters
yamlDocument.AddExcludePathsRegex([.. _excludedUrlRegexPatterns]);
#pragma warning restore S3878 // Arrays should not be created for params parameters

if (AdminIsExcluded) yamlDocument.AddExcludePathsRegex($".*{context.AdminUrlPrefix}.*");

if (UnusedDatabaseTechnologiesAreExcluded)
Expand Down
6 changes: 3 additions & 3 deletions Lombiq.Tests.UI/SecurityScanning/ZapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public async Task<SecurityScanResult> RunSecurityScanAsync(
_zapPort = await _portLeaseManager.LeaseAvailableRandomPortAsync();
_testOutputHelper.WriteLineTimestampedAndDebug("Running ZAP on port {0}.", _zapPort);

cliParameters.AddRange(new object[]
{
cliParameters.AddRange(
[
"--rm",
"--volume",
$"{mountedDirectoryPath}:{_zapWorkingDirectoryPath}:rw",
Expand All @@ -149,7 +149,7 @@ public async Task<SecurityScanResult> RunSecurityScanAsync(
_zapWorkingDirectoryPath + yamlFileName,
"-port",
_zapPort,
});
]);

var stdErrBuffer = new StringBuilder();

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Services/OrchardCoreInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public IEnumerable<IApplicationLog> GetLogs(CancellationToken cancellationToken
FullName = Path.GetFullPath(filePath),
ContentLoader = () => GetFileContentAsync(filePath, cancellationToken),
})
: Enumerable.Empty<IApplicationLog>();
: [];
}

public TService GetRequiredService<TService>() =>
Expand Down
3 changes: 1 addition & 2 deletions Lombiq.Tests.UI/Services/RemoteInstance.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -16,7 +15,7 @@ public sealed class RemoteInstance : IWebApplicationInstance

public Task<Uri> StartUpAsync() => Task.FromResult(_baseUri);

public IEnumerable<IApplicationLog> GetLogs(CancellationToken cancellationToken = default) => Enumerable.Empty<IApplicationLog>();
public IEnumerable<IApplicationLog> GetLogs(CancellationToken cancellationToken = default) => [];
public TService GetRequiredService<TService>() => throw new NotSupportedException();
public Task PauseAsync() => throw new NotSupportedException();
public Task ResumeAsync() => throw new NotSupportedException();
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Services/SqlServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task TakeSnapshotAsync(
if (File.Exists(filePathLocal)) File.Delete(filePathLocal);

await Cli.Wrap("docker")
.WithArguments(new[] { "cp", $"{containerName}:{filePathRemote}", filePathLocal })
.WithArguments(["cp", $"{containerName}:{filePathRemote}", filePathLocal])
.ExecuteAsync();
}

Expand Down