From 7957e097b2ea5e15632568319d1c609cf82568c7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:22:37 +0000 Subject: [PATCH 1/2] Bump xunit from 2.5.0 to 2.7.0 Bumps [xunit](https://github.com/xunit/xunit) from 2.5.0 to 2.7.0. - [Commits](https://github.com/xunit/xunit/compare/2.5.0...2.7.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- GetIntoTeachingApiTests/GetIntoTeachingApiTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GetIntoTeachingApiTests/GetIntoTeachingApiTests.csproj b/GetIntoTeachingApiTests/GetIntoTeachingApiTests.csproj index 0e1eb575c..2a76a68d9 100644 --- a/GetIntoTeachingApiTests/GetIntoTeachingApiTests.csproj +++ b/GetIntoTeachingApiTests/GetIntoTeachingApiTests.csproj @@ -31,7 +31,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 50b5db82058027a1edc7e525e5920dfdb61c654d Mon Sep 17 00:00:00 2001 From: Chidi Ekuma Date: Tue, 12 Mar 2024 18:36:26 +0000 Subject: [PATCH 2/2] Refactor model binder and notify service tests Test methods should not use blocking task operations, as they can cause deadlocks - This fix updates model binder and notify service tests to Use an async test method and await instead. - Following the upgrade of x-unit from 2.5 to 2.7 this check is mandatory --- .../ModelBinders/TrimStringModelBinderTests.cs | 10 ++++++---- GetIntoTeachingApiTests/Services/NotifyServiceTests.cs | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/GetIntoTeachingApiTests/ModelBinders/TrimStringModelBinderTests.cs b/GetIntoTeachingApiTests/ModelBinders/TrimStringModelBinderTests.cs index 825b8b918..c96a632e1 100644 --- a/GetIntoTeachingApiTests/ModelBinders/TrimStringModelBinderTests.cs +++ b/GetIntoTeachingApiTests/ModelBinders/TrimStringModelBinderTests.cs @@ -31,18 +31,19 @@ public void BindModelAsync_WithNullContext_ThrowsArgumentNullException() } [Fact] - public void BindModelAsync_WhenValueProviderResultIsNone_CompletesTask() + public async Task BindModelAsync_WhenValueProviderResultIsNone_CompletesTask() { _mockValueProvider.Setup(m => m.GetValue("key")).Returns(ValueProviderResult.None); var task = _binder.BindModelAsync(_mockContext.Object); - task.Wait(); + // task.Wait(); + await task; task.Should().Be(Task.CompletedTask); } [Fact] - public void BindModelAsync_WhenValueIsString_TrimsStringAndCompletesTask() + public async Task BindModelAsync_WhenValueIsString_TrimsStringAndCompletesTask() { var modelState = new ModelStateDictionary(); var valueProviderResult = new ValueProviderResult(" value "); @@ -51,7 +52,8 @@ public void BindModelAsync_WhenValueIsString_TrimsStringAndCompletesTask() var task = _binder.BindModelAsync(_mockContext.Object); - task.Wait(); + // task.Wait(); + await task; task.Should().Be(Task.CompletedTask); _mockContext.VerifySet(m => m.Result = ModelBindingResult.Success("value")); } diff --git a/GetIntoTeachingApiTests/Services/NotifyServiceTests.cs b/GetIntoTeachingApiTests/Services/NotifyServiceTests.cs index 6da99a4b9..e238fe554 100644 --- a/GetIntoTeachingApiTests/Services/NotifyServiceTests.cs +++ b/GetIntoTeachingApiTests/Services/NotifyServiceTests.cs @@ -9,6 +9,7 @@ using GetIntoTeachingApi.Models; using GetIntoTeachingApi.Utils; using Xunit; +using System.Threading.Tasks; namespace GetIntoTeachingApiTests.Services { @@ -68,7 +69,7 @@ public void SendEmail_SendsAnEmail(string templateId, string templateDescription } [Fact] - public void SendEmailAsync_WhenSendingFails_LogsException() + public async Task SendEmailAsync_WhenSendingFails_LogsException() { _mockNotificationClient.Setup( mock => mock.SendEmailAsync( @@ -79,7 +80,7 @@ public void SendEmailAsync_WhenSendingFails_LogsException() ) ).ThrowsAsync(new Exception("bang")); - _service.SendEmailAsync("email@address.com", NotifyService.NewPinCodeEmailTemplateId, _personalisation).Wait(); + await _service.SendEmailAsync("email@address.com", NotifyService.NewPinCodeEmailTemplateId, _personalisation); _mockLogger.VerifyWarningWasCalled("NotifyService - Failed to send email"); }