Skip to content

Commit

Permalink
check if method is async and await results, #199 (#201)
Browse files Browse the repository at this point in the history
* check if method is async and await results, #199

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* Add .NET 8 support (#200)

* Add .NET 8 support

Signed-off-by: Martin Pekurny <mpekurny@paychex.com>

* Update the init command to create a newer csproj file and removed the matrix for different dotnet versions in the build.yml

Signed-off-by: Martin Pekurny <mpekurny@paychex.com>

* Limiting the number of nodes to use for the feature tests

Signed-off-by: Martin Pekurny <mpekurny@paychex.com>

---------

Signed-off-by: Martin Pekurny <mpekurny@paychex.com>
Signed-off-by: sriv <srikanth.ddit@gmail.com>

* add check to guard against async void impl

step implementations with async void are treated as not implemented

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* bump version 0.6.0

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* fix nunit assert syntax

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* make MethodExecutor.Execute handle async, #199

the entire method execution chain is now async

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* preserve arguments check when executing hook

Signed-off-by: sriv <srikanth.ddit@gmail.com>

---------

Signed-off-by: sriv <srikanth.ddit@gmail.com>
Signed-off-by: Martin Pekurny <mpekurny@paychex.com>
Co-authored-by: mpekurny <49953914+mpekurny@users.noreply.github.com>
  • Loading branch information
sriv and mpekurny authored Feb 6, 2024
1 parent 92efd92 commit b7550c9
Show file tree
Hide file tree
Showing 53 changed files with 374 additions and 219 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ deploy
artifacts
.ionide
.DS_Store
.fake
.fake
.idea
Gauge.Dotnet.sln.DotSettings.user
_testdata/Sample/.gauge/
_testdata/Sample/logs/
_testdata/Sample/reports/
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ gauge run specs
#### Install specific version

```
gauge install dotnet --version 0.5.2
gauge install dotnet --version 0.6.0
```

#### Offline installation

Download the plugin from [Releases](https://github.com/getgauge/gauge-dotnet/releases)

```
gauge install dotnet --file gauge-dotnet-0.5.2.zip
gauge install dotnet --file gauge-dotnet-0.6.0.zip
```

#### Build from Source
Expand Down
2 changes: 1 addition & 1 deletion _testdata/Sample/IntegrationTestSample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions _testdata/Sample/StepImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public void SaySomething(string what, string who)
GaugeMessages.WriteMessage("{0}, {1}!", what, who);
}

[Step("Say <what> to <who> async")]
public async Task SaySomethingAsync(string what, string who)
{
Console.WriteLine("{0}, {1}!", what, who);
GaugeMessages.WriteMessage("{0}, {1}!", what, who);
await Task.Delay(100);
}

[Step("I throw an unserializable exception")]
public void ThrowUnserializableException()
{
Expand Down
5 changes: 3 additions & 2 deletions _testdata/Sample/gauge_bin/IntegrationTestSample.deps.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.0",
"name": ".NETCoreApp,Version=v7.0/linux-x64",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.0": {
".NETCoreApp,Version=v7.0": {},
".NETCoreApp,Version=v7.0/linux-x64": {
"IntegrationTestSample/1.0.0": {
"dependencies": {
"Gauge.CSharp.Lib": "0.7.6"
Expand Down
Binary file modified _testdata/Sample/gauge_bin/IntegrationTestSample.dll
Binary file not shown.
Binary file modified _testdata/Sample/gauge_bin/IntegrationTestSample.pdb
Binary file not shown.
9 changes: 5 additions & 4 deletions integration-test/ExecuteStepProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


using System.Threading;
using System.Threading.Tasks;
using Gauge.Dotnet.Models;
using Gauge.Dotnet.Processors;
using Gauge.Dotnet.Wrappers;
Expand All @@ -18,7 +19,7 @@ namespace Gauge.Dotnet.IntegrationTests
public class ExecuteStepProcessorTests : IntegrationTestsBase
{
[Test]
public void ShouldExecuteMethodFromRequest()
public async Task ShouldExecuteMethodFromRequest()
{
const string parameterizedStepText = "Step that takes a table {}";
const string stepText = "Step that takes a table <table>";
Expand Down Expand Up @@ -64,15 +65,15 @@ public void ShouldExecuteMethodFromRequest()
}
}
};
var result = executeStepProcessor.Process(message);
var result = await executeStepProcessor.Process(message);

var protoExecutionResult = result.ExecutionResult;
ClassicAssert.IsNotNull(protoExecutionResult);
ClassicAssert.IsFalse(protoExecutionResult.Failed);
}

[Test]
public void ShouldCaptureScreenshotOnFailure()
public async Task ShouldCaptureScreenshotOnFailure()
{
const string stepText = "I throw a serializable exception";
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -96,7 +97,7 @@ public void ShouldCaptureScreenshotOnFailure()
ActualStepText = stepText
};

var result = executeStepProcessor.Process(message);
var result = await executeStepProcessor.Process(message);
var protoExecutionResult = result.ExecutionResult;

ClassicAssert.IsNotNull(protoExecutionResult);
Expand Down
52 changes: 37 additions & 15 deletions integration-test/ExecutionOrchestratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gauge.CSharp.Lib;
using Gauge.Dotnet.Models;
using Gauge.Dotnet.Wrappers;
Expand All @@ -19,7 +20,7 @@ namespace Gauge.Dotnet.IntegrationTests
public class ExecutionOrchestratorTests : IntegrationTestsBase
{
[Test]
public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
public async Task RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -33,13 +34,13 @@ public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
var gaugeMethod = assemblyLoader.GetStepRegistry()
.MethodFor("I throw a serializable exception and continue");
var executionResult = orchestrator.ExecuteStep(gaugeMethod);
var executionResult = await orchestrator.ExecuteStep(gaugeMethod);
ClassicAssert.IsTrue(executionResult.Failed);
ClassicAssert.IsTrue(executionResult.RecoverableError);
}

[Test]
public void ShouldCreateTableFromTargetType()
public async Task ShouldCreateTableFromTargetType()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -56,12 +57,12 @@ public void ShouldCreateTableFromTargetType()
table.AddRow(new List<string> { "foorow1", "barrow1" });
table.AddRow(new List<string> { "foorow2", "barrow2" });

var executionResult = orchestrator.ExecuteStep(gaugeMethod, SerializeTable(table));
var executionResult = await orchestrator.ExecuteStep(gaugeMethod, SerializeTable(table));
ClassicAssert.False(executionResult.Failed);
}

[Test]
public void ShouldExecuteMethodAndReturnResult()
public async Task ShouldExecuteMethodAndReturnResult()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -76,13 +77,12 @@ public void ShouldExecuteMethodAndReturnResult()
var gaugeMethod = assemblyLoader.GetStepRegistry()
.MethodFor("A context step which gets executed before every scenario");

var executionResult = orchestrator.ExecuteStep(gaugeMethod);
var executionResult = await orchestrator.ExecuteStep(gaugeMethod);
ClassicAssert.False(executionResult.Failed);
}


[Test]
public void ShouldGetPendingMessages()
public async Task ShouldGetPendingMessages()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -97,14 +97,36 @@ public void ShouldGetPendingMessages()

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Say {} to {}");

var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "world");
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "world");

