Continue to update unit testing and debugging MD to use VS 2017 (#4308)
* update unit teting aspnet web api and some images * update image to display unit test's Text Explorer specific to VS2017 * update mocking EF md and its images * Change the version of Moq used to the version that is compatible with VS 2015 and VS 2017 * update further to notify Moq version * Update link of code sample to point to newer sample that uses VS 2017 * update wording based on PR feedbackpull/4321/head
|
@ -28,7 +28,7 @@ by [Tom FitzMacken](https://github.com/tfitzmac)
|
|||
> ## Software versions used in the tutorial
|
||||
>
|
||||
>
|
||||
> - [Visual Studio 2013](https://www.microsoft.com/visualstudio/eng/2013-downloads)
|
||||
> - [Visual Studio 2017](https://www.visualstudio.com/vs/)
|
||||
> - Web API 2
|
||||
|
||||
|
||||
|
@ -52,12 +52,12 @@ If you have already completed the steps in [Unit Testing with ASP.NET Web API 2]
|
|||
<a id="prereqs"></a>
|
||||
## Prerequisites
|
||||
|
||||
Visual Studio 2013 or Visual Studio Express 2013 for Web
|
||||
Visual Studio 2017 Community, Professional or Enterprise editioo
|
||||
|
||||
<a id="download"></a>
|
||||
## Download code
|
||||
|
||||
Download the [completed project](https://code.msdn.microsoft.com/Unit-Testing-with-ASPNET-e2867d4d). The downloadable project includes unit test code for this topic and for the [Unit Testing ASP.NET Web API 2](unit-testing-with-aspnet-web-api.md) topic.
|
||||
Download the [completed project](https://code.msdn.microsoft.com/Unit-Testing-with-ASPNET-1374bc11). The downloadable project includes unit test code for this topic and for the [Unit Testing ASP.NET Web API 2](unit-testing-with-aspnet-web-api.md) topic.
|
||||
|
||||
<a id="appwithunittest"></a>
|
||||
## Create application with unit test project
|
||||
|
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 14 KiB |
|
@ -21,10 +21,12 @@ by [Mike Wasson](https://github.com/MikeWasson)
|
|||
>
|
||||
> ## Software versions used in the tutorial
|
||||
>
|
||||
>
|
||||
> - [Visual Studio 2017](https://www.visualstudio.com/vs/)
|
||||
> - Web API 2
|
||||
> - Moq 4.2
|
||||
> - [Moq](https://github.com/Moq) 4.5.30
|
||||
|
||||
> [!NOTE]
|
||||
> I used Moq, but the same idea applies to any mocking framework. Moq 4.5.30 (and later) supports Visual Studio 2017, Roslyn and .NET 4.5 and later versions.
|
||||
|
||||
A common pattern in unit tests is "arrange-act-assert":
|
||||
|
||||
|
@ -63,15 +65,12 @@ The `Post` method calls **UrlHelper.Link** to create links in the response. This
|
|||
|
||||
The **UrlHelper** class needs the request URL and route data, so the test has to set values for these. Another option is mock or stub **UrlHelper**. With this approach, you replace the default value of [ApiController.Url](https://msdn.microsoft.com/en-us/library/system.web.http.apicontroller.url.aspx) with a mock or stub version that returns a fixed value.
|
||||
|
||||
Let's rewrite the test using the [Moq](https://github.com/Moq) framework.
|
||||
Let's rewrite the test using the [Moq](https://github.com/Moq) framework. Install the `Moq` NuGet package in the test project.
|
||||
|
||||
[!code-csharp[Main](unit-testing-controllers-in-web-api/samples/sample4.cs)]
|
||||
|
||||
In this version, you don't need to set up any route data, because the mock **UrlHelper** returns a constant string.
|
||||
|
||||
> [!NOTE]
|
||||
> I used Moq, but the same idea applies to any mocking framework.
|
||||
|
||||
|
||||
## Testing Actions that Return IHttpActionResult
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ by [Tom FitzMacken](https://github.com/tfitzmac)
|
|||
> ## Software versions used in the tutorial
|
||||
>
|
||||
>
|
||||
> - [Visual Studio 2013](https://www.microsoft.com/visualstudio/eng/2013-downloads)
|
||||
> - [Visual Studio 2017](https://www.visualstudio.com/vs/)
|
||||
> - Web API 2
|
||||
|
||||
|
||||
|
@ -50,12 +50,12 @@ This topic contains the following sections:
|
|||
<a id="prereqs"></a>
|
||||
## Prerequisites
|
||||
|
||||
Visual Studio 2013 or Visual Studio Express 2013 for Web
|
||||
Visual Studio 2017 Community, Professional or Enterprise edition
|
||||
|
||||
<a id="download"></a>
|
||||
## Download code
|
||||
|
||||
Download the [completed project](https://code.msdn.microsoft.com/Unit-Testing-with-ASPNET-e2867d4d). The downloadable project includes unit test code for this topic and for the [Mocking Entity Framework when Unit Testing ASP.NET Web API](mocking-entity-framework-when-unit-testing-aspnet-web-api-2.md) topic.
|
||||
Download the [completed project](https://code.msdn.microsoft.com/Unit-Testing-with-ASPNET-1374bc11). The downloadable project includes unit test code for this topic and for the [Mocking Entity Framework when Unit Testing ASP.NET Web API](mocking-entity-framework-when-unit-testing-aspnet-web-api-2.md) topic.
|
||||
|
||||
<a id="appwithunittest"></a>
|
||||
## Create application with unit test project
|
||||
|
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 45 KiB |