-
Notifications
You must be signed in to change notification settings - Fork 29
/
PageControllerTests.cs
77 lines (66 loc) · 3.42 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
74
75
76
77
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;
private Mock<IPublishedContent> publishedContent;
[SetUp]
public void SetUp()
{
controller = new PageController(Mock.Of<ILogger<RenderController>>(), Mock.Of<ICompositeViewEngine>(), Mock.Of<IUmbracoContextAccessor>());
publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(nameof(PageViewModel.PageTitle).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(PageViewModel.PageDescription).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(PageViewModel.Heading).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(PageViewModel.BodyText).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(PageViewModel.SiteName).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(PageViewModel.Blocks).ToCamelCase(), new BlockListModel(new List<BlockListItem>()));
}
[Test]
[TestCase("Heading")]
[TestCase("Other heading")]
public void Given_PublishedContentHasHeading_When_PageAction_Then_ReturnViewModelWithHeading(string heading)
{
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);
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>());
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);
}
}
}