-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathHomeControllerTests.cs
129 lines (106 loc) · 6.05 KB
/
HomeControllerTests.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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.Web;
using Umbraco.Cms.Web.Common.Controllers;
using UmbracoNineDemoSite.Core.Features.Home;
using UmbracoNineDemoSite.Tests.Extensions;
namespace UmbracoNineDemoSite.Tests.Unit.Features.Home
{
[TestFixture]
public class HomeControllerTests
{
private HomeController controller;
private Mock<IPublishedContent> publishedContent;
[SetUp]
public void SetUp()
{
controller = new HomeController(Mock.Of<ILogger<RenderController>>(), Mock.Of<ICompositeViewEngine>(), Mock.Of<IUmbracoContextAccessor>());
publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(nameof(HomeViewModel.PageTitle).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.PageDescription).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.Preamble).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.BackgroundImage).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.Heading).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.CallToActionLabel).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.CallToActionUrl).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.SiteName).ToCamelCase(), string.Empty);
publishedContent.SetupPropertyValue(nameof(HomeViewModel.Blocks).ToCamelCase(), new BlockListModel(new List<BlockListItem>()));
}
[Test]
[TestCase("PageTitle")]
[TestCase("Other PageTitle")]
public void Given_PublishedContentHasHeading_When_HomeAction_Then_ReturnViewModelWithPageTitle(string pageTitle)
{
publishedContent.SetupPropertyValue(nameof(HomeViewModel.PageTitle).ToCamelCase(), pageTitle);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(pageTitle, viewModel.PageTitle);
}
[Test]
[TestCase("PageDescription")]
[TestCase("Other PageDescription")]
public void Given_PublishedContentHasHeading_When_HomeAction_Then_ReturnViewModelWithPageDescrition(string pageDescription)
{
publishedContent.SetupPropertyValue(nameof(HomeViewModel.PageDescription).ToCamelCase(), pageDescription);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(pageDescription, viewModel.PageDescription);
}
[Test]
[TestCase("Heading")]
[TestCase("Other heading")]
public void Given_PublishedContentHasHeading_When_HomeAction_Then_ReturnViewModelWithHeading(string heading)
{
publishedContent.SetupPropertyValue(nameof(HomeViewModel.Heading).ToCamelCase(), heading);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(heading, viewModel.Heading);
}
[Test]
[TestCase("Preamble")]
[TestCase("Other preamble")]
public void Given_PublishedContentHasPreamble_When_HomeAction_Then_ReturnViewModelWithPreamble(string preamble)
{
publishedContent.SetupPropertyValue(nameof(HomeViewModel.Preamble).ToCamelCase(), preamble);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(preamble, viewModel.Preamble);
}
[Test]
[TestCase("BackgroundImage")]
[TestCase("Other backgroundImage")]
public void Given_PublishedContentHasBackgroundImage_When_HomeAction_Then_ReturnViewModelWithBackgroundImage(string backgroundImage)
{
publishedContent.SetupPropertyValue(nameof(HomeViewModel.BackgroundImage).ToCamelCase(), backgroundImage);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(backgroundImage, viewModel.BackgroundImage);
}
[Test]
[TestCase("CallToActionLabel")]
[TestCase("Other CallToActionLabel")]
public void Given_PublishedContentHasCallToActionLabel_When_HomeAction_Then_ReturnViewModelWithCallToActionLabel(string callToActionLabel)
{
publishedContent.SetupPropertyValue(nameof(HomeViewModel.CallToActionLabel).ToCamelCase(), callToActionLabel);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(callToActionLabel, viewModel.CallToActionLabel);
}
[Test]
public void Given_PublishedContentHasBlocks_When_HomeAction_Then_ReturnViewModelWithBlocks()
{
var blockList = new BlockListModel(new List<BlockListItem>());
publishedContent.SetupPropertyValue(nameof(HomeViewModel.Blocks).ToCamelCase(), blockList);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(blockList, viewModel.Blocks);
}
}
}