ClassicAssert.False(executionResult.Failed);
ClassicAssert.Contains("hello, world!", executionResult.Message);
}

[Test]
public void ShouldGetStacktraceForAggregateException()
public async Task ShouldExecuteAsyncStepImplementation()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
var classInstanceManager = assemblyLoader.GetClassInstanceManager();
var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
classInstanceManager,
new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Say {} to {} async");

var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "async world");

Assert.That(executionResult.Failed, Is.False, executionResult.ErrorMessage);
StringAssert.Contains("hello, async world!", executionResult.Message.ToString());
}

[Test]
public async Task ShouldGetStacktraceForAggregateException()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -118,7 +140,7 @@ public void ShouldGetStacktraceForAggregateException()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("I throw an AggregateException");
var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod);

ClassicAssert.True(executionResult.Failed);
ClassicAssert.True(executionResult.StackTrace.Contains("First Exception"));
Expand All @@ -141,7 +163,7 @@ public void ShouldGetStepTextsForMethod()
}

[Test]
public void SuccessIsFalseOnSerializableExceptionThrown()
public async Task SuccessIsFalseOnSerializableExceptionThrown()
{
const string expectedMessage = "I am a custom serializable exception";
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -156,7 +178,7 @@ public void SuccessIsFalseOnSerializableExceptionThrown()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("I throw a serializable exception");

var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod);

ClassicAssert.True(executionResult.Failed);
ClassicAssert.AreEqual(expectedMessage, executionResult.ErrorMessage);
Expand All @@ -165,7 +187,7 @@ public void SuccessIsFalseOnSerializableExceptionThrown()
}

[Test]
public void SuccessIsFalseOnUnserializableExceptionThrown()
public async Task SuccessIsFalseOnUnserializableExceptionThrown()
{
const string expectedMessage = "I am a custom exception";
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -180,7 +202,7 @@ public void SuccessIsFalseOnUnserializableExceptionThrown()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("I throw an unserializable exception");
var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod);
ClassicAssert.True(executionResult.Failed);
ClassicAssert.AreEqual(expectedMessage, executionResult.ErrorMessage);
StringAssert.Contains("IntegrationTestSample.StepImplementation.ThrowUnserializableException",
Expand Down
5 changes: 3 additions & 2 deletions integration-test/ExternalReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;
using Gauge.Dotnet.Models;
using Gauge.Dotnet.Processors;
using Gauge.Dotnet.Wrappers;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void ShouldGetStepsFromReference(string referenceType, string stepText, s
[Test]
[TestCase("ProjectReference", "Take Screenshot in reference Project", "ReferenceProject-IDoNotExist.png")]
[TestCase("DllReference", "Take Screenshot in reference DLL", "ReferenceDll-IDoNotExist.png")]
public void ShouldRegisterScreenshotWriterFromReference(string referenceType, string stepText, string expected)
public async Task ShouldRegisterScreenshotWriterFromReference(string referenceType, string stepText, string expected)
{
Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", TestUtils.GetIntegrationTestSampleDirectory(referenceType));
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -66,7 +67,7 @@ public void ShouldRegisterScreenshotWriterFromReference(string referenceType, st
ActualStepText = stepText
};

var result = executeStepProcessor.Process(message);
var result = await executeStepProcessor.Process(message);
var protoExecutionResult = result.ExecutionResult;

ClassicAssert.IsNotNull(protoExecutionResult);
Expand Down
2 changes: 1 addition & 1 deletion integration-test/ImplementCodeProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void ShouldProcessMessageForExistingClass()
var result = processor.Process(message);
ClassicAssert.AreEqual(1, result.TextDiffs.Count);
StringAssert.Contains("Step Method", result.TextDiffs[0].Content);
ClassicAssert.AreEqual(107, result.TextDiffs[0].Span.Start);
ClassicAssert.AreEqual(115, result.TextDiffs[0].Span.Start);
}

[Test]
Expand Down
Loading

0 comments on commit b7550c9

Please sign in to comment.