Skip to content

Commit

Permalink
Merge pull request #254 from ivaylokenov/development
Browse files Browse the repository at this point in the history
Publishing Tutorial
  • Loading branch information
ivaylokenov committed Oct 31, 2016
2 parents 0558949 + 2bea734 commit fb0f7b7
Show file tree
Hide file tree
Showing 365 changed files with 26,980 additions and 5,312 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MyTested.AspNetCore.Mvc is a unit testing library providing easy fluent interfac

## Getting started

It is strongly advised to start with the [tutorial](http://docs.mytestedasp.net/tutorial/intro.html) (coming soon) in order to get familiar with MyTested.AspNetCore.Mvc. Additionally, you may see the [testing guide](http://docs.mytestedasp.net/guide/intro.html) (coming soon) or the [API reference](http://docs.mytestedasp.net/api/index.html) for full list of available features. MyTested.AspNetCore.Mvc is 100% covered by [more than 1800 unit tests](https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc/tree/master/test/) and should work correctly. Almost all items in the [issues page](https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc/issues) are expected future features and enhancements.
It is strongly advised to start with the [tutorial](http://docs.mytestedasp.net/tutorial/intro.html) in order to get familiar with MyTested.AspNetCore.Mvc. Additionally, you may see the [testing guide](http://docs.mytestedasp.net/guide/intro.html) or the [API reference](http://docs.mytestedasp.net/api/index.html) for full list of available features. MyTested.AspNetCore.Mvc is 100% covered by [more than 1800 unit tests](https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc/tree/master/test/) and should work correctly. Almost all items in the [issues page](https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc/issues) are expected future features and enhancements.

## Installation

Expand Down Expand Up @@ -51,7 +51,7 @@ For other interesting packages check out:

## How to use

Make sure to check out the [tutorial](http://docs.mytestedasp.net/tutorial/intro.html) (coming soon) and the [testing guide](http://docs.mytestedasp.net/guide/intro.html) (coming soon) for a preview of the available features.
Make sure to check out the [tutorial](http://docs.mytestedasp.net/tutorial/intro.html) and the [testing guide](http://docs.mytestedasp.net/guide/intro.html) for a preview of the available features.

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.

Expand Down
12 changes: 0 additions & 12 deletions docs/_docfx/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion docs/_docfx/api/.manifest

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions docs/_docfx/custom/partials/head.tmpl.partial
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
<meta name="viewport" content="width=device-width">
<meta name="title" content="{{#title}}{{title}}{{/title}}{{^title}}{{>partials/title}}{{/title}} {{#_appTitle}}| {{_appTitle}} {{/_appTitle}}">
<meta name="generator" content="docfx {{_docfxVersion}}">
{% seo %}
{{#_description}}<meta name="description" content="{{_description}}">{{/_description}}
<link rel="shortcut icon" href="{{_rel}}favicon.ico">
<link rel="stylesheet" href="{{_rel}}styles/docfx.vendor.css">
<link rel="stylesheet" href="{{_rel}}styles/docfx.css">
<link rel="stylesheet" href="{{_rel}}styles/main.css">
<meta property="docfx:navrel" content="{{_navRel}}">
<meta property="docfx:tocrel" content="{{_tocRel}}">
{{#_enableSearch}}<meta property="docfx:rel" content="{{_rel}}">{{/_enableSearch}}
<meta property="docfx:rel" content="{{_rel}}">
<meta property="og:title" content="{{#metaTitle}}{{metaTitle}}{{/metaTitle}}{{^metaTitle}}Flexible and asynchronous testing framework for ASP.NET Core MVC{{/metaTitle}}">
<meta property="og:site_name" content="My Tested ASP.NET Core MVC Docs">
<meta property="og:url" content="http://docs.mytestedasp.net/">
<meta property="og:description" content="A fluent unit testing library for ASP.NET Core MVC">
<meta property="og:image" content="https://mytestedasp.net/Content/Images/logosocial.jpg">
<meta property="og:type" content="website">
<meta property="og:locale" content="en_US">
<meta property="twitter:card" content="summary">
<meta property="twitter:title" content="{{#metaTitle}}{{metaTitle}}{{/metaTitle}}{{^metaTitle}}Flexible and asynchronous testing framework for ASP.NET Core MVC{{/metaTitle}}">
<meta property="twitter:description" content="A fluent unit testing library for ASP.NET Core MVC">
<meta property="twitter:creator" content="@MyTestedASPNET">
<meta property="twitter:url" content="https://mytestedasp.net/">
<meta property="twitter:image" content="https://mytestedasp.net/Content/Images/logosocial.jpg">
</head>
23 changes: 23 additions & 0 deletions docs/_docfx/custom/partials/scripts.tmpl.partial
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>
42 changes: 30 additions & 12 deletions docs/_docfx/custom/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
font-size: 1.6em;
}

.content.wrap > h1 {
margin-top: -175px;
}

.navbar-brand:hover {
color: #eee !important;
}
Expand Down Expand Up @@ -127,13 +123,35 @@ footer a:hover {
display: none;
}

.content.wrap > h1 {
margin-top: -100px;
}

@media only screen and (max-width: 768px) {
.hero {
height: 500px;
margin-top: 0px;
}
.hero .button {
display: block;
margin: 12px;
}
.hero {
height: 500px;
margin-top: 0px;
}
.hero .button {
display: block;
margin: 12px;
}
.hero .text {
font-size: 36px;
}
.breadcrumb {
text-align: center;
}
}

@media only screen and (max-width: 800px) {
.nav.level1.navbar-nav {
float: none !important;
}
}

@media only screen and (min-width: 769px) {
.content.wrap > h1 {
margin-top: -160px;
}
}
4 changes: 4 additions & 0 deletions docs/_docfx/custom/styles/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ $(function() {
$('#toc.toc').show();
}
}, 200);

if ($(window).width() < 780) {
$('a.navbar-brand').text('MY TESTED MVC DOCS');
}
})
1 change: 1 addition & 0 deletions docs/_docfx/custom/styles/search-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function(){}())
1 change: 1 addition & 0 deletions docs/_docfx/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"**/**project.json"
],
"exclude": [
"**/MyTested.AspNetCore.Mvc.Lite/**",
"**/obj/**",
"**/bin/**",
"./**"
Expand Down
4 changes: 1 addition & 3 deletions docs/_docfx/guide/intro.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Welcome to the Testing Guide

Here you will find My Tested ASP.NET Core MVC user-friendly descriptions and examples for all available assertion APIs.
# Testing Guide

<strong class="article-contents">The testing guide is still work in progress...</strong>

Expand Down
7 changes: 7 additions & 0 deletions docs/_docfx/guide/licensing.md
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" />
8 changes: 6 additions & 2 deletions docs/_docfx/guide/packages.md
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" />
7 changes: 7 additions & 0 deletions docs/_docfx/guide/plugins.md
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" />
7 changes: 7 additions & 0 deletions docs/_docfx/guide/startuptypes.md
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" />
6 changes: 5 additions & 1 deletion docs/_docfx/guide/testconfig.md
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" />
7 changes: 7 additions & 0 deletions docs/_docfx/guide/testcontext.md
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" />
Binary file added docs/_docfx/images/tutorial/actiondebugging.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_docfx/images/tutorial/configjson.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_docfx/images/tutorial/configjsonerror.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_docfx/images/tutorial/coreintellisense.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.
Binary file added docs/_docfx/images/tutorial/firsttestpass.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.
Binary file added docs/_docfx/images/tutorial/net451fail.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.
Binary file added docs/_docfx/images/tutorial/nostartuperror.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_docfx/images/tutorial/projectjson.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_docfx/images/tutorial/terminal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_docfx/images/tutorial/testconfigfile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_docfx/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ footer{
<div class="col-md-6 text-center">
<section>
<h2>TUTORIAL</h2>
<p class="lead">Start from here to learn how to setup a your test project by using My Tested ASP.NET Core MVC</p>
<p class="lead">Start from here to learn how to setup a test project by using My Tested ASP.NET Core MVC</p>
</section>
</div>
<div class="col-md-6 text-center">
Expand Down
2 changes: 1 addition & 1 deletion docs/_docfx/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
- name: Troubleshoot
href: troubleshoot/
- name: About
href: http://mytestedasp.net/core/mvc
href: http://mytestedasp.net/core/mvc?r=docs
2 changes: 1 addition & 1 deletion docs/_docfx/troubleshoot/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
- name: Type Initializer Exception
href: typeinitexception.md
- name: Visual Studio Random Results
href: typeinitexception.md
href: randomtestresults.md
2 changes: 1 addition & 1 deletion docs/_docfx/troubleshoot/typeinitexception.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

In order to see more details about the problem, run the test in `Debug` mode and analyse the message of the `InnerException`.

<img src="/images/troubleshoot/typeinitexception.jpg" />
<img src="/images/troubleshoot/typeinitexception.jpg" alt="Debugging Type Initializer Exception" />
108 changes: 108 additions & 0 deletions docs/_docfx/tutorial/attributes.md
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).
Loading

0 comments on commit fb0f7b7

Please sign in to comment.