This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d444e22
Showing
12 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bin/ | ||
obj/ | ||
/packages/ | ||
riderModule.iml | ||
/_ReSharper.Caches/ | ||
.idea | ||
*.Dotsettings.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
ExecutionContext.App.Tests/ExecutionContext.App.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Feature: Test | ||
|
||
Scenario: Run test | ||
When test is run |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |