forked from Adolfi/UmbracoNineDemoSite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HomeControllerTests.cs
98 lines (81 loc) · 4.01 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
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.Core.Features.Shared.Constants;
using UmbracoNineDemoSite.Tests.Extensions;
namespace UmbracoNineDemoSite.Tests.Unit.Features.Home
{
[TestFixture]
public class HomeControllerTests
{
private HomeController controller;
[SetUp]
public void SetUp()
{
this.controller = new HomeController(Mock.Of<ILogger<RenderController>>(), Mock.Of<ICompositeViewEngine>(), Mock.Of<IUmbracoContextAccessor>());
}
[Test]
[TestCase("Heading")]
[TestCase("Other heading")]
public void Given_PublishedContentHasHeading_When_HomeAction_Then_ReturnViewModelWithHeading(string heading)
{
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.Heading, 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)
{
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.Preamble, 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)
{
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.BackgroundImage, 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)
{
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.CallToActionLabel, 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>());
var publishedContent = new Mock<IPublishedContent>();
publishedContent.SetupPropertyValue(PropertyAlias.Blocks, blockList);
var contentModel = new ContentModel(publishedContent.Object);
var viewModel = (HomeViewModel)((ViewResult)this.controller.Home(contentModel)).ViewData.Model;
Assert.AreEqual(blockList, viewModel.Blocks);
}
}
}