Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions 14/umbraco-cms/implementation/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,21 @@ public class PageSurfaceControllerTests
`ServiceContext.CreatePartial()` has optional parameters, and by naming them you only need to mock the dependencies that you need, for example: `ServiceContext.CreatePartial(contentService: Mock.Of<IContentService>());`
{% endhint %}

## Testing an UmbracoApiController
## Testing an ApiController

See [Reference documentation on UmbracoApiControllers](../reference/routing/umbraco-api-controllers/README.md#locally-declared-controller).

{% hint style="warning" %}
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
{% endhint %}

```csharp
[ApiController]
[Route("/umbraco/api/products")]
public class ProductsController : UmbracoApiController
{
public IEnumerable<string> GetAllProducts()
{
return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
}

[HttpGet]
[HttpGet("getallproductsjson")]
public JsonResult GetAllProductsJson()
{
return new JsonResult(this.GetAllProducts());
Expand Down
10 changes: 4 additions & 6 deletions 15/umbraco-cms/implementation/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,21 @@ public class PageSurfaceControllerTests
`ServiceContext.CreatePartial()` has optional parameters, and by naming them you only need to mock the dependencies that you need, for example: `ServiceContext.CreatePartial(contentService: Mock.Of<IContentService>());`
{% endhint %}

## Testing an UmbracoApiController
## Testing an ApiController

See [Reference documentation on UmbracoApiControllers](../reference/routing/umbraco-api-controllers/README.md#locally-declared-controller).

{% hint style="warning" %}
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
{% endhint %}

```csharp
[ApiController]
[Route("/umbraco/api/products")]
public class ProductsController : UmbracoApiController
{
public IEnumerable<string> GetAllProducts()
{
return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
}

[HttpGet]
[HttpGet("getallproductsjson")]
public JsonResult GetAllProductsJson()
{
return new JsonResult(this.GetAllProducts());
Expand Down