From e49805aaaf379d02a4689a3831969a821478aa8e Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sat, 15 Nov 2025 23:59:20 +0100 Subject: [PATCH] Fixed RetryFact not discovering facts --- .../AssetsPageTests.cs | 4 +-- .../RetryFactAttribute.cs | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/tests/Berufsschule_HAM.E2ETests/AssetsPageTests.cs b/tests/Berufsschule_HAM.E2ETests/AssetsPageTests.cs index 096533a..7f45e3c 100644 --- a/tests/Berufsschule_HAM.E2ETests/AssetsPageTests.cs +++ b/tests/Berufsschule_HAM.E2ETests/AssetsPageTests.cs @@ -22,7 +22,7 @@ public class AssetsPageTests : IDisposable serverProcess = app.Result; } - [Fact] + [RetryFact(5)] public void AssetsPage_ShouldShowButton() { AppHelper.Login(_driver); @@ -30,7 +30,7 @@ public class AssetsPageTests : IDisposable _driver.FindElement(By.CssSelector("button[data-bs-target=\"#createAssetModal\"]")); } - [Fact] + [RetryFact(5)] public void AssetsPage_ShouldShowCreateViewModal() { AppHelper.Login(_driver); diff --git a/tests/Berufsschule_HAM.E2ETests/RetryFactAttribute.cs b/tests/Berufsschule_HAM.E2ETests/RetryFactAttribute.cs index 893d919..0175373 100644 --- a/tests/Berufsschule_HAM.E2ETests/RetryFactAttribute.cs +++ b/tests/Berufsschule_HAM.E2ETests/RetryFactAttribute.cs @@ -5,7 +5,6 @@ using Xunit.Sdk; namespace Berufsschule_HAM.E2ETests; -[XunitTestCaseDiscoverer("YourNamespace.RetryFactDiscoverer", "YourAssemblyName")] public class RetryFactAttribute(int maxRetries = 5) : FactAttribute { public int MaxRetries { get; } = maxRetries; @@ -18,8 +17,13 @@ public class RetryTestCase : XunitTestCase [Obsolete("Called by the de-serializer", true)] public RetryTestCase() { } - public RetryTestCase(int maxRetries, ITestMethod testMethod) - : base(new NullMessageSink(), TestMethodDisplay.Method, TestMethodDisplayOptions.None, testMethod) + public RetryTestCase( + IMessageSink diagnosticMessageSink, + TestMethodDisplay defaultMethodDisplay, + TestMethodDisplayOptions defaultMethodDisplayOptions, + ITestMethod testMethod, + int maxRetries) + : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod) { _maxRetries = maxRetries; } @@ -46,4 +50,27 @@ public class RetryTestCase : XunitTestCase return summary; } +} + +public class RetryFactDiscoverer : IXunitTestCaseDiscoverer +{ + private readonly IMessageSink _diagnosticMessageSink; + + public RetryFactDiscoverer(IMessageSink diagnosticMessageSink) + { + _diagnosticMessageSink = diagnosticMessageSink; + } + + public IEnumerable Discover(ITestFrameworkDiscoveryOptions discoveryOptions, + ITestMethod testMethod, + IAttributeInfo factAttribute) + { + var maxRetries = factAttribute.GetNamedArgument("MaxRetries"); + yield return new RetryTestCase( + _diagnosticMessageSink, + discoveryOptions.MethodDisplayOrDefault(), + discoveryOptions.MethodDisplayOptionsOrDefault(), + testMethod, + maxRetries); + } } \ No newline at end of file