Skip to content

Commit

Permalink
Addressing warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Psichorex committed Jan 19, 2024
1 parent ee062f5 commit 10a5c7f
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using OrchardCore.ContentFields.ViewModels;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -37,7 +38,9 @@ public static Task GoToAdminRelativeUrlAsync(
public static Task GoToAbsoluteUrlAsync(this UITestContext context, Uri absoluteUri, bool onlyIfNotAlreadyThere = true) =>
context.ExecuteLoggedAsync(
nameof(GoToAbsoluteUrlAsync),
$"{absoluteUri} ({(onlyIfNotAlreadyThere ? "navigating also" : "not navigating")} if already there)",
string.Create(
CultureInfo.InvariantCulture,
$"{absoluteUri} ({(onlyIfNotAlreadyThere ? "navigating also" : "not navigating")} if already there)"),
async () =>
{
if (onlyIfNotAlreadyThere && context.GetCurrentUri() == absoluteUri) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ public static Task<ApplicationInfo> GetApplicationInfoAsync(this UITestContext c
context.GetApi().GetApplicationInfoFromApiAsync();

// This is required to instantiate ILogger<>.
#pragma warning disable S2094 // Classes should not be empty
private sealed class ExecuteRecipeShortcut { }
#pragma warning restore S2094 // Classes should not be empty

/// <summary>
/// Executes a recipe identified by its name directly.
Expand Down
19 changes: 12 additions & 7 deletions Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.MonkeyTesting;
Expand Down Expand Up @@ -97,10 +98,12 @@ private bool CanTestPage(PageMonkeyTestInfo pageTestInfo)

if (!canTest)
{
var culture = CultureInfo.InvariantCulture;

Log.Info(
!pageTestInfo.HasTimeToTest
? $"Available monkey testing time for \"{pageTestInfo.SanitizedUrl}\" is up and thus testing is complete."
: $"Navigated to \"{pageTestInfo.Url}\" that should not be tested.");
? string.Create(culture, $"Available monkey testing time for \"{pageTestInfo.SanitizedUrl}\" is up and thus testing is complete.")
: string.Create(culture, $"Navigated to \"{pageTestInfo.Url}\" that should not be tested."));
}

return canTest;
Expand All @@ -124,7 +127,7 @@ private PageMonkeyTestInfo GetCurrentPageTestInfo()
var pageTestInfo = _visitedPages.Find(pageInfo => pageInfo.SanitizedUrl == sanitizedUrl)
?? new PageMonkeyTestInfo(url, sanitizedUrl, _options.PageTestTime);

Log.Info($"Current page is \"{pageTestInfo.SanitizedUrl}\".");
Log.Info(string.Create(CultureInfo.InvariantCulture, $"Current page is \"{pageTestInfo.SanitizedUrl}\"."));

return pageTestInfo;
}
Expand All @@ -147,8 +150,10 @@ private Task TestCurrentPageWithRandomSeedAsync(PageMonkeyTestInfo pageTestInfo,
{
Log.ExecuteSection(
new LogSection(
$"Monkey test \"{pageTestInfo.SanitizedUrl}\" within {pageTestInfo.TimeToTest.ToShortIntervalString()} " +
$"with {randomSeed.ToTechnicalString()} random seed."),
string.Create(
CultureInfo.InvariantCulture,
$"Monkey test \"{pageTestInfo.SanitizedUrl}\" within {pageTestInfo.TimeToTest.ToShortIntervalString()} " +
$"with {randomSeed.ToTechnicalString()} random seed.")),
() =>
{
var pageTestTimeLeft = TestCurrentPageAndMeasureTestTimeLeft(pageTestInfo.TimeToTest, randomSeed);
Expand Down Expand Up @@ -200,8 +205,8 @@ private void WaitForGremlinsIndicatorsToDisappear() =>
private string BuildGremlinsRunScript(TimeSpan testTime, int randomSeed) =>
new GremlinsScripts.RunScriptBuilder
{
Species = _options.GremlinsSpecies.ToArray(),
Mogwais = _options.GremlinsMogwais.ToArray(),
Species = [.. _options.GremlinsSpecies],
Mogwais = [.. _options.GremlinsMogwais],
NumberOfAttacks = (int)(testTime.TotalMilliseconds / _options.GremlinsAttackDelay.TotalMilliseconds),
AttackDelay = (int)_options.GremlinsAttackDelay.TotalMilliseconds,
RandomSeed = randomSeed,
Expand Down
6 changes: 3 additions & 3 deletions Lombiq.Tests.UI/Pages/OrchardCoreSetupPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace Lombiq.Tests.UI.Pages;
using _ = OrchardCoreSetupPage;
#pragma warning restore IDE0065 // Misplaced using directive

[VerifyTitle(values: new[] { DefaultPageTitle, OlderPageTitle }, Format = "{0}")]
[VerifyH1(values: new[] { DefaultPageTitle, OlderPageTitle })]
[VerifyTitle(values: [DefaultPageTitle, OlderPageTitle], Format = "{0}")]
[VerifyH1(values: [DefaultPageTitle, OlderPageTitle])]
[TermFindSettings(
Case = TermCase.Pascal,
TargetAllChildren = true,
TargetAttributeTypes = new[] { typeof(FindByIdAttribute), typeof(FindByNameAttribute) })]
TargetAttributeTypes = [typeof(FindByIdAttribute), typeof(FindByNameAttribute)])]
public sealed class OrchardCoreSetupPage : Page<_>
{
public const string DefaultPageTitle = "Setup";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ internal async Task ApplyToPlanAsync(YamlDocument yamlDocument, UITestContext co
// pollPostData: ""
}

yamlDocument.AddExcludePathsRegex(_excludedUrlRegexPatterns.ToArray());
yamlDocument.AddExcludePathsRegex([.. _excludedUrlRegexPatterns]);
foreach (var rule in _disabledActiveScanRules) yamlDocument.DisableActiveScanRule(rule.Id, rule.Name);

foreach (var ruleConfiguration in _configuredActiveScanRules)
Expand Down
5 changes: 0 additions & 5 deletions Lombiq.Tests.UI/Services/AzureBlobStorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Azure.Storage.Blobs.Models;
using Lombiq.HelpfulLibraries.Common.Utilities;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;

Expand Down Expand Up @@ -42,10 +41,6 @@ public sealed class AzureBlobStorageManager : IAsyncDisposable
private BlobContainerClient _blobContainer;
private bool _isDisposed;

[SuppressMessage(
"Performance",
"CA1810:Initialize reference type static fields inline",
Justification = "No GetAgentIndexOrDefault() duplication this way.")]
static AzureBlobStorageManager()
{
var agentIndexTimesHundred = TestConfigurationManager.GetAgentIndexOrDefault() * 100;
Expand Down
6 changes: 1 addition & 5 deletions Lombiq.Tests.UI/Services/OrchardCoreInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,11 @@ private async Task StopOrchardAppAsync()

// Use cancellationToken in ReadToEndAsync() once it's available after a .NET upgrade, see:
// https://github.com/dotnet/runtime/pull/61898.
#pragma warning disable S1172 // Unused method parameters should be removed
#pragma warning disable IDE0060 // Remove unused parameter
private static async Task<string> GetFileContentAsync(string filePath, CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
#pragma warning restore S1172 // Unused method parameters should be removed
{
using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var streamReader = new StreamReader(fileStream);
return await streamReader.ReadToEndAsync();
return await streamReader.ReadToEndAsync(cancellationToken);
}

private async Task TakeSnapshotInnerAsync(string snapshotDirectoryPath)
Expand Down
7 changes: 1 addition & 6 deletions Lombiq.Tests.UI/Services/SqlServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.SqlServer.Management.Smo;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -56,10 +55,6 @@ public sealed class SqlServerManager : IAsyncDisposable
private string _password;
private bool _isDisposed;

[SuppressMessage(
"Performance",
"CA1810:Initialize reference type static fields inline",
Justification = "No GetAgentIndexOrDefault() duplication this way.")]
static SqlServerManager()
{
var agentIndexTimesHundred = TestConfigurationManager.GetAgentIndexOrDefault() * 100;
Expand Down Expand Up @@ -273,7 +268,7 @@ private static object[] CreateArguments(string containerName, params object[] co
var arguments = new List<object> { "exec", "-u", 0, containerName };
arguments.AddRange(command);

return arguments.ToArray();
return [.. arguments];
}

public async ValueTask DisposeAsync()
Expand Down

0 comments on commit 10a5c7f

Please sign in to comment.