Skip to content

Commit

Permalink
Kept AssemblyLocater singleton instead of using delegates
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Pekurny <mpekurny@paychex.com>
  • Loading branch information
mpekurny committed Dec 12, 2024
1 parent f0c5c0b commit f90cfee
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 104 deletions.
16 changes: 8 additions & 8 deletions integration-test/ExecuteStepProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public async Task ShouldExecuteMethodFromRequest()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); }, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper, activatorWrapper, new StepRegistry(),
_loggerFactory.CreateLogger<AssemblyLoader>(), (logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper, activatorWrapper, new StepRegistry(),
_loggerFactory.CreateLogger<AssemblyLoader>());
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper, dataStoreFactory, tableFormatter);
Expand Down Expand Up @@ -84,11 +85,10 @@ public async Task ShouldCaptureScreenshotOnFailure()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand Down
72 changes: 32 additions & 40 deletions integration-test/ExecutionOrchestratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ public async Task RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand All @@ -52,11 +51,10 @@ public async Task ShouldCreateTableFromTargetType()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand All @@ -80,11 +78,10 @@ public async Task ShouldExecuteMethodAndReturnResult()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand All @@ -107,11 +104,10 @@ public async Task ShouldGetPendingMessages()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand All @@ -135,11 +131,10 @@ public async Task ShouldGetStacktraceForAggregateException()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand All @@ -163,11 +158,10 @@ public void ShouldGetStepTextsForMethod()
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var registry = assemblyLoader.GetStepRegistry();
var gaugeMethod = registry.MethodFor("and an alias");
var stepTexts = gaugeMethod.Aliases.ToList();
Expand All @@ -183,11 +177,10 @@ public async Task SuccessIsFalseOnSerializableExceptionThrown()
const string expectedMessage = "I am a custom serializable exception";
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand All @@ -213,11 +206,10 @@ public async Task SuccessIsFalseOnUnserializableExceptionThrown()
const string expectedMessage = "I am a custom exception";
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(_fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(_fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(_fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand Down
18 changes: 8 additions & 10 deletions integration-test/ExternalReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ public async Task ShouldGetStepsFromReference(string referenceType, string stepT
var fileProvider = new PhysicalFileProvider(Path.Combine(testProjectPath, "gauge_bin"));

var serviceProvider = new ServiceCollection().BuildServiceProvider();
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, new ReflectionWrapper(),
new ActivatorWrapper(serviceProvider), new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, new ReflectionWrapper(),
new ActivatorWrapper(serviceProvider), new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());

var stepValidationProcessor = new StepValidationProcessor(assemblyLoader.GetStepRegistry());
var message = new StepValidateRequest
Expand Down Expand Up @@ -68,11 +67,10 @@ public async Task ShouldRegisterScreenshotWriterFromReference(string referenceTy
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper(serviceProvider);
var gaugeLoadContext = new GaugeLoadContext(() => { return AssemblyLocater.GetTestAssembly(fileProvider); },
_loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>(),
(logger) => { return AssemblyLocater.GetAssembliesReferencingGaugeLib(fileProvider, logger); });
var assemblyLocater = new AssemblyLocater(fileProvider, _loggerFactory.CreateLogger<AssemblyLocater>());
var gaugeLoadContext = new GaugeLoadContext(assemblyLocater, _loggerFactory.CreateLogger<GaugeLoadContext>());
var assemblyLoader = new AssemblyLoader(assemblyLocater, gaugeLoadContext, reflectionWrapper,
activatorWrapper, new StepRegistry(), _loggerFactory.CreateLogger<AssemblyLoader>());
var hookRegistry = new HookRegistry(assemblyLoader);
var dataStoreFactory = new DataStoreFactory(assemblyLoader, activatorWrapper);
var tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
Expand Down
3 changes: 0 additions & 3 deletions src/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Gauge.Dotnet;

public delegate string GetTestAssembly();
public delegate IEnumerable<string> GetAssembliesReferencingGaugeLib(ILogger logger);

public static class Constants
{
public static string GaugeLibAssemblyName => "Gauge.CSharp.Lib";
Expand Down
6 changes: 3 additions & 3 deletions src/Loaders/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class AssemblyLoader : IAssemblyLoader
private readonly IStepRegistry _registry;
private readonly ILogger<AssemblyLoader> _logger;

public AssemblyLoader(IGaugeLoadContext gaugeLoadContext, IReflectionWrapper reflectionWrapper, IActivatorWrapper activatorWrapper,
IStepRegistry registry, ILogger<AssemblyLoader> logger, GetAssembliesReferencingGaugeLib getAssembliesReferencingGaugeLib)
public AssemblyLoader(IAssemblyLocater assemblyLocater, IGaugeLoadContext gaugeLoadContext, IReflectionWrapper reflectionWrapper, IActivatorWrapper activatorWrapper,
IStepRegistry registry, ILogger<AssemblyLoader> logger)
{
_reflectionWrapper = reflectionWrapper;
_activatorWrapper = activatorWrapper;
Expand All @@ -37,7 +37,7 @@ public AssemblyLoader(IGaugeLoadContext gaugeLoadContext, IReflectionWrapper ref
_gaugeLoadContext = gaugeLoadContext;
_targetLibAssembly = _gaugeLoadContext.LoadFromAssemblyName(new AssemblyName(GaugeLibAssemblyName));
VerifyTargetAssemblyVersion();
ScanAndLoad(getAssembliesReferencingGaugeLib.Invoke(_logger));
ScanAndLoad(assemblyLocater.GetAssembliesReferencingGaugeLib());
var assembliesReferencingGaugeLib = _gaugeLoadContext.GetLoadedAssembliesReferencingGaugeLib().ToList();
_logger.LogDebug("Number of AssembliesReferencingGaugeLib : {AssembliesReferencingGaugeLibCount}", assembliesReferencingGaugeLib.Count);
SetDefaultTypes();
Expand Down
Loading

0 comments on commit f90cfee

Please sign in to comment.