-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from ivaylokenov/development
Publishing Tutorial
- Loading branch information
Showing
365 changed files
with
26,980 additions
and
5,312 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
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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,23 @@ | ||
<script type="text/javascript" src="{{_rel}}styles/docfx.vendor.js"></script> | ||
<script type="text/javascript" src="{{_rel}}styles/docfx.js"></script> | ||
<script type="text/javascript" src="{{_rel}}styles/main.js"></script> | ||
<script> | ||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); | ||
ga('create', 'UA-51720358-4', 'auto'); | ||
ga('send', 'pageview'); | ||
</script> | ||
<script> | ||
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod? | ||
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n; | ||
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0; | ||
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window, | ||
document,'script','https://connect.facebook.net/en_US/fbevents.js'); | ||
fbq('init', '884740311601716'); | ||
fbq('track', 'PageView'); | ||
</script> | ||
<noscript><img height="1" width="1" style="display:none" | ||
src="https://www.facebook.com/tr?id=884740311601716&ev=PageView&noscript=1" | ||
/></noscript> |
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
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
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 @@ | ||
(function(){}()) |
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
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
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 @@ | ||
# Licensing | ||
|
||
<strong class="article-contents">This document is still work in progress...</strong> | ||
|
||
<span>Sorry for the inconvenience caused! :(</span> | ||
|
||
<img src="/images/catsorry.jpg" /> |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# My Tested MVC Packages | ||
# Test Packages | ||
|
||
This document is still work in progress. | ||
<strong class="article-contents">This document is still work in progress...</strong> | ||
|
||
<span>Sorry for the inconvenience caused! :(</span> | ||
|
||
<img src="/images/catsorry.jpg" /> |
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 @@ | ||
# Test Plugins | ||
|
||
<strong class="article-contents">This document is still work in progress...</strong> | ||
|
||
<span>Sorry for the inconvenience caused! :(</span> | ||
|
||
<img src="/images/catsorry.jpg" /> |
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 @@ | ||
# Startup Types | ||
|
||
<strong class="article-contents">This document is still work in progress...</strong> | ||
|
||
<span>Sorry for the inconvenience caused! :(</span> | ||
|
||
<img src="/images/catsorry.jpg" /> |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Test Configuration | ||
|
||
This document is still work in progress. | ||
<strong class="article-contents">This document is still work in progress...</strong> | ||
|
||
<span>Sorry for the inconvenience caused! :(</span> | ||
|
||
<img src="/images/catsorry.jpg" /> |
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 @@ | ||
# Test Context | ||
|
||
<strong class="article-contents">This document is still work in progress...</strong> | ||
|
||
<span>Sorry for the inconvenience caused! :(</span> | ||
|
||
<img src="/images/catsorry.jpg" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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,108 @@ | ||
# Attributes | ||
|
||
This section will cover testing of attributes and their properties. | ||
|
||
## Controller attributes | ||
|
||
Let's assert that our **"CheckoutController"** is decorated with the commonly used **"AuthorizeAttribute"**. Go to the **CheckoutControllerTest"** class and add the following test: | ||
|
||
```c# | ||
[Fact] | ||
public void CheckoutControllerShouldHaveAuthorizeAttribute() | ||
=> MyController<CheckoutController> | ||
.Instance() | ||
.ShouldHave() | ||
.Attributes(attributes => attributes // <--- | ||
.RestrictingForAuthorizedRequests()); | ||
``` | ||
|
||
Simple as that. Additionally, in the the **"HomeControllerTest"** class, we can add: | ||
|
||
```c# | ||
[Fact] | ||
public void HomeControllerShouldHaveNoAttributes() | ||
=> MyController<HomeController> | ||
.Instance() | ||
.ShouldHave() | ||
.NoAttributes(); | ||
``` | ||
|
||
Of course, if you change **"NoAttributes"** to **"Attributes"**, you will receive an error: | ||
|
||
```text | ||
When testing HomeController was expected to have at least 1 attribute, but in fact none was found. | ||
``` | ||
|
||
## Action attributes | ||
|
||
Action attributes are not different. Let's test the **"RemoveAlbumConfirmed"** action in the **"StoreManagerController"**: | ||
|
||
```c# | ||
[HttpPost, ActionName("RemoveAlbum")] | ||
public async Task<IActionResult> RemoveAlbumConfirmed( | ||
[FromServices] IMemoryCache cache, | ||
int id, | ||
CancellationToken requestAborted) | ||
{ | ||
|
||
// action code skipped for brevity | ||
``` | ||
|
||
We need to test the **"HttpPost"** and **"ActionName"** attributes: | ||
|
||
```c# | ||
[Fact] | ||
public void RemoveAlbumConfirmedShouldHaveCorrectAttributes() | ||
=> MyController<StoreManagerController> | ||
.Instance() | ||
.Calling(c => c.RemoveAlbumConfirmed( | ||
With.No<IMemoryCache>(), | ||
With.No<int>(), | ||
With.No<CancellationToken>())) | ||
.ShouldHave() | ||
.ActionAttributes(attributes => attributes // <--- | ||
.RestrictingForHttpMethod(HttpMethod.Post) | ||
.ChangingActionNameTo("RemoveAlbum")); | ||
``` | ||
|
||
Working like a charm! :) | ||
|
||
## Custom attributes | ||
|
||
Sometimes you will have custom attributes which are not available in the fluent testing API. For example, you may have noticed that there is no method to test the **"ValidateAntiForgeryTokenAttribute"**". Actually, it's in the **"ViewFeatures"** package, but you don't know that! :) | ||
|
||
Let's see an example and test the HTTP Post **"Login"** action in the **"AccountController"**. It has these three attributes - **"HttpPost"**, **"AllowAnonymous"**, **"ValidateAntiForgeryToken"**. For the latter you can use the **"ContainingAttributeOfType"** method: | ||
|
||
```c# | ||
[Fact] | ||
public void LoginShouldHaveCorrectAttributes() | ||
=> MyController<AccountController> | ||
.Instance() | ||
.Calling(c => c.Login( | ||
With.Default<LoginViewModel>(), | ||
With.No<string>())) | ||
.ShouldHave() | ||
.ActionAttributes(attributes => attributes | ||
.RestrictingForHttpMethod(HttpMethod.Post) | ||
.AllowingAnonymousRequests() | ||
.ContainingAttributeOfType<ValidateAntiForgeryTokenAttribute>()); // <--- | ||
``` | ||
|
||
The action is still invoked in this test, so we need to provide a non-null value for the **"LoginViewModel"** parameter. A better approach for testing action attributes (without having to specify the parameters) will be available in the next major release of the library. :) | ||
|
||
Sometimes you may want to test specific property values of the attribute. You can use the **"PassingFor"** method: | ||
|
||
```c# | ||
[Fact] | ||
public void StoreManagerControllerShouldHaveCorrectAttributes() | ||
=> MyController<StoreManagerController> | ||
.Instance() | ||
.ShouldHave() | ||
.Attributes(attributes => attributes | ||
.SpecifyingArea("Admin") | ||
.PassingFor<AuthorizeAttribute>(authorize => authorize.Policy == "ManageStore")); | ||
``` | ||
|
||
## Section summary | ||
|
||
We saw how easy it is to assert and validate all kinds of controller and action attributes. But enough about them - in the next section we will cover thrown [Exceptions](/tutorial/exceptions.html). |
Oops, something went wrong.