From 4dbaabd913e806424e259df55c67547f6acbe441 Mon Sep 17 00:00:00 2001 From: Paul Mcilreavy Date: Wed, 24 Mar 2021 14:44:16 +1000 Subject: [PATCH] Add Azure.Messaging.EventGrid based tests (#24) * Migrate the Azure.Messaging.EventGrid tests into here from a previously uncontrolled separate solution. * Add test Traits --- .../ActualSimulatorFixture.cs | 104 ++++++++++++++++++ .../AzureMessagingEventGridTest.cs | 93 ++++++++++++++++ .../BasicTests.cs | 14 ++- .../IntegrationContextFixture.cs} | 5 +- .../ConfigurationLoadingTests.cs | 1 + .../AdvancedFilterEventAcceptanceTests.cs | 1 + .../AdvancedFilterValidationTests.cs | 1 + .../FilterSettingsValidationTests.cs | 1 + .../NegativeFilterTestCaseContainer.cs | 2 - .../PositiveFilterTestCaseContainer.cs | 2 - .../SimpleFilterEventAcceptanceTests.cs | 1 + ...icationEventsToSubscriberCommandHandler.cs | 3 - .../ValidateAllSubscriptionsCommandHandler.cs | 2 - .../ValidateSubscriptionCommandHandler.cs | 1 - .../Extensions/HttpContextExtensions.cs | 2 +- .../SubscriptionSettingsFilterExtensions.cs | 2 - .../Middleware/EventGridMiddleware.cs | 3 - .../Middleware/RequestLoggingMiddleware.cs | 2 - .../Middleware/SasKeyValidator.cs | 1 - .../Settings/SimulatorSettings.cs | 2 - .../Settings/SubscriptionValidationStatus.cs | 1 - src/AzureEventGridSimulator/Program.cs | 3 +- src/AzureEventGridSimulator/Startup.cs | 2 - 23 files changed, 216 insertions(+), 33 deletions(-) create mode 100644 src/AzureEventGridSimulator.Tests/AzureMessagingTests/ActualSimulatorFixture.cs create mode 100644 src/AzureEventGridSimulator.Tests/AzureMessagingTests/AzureMessagingEventGridTest.cs rename src/AzureEventGridSimulator.Tests/{Integration => IntegrationTests}/BasicTests.cs (74%) rename src/AzureEventGridSimulator.Tests/{Integration/TestContextFixture.cs => IntegrationTests/IntegrationContextFixture.cs} (84%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/ConfigurationLoadingTests.cs (98%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/Filtering/AdvancedFilterEventAcceptanceTests.cs (99%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/Filtering/AdvancedFilterValidationTests.cs (99%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/Filtering/FilterSettingsValidationTests.cs (98%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/Filtering/NegativeFilterTestCaseContainer.cs (99%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/Filtering/PositiveFilterTestCaseContainer.cs (99%) rename src/AzureEventGridSimulator.Tests/{Unit => UnitTests}/Filtering/SimpleFilterEventAcceptanceTests.cs (99%) diff --git a/src/AzureEventGridSimulator.Tests/AzureMessagingTests/ActualSimulatorFixture.cs b/src/AzureEventGridSimulator.Tests/AzureMessagingTests/ActualSimulatorFixture.cs new file mode 100644 index 0000000..a1d6bb7 --- /dev/null +++ b/src/AzureEventGridSimulator.Tests/AzureMessagingTests/ActualSimulatorFixture.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace AzureEventGridSimulator.Tests.AzureMessagingTests +{ + public class ActualSimulatorFixture : IDisposable, IAsyncLifetime + { + private const string SimulatorFileName = "AzureEventGridSimulator"; + private bool _disposed; + private string _simulatorExePath; + + private Process _simulatorProcess; + + public async Task InitializeAsync() + { + var simulatorDirectory = Directory.GetCurrentDirectory(); + _simulatorExePath = Path.Combine(simulatorDirectory, $"{SimulatorFileName}.exe"); + + KillExistingSimulators(); + + _simulatorProcess = Process.Start(new ProcessStartInfo(_simulatorExePath) + { + WorkingDirectory = simulatorDirectory, + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true, + Environment = { new KeyValuePair("ASPNETCORE_ENVIRONMENT", "Development") } + }); + + var isAlive = false; + + while (!isAlive && !_simulatorProcess.StandardOutput.EndOfStream) + { + var line = await _simulatorProcess.StandardOutput.ReadLineAsync(); + + isAlive = line.Contains("It's Alive"); + } + + if (!isAlive) + { + } + } + + public Task DisposeAsync() + { + Dispose(); + return Task.CompletedTask; + } + + public void Dispose() + { + if (!_disposed) + { + if (_simulatorProcess?.HasExited == false) + { + _simulatorProcess?.Kill(true); + _simulatorProcess?.WaitForExit(); + } + + _disposed = true; + GC.SuppressFinalize(this); + } + } + + private void KillExistingSimulators() + { + try + { + // Kill any existing instances of the test simulator that may still be hanging around. + // Note: there shouldn't be any unless something went wrong and the test runner didn't exit cleanly. + var simulatorProcesses = Process.GetProcesses() + .Where(o => o.ProcessName == SimulatorFileName) + .Where(o => string.Equals(o.MainModule?.FileName, _simulatorExePath, StringComparison.OrdinalIgnoreCase)) + .ToArray(); + + foreach (var process in simulatorProcesses) + { + process.Kill(); + } + } + catch + { + // + } + } + + ~ActualSimulatorFixture() + { + Dispose(); + } + } + + [CollectionDefinition(nameof(ActualSimulatorFixtureCollection))] + public class ActualSimulatorFixtureCollection : ICollectionFixture + { + // This class has no code, and is never created. Its purpose is simply + // to be the place to apply [CollectionDefinition] + } +} diff --git a/src/AzureEventGridSimulator.Tests/AzureMessagingTests/AzureMessagingEventGridTest.cs b/src/AzureEventGridSimulator.Tests/AzureMessagingTests/AzureMessagingEventGridTest.cs new file mode 100644 index 0000000..0ad52f4 --- /dev/null +++ b/src/AzureEventGridSimulator.Tests/AzureMessagingTests/AzureMessagingEventGridTest.cs @@ -0,0 +1,93 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Messaging.EventGrid; +using Shouldly; +using Xunit; + +namespace AzureEventGridSimulator.Tests.AzureMessagingTests +{ + /// + /// Simple tests to check that we can send an event via Azure.Messaging.EventGrid library. + /// NOTE: These tests require (and automatically start) an actual instance of AzureEventGridSimulator.exe as there is no way to inject an HttpClient (from a WebApplicationFactory) + /// into Azure.Messaging.EventGrid. + /// + [Collection(nameof(ActualSimulatorFixtureCollection))] + [Trait("Category","integration-actual")] + public class AzureMessagingEventGridTest + { + private readonly ActualSimulatorFixture _actualSimulatorFixture; + + public AzureMessagingEventGridTest(ActualSimulatorFixture actualSimulatorFixture) + { + _actualSimulatorFixture = actualSimulatorFixture; + } + + [Fact] + public async Task GivenValidEvent_WhenUriContainsNonStandardPort_ThenItShouldBeAccepted() + { + var client = new EventGridPublisherClient( + new Uri("https://localhost:60101/api/events"), + new AzureKeyCredential("TheLocal+DevelopmentKey=")); + + var response = await client.SendEventAsync(new EventGridEvent("/the/subject", "The.Event.Type", "v1", new { Id = 1, Foo = "Bar" })); + + response.Status.ShouldBe((int)HttpStatusCode.OK); + } + + [Fact] + public async Task GivenValidEvents_WhenUriContainsNonStandardPort_TheyShouldBeAccepted() + { + var client = new EventGridPublisherClient( + new Uri("https://localhost:60101/api/events"), + new AzureKeyCredential("TheLocal+DevelopmentKey=")); + + var events = new[] + { + new EventGridEvent("/the/subject1", "The.Event.Type1", "v1", new { Id = 1, Foo = "Bar" }), + new EventGridEvent("/the/subject2", "The.Event.Type2", "v1", new { Id = 2, Foo = "Baz" }) + }; + + var response = await client.SendEventsAsync(events); + + response.Status.ShouldBe((int)HttpStatusCode.OK); + } + + [Fact] + public async Task GivenValidEvent_WhenUriContainsNonExistentPort_ThenItShouldNotBeAccepted() + { + var client = new EventGridPublisherClient( + new Uri("https://localhost:19999/api/events"), + new AzureKeyCredential("TheLocal+DevelopmentKey="), + new EventGridPublisherClientOptions + { Retry = { Mode = RetryMode.Fixed, MaxRetries = 0, NetworkTimeout = TimeSpan.FromSeconds(5) } }); + + var exception = await Should.ThrowAsync(async () => + { + await client.SendEventAsync(new EventGridEvent("/the/subject", "The.Event.Type", "v1", + new { Id = 1, Foo = "Bar" })); + }); + + exception.Message.ShouldContain("actively refused"); + exception.Status.ShouldBe(0); + } + + [Fact] + public async Task GivenValidEvent_WhenKeyIsWrong_ThenItShouldNotBeAccepted() + { + var client = new EventGridPublisherClient( + new Uri("https://localhost:60101/api/events"), + new AzureKeyCredential("TheWrongLocal+DevelopmentKey=")); + + var exception = await Should.ThrowAsync(async () => + { + await client.SendEventAsync(new EventGridEvent("/the/subject", "The.Event.Type", "v1", + new { Id = 1, Foo = "Bar" })); + }); + + exception.Status.ShouldBe((int)HttpStatusCode.Unauthorized); + } + } +} diff --git a/src/AzureEventGridSimulator.Tests/Integration/BasicTests.cs b/src/AzureEventGridSimulator.Tests/IntegrationTests/BasicTests.cs similarity index 74% rename from src/AzureEventGridSimulator.Tests/Integration/BasicTests.cs rename to src/AzureEventGridSimulator.Tests/IntegrationTests/BasicTests.cs index 224ee9c..1bfcb15 100644 --- a/src/AzureEventGridSimulator.Tests/Integration/BasicTests.cs +++ b/src/AzureEventGridSimulator.Tests/IntegrationTests/BasicTests.cs @@ -10,14 +10,20 @@ using Shouldly; using Xunit; -namespace AzureEventGridSimulator.Tests.Integration +namespace AzureEventGridSimulator.Tests.IntegrationTests { + /// + /// These test use a WebApplicationFactory based instance of the simulator + /// and an HttpClient to send send events to the simulator. + /// Note: this is a WIP. + /// + [Trait("Category","integration")] public class BasicTests - : IClassFixture + : IClassFixture { - private readonly TestContextFixture _factory; + private readonly IntegrationContextFixture _factory; - public BasicTests(TestContextFixture factory) + public BasicTests(IntegrationContextFixture factory) { _factory = factory; } diff --git a/src/AzureEventGridSimulator.Tests/Integration/TestContextFixture.cs b/src/AzureEventGridSimulator.Tests/IntegrationTests/IntegrationContextFixture.cs similarity index 84% rename from src/AzureEventGridSimulator.Tests/Integration/TestContextFixture.cs rename to src/AzureEventGridSimulator.Tests/IntegrationTests/IntegrationContextFixture.cs index f01e14f..0e60fbe 100644 --- a/src/AzureEventGridSimulator.Tests/Integration/TestContextFixture.cs +++ b/src/AzureEventGridSimulator.Tests/IntegrationTests/IntegrationContextFixture.cs @@ -7,10 +7,9 @@ using Microsoft.Extensions.Logging; using Xunit; -namespace AzureEventGridSimulator.Tests.Integration +namespace AzureEventGridSimulator.Tests.IntegrationTests { - // ReSharper disable once ClassNeverInstantiated.Global - public class TestContextFixture : WebApplicationFactory, IAsyncLifetime + public class IntegrationContextFixture : WebApplicationFactory, IAsyncLifetime { public Task InitializeAsync() { diff --git a/src/AzureEventGridSimulator.Tests/Unit/ConfigurationLoadingTests.cs b/src/AzureEventGridSimulator.Tests/UnitTests/ConfigurationLoadingTests.cs similarity index 98% rename from src/AzureEventGridSimulator.Tests/Unit/ConfigurationLoadingTests.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/ConfigurationLoadingTests.cs index 1fd35a0..4910474 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/ConfigurationLoadingTests.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/ConfigurationLoadingTests.cs @@ -6,6 +6,7 @@ namespace AzureEventGridSimulator.Tests.Unit { + [Trait("Category","unit")] public class ConfigurationLoadingTests { [Fact] diff --git a/src/AzureEventGridSimulator.Tests/Unit/Filtering/AdvancedFilterEventAcceptanceTests.cs b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/AdvancedFilterEventAcceptanceTests.cs similarity index 99% rename from src/AzureEventGridSimulator.Tests/Unit/Filtering/AdvancedFilterEventAcceptanceTests.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/Filtering/AdvancedFilterEventAcceptanceTests.cs index 792ed3e..6a4237e 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/Filtering/AdvancedFilterEventAcceptanceTests.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/AdvancedFilterEventAcceptanceTests.cs @@ -7,6 +7,7 @@ namespace AzureEventGridSimulator.Tests.Unit.Filtering { + [Trait("Category","unit")] public class AdvancedFilterEventAcceptanceTests { private static readonly EventGridEvent _gridEvent = new() diff --git a/src/AzureEventGridSimulator.Tests/Unit/Filtering/AdvancedFilterValidationTests.cs b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/AdvancedFilterValidationTests.cs similarity index 99% rename from src/AzureEventGridSimulator.Tests/Unit/Filtering/AdvancedFilterValidationTests.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/Filtering/AdvancedFilterValidationTests.cs index 1c7f268..449ed0c 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/Filtering/AdvancedFilterValidationTests.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/AdvancedFilterValidationTests.cs @@ -7,6 +7,7 @@ namespace AzureEventGridSimulator.Tests.Unit.Filtering { + [Trait("Category","unit")] public class AdvancedFilterValidationTests { private static SimulatorSettings GetValidSimulatorSettings(AdvancedFilterSetting advancedFilter) diff --git a/src/AzureEventGridSimulator.Tests/Unit/Filtering/FilterSettingsValidationTests.cs b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/FilterSettingsValidationTests.cs similarity index 98% rename from src/AzureEventGridSimulator.Tests/Unit/Filtering/FilterSettingsValidationTests.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/Filtering/FilterSettingsValidationTests.cs index 49a38a1..b95b213 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/Filtering/FilterSettingsValidationTests.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/FilterSettingsValidationTests.cs @@ -6,6 +6,7 @@ namespace AzureEventGridSimulator.Tests.Unit.Filtering { + [Trait("Category","unit")] public class FilterSettingsValidationTests { private static SimulatorSettings GetValidSimulatorSettings(FilterSetting filter) diff --git a/src/AzureEventGridSimulator.Tests/Unit/Filtering/NegativeFilterTestCaseContainer.cs b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/NegativeFilterTestCaseContainer.cs similarity index 99% rename from src/AzureEventGridSimulator.Tests/Unit/Filtering/NegativeFilterTestCaseContainer.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/Filtering/NegativeFilterTestCaseContainer.cs index fa55115..a775af0 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/Filtering/NegativeFilterTestCaseContainer.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/NegativeFilterTestCaseContainer.cs @@ -4,8 +4,6 @@ using System.Linq; using AzureEventGridSimulator.Infrastructure.Settings; -// ReSharper disable StringLiteralTypo - namespace AzureEventGridSimulator.Tests.Unit.Filtering { internal class NegativeFilterTestCaseContainer : IEnumerable diff --git a/src/AzureEventGridSimulator.Tests/Unit/Filtering/PositiveFilterTestCaseContainer.cs b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/PositiveFilterTestCaseContainer.cs similarity index 99% rename from src/AzureEventGridSimulator.Tests/Unit/Filtering/PositiveFilterTestCaseContainer.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/Filtering/PositiveFilterTestCaseContainer.cs index 37c8be4..8219697 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/Filtering/PositiveFilterTestCaseContainer.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/PositiveFilterTestCaseContainer.cs @@ -4,8 +4,6 @@ using System.Linq; using AzureEventGridSimulator.Infrastructure.Settings; -// ReSharper disable StringLiteralTypo - namespace AzureEventGridSimulator.Tests.Unit.Filtering { internal class PositiveFilterTestCaseContainer : IEnumerable diff --git a/src/AzureEventGridSimulator.Tests/Unit/Filtering/SimpleFilterEventAcceptanceTests.cs b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/SimpleFilterEventAcceptanceTests.cs similarity index 99% rename from src/AzureEventGridSimulator.Tests/Unit/Filtering/SimpleFilterEventAcceptanceTests.cs rename to src/AzureEventGridSimulator.Tests/UnitTests/Filtering/SimpleFilterEventAcceptanceTests.cs index 9521da0..75012cf 100644 --- a/src/AzureEventGridSimulator.Tests/Unit/Filtering/SimpleFilterEventAcceptanceTests.cs +++ b/src/AzureEventGridSimulator.Tests/UnitTests/Filtering/SimpleFilterEventAcceptanceTests.cs @@ -6,6 +6,7 @@ namespace AzureEventGridSimulator.Tests.Unit.Filtering { + [Trait("Category","unit")] public class SimpleFilterEventAcceptanceTests { [Fact] diff --git a/src/AzureEventGridSimulator/Domain/Commands/SendNotificationEventsToSubscriberCommandHandler.cs b/src/AzureEventGridSimulator/Domain/Commands/SendNotificationEventsToSubscriberCommandHandler.cs index 86c319b..6419ee0 100644 --- a/src/AzureEventGridSimulator/Domain/Commands/SendNotificationEventsToSubscriberCommandHandler.cs +++ b/src/AzureEventGridSimulator/Domain/Commands/SendNotificationEventsToSubscriberCommandHandler.cs @@ -14,8 +14,6 @@ namespace AzureEventGridSimulator.Domain.Commands { - // ReSharper disable once UnusedMember.Global - // ReSharper disable once UnusedType.Global public class SendNotificationEventsToSubscriberCommandHandler : AsyncRequestHandler { private readonly IHttpClientFactory _httpClientFactory; @@ -99,7 +97,6 @@ private async Task SendToSubscriber(SubscriptionSettings subscription, IEnumerab { if (subscription.Filter.AcceptsEvent(evt)) { - // ReSharper disable once MethodHasAsyncOverload var json = JsonConvert.SerializeObject(new[] { evt }, Formatting.Indented); using var content = new StringContent(json, Encoding.UTF8, "application/json"); var httpClient = _httpClientFactory.CreateClient(); diff --git a/src/AzureEventGridSimulator/Domain/Commands/ValidateAllSubscriptionsCommandHandler.cs b/src/AzureEventGridSimulator/Domain/Commands/ValidateAllSubscriptionsCommandHandler.cs index 5c3ac17..1cdf8bd 100644 --- a/src/AzureEventGridSimulator/Domain/Commands/ValidateAllSubscriptionsCommandHandler.cs +++ b/src/AzureEventGridSimulator/Domain/Commands/ValidateAllSubscriptionsCommandHandler.cs @@ -14,7 +14,6 @@ namespace AzureEventGridSimulator.Domain.Commands { - // ReSharper disable once UnusedType.Global public class ValidateAllSubscriptionsCommandHandler : IRequestHandler { private readonly IHttpClientFactory _httpClientFactory; @@ -71,7 +70,6 @@ private async Task ValidateSubscription(TopicSettings topic, SubscriptionSetting } }; - // ReSharper disable once MethodHasAsyncOverload var json = JsonConvert.SerializeObject(new[] { evt }, Formatting.Indented); using var content = new StringContent(json, Encoding.UTF8, "application/json"); using var httpClient = _httpClientFactory.CreateClient(); diff --git a/src/AzureEventGridSimulator/Domain/Commands/ValidateSubscriptionCommandHandler.cs b/src/AzureEventGridSimulator/Domain/Commands/ValidateSubscriptionCommandHandler.cs index 2923625..586ab9f 100644 --- a/src/AzureEventGridSimulator/Domain/Commands/ValidateSubscriptionCommandHandler.cs +++ b/src/AzureEventGridSimulator/Domain/Commands/ValidateSubscriptionCommandHandler.cs @@ -7,7 +7,6 @@ namespace AzureEventGridSimulator.Domain.Commands { - // ReSharper disable once UnusedType.Global public class ValidateSubscriptionCommandHandler : IRequestHandler { private readonly ILogger _logger; diff --git a/src/AzureEventGridSimulator/Infrastructure/Extensions/HttpContextExtensions.cs b/src/AzureEventGridSimulator/Infrastructure/Extensions/HttpContextExtensions.cs index c82b26b..840d121 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Extensions/HttpContextExtensions.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Extensions/HttpContextExtensions.cs @@ -27,7 +27,7 @@ public static async Task WriteErrorResponse(this HttpContext context, HttpStatus context.Response.Headers.Add(HeaderNames.ContentType, "application/json"); context.Response.StatusCode = (int)statusCode; - // ReSharper disable once MethodHasAsyncOverload + await context.Response.WriteAsync(JsonConvert.SerializeObject(error, Formatting.Indented)); } } diff --git a/src/AzureEventGridSimulator/Infrastructure/Extensions/SubscriptionSettingsFilterExtensions.cs b/src/AzureEventGridSimulator/Infrastructure/Extensions/SubscriptionSettingsFilterExtensions.cs index 3ae4f06..013fc19 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Extensions/SubscriptionSettingsFilterExtensions.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Extensions/SubscriptionSettingsFilterExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Linq; using AzureEventGridSimulator.Domain.Entities; using AzureEventGridSimulator.Infrastructure.Settings; @@ -144,7 +143,6 @@ private static bool Try(Func function, bool valueOnException = false) } } - [SuppressMessage("ReSharper", "InvertIf")] private static bool TryGetValue(this EventGridEvent gridEvent, string key, out object value) { var retval = false; diff --git a/src/AzureEventGridSimulator/Infrastructure/Middleware/EventGridMiddleware.cs b/src/AzureEventGridSimulator/Infrastructure/Middleware/EventGridMiddleware.cs index 7a5c31f..8092424 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Middleware/EventGridMiddleware.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Middleware/EventGridMiddleware.cs @@ -11,7 +11,6 @@ namespace AzureEventGridSimulator.Infrastructure.Middleware { - // ReSharper disable once ClassNeverInstantiated.Global public class EventGridMiddleware { private readonly RequestDelegate _next; @@ -21,7 +20,6 @@ public EventGridMiddleware(RequestDelegate next) _next = next; } - // ReSharper disable once UnusedMember.Global public async Task InvokeAsync(HttpContext context, SimulatorSettings simulatorSettings, SasKeyValidator sasHeaderValidator, @@ -95,7 +93,6 @@ private async Task ValidateNotificationRequest(HttpContext context, foreach (var evt in events) { - // ReSharper disable once MethodHasAsyncOverload var eventSize = JsonConvert.SerializeObject(evt, Formatting.None).Length; logger.LogTrace("Event is {Bytes} in length", eventSize); diff --git a/src/AzureEventGridSimulator/Infrastructure/Middleware/RequestLoggingMiddleware.cs b/src/AzureEventGridSimulator/Infrastructure/Middleware/RequestLoggingMiddleware.cs index 14ad936..0059f94 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Middleware/RequestLoggingMiddleware.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Middleware/RequestLoggingMiddleware.cs @@ -10,7 +10,6 @@ namespace AzureEventGridSimulator.Infrastructure.Middleware { - // ReSharper disable once ClassNeverInstantiated.Global public class RequestLoggingMiddleware { private readonly RequestDelegate _next; @@ -20,7 +19,6 @@ public RequestLoggingMiddleware(RequestDelegate next) _next = next; } - // ReSharper disable once UnusedMember.Global public async Task InvokeAsync(HttpContext context, ILogger logger) { diff --git a/src/AzureEventGridSimulator/Infrastructure/Middleware/SasKeyValidator.cs b/src/AzureEventGridSimulator/Infrastructure/Middleware/SasKeyValidator.cs index af9133e..71d744a 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Middleware/SasKeyValidator.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Middleware/SasKeyValidator.cs @@ -48,7 +48,6 @@ public bool IsValid(IHeaderDictionary requestHeaders, string topicKey) return true; } - // ReSharper disable once InvertIf if (requestHeaders .Any(h => string.Equals(HeaderNames.Authorization, h.Key, StringComparison.OrdinalIgnoreCase))) { diff --git a/src/AzureEventGridSimulator/Infrastructure/Settings/SimulatorSettings.cs b/src/AzureEventGridSimulator/Infrastructure/Settings/SimulatorSettings.cs index 263e081..91ec054 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Settings/SimulatorSettings.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Settings/SimulatorSettings.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Linq; using Newtonsoft.Json; @@ -10,7 +9,6 @@ public class SimulatorSettings [JsonProperty(PropertyName = "topics", Required = Required.Always)] public TopicSettings[] Topics { get; set; } = Array.Empty(); - [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] public void Validate() { if (Topics.GroupBy(o => o.Port).Count() != Topics.Length) diff --git a/src/AzureEventGridSimulator/Infrastructure/Settings/SubscriptionValidationStatus.cs b/src/AzureEventGridSimulator/Infrastructure/Settings/SubscriptionValidationStatus.cs index 35b806a..9689915 100644 --- a/src/AzureEventGridSimulator/Infrastructure/Settings/SubscriptionValidationStatus.cs +++ b/src/AzureEventGridSimulator/Infrastructure/Settings/SubscriptionValidationStatus.cs @@ -2,7 +2,6 @@ { public enum SubscriptionValidationStatus { - // ReSharper disable once UnusedMember.Global None = 0, ValidationEventSent = 1, ValidationFailed = 2, diff --git a/src/AzureEventGridSimulator/Program.cs b/src/AzureEventGridSimulator/Program.cs index add62e2..7853fc9 100644 --- a/src/AzureEventGridSimulator/Program.cs +++ b/src/AzureEventGridSimulator/Program.cs @@ -41,7 +41,6 @@ private static IWebHostBuilder ConfigureWebHost(string[] args, IConfiguration co X509Certificate2 certificate = null; if (string.IsNullOrWhiteSpace(cert) == false && string.IsNullOrWhiteSpace(certPass) == false) { - // ReSharper disable once InconsistentLogPropertyNaming Log.Warning("ASPNETCORE_Kestrel__Certificates__Default__Path is defined, using '{ASPNETCORE_Kestrel__Certificates__Default__Path}'", cert); certificate = new X509Certificate2(cert, certPass); } @@ -166,7 +165,7 @@ private static void ShowSerilogUsingWarningIfNecessary(IConfiguration config) { var usingNeedsToBeConfigured = config.GetSection("Serilog").Exists() && !config.GetSection("Serilog:Using").Exists(); - // ReSharper disable once InvertIf + if (usingNeedsToBeConfigured) { // Warn the user about the necessity for the serilog using section with .net 5.0. diff --git a/src/AzureEventGridSimulator/Startup.cs b/src/AzureEventGridSimulator/Startup.cs index 76cfbc4..f9cfcaf 100644 --- a/src/AzureEventGridSimulator/Startup.cs +++ b/src/AzureEventGridSimulator/Startup.cs @@ -54,8 +54,6 @@ public void ConfigureServices(IServiceCollection services) }); } - // ReSharper disable once UnusedMember.Global - // ReSharper disable once CA1822 public static void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime, ILogger logger)