From 6a0cef1c16952ebac30036f20aa47ad67d15e987 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Saeed Date: Wed, 24 Aug 2022 10:56:24 +0100 Subject: [PATCH] Fix new Visual Studio warnings --- .../OpenGraph/ObjectTypes/OpenGraphMetadata.cs | 5 +---- .../Boxed.AspNetCore/Middleware/HttpExceptionMiddleware.cs | 2 +- Source/Boxed.DotnetNewTest/AsyncDisposableAction.cs | 2 +- Source/Boxed.DotnetNewTest/ConsoleColorScope.cs | 2 +- .../SchemaFilters/JsonPatchDocumentSchemaFilterTest.cs | 2 +- .../SubresourceIntegrityTagHelperTest.cs | 2 +- Tests/Boxed.AspNetCore.Test/CursorTest.cs | 2 +- .../Boxed.AspNetCore.Test/DistributedCacheExtensionsTest.cs | 6 +++--- .../Middleware/ServerTimingMiddlewareTest.cs | 2 +- 9 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Source/Boxed.AspNetCore.TagHelpers/OpenGraph/ObjectTypes/OpenGraphMetadata.cs b/Source/Boxed.AspNetCore.TagHelpers/OpenGraph/ObjectTypes/OpenGraphMetadata.cs index 0f0bd48b..93bc0bf0 100644 --- a/Source/Boxed.AspNetCore.TagHelpers/OpenGraph/ObjectTypes/OpenGraphMetadata.cs +++ b/Source/Boxed.AspNetCore.TagHelpers/OpenGraph/ObjectTypes/OpenGraphMetadata.cs @@ -297,10 +297,7 @@ public virtual void ToString(StringBuilder stringBuilder) stringBuilder.AppendMetaPropertyContent("og:type", this.Type.ToLowercaseString()); } - if (this.Url is null) - { - this.Url = this.GetRequestUrl(); - } + this.Url ??= this.GetRequestUrl(); stringBuilder.AppendMetaPropertyContent("og:url", this.Url); diff --git a/Source/Boxed.AspNetCore/Middleware/HttpExceptionMiddleware.cs b/Source/Boxed.AspNetCore/Middleware/HttpExceptionMiddleware.cs index db1e9388..a01927cb 100644 --- a/Source/Boxed.AspNetCore/Middleware/HttpExceptionMiddleware.cs +++ b/Source/Boxed.AspNetCore/Middleware/HttpExceptionMiddleware.cs @@ -11,7 +11,7 @@ namespace Boxed.AspNetCore.Middleware; /// The handling middleware. /// /// -internal class HttpExceptionMiddleware : IMiddleware +public class HttpExceptionMiddleware : IMiddleware { private readonly RequestDelegate next; private readonly HttpExceptionMiddlewareOptions options; diff --git a/Source/Boxed.DotnetNewTest/AsyncDisposableAction.cs b/Source/Boxed.DotnetNewTest/AsyncDisposableAction.cs index 57c24883..b354060c 100644 --- a/Source/Boxed.DotnetNewTest/AsyncDisposableAction.cs +++ b/Source/Boxed.DotnetNewTest/AsyncDisposableAction.cs @@ -7,7 +7,7 @@ namespace Boxed.DotnetNewTest; /// Executes an asynchronous operation when disposed. /// /// -internal class AsyncDisposableAction : IAsyncDisposable +internal sealed class AsyncDisposableAction : IAsyncDisposable { private readonly Func action; diff --git a/Source/Boxed.DotnetNewTest/ConsoleColorScope.cs b/Source/Boxed.DotnetNewTest/ConsoleColorScope.cs index dd7a4b39..0fe0b3d0 100644 --- a/Source/Boxed.DotnetNewTest/ConsoleColorScope.cs +++ b/Source/Boxed.DotnetNewTest/ConsoleColorScope.cs @@ -6,7 +6,7 @@ namespace Boxed.DotnetNewTest; /// Sets the console foreground and/or background colour for the specified scope. /// /// -internal class ConsoleColorScope : IDisposable +internal sealed class ConsoleColorScope : IDisposable { private readonly ConsoleColor backgroundColor; private readonly ConsoleColor foregroundColor; diff --git a/Tests/Boxed.AspNetCore.Swagger.Test/SchemaFilters/JsonPatchDocumentSchemaFilterTest.cs b/Tests/Boxed.AspNetCore.Swagger.Test/SchemaFilters/JsonPatchDocumentSchemaFilterTest.cs index 014c6e6b..b3a016b3 100644 --- a/Tests/Boxed.AspNetCore.Swagger.Test/SchemaFilters/JsonPatchDocumentSchemaFilterTest.cs +++ b/Tests/Boxed.AspNetCore.Swagger.Test/SchemaFilters/JsonPatchDocumentSchemaFilterTest.cs @@ -50,7 +50,7 @@ public void Apply_TypeIsModelStateDictionary_DoesNothing() } #pragma warning disable CA1812 // Never instantiated - internal class Model + internal sealed class Model #pragma warning restore CA1812 // Never instantiated { } diff --git a/Tests/Boxed.AspNetCore.TagHelpers.Test/SubresourceIntegrityTagHelperTest.cs b/Tests/Boxed.AspNetCore.TagHelpers.Test/SubresourceIntegrityTagHelperTest.cs index d734ee57..3d8c5dff 100644 --- a/Tests/Boxed.AspNetCore.TagHelpers.Test/SubresourceIntegrityTagHelperTest.cs +++ b/Tests/Boxed.AspNetCore.TagHelpers.Test/SubresourceIntegrityTagHelperTest.cs @@ -151,7 +151,7 @@ public async Task ProcessAsync_Sha256And384And512SriNotCached_CachesSriAndReturn Assert.Equal(expectedSri, htmlString.Value); } - internal class TestSubresourceIntegrityTagHelper : SubresourceIntegrityTagHelper + internal sealed class TestSubresourceIntegrityTagHelper : SubresourceIntegrityTagHelper { public TestSubresourceIntegrityTagHelper( IDistributedCache distributedCache, diff --git a/Tests/Boxed.AspNetCore.Test/CursorTest.cs b/Tests/Boxed.AspNetCore.Test/CursorTest.cs index a02b0567..e220549c 100644 --- a/Tests/Boxed.AspNetCore.Test/CursorTest.cs +++ b/Tests/Boxed.AspNetCore.Test/CursorTest.cs @@ -242,7 +242,7 @@ public void ToCursor_NullableDateOnlyValue_ReturnsPrefixedBase64Cursor() Assert.Equal("MjAwMC0wMS0wMQ==", cursor); } - private class Item + private sealed class Item { public int Integer { get; set; } } diff --git a/Tests/Boxed.AspNetCore.Test/DistributedCacheExtensionsTest.cs b/Tests/Boxed.AspNetCore.Test/DistributedCacheExtensionsTest.cs index a54565dd..2b5e2898 100644 --- a/Tests/Boxed.AspNetCore.Test/DistributedCacheExtensionsTest.cs +++ b/Tests/Boxed.AspNetCore.Test/DistributedCacheExtensionsTest.cs @@ -32,7 +32,7 @@ public async Task GetAsJsonAsync_ValidValue_ReturnsDeserializedObjectAsync() { this.distributedCacheMock .Setup(x => x.GetAsync("Key", cancellationTokenSource.Token)) - .ReturnsAsync(Encoding.UTF8.GetBytes("{\"Value\":1}")); + .ReturnsAsync(Encoding.UTF8.GetBytes(/*lang=json,strict*/ "{\"Value\":1}")); var testClass = await this.distributedCacheMock.Object .GetAsJsonAsync("Key", null, cancellationTokenSource.Token) @@ -61,7 +61,7 @@ public async Task SetAsJsonAsync_ValidValue_SavesSerializedValueAsync() this.distributedCacheMock .Setup(x => x.SetAsync( "Key", - It.Is(y => y.SequenceEqual(Encoding.UTF8.GetBytes("{\"Value\":1}"))), + It.Is(y => y.SequenceEqual(Encoding.UTF8.GetBytes(/*lang=json,strict*/ "{\"Value\":1}"))), null, cancellationTokenSource.Token)) .Returns(Task.CompletedTask); @@ -74,7 +74,7 @@ await this.distributedCacheMock.Object public void Dispose() => Mock.VerifyAll(this.distributedCacheMock); - internal class TestClass + internal sealed class TestClass { public int Value { get; set; } } diff --git a/Tests/Boxed.AspNetCore.Test/Middleware/ServerTimingMiddlewareTest.cs b/Tests/Boxed.AspNetCore.Test/Middleware/ServerTimingMiddlewareTest.cs index d11effa9..d7d64f3e 100644 --- a/Tests/Boxed.AspNetCore.Test/Middleware/ServerTimingMiddlewareTest.cs +++ b/Tests/Boxed.AspNetCore.Test/Middleware/ServerTimingMiddlewareTest.cs @@ -49,7 +49,7 @@ public async Task InvokeAsync_SupportsTrailingHeaders_AddsServerTimingHttpHeader Assert.Equal("app;dur=0.0", header.Value.ToString()); } - internal class ResponseTrailersFeature : IHttpResponseTrailersFeature + internal sealed class ResponseTrailersFeature : IHttpResponseTrailersFeature { public IHeaderDictionary Trailers { get; set; } = new HeaderDictionary(); }