From dec9aefd2b3dd0779b7b4470866c783bd8aa9ae5 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Sat, 5 Oct 2024 13:14:21 +0200 Subject: [PATCH 1/8] Change heading --- 14/umbraco-cms/implementation/unit-testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/14/umbraco-cms/implementation/unit-testing.md b/14/umbraco-cms/implementation/unit-testing.md index 99531847b60..35e2700d8b4 100644 --- a/14/umbraco-cms/implementation/unit-testing.md +++ b/14/umbraco-cms/implementation/unit-testing.md @@ -159,7 +159,7 @@ 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());` {% endhint %} -## Testing an UmbracoApiController +## Testing an ApiController See [Reference documentation on UmbracoApiControllers](../reference/routing/umbraco-api-controllers/README.md#locally-declared-controller). From e946616a4cda8491be65114d8c70170fb51928f9 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Sat, 5 Oct 2024 13:15:14 +0200 Subject: [PATCH 2/8] Add attributes --- 14/umbraco-cms/implementation/unit-testing.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/14/umbraco-cms/implementation/unit-testing.md b/14/umbraco-cms/implementation/unit-testing.md index 35e2700d8b4..500da39185a 100644 --- a/14/umbraco-cms/implementation/unit-testing.md +++ b/14/umbraco-cms/implementation/unit-testing.md @@ -168,6 +168,8 @@ The example below uses UmbracoApiController which is obsolete in Umbraco 14 and {% endhint %} ```csharp +[ApiController] +[Route("/umbraco/api/products")] public class ProductsController : UmbracoApiController { public IEnumerable GetAllProducts() @@ -175,7 +177,7 @@ public class ProductsController : UmbracoApiController return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" }; } - [HttpGet] + [HttpGet("getallproductsjson")] public JsonResult GetAllProductsJson() { return new JsonResult(this.GetAllProducts()); From 284b75addc711f76aebf7ff5f5845894684c2069 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Sat, 5 Oct 2024 13:15:56 +0200 Subject: [PATCH 3/8] Delete obsolete message --- 14/umbraco-cms/implementation/unit-testing.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/14/umbraco-cms/implementation/unit-testing.md b/14/umbraco-cms/implementation/unit-testing.md index 500da39185a..629c8b0b188 100644 --- a/14/umbraco-cms/implementation/unit-testing.md +++ b/14/umbraco-cms/implementation/unit-testing.md @@ -163,10 +163,6 @@ public class PageSurfaceControllerTests 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")] From fbb480e44d4a7364e9b376bff96c2427da206d37 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Sat, 5 Oct 2024 13:17:08 +0200 Subject: [PATCH 4/8] Update v15 --- 15/umbraco-cms/implementation/unit-testing.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/15/umbraco-cms/implementation/unit-testing.md b/15/umbraco-cms/implementation/unit-testing.md index 99531847b60..629c8b0b188 100644 --- a/15/umbraco-cms/implementation/unit-testing.md +++ b/15/umbraco-cms/implementation/unit-testing.md @@ -159,15 +159,13 @@ 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());` {% 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 GetAllProducts() @@ -175,7 +173,7 @@ public class ProductsController : UmbracoApiController return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" }; } - [HttpGet] + [HttpGet("getallproductsjson")] public JsonResult GetAllProductsJson() { return new JsonResult(this.GetAllProducts()); From bd4ac8d949a9f830e9ce1735760833a167ceb1fb Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Mon, 7 Oct 2024 09:01:27 +0200 Subject: [PATCH 5/8] Update 14/umbraco-cms/implementation/unit-testing.md Co-authored-by: sofietoft --- 14/umbraco-cms/implementation/unit-testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/14/umbraco-cms/implementation/unit-testing.md b/14/umbraco-cms/implementation/unit-testing.md index 629c8b0b188..ebdc7f0d5ac 100644 --- a/14/umbraco-cms/implementation/unit-testing.md +++ b/14/umbraco-cms/implementation/unit-testing.md @@ -166,7 +166,7 @@ See [Reference documentation on UmbracoApiControllers](../reference/routing/umbr ```csharp [ApiController] [Route("/umbraco/api/products")] -public class ProductsController : UmbracoApiController +public class ProductsController : Controller { public IEnumerable GetAllProducts() { From 9590ec7ea5d4de989deaebb2330565bce4e853f2 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Thu, 10 Oct 2024 10:57:34 +0200 Subject: [PATCH 6/8] Change UmbracoApiController to Controller --- 15/umbraco-cms/implementation/unit-testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/15/umbraco-cms/implementation/unit-testing.md b/15/umbraco-cms/implementation/unit-testing.md index 629c8b0b188..ebdc7f0d5ac 100644 --- a/15/umbraco-cms/implementation/unit-testing.md +++ b/15/umbraco-cms/implementation/unit-testing.md @@ -166,7 +166,7 @@ See [Reference documentation on UmbracoApiControllers](../reference/routing/umbr ```csharp [ApiController] [Route("/umbraco/api/products")] -public class ProductsController : UmbracoApiController +public class ProductsController : Controller { public IEnumerable GetAllProducts() { From a1ba5a1e0c07869d3e710808978ec9606b2cee6b Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Thu, 10 Oct 2024 14:25:42 +0200 Subject: [PATCH 7/8] Change heading to `Controller` --- 14/umbraco-cms/implementation/unit-testing.md | 2 +- 15/umbraco-cms/implementation/unit-testing.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/14/umbraco-cms/implementation/unit-testing.md b/14/umbraco-cms/implementation/unit-testing.md index ebdc7f0d5ac..a90bae2a439 100644 --- a/14/umbraco-cms/implementation/unit-testing.md +++ b/14/umbraco-cms/implementation/unit-testing.md @@ -159,7 +159,7 @@ 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());` {% endhint %} -## Testing an ApiController +## Testing a Controller See [Reference documentation on UmbracoApiControllers](../reference/routing/umbraco-api-controllers/README.md#locally-declared-controller). diff --git a/15/umbraco-cms/implementation/unit-testing.md b/15/umbraco-cms/implementation/unit-testing.md index ebdc7f0d5ac..a90bae2a439 100644 --- a/15/umbraco-cms/implementation/unit-testing.md +++ b/15/umbraco-cms/implementation/unit-testing.md @@ -159,7 +159,7 @@ 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());` {% endhint %} -## Testing an ApiController +## Testing a Controller See [Reference documentation on UmbracoApiControllers](../reference/routing/umbraco-api-controllers/README.md#locally-declared-controller). From 7a6b563323cf5b204e6b629dcb98e1d63b2688fe Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Thu, 10 Oct 2024 14:50:36 +0200 Subject: [PATCH 8/8] Update Unit Test --- 14/umbraco-cms/implementation/unit-testing.md | 6 +++--- 15/umbraco-cms/implementation/unit-testing.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/14/umbraco-cms/implementation/unit-testing.md b/14/umbraco-cms/implementation/unit-testing.md index a90bae2a439..3a8401bc474 100644 --- a/14/umbraco-cms/implementation/unit-testing.md +++ b/14/umbraco-cms/implementation/unit-testing.md @@ -197,15 +197,15 @@ public class ProductsControllerTests var result = this.controller.GetAllProducts(); - Assert.AreEqual(expected, result); + Assert.That(expected == result); } [Test] public void WhenGetAllProductsJson_ThenReturnViewModelWithExpectedJson() { - var json = serializer.Serialize(this.controller.GetAllProductsJson().Value); + var json = JsonSerializer.Serialize(this.controller.GetAllProductsJson().Value); - Assert.AreEqual("[\"Table\",\"Chair\",\"Desk\",\"Computer\",\"Beer fridge\"]", json); + Assert.That("[\"Table\",\"Chair\",\"Desk\",\"Computer\",\"Beer fridge\"]" == json); } } ``` diff --git a/15/umbraco-cms/implementation/unit-testing.md b/15/umbraco-cms/implementation/unit-testing.md index a90bae2a439..3a8401bc474 100644 --- a/15/umbraco-cms/implementation/unit-testing.md +++ b/15/umbraco-cms/implementation/unit-testing.md @@ -197,15 +197,15 @@ public class ProductsControllerTests var result = this.controller.GetAllProducts(); - Assert.AreEqual(expected, result); + Assert.That(expected == result); } [Test] public void WhenGetAllProductsJson_ThenReturnViewModelWithExpectedJson() { - var json = serializer.Serialize(this.controller.GetAllProductsJson().Value); + var json = JsonSerializer.Serialize(this.controller.GetAllProductsJson().Value); - Assert.AreEqual("[\"Table\",\"Chair\",\"Desk\",\"Computer\",\"Beer fridge\"]", json); + Assert.That("[\"Table\",\"Chair\",\"Desk\",\"Computer\",\"Beer fridge\"]" == json); } } ```