Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Failing on reqnroll
Browse files Browse the repository at this point in the history
  • Loading branch information
gediminas-milasius-cargoo-com committed May 9, 2024
0 parents commit d444e22
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
.idea
*.Dotsettings.user
22 changes: 22 additions & 0 deletions AsyncLocal_ReqNRoll.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExecutionContext.App", "ExecutionContext.App\ExecutionContext.App.csproj", "{4B00B6D9-D701-4251-B741-25F47067CB35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExecutionContext.App.Tests", "ExecutionContext.App.Tests\ExecutionContext.App.Tests.csproj", "{51057BAF-13E9-4736-B614-AC4936BBE288}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B00B6D9-D701-4251-B741-25F47067CB35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B00B6D9-D701-4251-B741-25F47067CB35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B00B6D9-D701-4251-B741-25F47067CB35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B00B6D9-D701-4251-B741-25F47067CB35}.Release|Any CPU.Build.0 = Release|Any CPU
{51057BAF-13E9-4736-B614-AC4936BBE288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51057BAF-13E9-4736-B614-AC4936BBE288}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51057BAF-13E9-4736-B614-AC4936BBE288}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51057BAF-13E9-4736-B614-AC4936BBE288}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions ExecutionContext.App.Tests/AppServiceProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ExecutionContext.App.Tests;

public static class AppServiceProvider
{
public static IServiceProvider ServiceProvider { get; set; } = null!;
}
14 changes: 14 additions & 0 deletions ExecutionContext.App.Tests/Bindings/MainBindings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Reqnroll;

namespace ExecutionContext.App.Tests.Bindings;

[Binding]
public class MainBindings(ScenarioContext scenarioContext)
{
[When(@"test is run")]
public void WhenTestIsRun()
{
Assert.True(scenarioContext.Get<IServiceProvider>().GetRequiredService<MyService>().CheckUser("Alice"));
}
}
35 changes: 35 additions & 0 deletions ExecutionContext.App.Tests/ExecutionContext.App.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Reqnroll.SpecFlowCompatibility" Version="1.0.1" />
<PackageReference Include="Reqnroll.xUnit" Version="1.0.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExecutionContext.App\ExecutionContext.App.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="Features/**/*.feature" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions ExecutionContext.App.Tests/Features/Test.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Feature: Test

Scenario: Run test
When test is run
132 changes: 132 additions & 0 deletions ExecutionContext.App.Tests/Features/Test.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ExecutionContext.App.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
32 changes: 32 additions & 0 deletions ExecutionContext.App.Tests/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.Extensions.DependencyInjection;
using TechTalk.SpecFlow;

namespace ExecutionContext.App.Tests;

[Binding]
public class Startup(Reqnroll.ScenarioContext scenarioContext)
{
[BeforeTestRun]
public static void BeforeTestRun()
{
AppServiceProvider.ServiceProvider = new ServiceCollection()
.AddHttpContextAccessor()
.AddScoped<MyService>()
.BuildServiceProvider();
}

[BeforeScenario(Order = BeforeTestRunAttribute.DefaultOrder - 1000)]
public void BeforeScenario()
{
var scope = AppServiceProvider.ServiceProvider.CreateScope();

scenarioContext.Set(scope);
scenarioContext.Set(scope.ServiceProvider);
}

[AfterScenario(Order = BeforeTestRunAttribute.DefaultOrder + 1000)]
public void AfterScenario()
{
scenarioContext.Get<IServiceScope>().Dispose();
}
}
28 changes: 28 additions & 0 deletions ExecutionContext.App.Tests/UserStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using TechTalk.SpecFlow;

namespace ExecutionContext.App.Tests;

[Binding]
public class UserStartup(Reqnroll.ScenarioContext scenarioContext)
{
[BeforeScenario]
public void BeforeScenario()
{
var accessor = scenarioContext.Get<IServiceProvider>().GetRequiredService<IHttpContextAccessor>();

// Prepopulate context with some default values.
accessor.HttpContext = new DefaultHttpContext()
{
Request =
{
Headers =
{
["UserId"] = "12345",
["UserName"] = "Alice"
}
}
};
}
}
13 changes: 13 additions & 0 deletions ExecutionContext.App/ExecutionContext.App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions ExecutionContext.App/MyService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Http;

namespace ExecutionContext.App;

public class MyService(IHttpContextAccessor accessor)
{
public bool CheckUser(string username)
{
var context = accessor.HttpContext ?? throw new InvalidOperationException("Context Should not be null here");
return context.Request.Headers["UserName"] == username;
}
}

0 comments on commit d444e22

Please sign in to comment.