From 15f008e9cc3a4240217d72bce3f4247938c7183a Mon Sep 17 00:00:00 2001 From: skwasjer Date: Sun, 10 Jul 2022 03:03:04 +0200 Subject: [PATCH] chore: enable nullable in test projects --- Directory.Build.props | 1 + .../Correlate.Abstractions.csproj | 1 - .../Correlate.AspNetCore.csproj | 1 - src/Correlate.Core/Correlate.Core.csproj | 1 - .../Correlate.DependencyInjection.csproj | 1 - .../AspNetCore/Fixtures/Startup.cs | 4 +- .../AspNetCore/Fixtures/TestController.cs | 4 +- .../Middleware/CorrelateMiddlewareTests.cs | 8 ++-- .../AspNetCore/TestResponseFeature.cs | 4 +- .../CorrelationContextAccessorTests.cs | 2 +- .../CorrelationManagerTests.cs | 40 +++++++++---------- .../Http/CorrelatingMessageHandlerTests.cs | 6 ++- .../HeaderDictionaryExtensionsTests.cs | 14 +++---- .../FluentAssertions/DelegateAssertions.cs | 18 ++++----- .../FluentAssertions/ExpectedRegistration.cs | 4 +- .../ResponseHeadersAssertions.cs | 8 ++-- .../ServiceCollectionAssertions.cs | 7 +++- .../TestCases/NullArgumentCheckFixture.cs | 3 +- test/Correlate.Testing/TestLogger.cs | 10 ++--- 19 files changed, 70 insertions(+), 67 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 5d580e2..c40e579 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,6 +4,7 @@ latest true false + enable enable diff --git a/src/Correlate.Abstractions/Correlate.Abstractions.csproj b/src/Correlate.Abstractions/Correlate.Abstractions.csproj index c7822f2..8173aab 100644 --- a/src/Correlate.Abstractions/Correlate.Abstractions.csproj +++ b/src/Correlate.Abstractions/Correlate.Abstractions.csproj @@ -3,7 +3,6 @@ net6.0;netstandard2.0 Correlate - enable diff --git a/src/Correlate.AspNetCore/Correlate.AspNetCore.csproj b/src/Correlate.AspNetCore/Correlate.AspNetCore.csproj index c2b7142..7eb80c4 100644 --- a/src/Correlate.AspNetCore/Correlate.AspNetCore.csproj +++ b/src/Correlate.AspNetCore/Correlate.AspNetCore.csproj @@ -3,7 +3,6 @@ net6.0;netcoreapp3.1 Correlate - enable diff --git a/src/Correlate.Core/Correlate.Core.csproj b/src/Correlate.Core/Correlate.Core.csproj index d9ea691..c629a91 100644 --- a/src/Correlate.Core/Correlate.Core.csproj +++ b/src/Correlate.Core/Correlate.Core.csproj @@ -3,7 +3,6 @@ net6.0;netstandard2.0 Correlate - enable diff --git a/src/Correlate.DependencyInjection/Correlate.DependencyInjection.csproj b/src/Correlate.DependencyInjection/Correlate.DependencyInjection.csproj index e9ed6de..a8b58bb 100644 --- a/src/Correlate.DependencyInjection/Correlate.DependencyInjection.csproj +++ b/src/Correlate.DependencyInjection/Correlate.DependencyInjection.csproj @@ -2,7 +2,6 @@ net6.0;netstandard2.0 - enable diff --git a/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/Startup.cs b/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/Startup.cs index 252fd64..0a48157 100644 --- a/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/Startup.cs +++ b/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/Startup.cs @@ -6,11 +6,11 @@ namespace Correlate.AspNetCore.Fixtures; public class Startup { - public static ITestCorrelatorContext LastRequestContext { get; private set; } + public static ITestCorrelatorContext LastRequestContext { get; private set; } = default!; public void ConfigureServices(IServiceCollection services) { - services.AddCorrelate(); + services.AddCorrelate(opts => opts.IncludeInResponse = true); services .AddHttpClient(client => client.BaseAddress = new Uri("http://0.0.0.0")) diff --git a/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/TestController.cs b/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/TestController.cs index fc90397..ba572b3 100644 --- a/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/TestController.cs +++ b/test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/TestController.cs @@ -23,7 +23,7 @@ public TestController(ILogger logger, ICorrelationContextAccesso [HttpGet] public IActionResult Get() { - _logger.LogInformation("controller action: ok - {Id}", _correlationContextAccessor.CorrelationContext.CorrelationId); + _logger.LogInformation("controller action: ok - {Id}", _correlationContextAccessor.CorrelationContext?.CorrelationId); return Ok("ok"); } @@ -34,7 +34,7 @@ public IActionResult Get() [HttpGet("correlate_client_request")] public async Task CorrelateClientRequest() { - _logger.LogInformation("controller action: ok - {Id}", _correlationContextAccessor.CorrelationContext.CorrelationId); + _logger.LogInformation("controller action: ok - {Id}", _correlationContextAccessor.CorrelationContext?.CorrelationId); HttpResponseMessage response = await _httpClient.GetAsync("correlated_external_call"); diff --git a/test/Correlate.AspNetCore.Tests/AspNetCore/Middleware/CorrelateMiddlewareTests.cs b/test/Correlate.AspNetCore.Tests/AspNetCore/Middleware/CorrelateMiddlewareTests.cs index b721c5d..d616f34 100644 --- a/test/Correlate.AspNetCore.Tests/AspNetCore/Middleware/CorrelateMiddlewareTests.cs +++ b/test/Correlate.AspNetCore.Tests/AspNetCore/Middleware/CorrelateMiddlewareTests.cs @@ -40,8 +40,10 @@ public CorrelateMiddlewareTests(TestAppFactory factory) public void Dispose() { + // ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract _factory?.Dispose(); _mockHttp?.Dispose(); + // ReSharper restore ConditionalAccessQualifierIsNonNullableAccordingToAPIContract GC.SuppressFinalize(this); } @@ -160,7 +162,7 @@ public async Task When_calling_external_service_in_microservice_should_forward_c HttpResponseMessage response = await client.SendAsync(request); // Assert - string errorMessage = null; + string? errorMessage = null; if (!response.IsSuccessStatusCode) { errorMessage = await response.Content.ReadAsStringAsync(); @@ -184,11 +186,11 @@ public async Task When_executing_multiple_requests_the_response_should_contain_n var responses = (await Task.WhenAll(requestTasks)).ToList(); // Assert - string[] correlationIds = responses + string?[] correlationIds = responses .Select(r => r.Headers.SingleOrDefault(h => h.Key == CorrelationHttpHeaders.CorrelationId).Value.FirstOrDefault()) .ToArray(); - var distinctCorrelationIds = new HashSet(correlationIds); + var distinctCorrelationIds = correlationIds.ToHashSet(); correlationIds .Should() .HaveCount(distinctCorrelationIds.Count) diff --git a/test/Correlate.AspNetCore.Tests/AspNetCore/TestResponseFeature.cs b/test/Correlate.AspNetCore.Tests/AspNetCore/TestResponseFeature.cs index 5f18d07..1c1929c 100644 --- a/test/Correlate.AspNetCore.Tests/AspNetCore/TestResponseFeature.cs +++ b/test/Correlate.AspNetCore.Tests/AspNetCore/TestResponseFeature.cs @@ -8,7 +8,7 @@ namespace Correlate.AspNetCore; internal class TestResponseFeature : IHttpResponseFeature { private readonly HeaderDictionary _headers = new(); - private string _reasonPhrase; + private string? _reasonPhrase; private Func _responseCompletedAsync = () => Task.FromResult(true); private Func _responseStartingAsync = () => Task.FromResult(true); private int _statusCode; @@ -42,7 +42,7 @@ public int StatusCode } } - public string ReasonPhrase + public string? ReasonPhrase { get => _reasonPhrase; set diff --git a/test/Correlate.Core.Tests/CorrelationContextAccessorTests.cs b/test/Correlate.Core.Tests/CorrelationContextAccessorTests.cs index e231832..db40737 100644 --- a/test/Correlate.Core.Tests/CorrelationContextAccessorTests.cs +++ b/test/Correlate.Core.Tests/CorrelationContextAccessorTests.cs @@ -20,7 +20,7 @@ private async Task RunChildTask(string id, int level = 0) await Task.Run(() => Task.Delay(_rnd.Next(100))); // Do nested run. - string childId = null; + string? childId = null; if (level < recursiveRuns) { childId = await RunChildTask(id, level + 1); diff --git a/test/Correlate.Core.Tests/CorrelationManagerTests.cs b/test/Correlate.Core.Tests/CorrelationManagerTests.cs index 3f0ce25..c082041 100644 --- a/test/Correlate.Core.Tests/CorrelationManagerTests.cs +++ b/test/Correlate.Core.Tests/CorrelationManagerTests.cs @@ -294,13 +294,13 @@ public Task When_starting_correlationContext_inside_running_context_with_same_id { return _sut.CorrelateAsync(async () => { - CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? parentContext = _correlationContextAccessor.CorrelationContext; parentContext.Should().NotBeNull(); await _sut.CorrelateAsync(parentContext?.CorrelationId, () => { - CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should() .NotBe(parentContext) .And.BeEquivalentTo(parentContext); @@ -315,11 +315,11 @@ public Task When_starting_correlationContext_inside_running_context_without_spec { return _sut.CorrelateAsync(async () => { - CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? parentContext = _correlationContextAccessor.CorrelationContext; await _sut.CorrelateAsync(() => { - CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should() .NotBe(parentContext) .And.BeEquivalentTo(parentContext); @@ -338,14 +338,14 @@ public Task When_starting_correlationContext_when_another_context_is_active_shou return _sut.CorrelateAsync(parentContextId, async () => { - CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? parentContext = _correlationContextAccessor.CorrelationContext; parentContext.Should().NotBeNull(); parentContext?.CorrelationId.Should().Be(parentContextId); await _sut.CorrelateAsync(innerContextId, () => { - CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should().NotBeNull(); innerContext.Should().NotBe(parentContext); innerContext?.CorrelationId.Should().Be(innerContextId); @@ -600,13 +600,13 @@ public void When_starting_correlationContext_inside_running_context_with_same_id { _sut.Correlate(() => { - CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? parentContext = _correlationContextAccessor.CorrelationContext; parentContext.Should().NotBeNull(); _sut.Correlate(parentContext?.CorrelationId, () => { - CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should() .NotBe(parentContext) .And.BeEquivalentTo(parentContext); @@ -619,11 +619,11 @@ public void When_starting_correlationContext_inside_running_context_without_spec { _sut.Correlate(() => { - CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? parentContext = _correlationContextAccessor.CorrelationContext; _sut.Correlate(() => { - CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should() .NotBe(parentContext) .And.BeEquivalentTo(parentContext); @@ -640,14 +640,14 @@ public void When_starting_correlationContext_when_another_context_is_active_shou _sut.Correlate(parentContextId, () => { - CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? parentContext = _correlationContextAccessor.CorrelationContext; parentContext.Should().NotBeNull(); parentContext?.CorrelationId.Should().Be(parentContextId); _sut.Correlate(innerContextId, () => { - CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; + CorrelationContext? innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should().NotBeNull(); innerContext.Should().NotBe(parentContext); innerContext?.CorrelationId.Should().Be(innerContextId); @@ -701,19 +701,19 @@ static int ReturningCorrelatedFunc() return new[] { // Instance members - DelegateTestCase.Create(instance.CorrelateAsync, (string)null, (Func)CorrelatedTask, (OnException)null), - DelegateTestCase.Create(instance.CorrelateAsync, (string)null, (Func>)ReturningCorrelatedTask, (OnException)null), - DelegateTestCase.Create(instance.Correlate, (string)null, (Action)CorrelatedAction, (OnException)null), - DelegateTestCase.Create(instance.Correlate, (string)null, (Func)ReturningCorrelatedFunc, (OnException)null), + DelegateTestCase.Create(instance.CorrelateAsync, (string?)null, (Func)CorrelatedTask, (OnException?)null), + DelegateTestCase.Create(instance.CorrelateAsync, (string?)null, (Func>)ReturningCorrelatedTask, (OnException?)null), + DelegateTestCase.Create(instance.Correlate, (string?)null, (Action)CorrelatedAction, (OnException?)null), + DelegateTestCase.Create(instance.Correlate, (string?)null, (Func)ReturningCorrelatedFunc, (OnException?)null), // Extensions DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, (Func)CorrelatedTask), DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, (Func>)ReturningCorrelatedTask), DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, (Action)CorrelatedAction), DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, (Func)ReturningCorrelatedFunc), - DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, (Func)CorrelatedTask, (OnException)null), - DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, (Func>)ReturningCorrelatedTask, (OnException)null), - DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, (Action)CorrelatedAction, (OnException)null), - DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, (Func)ReturningCorrelatedFunc, (OnException)null) + DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, (Func)CorrelatedTask, (OnException?)null), + DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, (Func>)ReturningCorrelatedTask, (OnException?)null), + DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, (Action)CorrelatedAction, (OnException?)null), + DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, (Func)ReturningCorrelatedFunc, (OnException?)null) } .SelectMany(tc => tc.GetNullArgumentTestCases()); } diff --git a/test/Correlate.Core.Tests/Http/CorrelatingMessageHandlerTests.cs b/test/Correlate.Core.Tests/Http/CorrelatingMessageHandlerTests.cs index ad33aa3..1e4e2a0 100644 --- a/test/Correlate.Core.Tests/Http/CorrelatingMessageHandlerTests.cs +++ b/test/Correlate.Core.Tests/Http/CorrelatingMessageHandlerTests.cs @@ -28,16 +28,18 @@ public CorrelatingMessageHandlerTests() public void Dispose() { + // ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract _sut?.Dispose(); _httpClient?.Dispose(); _mockHttp?.Dispose(); + // ReSharper restore ConditionalAccessQualifierIsNonNullableAccordingToAPIContract } [Fact] public async Task Given_a_correlation_context_should_add() { _contextAccessor.CorrelationContext?.CorrelationId.Should().NotBeNull(); - string correlationId = _contextAccessor.CorrelationContext!.CorrelationId; + string? correlationId = _contextAccessor.CorrelationContext?.CorrelationId; _mockHttp .When(matching => matching @@ -87,7 +89,7 @@ public async Task Given_headerName_is_overridden_should_not_use_default_headerNa { _correlateClientOptions.RequestHeader = "custom-header"; _contextAccessor.CorrelationContext?.CorrelationId.Should().NotBeNull(); - string correlationId = _contextAccessor.CorrelationContext!.CorrelationId; + string? correlationId = _contextAccessor.CorrelationContext?.CorrelationId; _mockHttp .When(matching => matching diff --git a/test/Correlate.Core.Tests/Http/Extensions/HeaderDictionaryExtensionsTests.cs b/test/Correlate.Core.Tests/Http/Extensions/HeaderDictionaryExtensionsTests.cs index 34410ac..d3feb85 100644 --- a/test/Correlate.Core.Tests/Http/Extensions/HeaderDictionaryExtensionsTests.cs +++ b/test/Correlate.Core.Tests/Http/Extensions/HeaderDictionaryExtensionsTests.cs @@ -20,7 +20,7 @@ public void Given_list_of_accepted_headers_when_request_contains_one_of_the_head _sut.Add(requestHeaderKey, new StringValues(CorrelationId)); // Act - KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { "first-header", "second-header", "third-header" }); + KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { "first-header", "second-header", "third-header" }); // Assert header.Should().BeEquivalentTo(new KeyValuePair(requestHeaderKey, CorrelationId)); @@ -37,7 +37,7 @@ public void When_getting_by_custom_header_name_should_get_value() _sut.Add(TestHeaderName, new StringValues(CorrelationId)); // Act - KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { TestHeaderName }); + KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { TestHeaderName }); // Assert header.Should().BeEquivalentTo(new KeyValuePair(TestHeaderName, CorrelationId)); @@ -49,7 +49,7 @@ public void When_getting_by_name_it_should_get_value() _sut.Add(CorrelationHttpHeaders.CorrelationId, new StringValues(CorrelationId)); // Act - KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { CorrelationHttpHeaders.CorrelationId }); + KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { CorrelationHttpHeaders.CorrelationId }); // Assert header.Should().BeEquivalentTo(new KeyValuePair(CorrelationHttpHeaders.CorrelationId, CorrelationId)); @@ -59,20 +59,20 @@ public void When_getting_by_name_it_should_get_value() public void When_header_is_not_found_should_return_preferred_header_without_value() { // Act - KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { TestHeaderName }); + KeyValuePair header = _sut.GetCorrelationIdHeader(new[] { TestHeaderName }); // Assert - header.Should().BeEquivalentTo(new KeyValuePair(TestHeaderName, null)); + header.Should().BeEquivalentTo(new KeyValuePair(TestHeaderName, null)); } [Fact] public void When_using_empty_accepted_headers_should_throw() { _sut.Add(CorrelationHttpHeaders.CorrelationId, new StringValues(CorrelationId)); - var expectedHeader = new KeyValuePair(CorrelationHttpHeaders.CorrelationId, null); + var expectedHeader = new KeyValuePair(CorrelationHttpHeaders.CorrelationId, null); // Act - KeyValuePair header = _sut.GetCorrelationIdHeader(Array.Empty()); + KeyValuePair header = _sut.GetCorrelationIdHeader(Array.Empty()); // Assert header.Should().BeEquivalentTo(expectedHeader, "it should not take correlation id from header dictionary but still return header key"); diff --git a/test/Correlate.Testing/FluentAssertions/DelegateAssertions.cs b/test/Correlate.Testing/FluentAssertions/DelegateAssertions.cs index 6d21b41..a9aca3e 100644 --- a/test/Correlate.Testing/FluentAssertions/DelegateAssertions.cs +++ b/test/Correlate.Testing/FluentAssertions/DelegateAssertions.cs @@ -60,15 +60,15 @@ public ExceptionAssertions Throw params object[] becauseArgs) { Execute.Assertion - .ForCondition(Subject != null) + .ForCondition(Subject is not null) .BecauseOf(because, becauseArgs) .FailWith("Expected {context} not to throw{reason}, but found ."); try { // ReSharper disable once PossibleNullReferenceException - return new AndWhichConstraint(this, Subject.DynamicInvoke()); + return new AndWhichConstraint(this, Subject!.DynamicInvoke()!); } - catch (TargetInvocationException ex) when (ex.InnerException != null) + catch (TargetInvocationException ex) when (ex.InnerException is not null) { NotThrowInternal(ex.InnerException, because, becauseArgs); return new AndWhichConstraint(this, default); @@ -98,15 +98,15 @@ public AndWhichConstraint NotThrow params object[] becauseArgs) { Execute.Assertion - .ForCondition(Subject != null) + .ForCondition(Subject is not null) .BecauseOf(because, becauseArgs) .FailWith("Expected {context} not to throw{reason}, but found ."); try { // ReSharper disable once PossibleNullReferenceException - return new AndWhichConstraint(this, Subject.DynamicInvoke(args)); + return new AndWhichConstraint(this, Subject!.DynamicInvoke(args)!); } - catch (TargetInvocationException ex) when (ex.InnerException != null) + catch (TargetInvocationException ex) when (ex.InnerException is not null) { NotThrowInternal(ex.InnerException, because, becauseArgs); return new AndWhichConstraint(this, default); @@ -118,14 +118,14 @@ public AndWhichConstraint NotThrow } } - private Exception InvokeSubjectWithInterception(object[] args) + private Exception? InvokeSubjectWithInterception(object[] args) { - Exception exception = null; + Exception? exception = null; try { Subject.DynamicInvoke(args); } - catch (TargetInvocationException ex) when (ex.InnerException != null) + catch (TargetInvocationException ex) when (ex.InnerException is not null) { exception = ex.InnerException; } diff --git a/test/Correlate.Testing/FluentAssertions/ExpectedRegistration.cs b/test/Correlate.Testing/FluentAssertions/ExpectedRegistration.cs index 9b31f9f..5d95084 100644 --- a/test/Correlate.Testing/FluentAssertions/ExpectedRegistration.cs +++ b/test/Correlate.Testing/FluentAssertions/ExpectedRegistration.cs @@ -4,8 +4,8 @@ namespace Correlate.Testing.FluentAssertions; public class ExpectedRegistration { - public Type ServiceType { get; set; } - public Type ImplementationType { get; set; } + public Type ServiceType { get; set; } = default!; + public Type ImplementationType { get; set; } = default!; public ServiceLifetime Lifetime { get; set; } public override string ToString() diff --git a/test/Correlate.Testing/FluentAssertions/ResponseHeadersAssertions.cs b/test/Correlate.Testing/FluentAssertions/ResponseHeadersAssertions.cs index 84ef642..191b845 100644 --- a/test/Correlate.Testing/FluentAssertions/ResponseHeadersAssertions.cs +++ b/test/Correlate.Testing/FluentAssertions/ResponseHeadersAssertions.cs @@ -23,14 +23,14 @@ public WhichValueConstraint> Cont .WithExpectation("Expected {context:headers} to contain {0}{reason}, ", headerName) .Given(() => { - Subject.TryGetValues(headerName!, out IEnumerable values); + Subject.TryGetValues(headerName!, out IEnumerable? values); return values; }) - .ForCondition(values => values != null) + .ForCondition(values => values is not null) .FailWith("but found no matching header.") ; - Subject.TryGetValues(headerName!, out IEnumerable obj); - return new WhichValueConstraint>(this, obj); + Subject.TryGetValues(headerName, out IEnumerable? obj); + return new WhichValueConstraint>(this, obj!); } } diff --git a/test/Correlate.Testing/FluentAssertions/ServiceCollectionAssertions.cs b/test/Correlate.Testing/FluentAssertions/ServiceCollectionAssertions.cs index fb51949..aef34fa 100644 --- a/test/Correlate.Testing/FluentAssertions/ServiceCollectionAssertions.cs +++ b/test/Correlate.Testing/FluentAssertions/ServiceCollectionAssertions.cs @@ -37,9 +37,12 @@ public AndConstraint BeRegistered(Type serviceType, .Given(reg => reg.FirstOrDefault(d => d.Lifetime == lifetime)) .ForCondition(r => // Match implementation, instance or factory + r is not null + && ( r.ImplementationType == implementationType - || (r.ImplementationInstance != null && implementationType.IsInstanceOfType(r.ImplementationInstance)) - || r.ImplementationFactory != null + || (r.ImplementationInstance is not null && implementationType.IsInstanceOfType(r.ImplementationInstance)) + || r.ImplementationFactory is not null + ) ) .FailWith("but it does not.") ; diff --git a/test/Correlate.Testing/TestCases/NullArgumentCheckFixture.cs b/test/Correlate.Testing/TestCases/NullArgumentCheckFixture.cs index 1b6fdd9..9752297 100644 --- a/test/Correlate.Testing/TestCases/NullArgumentCheckFixture.cs +++ b/test/Correlate.Testing/TestCases/NullArgumentCheckFixture.cs @@ -27,7 +27,6 @@ public static void Execute(params object[] testArgs) ArgumentException ex = param.ParameterType == typeof(string) ? func.Should().Throw(args).Which : func.Should().Throw(args).Which; - string paramName = ex.ParamName; - paramName.Should().Be(expectedParamName, "no null was provided for {1}", expectedParamName, testCase); + ex.ParamName.Should().Be(expectedParamName, "no null was provided for {1}", expectedParamName, testCase); } } diff --git a/test/Correlate.Testing/TestLogger.cs b/test/Correlate.Testing/TestLogger.cs index 561019f..b965421 100644 --- a/test/Correlate.Testing/TestLogger.cs +++ b/test/Correlate.Testing/TestLogger.cs @@ -5,8 +5,8 @@ namespace Correlate.Testing; public class TestLogger : TestLogger, ILogger { - public TestLogger(ILogger innerLogger, bool isEnabled = true) - : base(innerLogger, typeof(T).FullName, isEnabled) + public TestLogger(ILogger? innerLogger, bool isEnabled = true) + : base(innerLogger, typeof(T).FullName!, isEnabled) { } @@ -18,11 +18,11 @@ public TestLogger(bool isEnabled = true) public class TestLogger : ILogger { - private readonly ILogger _innerLogger; + private readonly ILogger? _innerLogger; private readonly bool _isEnabled; // ReSharper disable once UnusedParameter.Local - public TestLogger(ILogger innerLogger, string name, bool isEnabled = true) + public TestLogger(ILogger? innerLogger, string name, bool isEnabled = true) { _innerLogger = innerLogger; _isEnabled = isEnabled; @@ -33,7 +33,7 @@ public TestLogger(string name, bool isEnabled = true) { } - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { _innerLogger?.Log(logLevel, eventId, state, exception, formatter); }