|
1 | 1 | # SpecFlow.DependencyInjection |
2 | 2 |
|
3 | | -SpecFlow Plugin for Microsoft.Extensions.DependencyInjection |
| 3 | +SpecFlow plugin for using Microsoft.Extensions.DependencyInjection as a dependency injection framework. |
4 | 4 |
|
5 | | -Based on https://github.com/gasparnagy/SpecFlow.Autofac. |
| 5 | +Based on https://github.com/gasparnagy/SpecFlow.Autofac ([Apache License 2.0](https://github.com/gasparnagy/SpecFlow.Autofac/blob/master/LICENSE)) |
6 | 6 |
|
7 | | -## TODO |
| 7 | +Currently supports: |
| 8 | +* [SpecFlow v3.0](https://www.nuget.org/packages/SpecFlow/3.0) |
| 9 | +* [Microsoft.Extensions.DependencyInjection v2.2](https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/2.2) |
8 | 10 |
|
9 | | -Todo will move to GitHub Issues once 1.0.0 is released. For now this README will have to suffice. |
10 | | -You can find me (@mbhoek) on https://gitter.im/techtalk/specflow-plugin-dev for questions and feedback. |
| 11 | +License: MIT (https://github.com/solidtoken/SpecFlow.DependencyInjection/blob/master/LICENSE) |
11 | 12 |
|
12 | | -### Documentation |
| 13 | +NuGet: https://www.nuget.org/packages/SolidToken.SpecFlow.DependencyInjection |
13 | 14 |
|
14 | | -- [ ] Proper README |
15 | | -- [x] Add LICENSE |
16 | | -- [ ] Make issue tracker available (1.0.0+) |
17 | | -- [ ] Move TODO to TODO+ document? |
18 | | - - Too bad VS does not support TODO+ extension (it's VSCode only) |
19 | | -- [ ] Howto setup services |
20 | | - - [ ] NuGet |
21 | | - - [ ] Azure DevOps |
22 | | - - [ ] GitHub |
| 15 | +## Usage |
23 | 16 |
|
24 | | -### CI/CD |
| 17 | +Install plugin from NuGet into your SpecFlow project. |
25 | 18 |
|
26 | | -- [x] Semantic versioning |
27 | | - - GitVersion Build Task |
28 | | -- [x] GitHub workflow (?) |
29 | | - - https://guides.github.com/introduction/flow/ |
30 | | - - Can't really get used to this, I prefer gitflow thus far |
31 | | - - Trying to stick to it just to learn |
32 | | -- [x] CI -> Azure Pipelines |
33 | | - - [x] Build using Azure Pipelines |
34 | | - - [x] Smoke Test using the .Tests project |
35 | | -- [ ] CD -> NuGet |
36 | | - - [x] Release a succesful build (gating?) |
37 | | - - [ ] Signed packages |
38 | | - - https://docs.microsoft.com/en-us/nuget/reference/signed-packages-reference |
39 | | - - I'd like to sign the release commits (in git) as well (tags?) |
40 | | - - Signed packages feels like a hassle with the Certification needed (and costs) |
41 | | - - Probably best delayed until it's a really popular package |
42 | | - - [ ] GitHub Releases? How and why? |
43 | | - - [x] Implement GitHub Release from Azure DevOps |
44 | | - - Still feels like you always need a manual step to release (vs GitFlow which allows you to auto-release) |
| 19 | +```powershell |
| 20 | +PM> Install-Package SolidToken.SpecFlow.DependencyInjection |
| 21 | +``` |
45 | 22 |
|
46 | | -### Code |
| 23 | +Create a static method somewhere in the SpecFlow project (recommended to put it into the ```Support``` folder) that returns an Microsoft.Extensions.DependencyInjection ```IServiceCollection``` and tag it with the `[ScenarioDependencies]` attribute. Configure your dependencies for the scenario execution within the method. You also have to register the step definition classes, that you can do by either registering all classes marked with the ```[Binding]``` attribute: |
47 | 24 |
|
48 | | -- [x] Add .gitignore |
49 | | -- [ ] Add .editorconfig |
50 | | -- [ ] Add source code quality guidelines |
51 | | -- [x] Add SourceLink |
52 | | - - https://devblogs.microsoft.com/nuget/introducing-source-code-link-for-nuget-packages/ |
53 | | -- [x] Set Assembly metadata correctly |
| 25 | +```csharp |
| 26 | +foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute)))) |
| 27 | +{ |
| 28 | + services.AddSingleton(type); |
| 29 | +} |
| 30 | +``` |
54 | 31 |
|
55 | | -### Tests |
| 32 | +A typical dependency builder method probably looks like this: |
56 | 33 |
|
57 | | -- [ ] Add tests for SpecFlow classes (ScenarioContext, FeatureContext, etc) |
58 | | -- [ ] Add tests for parallel testing |
59 | | -- [ ] Add tests for high-load testing |
60 | | - - Test if we are properly disposing our plumbing code |
| 34 | +```csharp |
| 35 | +[ScenarioDependencies] |
| 36 | +public static IServiceCollection CreateServices() |
| 37 | +{ |
| 38 | + var services = new ServiceCollection(); |
| 39 | + |
| 40 | + // TODO: add customizations, stubs required for testing |
61 | 41 |
|
62 | | -### Social |
| 42 | + foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute)))) |
| 43 | + { |
| 44 | + services.AddSingleton(type); |
| 45 | + } |
63 | 46 |
|
64 | | -- [ ] Publish builds/releases on social networks |
65 | | - - [ ] Microsoft Teams |
66 | | - - [ ] Slack |
67 | | - - [ ] Twitter |
68 | | - - [ ] LinkedIn |
| 47 | + return services; |
| 48 | +} |
| 49 | +``` |
69 | 50 |
|
70 | | -### Issues |
71 | | - |
72 | | -- [ ] Determine minimal SpecFlow version to support |
73 | | - - I now got an error that my project has a lower SpecFlow version than this plugin, which then fails |
74 | | - - This is probably solved by a smart grep semver version thingy in package refs |
75 | | -- [ ] Documentation should include that you need to create a Setup Class/Method [ScenarioDependencies] |
76 | | - - [ ] Could also add a "AutoRegisterBindings" (default True) to [ScenarioDependencies] |
77 | | - - This would auto-register all [Bindings] in the same assembly/namespce as the tagged method |
| 51 | +Refer to ```SpecFlow.DependencyInjection.Tests``` for a typical implementation. |
0 commit comments