├── .gitignore
├── README.md
├── UmbracoUnitTesting.Core
├── Features
│ ├── Hero
│ │ └── HeroController.cs
│ ├── Home
│ │ ├── HomeController.cs
│ │ └── HomeViewModel.cs
│ ├── Member
│ │ ├── MemberProfileController.cs
│ │ └── MemberProfileViewModel.cs
│ ├── Products
│ │ ├── ProductPageUrlSegmentProvider.cs
│ │ ├── ProductsController.cs
│ │ └── RegisterCustomSegmentProviderComposer.cs
│ └── StandardPage
│ │ └── StandardPageViewModel.cs
├── Properties
│ └── AssemblyInfo.cs
├── UmbracoUnitTesting.Core.csproj
├── app.config
└── packages.config
├── UmbracoUnitTesting.Tests
├── ContentModel
│ └── ContentModelTests.cs
├── MembershipHelper
│ └── MembershipHelperTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── RenderMvcController
│ └── RenderMvcControllerTests.cs
├── Routing
│ └── ProductPageUrlSegmentProviderTests.cs
├── Shared
│ └── UmbracoBaseTest.cs
├── SurfaceController
│ └── SurfaceControllerTests.cs
├── UmbracoApiController
│ └── UmbracoApiControllerTests.cs
├── UmbracoHelper
│ ├── CultureDictionaryTests.cs
│ └── PublishedContentQueryTests.cs
├── UmbracoUnitTesting.Tests.csproj
├── app.config
└── packages.config
└── UmbracoUnitTesting.sln
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | *.obj
3 | *.pdb
4 | *.user
5 | *.aps
6 | *.pch
7 | *.vspscc
8 | [Bb]in
9 | [Db]ebug*/
10 | obj/
11 | [Bb]in/[Rr]elease*/
12 | _ReSharper*/
13 | *.[Pp]ublish.xml
14 | *.suo
15 | [sS]ource
16 | [sS]andbox
17 | /packages/*
18 | UmbracoUnitTesting.Umbraco/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unit Testing Umbraco version 8.x
2 | All example tests from the official Umbraco Documentation section on Unit Testing: https://our.umbraco.com/documentation/Implementation/Unit-Testing/
3 |
4 | ## Tests included:
5 | Some tests have been renamed or improved compared to the official documentation, mostly to be able to reuse models and controllers and reudece the size of each project.
6 | Every class in this solution has a summary with a link to the official documentation so any renaming should not be a problem.
7 |
8 | - [Mocking Umbraco](UmbracoUnitTesting.Tests/Shared/UmbracoBaseTest.cs)
9 | - [Testing ContentModels](UmbracoUnitTesting.Tests/ContentModel/ContentModelTests.cs)
10 | - [Testing RenderMvcControllers](UmbracoUnitTesting.Tests/RenderMvcController/RenderMvcControllerTests.cs)
11 | - [Testing SurfaceControllers](UmbracoUnitTesting.Tests/SurfaceController/SurfaceControllerTests.cs)
12 | - [Testing UmbracoApiControllers](UmbracoUnitTesting.Tests/UmbracoApiController/UmbracoApiControllerTests.cs)
13 | - [Testing UrlSegmentProviders](UmbracoUnitTesting.Tests/Routing/ProductPageUrlSegmentProviderTests.cs)
14 | - [Testing MembershipHelper](UmbracoUnitTesting.Tests/MembershipHelper/MembershipHelperTests.cs)
15 | - [Testing CultureDictionary using the UmbracoHelper](UmbracoUnitTesting.Tests/UmbracoHelper/CultureDictionaryTests.cs)
16 | - [Testing PublishedContentQuery using the UmbracoHelper](UmbracoUnitTesting.Tests/UmbracoHelper/PublishedContentQueryTests.cs)
17 |
18 | ## How to use this project:
19 | This solution contains two projects: A **.Core** project and a **.Tests** project. You'll notice that this solution does not contain any Umbraco website.
20 | This is intentional. Do not use this solution as a template or a base project. Use it as a reference and a source for inspiration to your own projects.
21 | Only the necessary assemblies to run each test have been installed such as:
22 | - UmbracoCms.Core
23 | - UmbracoCms.Web
24 | - NUnit
25 | - Moq
26 |
27 | ## Read more
28 | Go to [adolfi.dev](https://adolfi.dev) if you want to read more Umbraco and Unit Testing articles.
29 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Hero/HeroController.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Umbraco.Core.Cache;
3 | using Umbraco.Core.Logging;
4 | using Umbraco.Core.Persistence;
5 | using Umbraco.Core.Services;
6 | using Umbraco.Web;
7 | using Umbraco.Web.Mvc;
8 |
9 | namespace UmbracoUnitTesting.Core.Features.Hero {
10 | ///
11 | ///
12 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-surfacecontroller
13 | ///
14 | public class HeroController : SurfaceController {
15 | public HeroController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory umbracoDatabaseFactory, ServiceContext serviceContext, AppCaches appCaches, ILogger logger, IProfilingLogger profilingLogger, UmbracoHelper umbracoHelper) : base(umbracoContextAccessor, umbracoDatabaseFactory, serviceContext, appCaches, logger, profilingLogger, umbracoHelper) { }
16 |
17 | public ActionResult Index()
18 | {
19 | return Content("Hello World");
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Home/HomeController.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Umbraco.Core.Cache;
3 | using Umbraco.Core.Configuration;
4 | using Umbraco.Core.Logging;
5 | using Umbraco.Core.Services;
6 | using Umbraco.Web;
7 | using Umbraco.Web.Models;
8 | using Umbraco.Web.Mvc;
9 |
10 | namespace UmbracoUnitTesting.Core.Features.Home {
11 | ///
12 | ///
13 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-contentmodel
14 | /// Also: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-iculturedictionary-using-the-umbracohelper
15 | ///
16 | public class HomeController : RenderMvcController
17 | {
18 | public HomeController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext serviceContext, AppCaches appCaches, IProfilingLogger profilingLogger, UmbracoHelper umbracoHelper) : base(globalSettings, umbracoContextAccessor, serviceContext, appCaches, profilingLogger, umbracoHelper) { }
19 |
20 | public override ActionResult Index(ContentModel model)
21 | {
22 | var viewModel = new HomeViewModel(model.Content)
23 | {
24 | Heading = "Hello World",
25 | DictionaryTitle = this.Umbraco.GetDictionaryValue("myDictionaryKey"),
26 | Url = model.Content.Url
27 | };
28 |
29 | return View(viewModel);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Home/HomeViewModel.cs:
--------------------------------------------------------------------------------
1 | using Umbraco.Core.Models.PublishedContent;
2 | using Umbraco.Web.Models;
3 |
4 | namespace UmbracoUnitTesting.Core.Features.Home {
5 | ///
6 | ///
7 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-contentmodel
8 | ///
9 | public class HomeViewModel : ContentModel
10 | {
11 | public HomeViewModel(IPublishedContent content) : base(content){}
12 |
13 | public string Heading { get; set; }
14 | public string DictionaryTitle { get; set; }
15 | public string Url { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Member/MemberProfileController.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Umbraco.Core.Cache;
3 | using Umbraco.Core.Configuration;
4 | using Umbraco.Core.Logging;
5 | using Umbraco.Core.Services;
6 | using Umbraco.Web;
7 | using Umbraco.Web.Models;
8 | using Umbraco.Web.Mvc;
9 |
10 | namespace UmbracoUnitTesting.Core.Features.Member {
11 | ///
12 | ///
13 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-getcurrentmember-using-the-membershiphelper
14 | /// Also: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-ipublishedcontentquery-using-the-umbracohelper
15 | ///
16 | public class MemberProfileController : RenderMvcController {
17 | public MemberProfileController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext serviceContext, AppCaches appCaches, IProfilingLogger profilingLogger, UmbracoHelper umbracoHelper) : base(globalSettings, umbracoContextAccessor, serviceContext, appCaches, profilingLogger, umbracoHelper) { }
18 |
19 | public override ActionResult Index(ContentModel model)
20 | {
21 | var viewModel = new MemberProfileViewModel(model.Content)
22 | {
23 | Member = this.Umbraco.MembershipHelper.GetCurrentMember(), // TODO: Since writing this the UmbracoHelper.MembershipHelper is now obsolete and should instead inject MembershipHelper in the constructor. Keep this until documentation has been updated.
24 | OtherContent = this.Umbraco.Content(1062),
25 | ContentAtRoot = this.Umbraco.ContentAtRoot()
26 | };
27 | return View(viewModel);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Member/MemberProfileViewModel.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Umbraco.Core.Models.PublishedContent;
3 | using Umbraco.Web.Models;
4 |
5 | namespace UmbracoUnitTesting.Core.Features.Member {
6 | ///
7 | ///
8 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-getcurrentmember-using-the-membershiphelper
9 | /// Also: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-ipublishedcontentquery-using-the-umbracohelper
10 | ///
11 | public class MemberProfileViewModel : ContentModel {
12 | public MemberProfileViewModel(IPublishedContent content) : base(content) { }
13 | public IPublishedContent Member { get; set; }
14 | public IPublishedContent OtherContent { get; set; }
15 | public IEnumerable ContentAtRoot { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Products/ProductPageUrlSegmentProvider.cs:
--------------------------------------------------------------------------------
1 | using Umbraco.Core.Models;
2 | using Umbraco.Core.Strings;
3 |
4 | namespace UmbracoUnitTesting.Core.Features.Products {
5 | ///
6 | ///
7 | /// Docs: https://our.umbraco.com/documentation/reference/routing/request-pipeline/outbound-pipeline#1--create-segments
8 | ///
9 | public class ProductPageUrlSegmentProvider : IUrlSegmentProvider {
10 | private readonly IUrlSegmentProvider provider;
11 |
12 | public ProductPageUrlSegmentProvider(IUrlSegmentProvider urlSegmentProvider){
13 | provider = urlSegmentProvider;
14 | }
15 |
16 | public string GetUrlSegment(IContentBase content, string culture = null)
17 | {
18 | if (content.ContentType.Alias != "productPage") return null;
19 | var segment = provider.GetUrlSegment(content, culture);
20 | var productSku = content.GetValue(propertyTypeAlias: "productSku", culture: culture, segment: null, published: true);
21 | return string.Format("{0}-{1}", segment, productSku);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Products/ProductsController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Web.Mvc;
3 | using Umbraco.Core;
4 | using Umbraco.Core.Cache;
5 | using Umbraco.Core.Configuration;
6 | using Umbraco.Core.Logging;
7 | using Umbraco.Core.Mapping;
8 | using Umbraco.Core.Persistence;
9 | using Umbraco.Core.Services;
10 | using Umbraco.Web;
11 | using Umbraco.Web.WebApi;
12 |
13 | namespace UmbracoUnitTesting.Core.Features.Products {
14 | ///
15 | ///
16 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-an-umbracoapicontroller
17 | ///
18 | public class ProductsController : UmbracoApiController
19 | {
20 | public ProductsController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext serviceContext, AppCaches appCaches, IProfilingLogger profilingLogger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper) : base(globalSettings, umbracoContextAccessor, sqlContext, serviceContext, appCaches, profilingLogger, runtimeState, umbracoHelper, umbracoMapper) { }
21 |
22 | public IEnumerable GetAllProducts()
23 | {
24 | return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
25 | }
26 |
27 | [HttpGet]
28 | public JsonResult GetAllProductsJson()
29 | {
30 | return new JsonResult
31 | {
32 | Data = this.GetAllProducts(),
33 | JsonRequestBehavior = JsonRequestBehavior.AllowGet,
34 | };
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/Products/RegisterCustomSegmentProviderComposer.cs:
--------------------------------------------------------------------------------
1 | using Umbraco.Core;
2 | using Umbraco.Core.Composing;
3 | using Umbraco.Core.Strings;
4 |
5 | namespace UmbracoUnitTesting.Core.Features.Products {
6 | //
7 | //
8 | // Docs: https://our.umbraco.com/documentation/reference/routing/request-pipeline/outbound-pipeline#example
9 | //
10 | public class RegisterCustomSegmentProviderComposer : IUserComposer {
11 | public void Compose(Composition composition)
12 | {
13 | composition.Register();
14 | composition.UrlSegmentProviders().Insert();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Features/StandardPage/StandardPageViewModel.cs:
--------------------------------------------------------------------------------
1 | using Umbraco.Core.Models.PublishedContent;
2 | using Umbraco.Web;
3 | using Umbraco.Web.Models;
4 |
5 | namespace UmbracoUnitTesting.Core.Features.StandardPage {
6 | ///
7 | ///
8 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-contentmodel
9 | ///
10 | public class StandardPageViewModel : ContentModel
11 | {
12 | public StandardPageViewModel(IPublishedContent content) : base(content){}
13 |
14 | public string Heading => this.Content.Value(nameof(Heading));
15 | public string Url => this.Content.Url;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UmbracoUnitTesting.Core")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UmbracoUnitTesting.Core")]
13 | [assembly: AssemblyCopyright("Copyright © 2021")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ffd31510-57eb-4258-af8c-eceaf4b2f79c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/UmbracoUnitTesting.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Debug
7 | AnyCPU
8 | {FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}
9 | Library
10 | Properties
11 | UmbracoUnitTesting.Core
12 | UmbracoUnitTesting.Core
13 | v4.7.2
14 | 512
15 | true
16 |
17 |
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 | ..\packages\AngleSharp.0.9.11\lib\net45\AngleSharp.dll
39 |
40 |
41 | ..\packages\ClientDependency.1.9.9\lib\net45\ClientDependency.Core.dll
42 |
43 |
44 | ..\packages\ClientDependency-Mvc5.1.9.3\lib\net45\ClientDependency.Core.Mvc.dll
45 |
46 |
47 | ..\packages\CSharpTest.Net.Collections.14.906.1403.1082\lib\net40\CSharpTest.Net.Collections.dll
48 |
49 |
50 | ..\packages\Examine.1.0.2\lib\net452\Examine.dll
51 |
52 |
53 | ..\packages\HtmlAgilityPack.1.8.14\lib\Net45\HtmlAgilityPack.dll
54 |
55 |
56 | ..\packages\HtmlSanitizer.4.0.217\lib\net45\HtmlSanitizer.dll
57 |
58 |
59 | ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll
60 |
61 |
62 | ..\packages\ImageProcessor.2.7.0.100\lib\net452\ImageProcessor.dll
63 |
64 |
65 | ..\packages\LightInject.5.4.0\lib\net46\LightInject.dll
66 |
67 |
68 | ..\packages\LightInject.Annotation.1.1.0\lib\net46\LightInject.Annotation.dll
69 |
70 |
71 | ..\packages\LightInject.Mvc.2.0.0\lib\net46\LightInject.Mvc.dll
72 |
73 |
74 | ..\packages\LightInject.Web.2.0.0\lib\net46\LightInject.Web.dll
75 |
76 |
77 | ..\packages\LightInject.WebApi.2.0.0\lib\net46\LightInject.WebApi.dll
78 |
79 |
80 | ..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll
81 |
82 |
83 | ..\packages\Markdown.2.2.1\lib\net451\Markdown.dll
84 |
85 |
86 | ..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll
87 |
88 |
89 | ..\packages\Microsoft.AspNet.Identity.Owin.2.2.2\lib\net45\Microsoft.AspNet.Identity.Owin.dll
90 |
91 |
92 | ..\packages\Microsoft.AspNet.SignalR.Core.2.4.0\lib\net45\Microsoft.AspNet.SignalR.Core.dll
93 |
94 |
95 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
96 |
97 |
98 | ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll
99 |
100 |
101 | ..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll
102 |
103 |
104 | ..\packages\Microsoft.Owin.Host.SystemWeb.4.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
105 |
106 |
107 | ..\packages\Microsoft.Owin.Security.4.0.1\lib\net45\Microsoft.Owin.Security.dll
108 |
109 |
110 | ..\packages\Microsoft.Owin.Security.Cookies.4.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll
111 |
112 |
113 | ..\packages\Microsoft.Owin.Security.OAuth.4.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll
114 |
115 |
116 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
117 |
118 |
119 | ..\packages\MiniProfiler.4.0.138\lib\net461\MiniProfiler.dll
120 |
121 |
122 | ..\packages\MiniProfiler.Shared.4.0.138\lib\net461\MiniProfiler.Shared.dll
123 |
124 |
125 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll
126 |
127 |
128 | ..\packages\NPoco.3.9.4\lib\net45\NPoco.dll
129 |
130 |
131 | ..\packages\Owin.1.0\lib\net40\Owin.dll
132 |
133 |
134 | ..\packages\Semver.2.0.4\lib\net452\Semver.dll
135 |
136 |
137 | ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll
138 |
139 |
140 | ..\packages\Serilog.Enrichers.Process.2.0.1\lib\net45\Serilog.Enrichers.Process.dll
141 |
142 |
143 | ..\packages\Serilog.Enrichers.Thread.3.0.0\lib\net45\Serilog.Enrichers.Thread.dll
144 |
145 |
146 | ..\packages\Serilog.Filters.Expressions.2.0.0\lib\net45\Serilog.Filters.Expressions.dll
147 |
148 |
149 | ..\packages\Serilog.Formatting.Compact.1.0.0\lib\net45\Serilog.Formatting.Compact.dll
150 |
151 |
152 | ..\packages\Serilog.Formatting.Compact.Reader.1.0.3\lib\net45\Serilog.Formatting.Compact.Reader.dll
153 |
154 |
155 | ..\packages\Serilog.Settings.AppSettings.2.2.2\lib\net45\Serilog.Settings.AppSettings.dll
156 |
157 |
158 | ..\packages\Serilog.Sinks.Async.1.3.0\lib\net45\Serilog.Sinks.Async.dll
159 |
160 |
161 | ..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll
162 |
163 |
164 | ..\packages\Serilog.Sinks.Map.1.0.0\lib\netstandard2.0\Serilog.Sinks.Map.dll
165 |
166 |
167 | ..\packages\Superpower.2.0.0\lib\net45\Superpower.dll
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 | ..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.dll
176 |
177 |
178 | ..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.Entity.dll
179 |
180 |
181 | ..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll
182 |
183 |
184 |
185 |
186 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 | ..\packages\System.Threading.Tasks.Dataflow.4.9.0\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll
195 |
196 |
197 |
198 | ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
199 |
200 |
201 |
202 |
203 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll
204 |
205 |
206 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll
207 |
208 |
209 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll
210 |
211 |
212 | ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll
213 |
214 |
215 | ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll
216 |
217 |
218 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll
219 |
220 |
221 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll
222 |
223 |
224 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 | ..\packages\UmbracoCms.Core.8.10.1\lib\net472\Umbraco.Core.dll
234 |
235 |
236 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.Examine.dll
237 |
238 |
239 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.ModelsBuilder.Embedded.dll
240 |
241 |
242 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.Web.dll
243 |
244 |
245 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.Web.UI.dll
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
269 |
270 |
271 |
272 |
273 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/app.config:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Core/packages.config:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/ContentModel/ContentModelTests.cs:
--------------------------------------------------------------------------------
1 | using Moq;
2 | using NUnit.Framework;
3 | using Umbraco.Core.Models.PublishedContent;
4 | using UmbracoUnitTesting.Core.Features.Home;
5 | using UmbracoUnitTesting.Core.Features.StandardPage;
6 | using UmbracoUnitTesting.Tests.Shared;
7 |
8 | namespace UmbracoUnitTesting.Tests.ContentModel {
9 | ///
10 | ///
11 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-contentmodel
12 | ///
13 | [TestFixture]
14 | public class ContentModelTests : UmbracoBaseTest
15 | {
16 | [SetUp]
17 | public override void SetUp()
18 | {
19 | base.SetUp();
20 | }
21 |
22 | [Test]
23 | [TestCase("", "")]
24 | [TestCase("My Heading", "My Heading")]
25 | [TestCase("Another Heading", "Another Heading")]
26 | public void GivenPublishedContent_WhenGetHeading_ThenReturnCustomViewModelWithHeadingValue(string value, string expected)
27 | {
28 | var publishedContent = new Mock();
29 | base.SetupPropertyValue(publishedContent, nameof(StandardPageViewModel.Heading), value);
30 |
31 | var model = new StandardPageViewModel(publishedContent.Object);
32 |
33 | Assert.AreEqual(expected, model.Heading);
34 | }
35 |
36 | [Test]
37 | [TestCase("/", "/")]
38 | [TestCase("/umbraco", "/umbraco")]
39 | [TestCase("https://www.umbraco.com", "https://www.umbraco.com")]
40 | public void GivenPublishedContent_WhenGetUrl_ThenReturnCustomViewModelWithUrl(string url, string expected)
41 | {
42 | var content = new Mock();
43 | content.Setup(x => x.Url).Returns(url);
44 |
45 | var model = new StandardPageViewModel(content.Object);
46 |
47 | Assert.AreEqual(expected, model.Url);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/MembershipHelper/MembershipHelperTests.cs:
--------------------------------------------------------------------------------
1 | using System.Security.Principal;
2 | using System.Threading;
3 | using System.Web.Mvc;
4 | using Moq;
5 | using NUnit.Framework;
6 | using Umbraco.Core.Cache;
7 | using Umbraco.Core.Configuration;
8 | using Umbraco.Core.Logging;
9 | using Umbraco.Core.Models;
10 | using Umbraco.Core.Models.PublishedContent;
11 | using Umbraco.Web;
12 | using UmbracoUnitTesting.Core.Features.Member;
13 | using UmbracoUnitTesting.Tests.Shared;
14 |
15 | namespace UmbracoUnitTesting.Tests.MembershipHelper
16 | {
17 | ///
18 | ///
19 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-getcurrentmember-using-the-membershiphelper
20 | ///
21 | [TestFixture]
22 | public class MembershipHelperTests : UmbracoBaseTest
23 | {
24 | private MemberProfileController controller;
25 |
26 | [SetUp]
27 | public override void SetUp()
28 | {
29 | base.SetUp();
30 | this.controller = new MemberProfileController(Mock.Of(), Mock.Of(), base.ServiceContext, AppCaches.NoCache, Mock.Of(), base.UmbracoHelper);
31 | }
32 |
33 | [Test]
34 | [TestCase("member1")]
35 | [TestCase("member2")]
36 | public void GivenExistingMemberIsAuthenticated_WhenIndexAction_ThenReturnViewModelWithCurrentMember(string username)
37 | {
38 | var member = new Mock();
39 | member.Setup(x => x.Username).Returns(username);
40 | base.memberService.Setup(x => x.GetByUsername(username)).Returns(member.Object);
41 |
42 | var expected = Mock.Of();
43 | base.memberCache.Setup(x => x.GetByMember(member.Object)).Returns(expected);
44 |
45 | var identity = new Mock();
46 | identity.Setup(user => user.IsAuthenticated).Returns(true);
47 | identity.Setup(user => user.Name).Returns(username);
48 |
49 | var principal = new Mock();
50 | principal.Setup(user => user.Identity).Returns(identity.Object);
51 |
52 | this.HttpContext.Setup(ctx => ctx.User).Returns(principal.Object);
53 | Thread.CurrentPrincipal = principal.Object;
54 |
55 | var actual = (MemberProfileViewModel) ((ViewResult) this.controller.Index(new Umbraco.Web.Models.ContentModel(Mock.Of()))).Model;
56 |
57 | Assert.AreEqual(expected, actual.Member);
58 | }
59 |
60 | [Test]
61 | [TestCase("member1")]
62 | [TestCase("member2")]
63 | public void GivenExistingMemberIsNotAuthenticated_WhenIndexAction_ThenReturnViewModelWithNullMember(string username)
64 | {
65 | var member = new Mock();
66 | member.Setup(x => x.Username).Returns(username);
67 | base.memberService.Setup(x => x.GetByUsername(username)).Returns(member.Object);
68 | base.memberCache.Setup(x => x.GetByMember(member.Object)).Returns(Mock.Of());
69 |
70 | var actual = (MemberProfileViewModel)((ViewResult)this.controller.Index(new Umbraco.Web.Models.ContentModel(Mock.Of()))).Model;
71 |
72 | Assert.Null(actual.Member);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UmbracoUnitTesting.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UmbracoUnitTesting.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2021")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("37ac7380-12e9-40eb-8e06-450624cd511f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/RenderMvcController/RenderMvcControllerTests.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Moq;
3 | using NUnit.Framework;
4 | using Umbraco.Core.Cache;
5 | using Umbraco.Core.Configuration;
6 | using Umbraco.Core.Logging;
7 | using Umbraco.Core.Models.PublishedContent;
8 | using Umbraco.Web;
9 | using UmbracoUnitTesting.Core.Features.Home;
10 | using UmbracoUnitTesting.Tests.Shared;
11 |
12 | namespace UmbracoUnitTesting.Tests.RenderMvcController {
13 | ///
14 | ///
15 | /// Documentation: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-rendermvccontroller
16 | ///
17 | [TestFixture]
18 | public class RenderMvcControllerTests : UmbracoBaseTest {
19 | private HomeController controller;
20 |
21 | [SetUp]
22 | public override void SetUp()
23 | {
24 | base.SetUp();
25 | this.controller = new HomeController(Mock.Of(), Mock.Of(), base.ServiceContext, AppCaches.NoCache, Mock.Of(), base.UmbracoHelper);
26 | }
27 |
28 | [Test]
29 | public void WhenIndexAction_ThenResultIsIsAssignableFromContentResult()
30 | {
31 | var model = new Umbraco.Web.Models.ContentModel(new Mock().Object);
32 |
33 | var result = this.controller.Index(model);
34 |
35 | Assert.IsAssignableFrom(result);
36 | }
37 |
38 | [Test]
39 | public void GivenContentModel_WhenIndex_ThenReturnViewModelWithMyProperty()
40 | {
41 | var model = new Umbraco.Web.Models.ContentModel(new Mock().Object);
42 |
43 | var result = (HomeViewModel)((ViewResult)this.controller.Index(model)).Model;
44 |
45 | Assert.AreEqual("Hello World", result.Heading);
46 | }
47 |
48 | [Test]
49 | [TestCase("/")]
50 | [TestCase("https://www.umbraco.com")]
51 | public void GivenContentModelWithUrl_WhenIndex_ThenReturnViewModelWithUrl(string url)
52 | {
53 | var content = new Mock();
54 | content.Setup(x => x.Url).Returns(url);
55 |
56 | var model = new Umbraco.Web.Models.ContentModel(content.Object);
57 |
58 | var result = (HomeViewModel)((ViewResult)this.controller.Index(model)).Model;
59 |
60 | Assert.AreEqual(url, result.Url);
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/Routing/ProductPageUrlSegmentProviderTests.cs:
--------------------------------------------------------------------------------
1 | using Moq;
2 | using NUnit.Framework;
3 | using Umbraco.Core.Models;
4 | using Umbraco.Core.Strings;
5 | using UmbracoUnitTesting.Core.Features.Products;
6 |
7 | namespace UmbracoUnitTesting.Tests.Routing {
8 | ///
9 | /// Docs: https://our.umbraco.com/documentation/reference/routing/request-pipeline/outbound-pipeline#1--create-segments
10 | ///
11 | public class ProductPageUrlSegmentProviderTests {
12 | private Mock defaultUrlSegmentProvider;
13 | private ProductPageUrlSegmentProvider productPageUrlSegmentProvider;
14 |
15 | [SetUp]
16 | public void SetUp()
17 | {
18 | this.defaultUrlSegmentProvider = new Mock();
19 | this.productPageUrlSegmentProvider = new ProductPageUrlSegmentProvider(defaultUrlSegmentProvider.Object);
20 | }
21 |
22 | [Test]
23 | [TestCase("en", "swibble", "123xyz", "swibble-123xyz")]
24 | [TestCase("en-US", "dibble", "456abc", "dibble-456abc")]
25 | public void Given_ProductHasSku_When_GetUrlSegment_Then_ReturnExpectedUrlSegment(string culture, string defaultUrlSegment, string productSku, string expected)
26 | {
27 | // Arrange
28 | var contentType = new Mock();
29 | contentType.Setup(x => x.Alias).Returns("productPage");
30 |
31 | var content = new Mock();
32 | content.Setup(x => x.ContentType).Returns(contentType.Object);
33 | content.Setup(x => x.GetValue("productSku", culture, null, true)).Returns(productSku);
34 |
35 | defaultUrlSegmentProvider.Setup(x => x.GetUrlSegment(content.Object, culture)).Returns(defaultUrlSegment);
36 |
37 | // Act
38 | var result = productPageUrlSegmentProvider.GetUrlSegment(content.Object, culture);
39 |
40 | // Assert
41 | Assert.AreEqual(expected, result);
42 | }
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/Shared/UmbracoBaseTest.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Web;
3 | using System.Web.Security;
4 | using Moq;
5 | using NUnit.Framework;
6 | using Umbraco.Core.Cache;
7 | using Umbraco.Core.Dictionary;
8 | using Umbraco.Core.Logging;
9 | using Umbraco.Core.Mapping;
10 | using Umbraco.Core.Models.PublishedContent;
11 | using Umbraco.Core.Services;
12 | using Umbraco.Web;
13 | using Umbraco.Web.PublishedCache;
14 | using Umbraco.Web.Security;
15 | using Umbraco.Web.Security.Providers;
16 |
17 | namespace UmbracoUnitTesting.Tests.Shared {
18 | ///
19 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#mocking
20 | ///
21 | public abstract class UmbracoBaseTest
22 | {
23 | public ServiceContext ServiceContext;
24 | public Umbraco.Web.Security.MembershipHelper MembershipHelper;
25 | public Umbraco.Web.UmbracoHelper UmbracoHelper;
26 | public UmbracoMapper UmbracoMapper;
27 |
28 | public Mock CultureDictionary;
29 | public Mock CultureDictionaryFactory;
30 | public Mock PublishedContentQuery;
31 |
32 | public Mock HttpContext;
33 | public Mock memberService;
34 | public Mock memberCache;
35 |
36 | [SetUp]
37 | public virtual void SetUp()
38 | {
39 | this.SetupHttpContext();
40 | this.SetupCultureDictionaries();
41 | this.SetupPublishedContentQuerying();
42 | this.SetupMembership();
43 |
44 | this.ServiceContext = ServiceContext.CreatePartial();
45 | this.UmbracoHelper = new Umbraco.Web.UmbracoHelper(Mock.Of(), Mock.Of(), this.CultureDictionaryFactory.Object, Mock.Of(), this.PublishedContentQuery.Object, this.MembershipHelper);
46 | this.UmbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new List()));
47 | }
48 |
49 | public virtual void SetupHttpContext()
50 | {
51 | this.HttpContext = new Mock();
52 | }
53 |
54 | public virtual void SetupCultureDictionaries()
55 | {
56 | this.CultureDictionary = new Mock();
57 | this.CultureDictionaryFactory = new Mock();
58 | this.CultureDictionaryFactory.Setup(x => x.CreateDictionary()).Returns(this.CultureDictionary.Object);
59 | }
60 |
61 | public virtual void SetupPublishedContentQuerying()
62 | {
63 | this.PublishedContentQuery = new Mock();
64 | }
65 |
66 | public virtual void SetupMembership()
67 | {
68 | this.memberService = new Mock();
69 | var memberTypeService = Mock.Of();
70 | var membershipProvider = new MembersMembershipProvider(memberService.Object, memberTypeService);
71 |
72 | this.memberCache = new Mock();
73 | this.MembershipHelper = new Umbraco.Web.Security.MembershipHelper(this.HttpContext.Object, this.memberCache.Object, membershipProvider, Mock.Of(), memberService.Object, memberTypeService, Mock.Of(), Mock.Of(), AppCaches.NoCache, Mock.Of());
74 | }
75 |
76 | public void SetupPropertyValue(Mock publishedContentMock, string alias, object value, string culture = null, string segment = null)
77 | {
78 | var property = new Mock();
79 | property.Setup(x => x.Alias).Returns(alias);
80 | property.Setup(x => x.GetValue(culture, segment)).Returns(value);
81 | property.Setup(x => x.HasValue(culture, segment)).Returns(value != null);
82 | publishedContentMock.Setup(x => x.GetProperty(alias)).Returns(property.Object);
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/SurfaceController/SurfaceControllerTests.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Moq;
3 | using NUnit.Framework;
4 | using Umbraco.Core.Cache;
5 | using Umbraco.Core.Logging;
6 | using Umbraco.Core.Persistence;
7 | using Umbraco.Web;
8 | using UmbracoUnitTesting.Core.Features.Hero;
9 | using UmbracoUnitTesting.Tests.Shared;
10 |
11 | namespace UmbracoUnitTesting.Tests.SurfaceController {
12 | ///
13 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-a-surfacecontroller
14 | ///
15 | public class SurfaceControllerTests {
16 | [TestFixture]
17 | public class MySurfaceControllerTests : UmbracoBaseTest {
18 | private HeroController controller;
19 |
20 | [SetUp]
21 | public override void SetUp()
22 | {
23 | base.SetUp();
24 | this.controller = new HeroController(Mock.Of(), Mock.Of(), base.ServiceContext, AppCaches.NoCache, Mock.Of(), Mock.Of(), base.UmbracoHelper);
25 | }
26 |
27 | [Test]
28 | public void WhenIndexAction_ThenResultIsIsAssignableFromContentResult()
29 | {
30 | var result = this.controller.Index();
31 |
32 | Assert.IsAssignableFrom(result);
33 | }
34 |
35 | [Test]
36 | public void GivenResultIsAssignableFromContentResult_WhenIndexAction_ThenContentIsExpected()
37 | {
38 | var result = (ContentResult)this.controller.Index();
39 |
40 | Assert.AreEqual("Hello World", result.Content);
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/UmbracoApiController/UmbracoApiControllerTests.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Moq;
3 | using Newtonsoft.Json;
4 | using NUnit.Framework;
5 | using Umbraco.Core;
6 | using Umbraco.Core.Cache;
7 | using Umbraco.Core.Configuration;
8 | using Umbraco.Core.Logging;
9 | using Umbraco.Core.Persistence;
10 | using Umbraco.Web;
11 | using UmbracoUnitTesting.Core.Features.Products;
12 | using UmbracoUnitTesting.Tests.Shared;
13 |
14 | namespace UmbracoUnitTesting.Tests.UmbracoApiController {
15 | ///
16 | ///
17 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-an-umbracoapicontroller
18 | ///
19 | [TestFixture]
20 | public class UmbracoApiControllerTests : UmbracoBaseTest
21 | {
22 | private ProductsController controller;
23 |
24 | [SetUp]
25 | public override void SetUp()
26 | {
27 | base.SetUp();
28 | this.controller = new ProductsController(Mock.Of(), Mock.Of(), Mock.Of(), this.ServiceContext, AppCaches.NoCache, Mock.Of(), Mock.Of(), base.UmbracoHelper, base.UmbracoMapper);
29 | }
30 |
31 | [Test]
32 | public void WhenGetAllProducts_ThenReturnViewModelWithExpectedProducts()
33 | {
34 | var expected = new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
35 |
36 | var result = this.controller.GetAllProducts();
37 |
38 | Assert.AreEqual(expected, result);
39 | }
40 |
41 | [Test]
42 | public void WhenGetAllProducts_ThenReturnViewModelWithExpectedJson()
43 | {
44 | var json = JsonConvert.SerializeObject(((JsonResult)this.controller.GetAllProductsJson()).Data);
45 |
46 | Assert.AreEqual("[\"Table\",\"Chair\",\"Desk\",\"Computer\",\"Beer fridge\"]", json);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/UmbracoHelper/CultureDictionaryTests.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 | using Moq;
3 | using NUnit.Framework;
4 | using Umbraco.Core.Cache;
5 | using Umbraco.Core.Configuration;
6 | using Umbraco.Core.Dictionary;
7 | using Umbraco.Core.Logging;
8 | using Umbraco.Core.Models.PublishedContent;
9 | using Umbraco.Web;
10 | using UmbracoUnitTesting.Core.Features.Home;
11 | using UmbracoUnitTesting.Tests.Shared;
12 |
13 | namespace UmbracoUnitTesting.Tests.UmbracoHelper {
14 | ///
15 | ///
16 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-iculturedictionary-using-the-umbracohelper
17 | ///
18 | [TestFixture]
19 | public class CultureDictionaryTests : UmbracoBaseTest {
20 | private HomeController controller;
21 |
22 | [SetUp]
23 | public override void SetUp()
24 | {
25 | base.SetUp();
26 | this.controller = new HomeController(Mock.Of(), Mock.Of(), base.ServiceContext, AppCaches.NoCache, Mock.Of(), base.UmbracoHelper);
27 | }
28 |
29 | [Test]
30 | [TestCase("myDictionaryKey", "myDictionaryValue")]
31 | public void GivenMyDictionaryKey_WhenIndexAction_ThenReturnViewModelWithMyPropertyDictionaryValue(string key, string expected)
32 | {
33 | var model = new Umbraco.Web.Models.ContentModel(new Mock().Object);
34 | base.CultureDictionary.Setup(x => x[key]).Returns(expected);
35 |
36 | var result = (HomeViewModel)((ViewResult)this.controller.Index(model)).Model;
37 |
38 | Assert.AreEqual(expected, result.DictionaryTitle);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/UmbracoHelper/PublishedContentQueryTests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Web.Mvc;
3 | using Moq;
4 | using NUnit.Framework;
5 | using Umbraco.Core.Cache;
6 | using Umbraco.Core.Configuration;
7 | using Umbraco.Core.Logging;
8 | using Umbraco.Core.Models.PublishedContent;
9 | using Umbraco.Web;
10 | using UmbracoUnitTesting.Core.Features.Member;
11 | using UmbracoUnitTesting.Tests.Shared;
12 |
13 | namespace UmbracoUnitTesting.Tests.UmbracoHelper {
14 | public class PublishedContentQueryTests : UmbracoBaseTest {
15 | ///
16 | /// Docs: https://our.umbraco.com/documentation/Implementation/Unit-Testing/#testing-ipublishedcontentquery-using-the-umbracohelper
17 | ///
18 | private MemberProfileController controller;
19 |
20 | [SetUp]
21 | public override void SetUp()
22 | {
23 | base.SetUp();
24 | this.controller = new MemberProfileController(Mock.Of(), Mock.Of(), base.ServiceContext, AppCaches.NoCache, Mock.Of(), base.UmbracoHelper);
25 | }
26 |
27 | [Test]
28 | public void GivenContentQueryReturnsOtherContent_WhenIndexAction_ThenReturnViewModelWithOtherContent()
29 | {
30 | var currentContent = new Umbraco.Web.Models.ContentModel(new Mock().Object);
31 | var otherContent = Mock.Of();
32 | base.PublishedContentQuery.Setup(x => x.Content(1062)).Returns(otherContent);
33 |
34 | var result = (MemberProfileViewModel)((ViewResult)this.controller.Index(currentContent)).Model;
35 |
36 | Assert.AreEqual(otherContent, result.OtherContent);
37 | }
38 |
39 | [Test]
40 | public void GivenContentQueryReturnsContentAtRoot_WhenIndexAction_ThenReturnViewModelWithContentAtRoot()
41 | {
42 | var currentContent = new Umbraco.Web.Models.ContentModel(new Mock().Object);
43 | var contentAtRoot = new List()
44 | {
45 | Mock.Of()
46 | };
47 | base.PublishedContentQuery.Setup(x => x.ContentAtRoot()).Returns(contentAtRoot);
48 |
49 | var result = (MemberProfileViewModel)((ViewResult)this.controller.Index(currentContent)).Model;
50 |
51 | Assert.AreEqual(contentAtRoot, result.ContentAtRoot);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/UmbracoUnitTesting.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Debug
8 | AnyCPU
9 | {37AC7380-12E9-40EB-8E06-450624CD511F}
10 | Library
11 | Properties
12 | UmbracoUnitTesting.Tests
13 | UmbracoUnitTesting.Tests
14 | v4.7.2
15 | 512
16 | true
17 |
18 |
19 |
20 |
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 | ..\packages\AngleSharp.0.9.11\lib\net45\AngleSharp.dll
40 |
41 |
42 | ..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll
43 |
44 |
45 | ..\packages\ClientDependency.1.9.9\lib\net45\ClientDependency.Core.dll
46 |
47 |
48 | ..\packages\ClientDependency-Mvc5.1.9.3\lib\net45\ClientDependency.Core.Mvc.dll
49 |
50 |
51 | ..\packages\CSharpTest.Net.Collections.14.906.1403.1082\lib\net40\CSharpTest.Net.Collections.dll
52 |
53 |
54 | ..\packages\Examine.1.0.2\lib\net452\Examine.dll
55 |
56 |
57 | ..\packages\HtmlAgilityPack.1.8.14\lib\Net45\HtmlAgilityPack.dll
58 |
59 |
60 | ..\packages\HtmlSanitizer.4.0.217\lib\net45\HtmlSanitizer.dll
61 |
62 |
63 | ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll
64 |
65 |
66 | ..\packages\ImageProcessor.2.7.0.100\lib\net452\ImageProcessor.dll
67 |
68 |
69 | ..\packages\LightInject.5.4.0\lib\net46\LightInject.dll
70 |
71 |
72 | ..\packages\LightInject.Annotation.1.1.0\lib\net46\LightInject.Annotation.dll
73 |
74 |
75 | ..\packages\LightInject.Mvc.2.0.0\lib\net46\LightInject.Mvc.dll
76 |
77 |
78 | ..\packages\LightInject.Web.2.0.0\lib\net46\LightInject.Web.dll
79 |
80 |
81 | ..\packages\LightInject.WebApi.2.0.0\lib\net46\LightInject.WebApi.dll
82 |
83 |
84 | ..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll
85 |
86 |
87 | ..\packages\Markdown.2.2.1\lib\net451\Markdown.dll
88 |
89 |
90 | ..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll
91 |
92 |
93 | ..\packages\Microsoft.AspNet.Identity.Owin.2.2.2\lib\net45\Microsoft.AspNet.Identity.Owin.dll
94 |
95 |
96 | ..\packages\Microsoft.AspNet.SignalR.Core.2.4.0\lib\net45\Microsoft.AspNet.SignalR.Core.dll
97 |
98 |
99 | ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll
100 |
101 |
102 | ..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll
103 |
104 |
105 | ..\packages\Microsoft.Owin.Host.SystemWeb.4.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
106 |
107 |
108 | ..\packages\Microsoft.Owin.Security.4.0.1\lib\net45\Microsoft.Owin.Security.dll
109 |
110 |
111 | ..\packages\Microsoft.Owin.Security.Cookies.4.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll
112 |
113 |
114 | ..\packages\Microsoft.Owin.Security.OAuth.4.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll
115 |
116 |
117 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
118 |
119 |
120 | ..\packages\MiniProfiler.4.0.138\lib\net461\MiniProfiler.dll
121 |
122 |
123 | ..\packages\MiniProfiler.Shared.4.0.138\lib\net461\MiniProfiler.Shared.dll
124 |
125 |
126 | ..\packages\Moq.4.16.0\lib\net45\Moq.dll
127 |
128 |
129 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll
130 |
131 |
132 | ..\packages\NPoco.3.9.4\lib\net45\NPoco.dll
133 |
134 |
135 | ..\packages\NUnit.3.13.0\lib\net45\nunit.framework.dll
136 |
137 |
138 | ..\packages\Owin.1.0\lib\net40\Owin.dll
139 |
140 |
141 | ..\packages\Semver.2.0.4\lib\net452\Semver.dll
142 |
143 |
144 | ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll
145 |
146 |
147 | ..\packages\Serilog.Enrichers.Process.2.0.1\lib\net45\Serilog.Enrichers.Process.dll
148 |
149 |
150 | ..\packages\Serilog.Enrichers.Thread.3.0.0\lib\net45\Serilog.Enrichers.Thread.dll
151 |
152 |
153 | ..\packages\Serilog.Filters.Expressions.2.0.0\lib\net45\Serilog.Filters.Expressions.dll
154 |
155 |
156 | ..\packages\Serilog.Formatting.Compact.1.0.0\lib\net45\Serilog.Formatting.Compact.dll
157 |
158 |
159 | ..\packages\Serilog.Formatting.Compact.Reader.1.0.3\lib\net45\Serilog.Formatting.Compact.Reader.dll
160 |
161 |
162 | ..\packages\Serilog.Settings.AppSettings.2.2.2\lib\net45\Serilog.Settings.AppSettings.dll
163 |
164 |
165 | ..\packages\Serilog.Sinks.Async.1.3.0\lib\net45\Serilog.Sinks.Async.dll
166 |
167 |
168 | ..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll
169 |
170 |
171 | ..\packages\Serilog.Sinks.Map.1.0.0\lib\netstandard2.0\Serilog.Sinks.Map.dll
172 |
173 |
174 | ..\packages\Superpower.2.0.0\lib\net45\Superpower.dll
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 | ..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.dll
183 |
184 |
185 | ..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.Entity.dll
186 |
187 |
188 | ..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll
189 |
190 |
191 |
192 |
193 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll
194 |
195 |
196 |
197 |
198 | ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll
199 |
200 |
201 |
202 |
203 |
204 | ..\packages\System.Threading.Tasks.Dataflow.4.9.0\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll
205 |
206 |
207 | ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll
208 |
209 |
210 |
211 | ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
212 |
213 |
214 |
215 |
216 |
217 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll
218 |
219 |
220 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll
221 |
222 |
223 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll
224 |
225 |
226 | ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll
227 |
228 |
229 | ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll
230 |
231 |
232 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll
233 |
234 |
235 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll
236 |
237 |
238 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 | ..\packages\UmbracoCms.Core.8.10.1\lib\net472\Umbraco.Core.dll
248 |
249 |
250 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.Examine.dll
251 |
252 |
253 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.ModelsBuilder.Embedded.dll
254 |
255 |
256 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.Web.dll
257 |
258 |
259 | ..\packages\UmbracoCms.Web.8.10.1\lib\net472\Umbraco.Web.UI.dll
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 | {FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}
277 | UmbracoUnitTesting.Core
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
289 |
290 |
291 |
292 |
293 |
294 |
295 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/app.config:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.Tests/packages.config:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/UmbracoUnitTesting.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.438
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UmbracoUnitTesting.Core", "UmbracoUnitTesting.Core\UmbracoUnitTesting.Core.csproj", "{FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UmbracoUnitTesting.Tests", "UmbracoUnitTesting.Tests\UmbracoUnitTesting.Tests.csproj", "{37AC7380-12E9-40EB-8E06-450624CD511F}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {FFD31510-57EB-4258-AF8C-ECEAF4B2F79C}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {37AC7380-12E9-40EB-8E06-450624CD511F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {37AC7380-12E9-40EB-8E06-450624CD511F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {37AC7380-12E9-40EB-8E06-450624CD511F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {37AC7380-12E9-40EB-8E06-450624CD511F}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {839C3AFD-E37D-432B-9A36-EB96CF56CA53}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------