Skip to content

Commit

Permalink
Fix: Could not load System.CodeDom exception with xRetry.Reqnroll plu…
Browse files Browse the repository at this point in the history
…gin (#310)
  • Loading branch information
gasparnagy committed Nov 5, 2024
1 parent 7c22e2f commit 3695956
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Reqnroll.Tools.MsBuild.Generation/AssemblyResolveLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Reflection;

namespace Reqnroll.Tools.MsBuild.Generation
Expand All @@ -23,6 +24,18 @@ public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs ar
{
_taskLoggingWrapper.LogMessage(args.Name);

try
{
var requestedAssemblyName = new AssemblyName(args.Name);
var loadedAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == requestedAssemblyName.Name);
if (loadedAssembly != null) return loadedAssembly;
}
catch (Exception ex)
{
_taskLoggingWrapper.LogError(ex.Message);
return null;
}

return null;
}

Expand Down
82 changes: 82 additions & 0 deletions Tests/Reqnroll.SystemTests/Plugins/XRetryPluginTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Reqnroll.TestProjectGenerator;
using Reqnroll.TestProjectGenerator.Driver;
using System.Linq;

namespace Reqnroll.SystemTests.Plugins;

[TestClass]
public class XRetryPluginTest : SystemTestBase
{
protected override void TestInitialize()
{
base.TestInitialize();
_testRunConfiguration.UnitTestProvider = UnitTestProvider.xUnit;
_projectsDriver.AddNuGetPackage("xRetry.Reqnroll", "1.0.0");
}

[TestMethod]
public void XRetry_should_work_with_Reqnroll()
{
AddScenario(
"""
@retry
Scenario: Scenario with Retry
When fail for first 2 times A
""");
AddScenario(
"""
@retry
Scenario Outline: Scenario outline with Retry
When fail for first 2 times <label>
Examples:
| label |
| B |
| C |
""");
AddBindingClass(
"""
using System.Collections.Generic;
namespace XRetryPluginTest.StepDefinitions
{
[Binding]
public class XRetryPluginTestStepDefinitions
{
private static readonly Dictionary<string, int> RetriesByLabel = new Dictionary<string, int>();
[When("fail for first {int} times {word}")]
public void WhenFailForFirstTwoTimes(int retryCount, string label)
{
if (!RetriesByLabel.TryGetValue(label, out var retries))
{
retries = 0;
}
var failTest = retries < retryCount;
RetriesByLabel[label] = ++retries;
if (failTest)
{
Log.LogCustom("simulated-error", label);
throw new Exception($"simulated error for {label}");
}
}
}
}
""");

ExecuteTests();

ShouldAllScenariosPass();

var simulatedErrors = _bindingDriver.GetActualLogLines("simulated-error").ToList();
simulatedErrors.Should().HaveCount(_preparedTests * 2); // two simulated error per test
}

[TestMethod]
public void XRetry_should_work_with_Reqnroll_on_DotNetFramework_generation()
{
// compiling with MsBuild forces the generation to run with .NET Framework
_compilationDriver.SetBuildTool(BuildTool.MSBuild);
XRetry_should_work_with_Reqnroll();
}
}

0 comments on commit 3695956

Please sign in to comment.