-
Notifications
You must be signed in to change notification settings - Fork 3
/
RenderMvcControllerTests.cs
63 lines (51 loc) · 2.15 KB
/
RenderMvcControllerTests.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using UmbracoUnitTesting.Core.Features.Home;
using UmbracoUnitTesting.Tests.Shared;
namespace UmbracoUnitTesting.Tests.RenderMvcController {
/// <inheritdoc />
/// <summary>
/// Documentation: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-rendermvccontroller
/// </summary>
[TestFixture]
public class RenderMvcControllerTests : UmbracoBaseTest {
private HomeController controller;
[SetUp]
public override void SetUp()
{
base.SetUp();
this.controller = new HomeController(Mock.Of<IGlobalSettings>(), Mock.Of<IUmbracoContextAccessor>(), base.ServiceContext, AppCaches.NoCache, Mock.Of<IProfilingLogger>(), base.UmbracoHelper);
}
[Test]
public void WhenIndexAction_ThenResultIsIsAssignableFromContentResult()
{
var model = new Umbraco.Web.Models.ContentModel(new Mock<IPublishedContent>().Object);
var result = this.controller.Index(model);
Assert.IsAssignableFrom<ViewResult>(result);
}
[Test]
public void GivenContentModel_WhenIndex_ThenReturnViewModelWithMyProperty()
{
var model = new Umbraco.Web.Models.ContentModel(new Mock<IPublishedContent>().Object);
var result = (HomeViewModel)((ViewResult)this.controller.Index(model)).Model;
Assert.AreEqual("Hello World", result.Heading);
}
[Test]
[TestCase("/")]
[TestCase("https://www.umbraco.com")]
public void GivenContentModelWithUrl_WhenIndex_ThenReturnViewModelWithUrl(string url)
{
var content = new Mock<IPublishedContent>();
content.Setup(x => x.Url).Returns(url);
var model = new Umbraco.Web.Models.ContentModel(content.Object);
var result = (HomeViewModel)((ViewResult)this.controller.Index(model)).Model;
Assert.AreEqual(url, result.Url);
}
}
}