Skip to content

Commit c77dc5d

Browse files
Shazwazzabergmania
andauthored
Migrating tests that depend on Published Cache from the old test project (#11242)
* starts cleaning up old test project, removing ones we'll never convert, moves new test to where it should be. * Makes ContentNodeKit immutable properties, moves first nucache tests over * Gets the Nucache unit tests working and refactors a bit to use builder pattern for models. * Migrates first xml based cache test to use nucache. * Migrates a bunch more * Migrates remaining tests for PublishedContentTests * Moves PublishedRouterTests * Moves PublishedContentExtensionTests * Moves more tests. * committing wip * committing wip * Gets PublishedContentLanguageVariantTests converted and working. * Fixes DataTable ext method and moves PublishedContentDataTableTests * Moves PublishedMediaTests * wip - moving EntityXmlSerializerTests * Moves more tests * moves more tests * moves more tests * Move another test * Moves more tests * Fix test * move another test * Moves more tests * Moves more tests * Moves more tests * wip before merge * More tests * More tests * More tests * More tests * More tests * More tests * Cleanup and moving classes. * Remove unused code * Fixed failing tests, due to new null checks, that did not exist in v8 * Avoid breaking changes * Unbreak more things, even that it the old solution was crazy.. * Fixed bug where ordering of stream readings was changed.. * cleanup Co-authored-by: Bjarke Berg <[email protected]>
1 parent 49e1aec commit c77dc5d

File tree

171 files changed

+5383
-17927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+5383
-17927
lines changed

src/Umbraco.Core/Cache/FastDictionaryAppCache.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -18,6 +18,8 @@ public class FastDictionaryAppCache : IAppCache
1818
/// </summary>
1919
private readonly ConcurrentDictionary<string, Lazy<object>> _items = new ConcurrentDictionary<string, Lazy<object>>();
2020

21+
public IEnumerable<string> Keys => _items.Keys;
22+
2123
public int Count => _items.Count;
2224

2325
/// <inheritdoc />

src/Umbraco.Core/Extensions/PublishedContentExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,8 +1328,8 @@ private static Dictionary<string, string> GetAliasesAndNames(IContentTypeService
13281328
{"NodeTypeAlias", "NodeTypeAlias"},
13291329
{"CreateDate", "CreateDate"},
13301330
{"UpdateDate", "UpdateDate"},
1331-
{"CreatorName", "CreatorName"},
1332-
{"WriterName", "WriterName"},
1331+
{"CreatorId", "CreatorId"},
1332+
{"WriterId", "WriterId"},
13331333
{"Url", "Url"}
13341334
};
13351335

src/Umbraco.Core/PropertyEditors/VoidEditor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.Logging;
1+
using Microsoft.Extensions.Logging;
22
using Umbraco.Cms.Core.Composing;
33
using Umbraco.Cms.Core.Hosting;
44
using Umbraco.Cms.Core.Serialization;
@@ -16,8 +16,6 @@ namespace Umbraco.Cms.Core.PropertyEditors
1616
[HideFromTypeFinder]
1717
public class VoidEditor : DataEditor
1818
{
19-
private readonly IJsonSerializer _jsonSerializer;
20-
2119
/// <summary>
2220
/// Initializes a new instance of the <see cref="VoidEditor"/> class.
2321
/// </summary>

src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Linq;
45
using Umbraco.Cms.Core.Models.PublishedContent;
56
using Umbraco.Extensions;
67

78
namespace Umbraco.Cms.Core.PublishedCache.Internal
89
{
9-
10+
// TODO: Only used in unit tests, needs to be moved to test project
11+
[EditorBrowsable(EditorBrowsableState.Never)]
1012
public sealed class InternalPublishedContent : IPublishedContent
1113
{
1214
public InternalPublishedContent(IPublishedContentType contentType)

src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Linq;
45
using Umbraco.Cms.Core.Models.PublishedContent;
56
using Umbraco.Cms.Core.Xml;
67

78
namespace Umbraco.Cms.Core.PublishedCache.Internal
89
{
10+
// TODO: Only used in unit tests, needs to be moved to test project
11+
[EditorBrowsable(EditorBrowsableState.Never)]
912
public sealed class InternalPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache
1013
{
1114
private readonly Dictionary<int, IPublishedContent> _content = new Dictionary<int, IPublishedContent>();

src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using Umbraco.Cms.Core.Models.PublishedContent;
1+
using System.ComponentModel;
2+
using Umbraco.Cms.Core.Models.PublishedContent;
23

34
namespace Umbraco.Cms.Core.PublishedCache.Internal
45
{
6+
// TODO: Only used in unit tests, needs to be moved to test project
7+
[EditorBrowsable(EditorBrowsableState.Never)]
58
public class InternalPublishedProperty : IPublishedProperty
69
{
710
public IPublishedPropertyType PropertyType { get; set; }

src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System;
2+
using System.ComponentModel;
23
using Umbraco.Cms.Core.Cache;
34

45
namespace Umbraco.Cms.Core.PublishedCache.Internal
56
{
7+
8+
// TODO: Only used in unit tests, needs to be moved to test project
9+
[EditorBrowsable(EditorBrowsableState.Never)]
610
public sealed class InternalPublishedSnapshot : IPublishedSnapshot
711
{
812
public InternalPublishedContentCache InnerContentCache { get; } = new InternalPublishedContentCache();

src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System.Collections.Generic;
2+
using System.ComponentModel;
23
using System.Threading.Tasks;
34
using Umbraco.Cms.Core.Cache;
45
using Umbraco.Extensions;
56

67
namespace Umbraco.Cms.Core.PublishedCache.Internal
78
{
9+
// TODO: Only used in unit tests, needs to be moved to test project
10+
[EditorBrowsable(EditorBrowsableState.Never)]
811
public class InternalPublishedSnapshotService : IPublishedSnapshotService
912
{
1013
private InternalPublishedSnapshot _snapshot;

src/Umbraco.Core/Routing/DefaultUrlProvider.cs

Lines changed: 104 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,109 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
using Microsoft.Extensions.DependencyInjection;
45
using Microsoft.Extensions.Logging;
56
using Microsoft.Extensions.Options;
67
using Umbraco.Cms.Core.Configuration.Models;
78
using Umbraco.Cms.Core.Models.PublishedContent;
9+
using Umbraco.Cms.Core.Services;
810
using Umbraco.Cms.Core.Web;
11+
using Umbraco.Cms.Web.Common.DependencyInjection;
912
using Umbraco.Extensions;
1013

1114
namespace Umbraco.Cms.Core.Routing
1215
{
1316
/// <summary>
14-
/// Provides urls.
17+
/// Provides urls.
1518
/// </summary>
1619
public class DefaultUrlProvider : IUrlProvider
1720
{
18-
private readonly RequestHandlerSettings _requestSettings;
21+
private readonly ILocalizationService _localizationService;
22+
private readonly ILocalizedTextService _localizedTextService;
1923
private readonly ILogger<DefaultUrlProvider> _logger;
24+
private readonly RequestHandlerSettings _requestSettings;
2025
private readonly ISiteDomainMapper _siteDomainMapper;
2126
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
2227
private readonly UriUtility _uriUtility;
2328

24-
public DefaultUrlProvider(IOptions<RequestHandlerSettings> requestSettings, ILogger<DefaultUrlProvider> logger, ISiteDomainMapper siteDomainMapper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility)
29+
[Obsolete("Use ctor with all parameters")]
30+
public DefaultUrlProvider(IOptions<RequestHandlerSettings> requestSettings, ILogger<DefaultUrlProvider> logger,
31+
ISiteDomainMapper siteDomainMapper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility)
32+
: this(requestSettings, logger, siteDomainMapper, umbracoContextAccessor, uriUtility,
33+
StaticServiceProvider.Instance.GetRequiredService<ILocalizationService>())
34+
{
35+
}
36+
37+
public DefaultUrlProvider(
38+
IOptions<RequestHandlerSettings> requestSettings,
39+
ILogger<DefaultUrlProvider> logger,
40+
ISiteDomainMapper siteDomainMapper,
41+
IUmbracoContextAccessor umbracoContextAccessor,
42+
UriUtility uriUtility,
43+
ILocalizationService localizationService)
2544
{
2645
_requestSettings = requestSettings.Value;
2746
_logger = logger;
2847
_siteDomainMapper = siteDomainMapper;
29-
_uriUtility = uriUtility;
3048
_umbracoContextAccessor = umbracoContextAccessor;
49+
_uriUtility = uriUtility;
50+
_localizationService = localizationService;
3151
}
3252

33-
#region GetUrl
34-
35-
/// <inheritdoc />
36-
public virtual UrlInfo GetUrl(IPublishedContent content, UrlMode mode, string culture, Uri current)
37-
{
38-
if (!current.IsAbsoluteUri) throw new ArgumentException("Current URL must be absolute.", nameof(current));
39-
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
40-
// will not use cache if previewing
41-
var route = umbracoContext.Content.GetRouteById(content.Id, culture);
42-
43-
return GetUrlFromRoute(route, umbracoContext, content.Id, current, mode, culture);
44-
}
45-
46-
internal UrlInfo GetUrlFromRoute(string route, IUmbracoContext umbracoContext, int id, Uri current, UrlMode mode, string culture)
47-
{
48-
if (string.IsNullOrWhiteSpace(route))
49-
{
50-
_logger.LogDebug("Couldn't find any page with nodeId={NodeId}. This is most likely caused by the page not being published.", id);
51-
return null;
52-
}
53-
54-
// extract domainUri and path
55-
// route is /<path> or <domainRootId>/<path>
56-
var pos = route.IndexOf('/');
57-
var path = pos == 0 ? route : route.Substring(pos);
58-
var domainUri = pos == 0
59-
? null
60-
: DomainUtilities.DomainForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture), current, culture);
61-
62-
// assemble the URL from domainUri (maybe null) and path
63-
var url = AssembleUrl(domainUri, path, current, mode).ToString();
64-
65-
return UrlInfo.Url(url, culture);
66-
}
67-
68-
#endregion
69-
7053
#region GetOtherUrls
7154

7255
/// <summary>
73-
/// Gets the other URLs of a published content.
56+
/// Gets the other URLs of a published content.
7457
/// </summary>
7558
/// <param name="umbracoContextAccessor">The Umbraco context.</param>
7659
/// <param name="id">The published content id.</param>
7760
/// <param name="current">The current absolute URL.</param>
7861
/// <returns>The other URLs for the published content.</returns>
7962
/// <remarks>
80-
/// <para>Other URLs are those that <c>GetUrl</c> would not return in the current context, but would be valid
81-
/// URLs for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
63+
/// <para>
64+
/// Other URLs are those that <c>GetUrl</c> would not return in the current context, but would be valid
65+
/// URLs for the node in other contexts (different domain for current request, umbracoUrlAlias...).
66+
/// </para>
8267
/// </remarks>
8368
public virtual IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
8469
{
85-
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
86-
var node = umbracoContext.Content.GetById(id);
70+
IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
71+
IPublishedContent node = umbracoContext.Content.GetById(id);
8772
if (node == null)
8873
{
8974
yield break;
9075
}
9176

9277
// look for domains, walking up the tree
93-
var n = node;
94-
var domainUris = DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, n.Id, current, false);
78+
IPublishedContent n = node;
79+
IEnumerable<DomainAndUri> domainUris =
80+
DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, n.Id,
81+
current, false);
9582
while (domainUris == null && n != null) // n is null at root
9683
{
9784
n = n.Parent; // move to parent node
98-
domainUris = n == null ? null : DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, n.Id, current, excludeDefault: true);
85+
domainUris = n == null
86+
? null
87+
: DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, n.Id,
88+
current);
9989
}
10090

10191
// no domains = exit
102-
if (domainUris ==null)
92+
if (domainUris == null)
10393
{
10494
yield break;
10595
}
10696

107-
foreach (var d in domainUris)
97+
foreach (DomainAndUri d in domainUris)
10898
{
10999
var culture = d?.Culture;
110100

111101
// although we are passing in culture here, if any node in this path is invariant, it ignores the culture anyways so this is ok
112102
var route = umbracoContext.Content.GetRouteById(id, culture);
113-
if (route == null) continue;
103+
if (route == null)
104+
{
105+
continue;
106+
}
114107

115108
// need to strip off the leading ID for the route if it exists (occurs if the route is for a node with a domain assigned)
116109
var pos = route.IndexOf('/');
@@ -124,9 +117,57 @@ public virtual IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
124117

125118
#endregion
126119

120+
#region GetUrl
121+
122+
/// <inheritdoc />
123+
public virtual UrlInfo GetUrl(IPublishedContent content, UrlMode mode, string culture, Uri current)
124+
{
125+
if (!current.IsAbsoluteUri)
126+
{
127+
throw new ArgumentException("Current URL must be absolute.", nameof(current));
128+
}
129+
130+
IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
131+
// will not use cache if previewing
132+
var route = umbracoContext.Content.GetRouteById(content.Id, culture);
133+
134+
return GetUrlFromRoute(route, umbracoContext, content.Id, current, mode, culture);
135+
}
136+
137+
internal UrlInfo GetUrlFromRoute(string route, IUmbracoContext umbracoContext, int id, Uri current,
138+
UrlMode mode, string culture)
139+
{
140+
if (string.IsNullOrWhiteSpace(route))
141+
{
142+
_logger.LogDebug(
143+
"Couldn't find any page with nodeId={NodeId}. This is most likely caused by the page not being published.",
144+
id);
145+
return null;
146+
}
147+
148+
// extract domainUri and path
149+
// route is /<path> or <domainRootId>/<path>
150+
var pos = route.IndexOf('/');
151+
var path = pos == 0 ? route : route.Substring(pos);
152+
var domainUri = pos == 0
153+
? null
154+
: DomainUtilities.DomainForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture), current, culture);
155+
156+
var defaultCulture = _localizationService.GetDefaultLanguageIsoCode();
157+
if (domainUri is not null || culture == defaultCulture || culture is null)
158+
{
159+
var url = AssembleUrl(domainUri, path, current, mode).ToString();
160+
return UrlInfo.Url(url, culture);
161+
}
162+
163+
return null;
164+
}
165+
166+
#endregion
167+
127168
#region Utilities
128169

129-
Uri AssembleUrl(DomainAndUri domainUri, string path, Uri current, UrlMode mode)
170+
private Uri AssembleUrl(DomainAndUri domainUri, string path, Uri current, UrlMode mode)
130171
{
131172
Uri uri;
132173

@@ -135,7 +176,9 @@ Uri AssembleUrl(DomainAndUri domainUri, string path, Uri current, UrlMode mode)
135176
if (domainUri == null) // no domain was found
136177
{
137178
if (current == null)
179+
{
138180
mode = UrlMode.Relative; // best we can do
181+
}
139182

140183
switch (mode)
141184
{
@@ -155,10 +198,15 @@ Uri AssembleUrl(DomainAndUri domainUri, string path, Uri current, UrlMode mode)
155198
if (mode == UrlMode.Auto)
156199
{
157200
//this check is a little tricky, we can't just compare domains
158-
if (current != null && domainUri.Uri.GetLeftPart(UriPartial.Authority) == current.GetLeftPart(UriPartial.Authority))
201+
if (current != null && domainUri.Uri.GetLeftPart(UriPartial.Authority) ==
202+
current.GetLeftPart(UriPartial.Authority))
203+
{
159204
mode = UrlMode.Relative;
205+
}
160206
else
207+
{
161208
mode = UrlMode.Absolute;
209+
}
162210
}
163211

164212
switch (mode)
@@ -179,9 +227,9 @@ Uri AssembleUrl(DomainAndUri domainUri, string path, Uri current, UrlMode mode)
179227
return _uriUtility.UriFromUmbraco(uri, _requestSettings);
180228
}
181229

182-
string CombinePaths(string path1, string path2)
230+
private string CombinePaths(string path1, string path2)
183231
{
184-
string path = path1.TrimEnd(Constants.CharArrays.ForwardSlash) + path2;
232+
var path = path1.TrimEnd(Constants.CharArrays.ForwardSlash) + path2;
185233
return path == "/" ? path : path.TrimEnd(Constants.CharArrays.ForwardSlash);
186234
}
187235

0 commit comments

Comments
 (0)