From 03f93bd6cef999a76a9d7f589a9489b25dc8f866 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 28 Jun 2024 13:40:54 +1000 Subject: [PATCH] remove some redundant ToString --- .../Extensions/BlobStorageVulnerabilityWriter.cs | 6 +++--- .../Diagnostics/DiagnosticsServiceExtensions.cs | 2 +- .../Services/CloudBlobCoreFileStorageService.cs | 4 ++-- src/NuGetGallery.Services/Storage/ContentService.cs | 2 +- src/NuGetGallery/App_Code/ViewHelpers.cshtml | 2 +- .../ViewModelExtensions/ListPackageItemViewModelFactory.cs | 2 +- .../Infrastructure/Lucene/ExternalSearchService.cs | 2 +- src/NuGetGallery/Infrastructure/TracingHttpHandler.cs | 2 +- src/NuGetGallery/Telemetry/CustomerResourceIdEnricher.cs | 2 +- .../NuGetGallery.Core.Facts/TestUtils/BlobStorageFixture.cs | 2 +- tests/NuGetGallery.Core.Facts/TestUtils/TestPackage.cs | 2 +- .../Controllers/PackagesControllerFacts.cs | 4 ++-- .../Serializers/V2FeedPackageAnnotationStrategyFacts.cs | 2 +- .../Services/PackageUploadServiceFacts.cs | 6 +++--- .../Telemetry/ClientTelemetryPIIProcessorTests.cs | 4 ++-- .../Views/Packages/ValidationIssueFacts.cs | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/GitHubVulnerabilities2v3/Extensions/BlobStorageVulnerabilityWriter.cs b/src/GitHubVulnerabilities2v3/Extensions/BlobStorageVulnerabilityWriter.cs index f5213655dc..4667ef7081 100644 --- a/src/GitHubVulnerabilities2v3/Extensions/BlobStorageVulnerabilityWriter.cs +++ b/src/GitHubVulnerabilities2v3/Extensions/BlobStorageVulnerabilityWriter.cs @@ -279,7 +279,7 @@ private async Task RunUpdate(string stringContentOutput, Uri indexStorageUri, st { if (indexEntries[i].Name.Equals(UPDATE_ENTRY_NAME)) { - indexEntries[i].Id = updateUriBuilder.Uri.AbsoluteUri.ToString(); + indexEntries[i].Id = updateUriBuilder.Uri.AbsoluteUri; indexEntries[i].Updated = DateTime.UtcNow; break; } @@ -320,14 +320,14 @@ private async Task RunRegenerate(string stringContentOutput, Uri indexStorageUri new IndexEntry { Name=BASE_ENTRY_NAME, - Id=baseUriBuilder.Uri.AbsoluteUri.ToString(), + Id=baseUriBuilder.Uri.AbsoluteUri, Updated=updatedTime, Comment="The base data for vulnerability update periodically" }, new IndexEntry { Name=UPDATE_ENTRY_NAME, - Id=updateUriBuilder.Uri.AbsoluteUri.ToString(), + Id=updateUriBuilder.Uri.AbsoluteUri, Updated=updatedTime, Comment="The patch data for the vulnerability. Contains all the vulnerabilities since base was last updated." }, diff --git a/src/NuGetGallery.Core/Diagnostics/DiagnosticsServiceExtensions.cs b/src/NuGetGallery.Core/Diagnostics/DiagnosticsServiceExtensions.cs index 3796b56888..5d21478038 100644 --- a/src/NuGetGallery.Core/Diagnostics/DiagnosticsServiceExtensions.cs +++ b/src/NuGetGallery.Core/Diagnostics/DiagnosticsServiceExtensions.cs @@ -19,7 +19,7 @@ public static IDiagnosticsSource SafeGetSource(this IDiagnosticsService self, st } catch(Exception ex) { - System.Diagnostics.Trace.WriteLine("Error getting trace source: " + ex.ToString()); + System.Diagnostics.Trace.WriteLine($"Error getting trace source: {ex}"); return NullDiagnosticsSource.Instance; } } diff --git a/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs b/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs index 3c4f072df7..514aeedb40 100644 --- a/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs +++ b/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs @@ -197,14 +197,14 @@ private async Task CopyFileAsync( _trace.TraceEvent( LogLevel.Information, eventId: 0, - message: $"Source blob ('{srcBlob.Uri.ToString()}') doesn't have the Sha512 hash."); + message: $"Source blob ('{srcBlob.Uri}') doesn't have the Sha512 hash."); } if (!destinationBlobHasSha512Hash) { _trace.TraceEvent( LogLevel.Information, eventId: 0, - message: $"Destination blob ('{destBlob.Uri.ToString()}') doesn't have the Sha512 hash."); + message: $"Destination blob ('{destBlob.Uri}') doesn't have the Sha512 hash."); } if (sourceBlobHasSha512Hash && destinationBlobHasSha512Hash && sourceBlobSha512Hash == destinationBlobSha512Hash && srcBlob.Properties.Length == destBlob.Properties.Length) { diff --git a/src/NuGetGallery.Services/Storage/ContentService.cs b/src/NuGetGallery.Services/Storage/ContentService.cs index d1d6ada03c..10cc8d8dbd 100644 --- a/src/NuGetGallery.Services/Storage/ContentService.cs +++ b/src/NuGetGallery.Services/Storage/ContentService.cs @@ -75,7 +75,7 @@ private async Task GetContentItemCore(string name, string[] extensi ContentItem cachedItem = null; if (ContentCache.TryGetValue(name, out cachedItem) && DateTime.UtcNow < cachedItem.ExpiryUtc) { - Trace.Verbose("Cache Valid. Expires at: " + cachedItem.ExpiryUtc.ToString()); + Trace.Verbose("Cache Valid. Expires at: " + cachedItem.ExpiryUtc); return cachedItem.Content; } Trace.Verbose("Cache Expired."); diff --git a/src/NuGetGallery/App_Code/ViewHelpers.cshtml b/src/NuGetGallery/App_Code/ViewHelpers.cshtml index 75f848e8c2..613a00f019 100644 --- a/src/NuGetGallery/App_Code/ViewHelpers.cshtml +++ b/src/NuGetGallery/App_Code/ViewHelpers.cshtml @@ -415,7 +415,7 @@ string dataKey = "___AccordionCounter_" + groupName; int lastId = (int)(HttpContext.Current.Items[dataKey] ?? 0); int id = lastId + 1; HttpContext.Current.Items[dataKey] = id; -string name = groupName + "-" + id.ToString(); +string name = groupName + "-" + id; string actionsId = name + "-actions"; var hlp = new AccordionHelper(name, formModelStatePrefix, expanded, page); diff --git a/src/NuGetGallery/Helpers/ViewModelExtensions/ListPackageItemViewModelFactory.cs b/src/NuGetGallery/Helpers/ViewModelExtensions/ListPackageItemViewModelFactory.cs index 02f96bf58c..2163852224 100644 --- a/src/NuGetGallery/Helpers/ViewModelExtensions/ListPackageItemViewModelFactory.cs +++ b/src/NuGetGallery/Helpers/ViewModelExtensions/ListPackageItemViewModelFactory.cs @@ -71,7 +71,7 @@ private ListPackageItemViewModel SetupInternal(ListPackageItemViewModel viewMode viewModel.CanDeprecate = CanPerformAction(currentUser, package, ActionsRequiringPermissions.DeprecatePackage); viewModel.CanDisplayTfmBadges = _featureFlagService.IsDisplayTfmBadgesEnabled(currentUser); - PackageFrameworkCompatibility packageFrameworkCompatibility = _frameworkCompatibilityFactory.Create(package.SupportedFrameworks, package.Id, package.Version.ToString(), includeComputedBadges); + PackageFrameworkCompatibility packageFrameworkCompatibility = _frameworkCompatibilityFactory.Create(package.SupportedFrameworks, package.Id, package.Version, includeComputedBadges); viewModel.FrameworkBadges = viewModel.CanDisplayTfmBadges ? packageFrameworkCompatibility?.Badges : new PackageFrameworkCompatibilityBadges(); viewModel.SetShortDescriptionFrom(viewModel.Description); diff --git a/src/NuGetGallery/Infrastructure/Lucene/ExternalSearchService.cs b/src/NuGetGallery/Infrastructure/Lucene/ExternalSearchService.cs index 8163cf8669..fa527e61f2 100644 --- a/src/NuGetGallery/Infrastructure/Lucene/ExternalSearchService.cs +++ b/src/NuGetGallery/Infrastructure/Lucene/ExternalSearchService.cs @@ -162,7 +162,7 @@ private async Task EnsureDiagnostics() var resp = await _searchClient.GetDiagnostics(); if (!resp.IsSuccessStatusCode) { - Trace.Error("HTTP Error when retrieving diagnostics: " + ((int)resp.StatusCode).ToString()); + Trace.Error("HTTP Error when retrieving diagnostics: " + ((int)resp.StatusCode)); _diagCache = new JObject(); } else diff --git a/src/NuGetGallery/Infrastructure/TracingHttpHandler.cs b/src/NuGetGallery/Infrastructure/TracingHttpHandler.cs index aaf69cb3fd..a18861ae0c 100644 --- a/src/NuGetGallery/Infrastructure/TracingHttpHandler.cs +++ b/src/NuGetGallery/Infrastructure/TracingHttpHandler.cs @@ -25,7 +25,7 @@ protected override async Task SendAsync(HttpRequestMessage resp = await base.SendAsync(request, cancellationToken); } - string message = ((int)resp.StatusCode).ToString() + " " + request.RequestUri.AbsoluteUri; + string message = ((int)resp.StatusCode) + " " + request.RequestUri.AbsoluteUri; if (resp.IsSuccessStatusCode) { Trace.Information(message); diff --git a/src/NuGetGallery/Telemetry/CustomerResourceIdEnricher.cs b/src/NuGetGallery/Telemetry/CustomerResourceIdEnricher.cs index 62c3858b5f..9f2a1c8611 100644 --- a/src/NuGetGallery/Telemetry/CustomerResourceIdEnricher.cs +++ b/src/NuGetGallery/Telemetry/CustomerResourceIdEnricher.cs @@ -15,7 +15,7 @@ public class CustomerResourceIdEnricher : ITelemetryInitializer private const string CustomerResourceId = "CustomerResourceId"; private const string CustomerResourceIdConstant = "CustomerResourceIdConstant"; private const string Prefix = "/tenants/"; - private static readonly string Empty = Prefix + Guid.Empty.ToString(); + private static readonly string Empty = Prefix + Guid.Empty; private static readonly HashSet CustomMetricNames = new HashSet { diff --git a/tests/NuGetGallery.Core.Facts/TestUtils/BlobStorageFixture.cs b/tests/NuGetGallery.Core.Facts/TestUtils/BlobStorageFixture.cs index bd05293929..034b2f4ce7 100644 --- a/tests/NuGetGallery.Core.Facts/TestUtils/BlobStorageFixture.cs +++ b/tests/NuGetGallery.Core.Facts/TestUtils/BlobStorageFixture.cs @@ -76,7 +76,7 @@ private void DeleteTestBlobs(string connectionString) foreach (var container in containers) { var blobs = container.ListBlobs( - prefix: TestRunId.ToString(), + prefix: TestRunId, useFlatBlobListing: true); foreach (var blob in blobs.OfType()) diff --git a/tests/NuGetGallery.Core.Facts/TestUtils/TestPackage.cs b/tests/NuGetGallery.Core.Facts/TestUtils/TestPackage.cs index a2b4e9fe0d..5cb173509e 100644 --- a/tests/NuGetGallery.Core.Facts/TestUtils/TestPackage.cs +++ b/tests/NuGetGallery.Core.Facts/TestUtils/TestPackage.cs @@ -156,7 +156,7 @@ private static string WritePackageTypes(IEnumerable"); diff --git a/tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs b/tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs index dc7d1080db..02d7fdeb98 100644 --- a/tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs +++ b/tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs @@ -472,7 +472,7 @@ public TheDisplayPackageMethod() public async Task IsIndexCheckOnlyHappensForRecentlyChangedPackages(DateTime created, DateTime? lastEdited, int searchTimes) { // Arrange - var id = "Test" + Guid.NewGuid().ToString(); + var id = "Test" + Guid.NewGuid(); var packageService = new Mock(); var diagnosticsService = new Mock(); var searchClient = new Mock(); @@ -9614,7 +9614,7 @@ public async Task WillRedirectToPackageDetailsPageAfterSuccessfullyCreatingSymbo public class TheUploadProgressAction : TestContainer { - private static readonly string FakeUploadName = "upload-" + TestUtility.FakeUserName + Guid.Empty.ToString(); + private static readonly string FakeUploadName = "upload-" + TestUtility.FakeUserName + Guid.Empty; [Fact] public void WillReturnHttpNotFoundForUnknownUser() diff --git a/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs b/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs index ba58f4517d..2425a53fd6 100644 --- a/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs +++ b/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs @@ -117,7 +117,7 @@ public void NormalizesNavigationLinksWhenSet(string requestUri) // Assert Assert.Equal(expectedNormalizedLink, oDataEntry.ReadLink.ToString()); Assert.Equal(expectedNormalizedLink, oDataEntry.EditLink.ToString()); - Assert.Equal(expectedNormalizedLink, oDataEntry.Id.ToString()); + Assert.Equal(expectedNormalizedLink, oDataEntry.Id); } [Fact] diff --git a/tests/NuGetGallery.Facts/Services/PackageUploadServiceFacts.cs b/tests/NuGetGallery.Facts/Services/PackageUploadServiceFacts.cs index 0b66671ff0..d2e792bf8c 100644 --- a/tests/NuGetGallery.Facts/Services/PackageUploadServiceFacts.cs +++ b/tests/NuGetGallery.Facts/Services/PackageUploadServiceFacts.cs @@ -615,7 +615,7 @@ public async Task CleansUpLicenseIfDbUpdateFails(PackageStatus packageStatus, bo await Assert.ThrowsAsync(() => _target.CommitPackageAsync(_package, _packageFile)); _licenseFileService.Verify( - lfs => lfs.DeleteLicenseFileAsync(_package.Id, _package.NormalizedVersion.ToString()), + lfs => lfs.DeleteLicenseFileAsync(_package.Id, _package.NormalizedVersion), expectedLicenseDelete ? Times.Once() : Times.Never()); } @@ -720,11 +720,11 @@ public async Task CleansUpReadmeIfDbUpdateFails(PackageStatus packageStatus, boo await Assert.ThrowsAsync(() => _target.CommitPackageAsync(_package, _packageFile)); _licenseFileService.Verify( - lfs => lfs.DeleteLicenseFileAsync(_package.Id, _package.NormalizedVersion.ToString()), + lfs => lfs.DeleteLicenseFileAsync(_package.Id, _package.NormalizedVersion), expectedFileDelete ? Times.Once() : Times.Never()); _readmeFileService.Verify( - lfs => lfs.DeleteReadmeFileAsync(_package.Id, _package.NormalizedVersion.ToString()), + lfs => lfs.DeleteReadmeFileAsync(_package.Id, _package.NormalizedVersion), expectedFileDelete ? Times.Once() : Times.Never()); } } diff --git a/tests/NuGetGallery.Facts/Telemetry/ClientTelemetryPIIProcessorTests.cs b/tests/NuGetGallery.Facts/Telemetry/ClientTelemetryPIIProcessorTests.cs index 182605a834..2463615f73 100644 --- a/tests/NuGetGallery.Facts/Telemetry/ClientTelemetryPIIProcessorTests.cs +++ b/tests/NuGetGallery.Facts/Telemetry/ClientTelemetryPIIProcessorTests.cs @@ -240,7 +240,7 @@ private List GetPIIOperationsFromRoute() var piiRoutes = _currentRoutes.Where((r) => { Route webRoute = r as Route; - return webRoute != null ? IsPIIUrl(webRoute.Url.ToString()) : false; + return webRoute != null ? IsPIIUrl(webRoute.Url) : false; }).Select((r) => { var dd = ((Route)r).Defaults; @@ -255,7 +255,7 @@ private List GetPIIRoutesUrls() var piiRoutes = _currentRoutes.Where((r) => { Route webRoute = r as Route; - return webRoute != null ? IsPIIUrl(webRoute.Url.ToString()) : false; + return webRoute != null ? IsPIIUrl(webRoute.Url) : false; }).Select((r) => ((Route)r).Url).Distinct().ToList(); return piiRoutes; diff --git a/tests/NuGetGallery.Facts/Views/Packages/ValidationIssueFacts.cs b/tests/NuGetGallery.Facts/Views/Packages/ValidationIssueFacts.cs index 439d4c3fc7..f5262f2737 100644 --- a/tests/NuGetGallery.Facts/Views/Packages/ValidationIssueFacts.cs +++ b/tests/NuGetGallery.Facts/Views/Packages/ValidationIssueFacts.cs @@ -30,7 +30,7 @@ public void HasACaseForAllIssueTypes(ValidationIssue issue) var template = GetTemplate(); // Assert - Assert.Contains("case ValidationIssueCode." + issue.IssueCode.ToString(), template); + Assert.Contains("case ValidationIssueCode." + issue.IssueCode, template); } [Theory]