Skip to content

Commit c58fecd

Browse files
authored
Merge pull request #362 - Versioning plugin
Versioning plugin
2 parents 97b20c0 + a1a7b79 commit c58fecd

File tree

227 files changed

+2366
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2366
-854
lines changed

BACKERS.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ Additionally, funds donated via [Patreon](https://www.patreon.com/ivaylokenov) (
2525
<tr>
2626
<td align="center" valign="middle">
2727
<a href="http://bit.ly/bellatrixsolutions" target="_blank">
28-
<img width="323px" src="https://user-images.githubusercontent.com/3391906/68993273-d4f5c700-087e-11ea-9b39-e173733fcbfb.png" alt=""The Ultimate Cross-Platform .NET Framework>
29-
</a>
28+
<img width="323px" src="https://user-images.githubusercontent.com/3391906/68993273-d4f5c700-087e-11ea-9b39-e173733fcbfb.png" alt="The Ultimate Cross-Platform .NET Framework">
29+
</a>
30+
</td>
31+
<td align="center" valign="middle">
32+
<a href="https://www.jetbrains.com/?from=MyTestedASP.NET" target="_blank">
33+
<img width="323px" src="https://user-images.githubusercontent.com/3391906/72542498-ee21f080-388c-11ea-92ac-0b0153028933.png" alt="JetBrains">
34+
</a>
3035
</td>
3136
</tr>
3237
</tbody>
@@ -98,7 +103,7 @@ Additionally, funds donated via [Patreon](https://www.patreon.com/ivaylokenov) (
98103
Aleksandur Gyuzelov, Desislav Stoyanov, Emil Venkov, Georgi Krasimirov Georgiev, Kristiyan Mihailov, Lyubomir Krastanov, Nikolay Boyadzhiev, Nikolay Mihaylov, Rositsa Nenova, Slavi Bozhikov, Vasil Bonev, Yuriy Georgiev, Калин Ценков, Velina Getova
99104

100105
## One-Time Donations
101-
Stilgar Naibski, Ivomir Assi, Maria Georgieva, Tyler Austen, Stefan Minchev, Borislav Lazarov, Georgi Petrov, Yuliyana Tahova, Philip Shishov, Mariya Georgieva, Tanya Georgieva, Danny Berova, German Dimitrov, Aleksandar Evangelatov, Anton Petrov, Hristo Ivanov, Anna Stambolieva, Nedelcho Penev, Yulian Ashikov, Boyana Aleksova, Plamen Haralambiev, Victoria Karamanova, Ivaylo Goranov, Aneliya Drazheva, Zdravko Yakimov, Vanya Kuncheva, Georgi Petrov, Stanimir Pavlov, Teodor Stefanov, Stefan Minchev, Simon Valentinova Kochova, Marin Marinov, Petar Peshev, Radoslav Astardzhiev, Dimitar Radkov, Aleksandar Tsvetkov, Georgi Dragnev, Veselin Neychev, Kaloyan Kolev, Andrey Blagoev, Yordan Penev, Ventsislav Yordanov, Nikolay Georgiev, Siyana Yasenova Zdravkova, Ani Kalpachka, Gergana Damyanova, Petya Koleva, Dyanko Petkov, Nikola Kolchakov, Borislava Hranova
106+
Stilgar Naibski, Ivomir Assi, Maria Georgieva, Tyler Austen, Stefan Minchev, Borislav Lazarov, Yuliyana Tahova, Philip Shishov, Mariya Georgieva, Tanya Georgieva, Danny Berova, German Dimitrov, Aleksandar Evangelatov, Anton Petrov, Hristo Ivanov, Anna Stambolieva, Nedelcho Penev, Yulian Ashikov, Boyana Aleksova, Plamen Haralambiev, Victoria Karamanova, Ivaylo Goranov, Aneliya Drazheva, Zdravko Yakimov, Vanya Kuncheva, Georgi Petrov, Stanimir Pavlov, Teodor Stefanov, Stefan Minchev, Simon Valentinova Kochova, Marin Marinov, Petar Peshev, Radoslav Astardzhiev, Dimitar Radkov, Aleksandar Tsvetkov, Georgi Dragnev, Veselin Neychev, Kaloyan Kolev, Andrey Blagoev, Yordan Penev, Ventsislav Yordanov, Nikolay Georgiev, Siyana Yasenova Zdravkova, Ani Kalpachka, Gergana Damyanova, Petya Koleva, Dyanko Petkov, Nikola Kolchakov, Borislava Hranova
102107

103108
## Previous Supporters
104109
- Regina Uzunova

MyTested.AspNetCore.Mvc.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.MultipleEntryPoints",
231231
EndProject
232232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "samples\Configuration\Common\Common.csproj", "{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}"
233233
EndProject
234+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Versioning", "plugins\MyTested.AspNetCore.Mvc.Versioning\MyTested.AspNetCore.Mvc.Versioning.csproj", "{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}"
235+
EndProject
236+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Versioning.Test", "test\MyTested.AspNetCore.Mvc.Versioning.Test\MyTested.AspNetCore.Mvc.Versioning.Test.csproj", "{6541FC98-C8B1-48CF-A3A5-7028B19455E8}"
237+
EndProject
234238
Global
235239
GlobalSection(SolutionConfigurationPlatforms) = preSolution
236240
Debug|Any CPU = Debug|Any CPU
@@ -645,6 +649,14 @@ Global
645649
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}.Debug|Any CPU.Build.0 = Debug|Any CPU
646650
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}.Release|Any CPU.ActiveCfg = Release|Any CPU
647651
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}.Release|Any CPU.Build.0 = Release|Any CPU
652+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
653+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Debug|Any CPU.Build.0 = Debug|Any CPU
654+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Release|Any CPU.ActiveCfg = Release|Any CPU
655+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Release|Any CPU.Build.0 = Release|Any CPU
656+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
657+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
658+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
659+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Release|Any CPU.Build.0 = Release|Any CPU
648660
EndGlobalSection
649661
GlobalSection(SolutionProperties) = preSolution
650662
HideSolutionNode = FALSE
@@ -760,6 +772,8 @@ Global
760772
{25649D8E-C12B-492E-8778-9638B0C4B31C} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
761773
{840C7C04-90CC-4F0F-BDF9-0D97D399BA3F} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
762774
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
775+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73} = {EF386110-3D7B-4BDF-B403-8DC2AB8CF7BB}
776+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
763777
EndGlobalSection
764778
GlobalSection(ExtensibilityGlobals) = postSolution
765779
SolutionGuid = {99A2DEDD-5195-4EE6-A546-B1CA54C5539F}

