Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions Gauge.CSharp.Lib.UnitTests/DataStoreFactoryTests.cs

This file was deleted.

21 changes: 9 additions & 12 deletions Gauge.CSharp.Lib.UnitTests/DefaultClassInstanceManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Gauge.CSharp.Lib.UnitTests;
[TestFixture]
public class DefaultClassInstanceManagerTests
{
[SetUp]
public void SetUp()
{
DataStoreFactory.ClearAllDataStores();
}

[Test]
public void ShouldGetInstanceForType()
{
Expand All @@ -39,11 +33,12 @@ public void ShouldGetMemoizedInstanceForType()
[Test]
public async Task InvokeMethod_ShouldCreateInstanceAndInvokeMethod_WhenInstanceIsNotCached()
{
var context = new ExecutionContext();
var instanceManager = new DefaultClassInstanceManager();
var methodInfo = typeof(MethodInvokeTests).GetMethod(nameof(MethodInvokeTests.InvokeMethod1));
MethodInvokeTests.InvokeMethod1Called = false;

await instanceManager.InvokeMethod(methodInfo, 1);
await instanceManager.InvokeMethod(methodInfo, context);

Assert.That(MethodInvokeTests.InvokeMethod1Called);
}
Expand All @@ -52,13 +47,14 @@ public async Task InvokeMethod_ShouldCreateInstanceAndInvokeMethod_WhenInstanceI
public async Task InvokeMethod_ShouldSetDataStores_WhenDataStoresAreInitialized()
{
var instanceManager = new DefaultClassInstanceManager();
DataStoreFactory.AddDataStore(1, DataStoreType.Suite);
DataStoreFactory.AddDataStore(1, DataStoreType.Spec);
DataStoreFactory.AddDataStore(1, DataStoreType.Scenario);
var context = new ExecutionContext();
context.DataStores.SuiteDataStore = new DataStore();
context.DataStores.SpecDataStore = new DataStore();
context.DataStores.ScenarioDataStore = new DataStore();
var methodInfo = typeof(MethodInvokeTests).GetMethod(nameof(MethodInvokeTests.InvokeMethod2));
MethodInvokeTests.InvokeMethod2Called = false;

await instanceManager.InvokeMethod(methodInfo, 1);
await instanceManager.InvokeMethod(methodInfo, context);

Assert.That(MethodInvokeTests.InvokeMethod2Called);
}
Expand All @@ -67,10 +63,11 @@ public async Task InvokeMethod_ShouldSetDataStores_WhenDataStoresAreInitialized(
public async Task InvokeMethod_ShouldNotFail_WhenMethodInvokedIsNotAsync()
{
var instanceManager = new DefaultClassInstanceManager();
var context = new ExecutionContext();
var methodInfo = typeof(MethodInvokeTests).GetMethod(nameof(MethodInvokeTests.InvokeMethod3));
MethodInvokeTests.InvokeMethod3Called = false;

await instanceManager.InvokeMethod(methodInfo, 1);
await instanceManager.InvokeMethod(methodInfo, context);

Assert.That(MethodInvokeTests.InvokeMethod3Called);
}
Expand Down
92 changes: 0 additions & 92 deletions Gauge.CSharp.Lib/DataStoreFactory.cs

This file was deleted.

13 changes: 6 additions & 7 deletions Gauge.CSharp.Lib/DefaultClassInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public object Get(Type declaringType)
return instance;
}

public async Task InvokeMethod(MethodInfo method, int stream, params object[] parameters)
public async Task InvokeMethod(MethodInfo method, ExecutionContext context, params object[] parameters)
{
SetDataStores(stream);
SetDataStores(context.DataStores);
var instance = Get(method.DeclaringType);
var response = method.Invoke(instance, parameters);
if (response is Task task)
Expand All @@ -38,20 +38,19 @@ public async Task InvokeMethod(MethodInfo method, int stream, params object[] pa
}
}

private static void SetDataStores(int stream)
private static void SetDataStores(ExecutionContext.CurrentDataStores dataStores)
{
var dataStore = DataStoreFactory.GetDataStoresByStream(stream);
lock (SuiteDataStore.Store)
{
SuiteDataStore.Store.Value = DataStoreFactory.SuiteDataStore;
SuiteDataStore.Store.Value = dataStores.SuiteDataStore;
}
lock (SpecDataStore.Store)
{
SpecDataStore.Store.Value = dataStore.GetValueOrDefault(DataStoreType.Spec, null);
SpecDataStore.Store.Value = dataStores.SpecDataStore;
}
lock (ScenarioDataStore.Store)
{
ScenarioDataStore.Store.Value = dataStore.GetValueOrDefault(DataStoreType.Scenario, null);
ScenarioDataStore.Store.Value = dataStores.ScenarioDataStore;
}
}

Expand Down
Loading