Skip to content

Commit 48805d0

Browse files
committed
Updated README.md
1 parent 4d62034 commit 48805d0

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,31 @@ For other interesting packages check out:
2727
## How to use
2828

2929
Make sure to check out the [tutorial](http://ivaylokenov.github.io/MyTested.AspNetCore.Mvc/tutorial/intro.html) (comming soon) and the [documentation](http://ivaylokenov.github.io/MyTested.AspNetCore.Mvc/guide/intro.html) (comming soon) for a preview of the available features.
30+
3031
You can also check out the [provided samples](https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc/tree/master/samples) for real-life ASP.NET Core MVC application testing.
3132

32-
Basically you can create a test case by using the fluent API the library provides. You are given a static `MyMvc` class from which all assertions can be easily configured.
33+
First we need to create a `TestStartup` class in the root of the test project in order to register the dependency injection services. The easiest way is to inherit from the web project's `Startup` class and replace some of the services with mocked ones by using the provided extension methods.
34+
35+
```c#
36+
namespace MyApp.Tests
37+
{
38+
using MyTested.AspNetCore.Mvc;
39+
40+
using Microsoft.Extensions.DependencyInjection;
41+
42+
public class TestStartup : Startup
43+
{
44+
public void ConfigureTestServices(IServiceCollection services)
45+
{
46+
base.ConfigureServices(services);
47+
48+
services.Replace<IRepository, MockedRepository>();
49+
}
50+
}
51+
}
52+
```
53+
54+
And then you can create a test case by using the fluent API the library provides. You are given a static `MyMvc` class from which all assertions can be easily configured.
3355

3456
```c#
3557
namespace MyApp.Tests.Controllers
@@ -57,31 +79,9 @@ namespace MyApp.Tests.Controllers
5779
The example uses [xUnit](http://xunit.github.io/) but you can use whatever testing framework you want.
5880
Basically, MyTested.AspNetCore.Mvc throws an unhandled exception with a friendly error message if the assertion does not pass and the test fails.
5981

60-
Here are some random examples of what the fluent testing API is capable of:
82+
Here are other random examples of what the fluent testing API is capable of:
6183

6284
```c#
63-
// first we need to create TestStartup class to register dependency injection services
64-
65-
// the easiest way is to inherit from the web project's Startup class
66-
// and replace some of the services with mocked ones
67-
68-
public class TestStartup : Startup
69-
{
70-
public TestStartup(IHostingEnvironment env)
71-
: base(env)
72-
{
73-
}
74-
75-
public void ConfigureTestServices(IServiceCollection services)
76-
{
77-
base.ConfigureServices(services);
78-
79-
services.Replace<IRepository, MockedRepository>();
80-
}
81-
}
82-
83-
// and then we can write our tests
84-
8585
// tests a route for correct controller, action and resolved route values
8686
MyMvc
8787
.Routes()
@@ -99,7 +99,7 @@ MyMvc
9999
String = "Text"
100100
}));
101101

102-
// creates controller with the registered services
102+
// instantiates controller with the registered services
103103
// and mocks authenticated user
104104
// and tests for valid model state
105105
// and tests for valid view bag entry

0 commit comments

Comments
 (0)