-
Notifications
You must be signed in to change notification settings - Fork 29
/
SiteSettingsTests.cs
144 lines (117 loc) · 5.95 KB
/
SiteSettingsTests.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using Moq;
using NUnit.Framework;
using System.Collections.Generic;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Dictionary;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Templates;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common;
using Umbraco.Extensions;
using UmbracoNineDemoSite.Core.Features.Shared.Constants;
using UmbracoNineDemoSite.Core.Features.Shared.Settings;
using UmbracoNineDemoSite.Tests.Extensions;
using generatedModels = UmbracoNineDemoSite.Core;
namespace UmbracoNineDemoSite.Tests.Unit.Features.Shared.Settings
{
[TestFixture]
public class SiteSettingsTests
{
private delegate void ServiceTryGetUmbracoContext(out IUmbracoContext context);
private Mock<IPublishedContentCache> contentCache;
private Mock<generatedModels.SiteSettings> siteSettings;
private Mock<generatedModels.Home> homeContent;
private SiteSettings siteSettingsViewModel;
private Mock<IUmbracoContextAccessor> umbracoContextAccessor;
[SetUp]
public void SetUp()
{
var productsContainerContent = Mock.Of<IPublishedContent>();
var productsContainerFallback = Mock.Of<IPublishedValueFallback>();
homeContent = new Mock<generatedModels.Home>(
productsContainerContent, productsContainerFallback);
siteSettings = new Mock<generatedModels.SiteSettings>(
productsContainerContent, productsContainerFallback);
var contentType = new Mock<IPublishedContentType>();
contentType.Setup(s => s.Alias).Returns(generatedModels.SiteSettings.ModelTypeAlias);
siteSettings.Setup(s => s.ContentType).Returns(contentType.Object);
homeContent.Setup(s => s.Children)
.Returns(new IPublishedContent[] { siteSettings.Object });
contentCache = new Mock<IPublishedContentCache>();
contentCache.Setup(s => s.GetAtRoot(null))
.Returns(new IPublishedContent[] { homeContent.Object });
var umbracoContext = new Mock<IUmbracoContext>();
umbracoContext.Setup(s => s.Content)
.Returns(contentCache.Object);
IUmbracoContext ctx;
umbracoContextAccessor = new Mock<IUmbracoContextAccessor>();
umbracoContextAccessor
.Setup(x => x.TryGetUmbracoContext(out ctx))
.Callback(new ServiceTryGetUmbracoContext((out IUmbracoContext uContext) =>
{
uContext = umbracoContext.Object;
}));
}
[Test]
[TestCase("Site name")]
[TestCase("Umbraco 9 Demo")]
public void Given_HomeNodeExistsAtXPath_When_GetSiteName_Then_ReturnExpectedSiteNameFromHomeNode(string siteName)
{
homeContent.Setup(s => s.Name).Returns(siteName);
siteSettingsViewModel = new SiteSettings(umbracoContextAccessor.Object);
var result = this.siteSettingsViewModel.SiteName;
Assert.AreEqual(siteName, result);
}
[Test]
[TestCase("Call To Action Header")]
[TestCase("Welcome to the Umbraco 9 Demo")]
public void Given_SettingsNodeHasCallToActionHeader_When_GetCallToActionHeader_Then_ReturnExpectedCallToActionHeader(string callToActionHeader)
{
siteSettings.Setup(s => s.CallToActionHeader).Returns(callToActionHeader);
siteSettingsViewModel = new SiteSettings(umbracoContextAccessor.Object);
var result = this.siteSettingsViewModel.CallToActionHeader;
Assert.AreEqual(callToActionHeader, result);
}
[Test]
[TestCase("Call To Action Description")]
[TestCase("Description for the Umbraco 9 Demo")]
public void Given_SettingsNodeHasCallToActionDescription_When_GetCallToActionDescription_Then_ReturnExpectedCallToActionDescription(string callToActionDescription)
{
siteSettings.Setup(s => s.CallToActionDescription).Returns(callToActionDescription);
siteSettingsViewModel = new SiteSettings(umbracoContextAccessor.Object);
var result = this.siteSettingsViewModel.CallToActionDescription;
Assert.AreEqual(callToActionDescription, result);
}
[Test]
public void Given_SettingsNodeHasCallToActionUrl_When_GetCallToActionUrl_Then_ReturnExpectedCallToActionUrl()
{
var callToActionContentReference = Mock.Of<IPublishedContent>();
siteSettings.Setup(s => s.CallToActionUrl).Returns(callToActionContentReference);
siteSettingsViewModel = new SiteSettings(umbracoContextAccessor.Object);
var result = this.siteSettingsViewModel.CallToActionUrl;
Assert.AreEqual(callToActionContentReference, result);
}
[Test]
[TestCase("Call To Action Label")]
[TestCase("Label for the Umbraco 9 Demo")]
public void Given_SettingsNodeHasCallToActionButtonLabel_When_GetCallToActionButtonLabel_Then_ReturnExpectedCallToActionButtonLabel(string callToActionButtonLabel)
{
siteSettings.Setup(s => s.CallToActionButtonLabel).Returns(callToActionButtonLabel);
siteSettingsViewModel = new SiteSettings(umbracoContextAccessor.Object);
var result = this.siteSettingsViewModel.CallToActionButtonLabel;
Assert.AreEqual(callToActionButtonLabel, result);
}
[Test]
[TestCase("Footer Text")]
[TestCase("Footer Text for the Umbraco 9 Demo")]
public void Given_SettingsNodeHasFooterText_When_GetFooterText_Then_ReturnExpectedFooterText(string footerText)
{
siteSettings.Setup(s => s.FooterText).Returns(footerText);
siteSettingsViewModel = new SiteSettings(umbracoContextAccessor.Object);
var result = this.siteSettingsViewModel.FooterText;
Assert.AreEqual(footerText, result);
}
}
}