You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-18Lines changed: 43 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -38,15 +38,15 @@ On your .NET Core Unit Test project
38
38
* Add your ASP.NET Core web project as a project reference
39
39
### Configuration
40
40
The Test environment provided by *Testavior* is based on a **Startup Configuration Service** that let you separate the **Production** environment configuration from the **Test** environment configuration.
41
-
This configuration service is represented by a contract **IStartupConfigurationService** which define 3 methods: *Configure, ConfigureEnvironment, ConfigureService* that have to be called within the **Startup Routine** to inject environment dependent configuration.
41
+
This configuration service is represented by a contract `IStartupConfigurationService` which define 3 methods: `Configure` - `ConfigureEnvironment - ConfigureService` that have to be called within the **Startup Routine** to inject environment dependent configuration.
42
42
43
43
1 - In your **ASP.NET Core** project:
44
-
* Add a *StartupConfigurationService* class (change name if you wish) to your web project.
45
-
* Implement the **IStartupConfigurationService** interface (optionally, inherit from *DefaultStartupConfigurationService* to use the default empty implementation)
44
+
* Add a `StartupConfigurationService` class (change name if you wish) to your web project.
45
+
* Implement the `IStartupConfigurationService` interface (optionally, inherit from `DefaultStartupConfigurationService` to use the default empty implementation)
46
46
* Implement the configuration specific to the Production environment and which must not be executed in the Test environment:
47
-
**ConfigureServices*: implement the configuration options that are specific to the Production environment
48
-
**Configure*: implement the *middleware* configuration specific to the Production environment
49
-
**ConfigureEnvironment*: implement what has to be executed before anything
47
+
*`ConfigureServices`: implement the configuration options that are specific to the Production environment
48
+
*`Configure`: implement the *middleware* configuration specific to the Production environment
49
+
*`ConfigureEnvironment`: implement what has to be executed before anything
50
50
51
51
Sample:
52
52
```csharp
@@ -65,19 +65,19 @@ This configuration service is represented by a contract **IStartupConfigurationS
65
65
```
66
66
67
67
2 - In your **Program** class:
68
-
Inject your *StartupConfigurationService* by calling the **ConfigureStartup** method on your **WebHostBuilder**:
68
+
Inject your `StartupConfigurationService` by calling the `ConfigureStartup` method on your `WebHostBuilder`:
69
69
```csharp
70
70
newWebHostBuilder()
71
71
...
72
72
.UseStartup<Startup>()
73
73
.ConfigureStartup<StartupConfigurationService>()
74
74
```
75
75
76
-
3 - In your **Startup** class:
77
-
* Inject the *IStartupConfigurationService* interface into the Startup class
78
-
* Call the *ConfigureEnvironment* method at the end of the Startup constructor
79
-
* Call the *ConfigureServices* method at the end of the original StartupConfigureServices method
80
-
* Call the *Configure* method at the beginning of the original StartupConfigure method
76
+
3 - In your `Startup` class:
77
+
* Inject the `IStartupConfigurationService` interface into the `Startup` class
78
+
* Call the `ConfigureEnvironment` method at the end of the `Startup` constructor
79
+
* Call the `ConfigureServices` method at the end of the original `Startup.ConfigureServices` method
80
+
* Call the `Configure` method at the beginning of the original `Startup.Configure` method
81
81
82
82
Sample:
83
83
```csharp
@@ -108,13 +108,38 @@ public class Startup
108
108
}
109
109
```
110
110
111
+
4 - In your test project file:
112
+
The **Razor** engine uses dependency files (.deps.json) to resolve some references at runtime. So in order to test the **MVC** part of a application, it is necessary to import these files. To do it, add the following section to your `.csproj`:
If you intend to use xUnit, first follow the [official documention](https://xunit.github.io/docs/getting-started-dotnet-core), then add a `xunit.runner.json` file to your test project:
A specific *IStartupConfigurationService* is required for the **Test** environment if you want to implement **Test Specific** configuration.
114
-
*Testavior* comes with a test specific *IStartupConfigurationService* implementation: **TestStartupConfigurationService** which provide a **Test Environment** full of useful features (see **Features** section).
115
-
Of course you can implement your own *Test StartupConfigurationService*(by using the onboard TestStartupConfigurationService or not).
138
+
A specific `IStartupConfigurationService` is required for the **Test** environment if you want to implement **Test Specific** configuration.
139
+
*Testavior* comes with a test specific `IStartupConfigurationService` implementation: `TestStartupConfigurationService` which provide a **Test Environment** full of useful features (see **Features** section).
140
+
Of course you can implement your own Startup configuration service (by using the onboard `TestStartupConfigurationService` or not).
116
141
117
-
To create a *Test Environment*, just instanciate the **TestEnvironment** class by passing it your ASP.NET Core application *Startup*, your *IStartupConfigurationService* implementation, the type of your EF Core ObjectContext and the relative path to your ASP.NET Core project (required to resolve MVC views).
142
+
To create a *Test Environment*, just instanciate the `TestEnvironment` class by passing it your ASP.NET Core application `Startup`, your `IStartupConfigurationService` implementation, the type of your EF Core ObjectContext and the relative path to your ASP.NET Core project (required to resolve MVC views).
@@ -24,9 +27,18 @@ public IServiceProvider ServiceProvider
24
27
}
25
28
}
26
29
27
-
publicTestEnvironment(stringcontentRootPath=null)
30
+
/// <summary>
31
+
/// Creates a new instance of the TestEnvironment class.
32
+
/// </summary>
33
+
/// <param name="targetProjectRelativePath">Optional. Defines the relative path of the target project to test. Can be useful if the automatic detection does not work.</param>
0 commit comments