README.md

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
<tr>
88
<td align="center" valign="middle">
99
<a href="http://bit.ly/bellatrixsolutions" target="_blank">
10-
<img width="323px" src="https://user-images.githubusercontent.com/3391906/68993273-d4f5c700-087e-11ea-9b39-e173733fcbfb.png" alt=""The Ultimate Cross-Platform .NET Framework>
11-
</a>
10+
<img width="323px" src="https://user-images.githubusercontent.com/3391906/68993273-d4f5c700-087e-11ea-9b39-e173733fcbfb.png" alt="The Ultimate Cross-Platform .NET Framework">
11+
</a>
12+
</td>
13+
<td align="center" valign="middle">
14+
<a href="https://www.jetbrains.com/?from=MyTestedASP.NET" target="_blank">
15+
<img width="323px" src="https://user-images.githubusercontent.com/3391906/72542498-ee21f080-388c-11ea-92ac-0b0153028933.png" alt="JetBrains">
16+
</a>
1217
</td>
1318
</tr>
1419
</tbody>
@@ -49,7 +54,7 @@
4954

5055
*Windows:* [![Build status](https://ci.appveyor.com/api/projects/status/3xlag3a7f87bg4on?svg=true)](https://ci.appveyor.com/project/ivaylokenov/mytested-aspnetcore-mvc)
5156

52-
*Ubuntu & Mac OS:* [![Build Status](https://travis-ci.org/ivaylokenov/MyTested.AspNetCore.Mvc.svg?branch=development)](https://travis-ci.org/ivaylokenov/MyTested.AspNetCore.Mvc)
57+
*Ubuntu & Mac OS:* [![Build Status](https://travis-ci.org/ivaylokenov/MyTested.AspNetCore.Mvc.svg?branch=development)](https://travis-ci.com/ivaylokenov/MyTested.AspNetCore.Mvc)
5358

5459
*Downloads:* [![NuGet Badge](https://buildstats.info/nuget/MyTested.AspNetCore.Mvc)](https://www.nuget.org/packages/MyTested.AspNetCore.Mvc/)
5560

@@ -103,39 +108,59 @@ Funds donated via both platforms are used for development and marketing purposes
103108

104109
Additionally, funds donated via [Patreon](https://www.patreon.com/ivaylokenov) (see the stretch goals) give me the freedom to add more features to the free `Lite` edition of the library.
105110

111+
## Main Features
112+
113+
- **Built-in service mock resolver** - register your mocks once, use them everywhere.
114+
- **Full request setup** - excellent arrangement of fake request data.
115+
- **Detailed response assertions** - precise validation for all available result objects.
116+
- **Controller tests** - unit or integration tests for both MVC and API scenarios.
117+
- **View component tests** - validate your view logic as fast as possible.
118+
- **Route tests** - asserting route paths and model binding is as accessible as it can get.
119+
- **Pipeline tests** - from the web request to the returned response - the whole chain is validated.
120+
- **Simple and easy to learn fluent API** - takes no more than 20 minutes to learn the library.
121+
- **Strongly-typed assertions** - the fluent test chain is designed to be developer-friendly and helpful.
122+
- **Friendly error messages** - failed tests throw exceptions with detailed error reports.
123+
- **Isolated test scope** - each test is run in isolated scope, making asynchronous execution more than welcome.
124+
- **Built-in mocks** - in-memory database, authentication, authorization, session, caching, temp data, and more.
125+
106126
## Quick Start
107127

128+
This quick start is for ASP.NET Core 3.1. For previous versions, check the [corresponding branches](https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc/branches).
129+
108130
To add **MyTested.AspNetCore.Mvc** to your solution, you must follow these simple steps:
109131

110132
1. Create a test project.
111133
2. Reference your web application.
112134
3. Install **`MyTested.AspNetCore.Mvc.Universe`** (or just the [testing packages](#package-installation) you need) from [NuGet](https://www.nuget.org/packages/MyTested.AspNetCore.Mvc.Universe/).
113-
4. Open the test project's `.csproj` file.
114-
5. Change the project SDK to `Microsoft.NET.Sdk.Web`:
115-
116-
```xml
117-
<Project Sdk="Microsoft.NET.Sdk.Web">
118-
```
119-
120-
6. Add a package reference to the web framework - `Microsoft.AspNetCore.App`:
135+
4. Create a `testsettings.json` file at the root of the test project, set its `Copy to Output Directory` property to `Copy if newer`, and set your required application settings to fake ones:
121136

122-
```xml
123-
<PackageReference Include="Microsoft.AspNetCore.App" />
137+
```json
138+
{
139+
"ConnectionStrings": {
140+
"DefaultConnection": "My Fake Connection String"
141+
},
142+
"AllowedHosts": "*"
143+
}
124144
```
125145

126-
7. Your test project's `.csproj` file should be similar to this one:
146+
5. Your test project's `.csproj` file should be similar to this one:
127147

128148
```xml
129-
<Project Sdk="Microsoft.NET.Sdk.Web"> <!-- Changed project SDK -->
149+
<Project Sdk="Microsoft.NET.Sdk">
130150

131151
<PropertyGroup>
132-
<TargetFramework>netcoreapp2.2</TargetFramework>
152+
<TargetFramework>netcoreapp3.1</TargetFramework>
133153
</PropertyGroup>
134154

135155
<ItemGroup>
136-
<PackageReference Include="Microsoft.AspNetCore.App" /> <!-- Reference to the web framework -->
137-
<PackageReference Include="MyTested.AspNetCore.Mvc.Universe" Version="2.2.0" />
138-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
156+
<None Update="testsettings.json">
157+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
158+
</None>
159+
</ItemGroup>
160+
161+
<ItemGroup>
162+
<PackageReference Include="MyTested.AspNetCore.Mvc.Universe" Version="3.1.1" />
163+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
139164
<PackageReference Include="xunit" Version="2.4.1" /> <!-- Can be any testing framework -->
140165
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
141166
</ItemGroup>
@@ -147,7 +172,7 @@ To add **MyTested.AspNetCore.Mvc** to your solution, you must follow these simpl
147172
</Project>
148173
```
149174

150-
8. Create a `TestStartup` class at the root of the test project to register the dependency injection services, which will be used by all test cases in the assembly. A quick solution is to inherit from the web project's `Startup` class. By default **MyTested.AspNetCore.Mvc** replaces all ASP.NET Core services with ready to be used mocks. You only need to replace your own custom services with mocked ones by using the provided extension methods.
175+
6. Create a `TestStartup` class at the root of the test project to register the dependency injection services, which will be used by all test cases in the assembly. A quick solution is to inherit from the web project's `Startup` class. By default **MyTested.AspNetCore.Mvc** replaces all ASP.NET Core services with ready to be used mocks. You only need to replace your own custom services with mocked ones by using the provided extension methods.
151176

152177
```c#
153178
namespace MyApp.Tests
@@ -170,7 +195,7 @@ namespace MyApp.Tests
170195
}
171196
```
172197

173-
9. 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:
198+
7. 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:
174199

175200
```c#
176201
namespace MyApp.Tests.Controllers
@@ -183,12 +208,16 @@ namespace MyApp.Tests.Controllers
183208
public class HomeControllerShould
184209
{
185210
[Fact]
186-
public void ReturnViewWhenCallingIndexAction()
211+
public void ReturnOkWithCorrectModelWhenCallingAuthenticatedIndexAction()
187212
=> MyMvc
188-
.Controller<HomeController>()
213+
.Controller<HomeController>(instance => instance
214+
.WithUser("TestUser")
215+
.WithData(MyTestData.GetData()))
189216
.Calling(c => c.Index())
190217
.ShouldReturn()
191-
.Ok();
218+
.Ok(result => result
219+
.WithModelOfType<List<MyResponseModel>>()
220+
.Passing(model => model.Count == 10));
192221
}
193222
}
194223
```
@@ -330,7 +359,7 @@ MyController<MyMvcController>
330359

331360
### Route Tests
332361

333-
A route test validates the web application's routing configuration:
362+
A route test validates the web application's routing configuration, without executing the defined filters:
334363

335364
```c#
336365
// Tests a route for correct controller, action, and resolved route values.
@@ -340,7 +369,7 @@ MyRouting
340369
.To<MyController>(c => c.Action(1));
341370

342371
// Tests a route for correct controller, action, and resolved route values
343-
// with authenticated post request and submitted form.
372+
// with post request and submitted form.
344373
MyRouting
345374
.Configuration()
346375
.ShouldMap(request => request
@@ -350,9 +379,7 @@ MyRouting
350379
{
351380
Title = title,
352381
Content = content
353-
})
354-
.WithUser()
355-
.WithAntiForgeryToken())
382+
}))
356383
.To<MyController>(c => c.Action(new MyFormModel
357384
{
358385
Title = title,
@@ -362,14 +389,12 @@ MyRouting
362389
.ToValidModelState();
363390

364391
// Tests a route for correct controller, action, and resolved route values
365-
// with authenticated post request and JSON body.
392+
// with post request and JSON body.
366393
MyRouting
367394
.Configuration()
368395
.ShouldMap(request => request
369396
.WithLocation("/My/Action/1")
370397
.WithMethod(HttpMethod.Post)
371-
.WithUser()
372-
.WithAntiForgeryToken()
373398
.WithJsonBody(new
374399
{
375400
Integer = 1,
@@ -384,11 +409,11 @@ MyRouting
384409
.ToValidModelState();
385410
```
386411

387-
*Note: route tests execute action filters.*
412+
*Note: route tests do not execute action filters.*
388413

389414
### Pipeline tests
390415

391-
A pipeline test provides strongly-typed assertions for the MVC pipeline (from routing to action result):
416+
A pipeline test provides strongly-typed assertions for the MVC pipeline (from routing to action result, including the application filters):
392417

393418
```c#
394419
// Tests a route for correct route values,
@@ -398,26 +423,33 @@ A pipeline test provides strongly-typed assertions for the MVC pipeline (from ro
398423
// while resolving services from the `TestStartup` class.
399424
MyMvc
400425
.Pipeline()
401-
.ShouldMap("/My/Action/1")
426+
.ShouldMap(request => request
427+
.WithLocation("/My/Action/1")
428+
.WithMethod(HttpMethod.Post)
429+
.WithUser()
430+
.WithAntiForgeryToken()
431+
.WithJsonBody(new
432+
{
433+
Integer = 1,
434+
String = "Text"
435+
}))
402436
.To<MyController>(c => c.Action(1))
403437
.Which(controller => controller
404-
.WithUser()
405438
.WithData(MyDataProvider.GetMyModels()))
406439
.ShouldReturn()
407440
.Redirect(redirect => redirect
408441
.To<AnotherController>(c => c.AnotherAction()));
409442

410443
// Tests a route for correct route values,
411444
// and validates whether the controller action
412-
// with an authenticated user and the provided data
445+
// with the provided data
413446
// returns view result with a specific model,
414447
// while resolving services from the provided mocks.
415448
MyMvc
416449
.Pipeline()
417450
.ShouldMap("/My/Action/1")
418451
.To<MyController>(c => c.Action(1))
419452
.Which(controller => controller
420-
.WithUser()
421453
.WithData(MyDataProvider.GetMyModels())
422454
.WithDependencies(
423455
serviceMock,
@@ -647,7 +679,7 @@ using MyTested.AspNetCore.Mvc;
647679

648680
## Versioning
649681

650-
**MyTested.AspNetCore.Mvc** follows the ASP.NET Core MVC versions with which the testing framework is fully compatible. Specifically, the *major* and the *minor* versions will be incremented only when the MVC framework has a new official release. For example, version 2.2.\* of the testing framework is fully compatible with ASP.NET Core MVC 2.2.\*, version 1.1.\* is fully compatible with ASP.NET Core MVC 1.1.\*, version 1.0.15 is fully compatible with ASP.NET Core MVC 1.0.\*, and so on.
682+
**MyTested.AspNetCore.Mvc** follows the ASP.NET Core MVC versions with which the testing framework is fully compatible. Specifically, the *major* and the *minor* versions will be incremented only when the MVC framework has a new official release. For example, version 3.1.\* of the testing framework is fully compatible with ASP.NET Core MVC 3.1.\*, version 2.2.\* is fully compatible with ASP.NET Core MVC 2.2.\*, version 1.0.15 is fully compatible with ASP.NET Core MVC 1.0.\*, and so on.
651683

652684
The public interface of **MyTested.AspNetCore.Mvc** will not have any breaking changes when the version increases (unless entirely necessary).
653685

plugins/MyTested.AspNetCore.Mvc.NewtonsoftJson/MyTested.AspNetCore.Mvc.NewtonsoftJson.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>My Tested ASP.NET Core MVC Newtonsoft JSON components.</Description>
55
<Copyright>2015-2019 Ivaylo Kenov</Copyright>
66
<AssemblyTitle>MyTested.AspNetCore.Mvc.NewtonsoftJson</AssemblyTitle>
7-
<VersionPrefix>3.1.0</VersionPrefix>
7+
<VersionPrefix>3.1.1</VersionPrefix>
88
<Authors>Ivaylo Kenov</Authors>
99
<TargetFramework>netcoreapp3.1</TargetFramework>
1010
<NoWarn>$(NoWarn);CS1591</NoWarn>
@@ -29,7 +29,7 @@
2929
</PropertyGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
32+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
3333
</ItemGroup>
3434

3535
<ItemGroup>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyProduct("MyTested.AspNetCore.Mvc.NewtonsoftJson")]
5+
[assembly: ComVisible(false)]

0 commit comments

Comments
 (0)