-
Notifications
You must be signed in to change notification settings - Fork 3
/
UmbracoApiControllerTests.cs
49 lines (42 loc) · 1.67 KB
/
UmbracoApiControllerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Web.Mvc;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Web;
using UmbracoUnitTesting.Core.Features.Products;
using UmbracoUnitTesting.Tests.Shared;
namespace UmbracoUnitTesting.Tests.UmbracoApiController {
/// <inheritdoc />
/// <summary>
/// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-an-umbracoapicontroller
/// </summary>
[TestFixture]
public class UmbracoApiControllerTests : UmbracoBaseTest
{
private ProductsController controller;
[SetUp]
public override void SetUp()
{
base.SetUp();
this.controller = new ProductsController(Mock.Of<IGlobalSettings>(), Mock.Of<IUmbracoContextAccessor>(), Mock.Of<ISqlContext>(), this.ServiceContext, AppCaches.NoCache, Mock.Of<IProfilingLogger>(), Mock.Of<IRuntimeState>(), base.UmbracoHelper, base.UmbracoMapper);
}
[Test]
public void WhenGetAllProducts_ThenReturnViewModelWithExpectedProducts()
{
var expected = new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
var result = this.controller.GetAllProducts();
Assert.AreEqual(expected, result);
}
[Test]
public void WhenGetAllProducts_ThenReturnViewModelWithExpectedJson()
{
var json = JsonConvert.SerializeObject(((JsonResult)this.controller.GetAllProductsJson()).Data);
Assert.AreEqual("[\"Table\",\"Chair\",\"Desk\",\"Computer\",\"Beer fridge\"]", json);
}
}
}