forked from Adolfi/UmbracoNineDemoSite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSiteSettingsTests.cs
125 lines (101 loc) · 5.34 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
using Moq;
using NUnit.Framework;
using System.Collections.Generic;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Dictionary;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Templates;
using Umbraco.Cms.Web.Common;
using UmbracoNineDemoSite.Core.Features.Shared.Constants;
using UmbracoNineDemoSite.Core.Features.Shared.Settings;
using UmbracoNineDemoSite.Tests.Extensions;
namespace UmbracoNineDemoSite.Tests.Unit.Features.Shared.Settings
{
[TestFixture]
public class SiteSettingsTests
{
private Mock<ICultureDictionaryFactory> cultureDictionaryFactory;
private Mock<IUmbracoComponentRenderer> componentRenderer;
private Mock<IPublishedContentQuery> publishedContentQuery;
private UmbracoHelper umbracoHelper;
private SiteSettings siteSettings;
[SetUp]
public void SetUp()
{
this.cultureDictionaryFactory = new Mock<ICultureDictionaryFactory>();
this.componentRenderer = new Mock<IUmbracoComponentRenderer>();
this.publishedContentQuery = new Mock<IPublishedContentQuery>();
this.umbracoHelper = new UmbracoHelper(this.cultureDictionaryFactory.Object, this.componentRenderer.Object, this.publishedContentQuery.Object);
this.siteSettings = new SiteSettings(this.umbracoHelper);
}
[Test]
[TestCase("Site name")]
[TestCase("Umbraco 9 Demo")]
public void Given_HomeNodeExistsAtXPath_When_GetSiteName_Then_ReturnExpectedSiteNameFromHomeNode(string siteName)
{
var homeNode = new Mock<IPublishedContent>();
homeNode.Setup(home => home.Name).Returns(siteName);
this.MockContentQueryXPAth($"//{ContentTypeAlias.Home}", homeNode.Object);
var result = this.siteSettings.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)
{
var settingsNode = new Mock<IPublishedContent>();
settingsNode.SetupPropertyValue(PropertyAlias.CallToActionHeader, callToActionHeader);
this.MockContentQueryXPAth($"//{ContentTypeAlias.SiteSettings}", settingsNode.Object);
var result = this.siteSettings.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)
{
var settingsNode = new Mock<IPublishedContent>();
settingsNode.SetupPropertyValue(PropertyAlias.CallToActionDescription, callToActionDescription);
this.MockContentQueryXPAth($"//{ContentTypeAlias.SiteSettings}", settingsNode.Object);
var result = this.siteSettings.CallToActionDescription;
Assert.AreEqual(callToActionDescription, result);
}
[Test]
public void Given_SettingsNodeHasCallToActionUrl_When_GetCallToActionUrl_Then_ReturnExpectedCallToActionUrl()
{
var callToActionContentReference = Mock.Of<IPublishedContent>();
var settingsNode = new Mock<IPublishedContent>();
settingsNode.SetupPropertyValue(PropertyAlias.CallToActionUrl, callToActionContentReference);
this.MockContentQueryXPAth($"//{ContentTypeAlias.SiteSettings}", settingsNode.Object);
var result = this.siteSettings.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)
{
var settingsNode = new Mock<IPublishedContent>();
settingsNode.SetupPropertyValue(PropertyAlias.CallToActionButtonLabel, callToActionButtonLabel);
this.MockContentQueryXPAth($"//{ContentTypeAlias.SiteSettings}", settingsNode.Object);
var result = this.siteSettings.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)
{
var settingsNode = new Mock<IPublishedContent>();
settingsNode.SetupPropertyValue(PropertyAlias.FooterText, footerText);
this.MockContentQueryXPAth($"//{ContentTypeAlias.SiteSettings}", settingsNode.Object);
var result = this.siteSettings.FooterText;
Assert.AreEqual(footerText, result);
}
private void MockContentQueryXPAth(string xpath, IPublishedContent content)
{
this.publishedContentQuery.Setup(query => query.ContentAtXPath(xpath)).Returns(new List<IPublishedContent>() { content });
}
}
}