forked from Adolfi/UmbracoNineDemoSite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PageControllerTests.cs
73 lines (61 loc) · 2.79 KB
/
PageControllerTests.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
64
65
66
67
68
69
70
71
72
73
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using UmbracoNineDemoSite.Core.Features.Page;
using UmbracoNineDemoSite.Core.Features.Shared.Constants;
using UmbracoNineDemoSite.Tests.Extensions;
namespace UmbracoNineDemoSite.Tests.Unit.Features.Page
{
[TestFixture]
public class PageControllerTests
{
private PageController controller;
[SetUp]
public void SetUp()
{
this.controller = new PageController(Mock.Of<ILogger<RenderController>>(), Mock.Of<ICompositeViewEngine>(), Mock.Of<IUmbracoContextAccessor>());
}
[Test]
[TestCase("Heading")]
[TestCase("Other heading")]
public void Given_PublishedContentHasHeading_When_PageAction_Then_ReturnViewModelWithHeading(string heading)
{
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.Heading, heading);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (PageViewModel)((ViewResult)this.controller.Page(contentModel)).ViewData.Model;
Assert.AreEqual(heading, viewModel.Heading);
}
[Test]
[TestCase("BodyText")]
[TestCase("Other BodyText")]
public void Given_PublishedContentHasBodyText_When_PageAction_Then_ReturnViewModelWithBodyText(string bodyText)
{
var bodyTextEncodedHtml = new HtmlEncodedString(bodyText);
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.BodyText, bodyTextEncodedHtml);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (PageViewModel)((ViewResult)this.controller.Page(contentModel)).ViewData.Model;
Assert.AreEqual(bodyTextEncodedHtml, viewModel.BodyText);
}
[Test]
public void Given_PublishedContentHasBlocks_When_PageAction_Then_ReturnViewModelWithBlocks()
{
var blockList = new BlockListModel(new List<BlockListItem>());
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.Blocks, blockList);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (PageViewModel)((ViewResult)this.controller.Page(contentModel)).ViewData.Model;
Assert.AreEqual(blockList, viewModel.Blocks);
}
}
}