2018-04-29 20:02:38 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2019-12-10 08:37:19 +01:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
2018-04-29 20:02:38 +02:00
|
|
|
|
using Umbraco.Core.Scoping;
|
2019-10-22 00:53:52 +11:00
|
|
|
|
using Umbraco.Web;
|
2018-04-29 20:02:38 +02:00
|
|
|
|
using Umbraco.Web.PublishedCache.NuCache;
|
|
|
|
|
|
using Umbraco.Web.PublishedCache.NuCache.DataSource;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Testing.Objects
|
|
|
|
|
|
{
|
2019-10-22 00:53:52 +11:00
|
|
|
|
|
2018-04-29 20:02:38 +02:00
|
|
|
|
internal class TestDataSource : IDataSource
|
|
|
|
|
|
{
|
2019-12-10 08:37:19 +01:00
|
|
|
|
|
|
|
|
|
|
private IPublishedModelFactory PublishedModelFactory { get; } = new NoopPublishedModelFactory();
|
|
|
|
|
|
|
2018-04-29 20:02:38 +02:00
|
|
|
|
public TestDataSource(params ContentNodeKit[] kits)
|
|
|
|
|
|
: this((IEnumerable<ContentNodeKit>) kits)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public TestDataSource(IEnumerable<ContentNodeKit> kits)
|
|
|
|
|
|
{
|
2019-05-29 16:48:20 +02:00
|
|
|
|
Kits = kits.ToDictionary(x => x.Node.Id, x => x);
|
2018-04-29 20:02:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-29 16:48:20 +02:00
|
|
|
|
public Dictionary<int, ContentNodeKit> Kits { get; }
|
|
|
|
|
|
|
|
|
|
|
|
// note: it is important to clone the returned kits, as the inner
|
|
|
|
|
|
// ContentNode is directly reused and modified by the snapshot service
|
|
|
|
|
|
|
2018-04-29 20:02:38 +02:00
|
|
|
|
public ContentNodeKit GetContentSource(IScope scope, int id)
|
2019-12-10 08:37:19 +01:00
|
|
|
|
=> Kits.TryGetValue(id, out var kit) ? kit.Clone(PublishedModelFactory) : default;
|
2018-04-29 20:02:38 +02:00
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ContentNodeKit> GetAllContentSources(IScope scope)
|
2019-05-29 16:48:20 +02:00
|
|
|
|
=> Kits.Values
|
|
|
|
|
|
.OrderBy(x => x.Node.Level)
|
2019-08-19 17:18:45 +10:00
|
|
|
|
.ThenBy(x => x.Node.ParentContentId)
|
|
|
|
|
|
.ThenBy(x => x.Node.SortOrder)
|
2019-12-10 08:37:19 +01:00
|
|
|
|
.Select(x => x.Clone(PublishedModelFactory));
|
2018-04-29 20:02:38 +02:00
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ContentNodeKit> GetBranchContentSources(IScope scope, int id)
|
2019-05-29 16:48:20 +02:00
|
|
|
|
=> Kits.Values
|
|
|
|
|
|
.Where(x => x.Node.Path.EndsWith("," + id) || x.Node.Path.Contains("," + id + ","))
|
2019-08-19 17:18:45 +10:00
|
|
|
|
.OrderBy(x => x.Node.Level)
|
|
|
|
|
|
.ThenBy(x => x.Node.ParentContentId)
|
|
|
|
|
|
.ThenBy(x => x.Node.SortOrder)
|
2019-12-10 08:37:19 +01:00
|
|
|
|
.Select(x => x.Clone(PublishedModelFactory));
|
2018-04-29 20:02:38 +02:00
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ContentNodeKit> GetTypeContentSources(IScope scope, IEnumerable<int> ids)
|
2019-05-29 16:48:20 +02:00
|
|
|
|
=> Kits.Values
|
|
|
|
|
|
.Where(x => ids.Contains(x.ContentTypeId))
|
2019-08-19 17:18:45 +10:00
|
|
|
|
.OrderBy(x => x.Node.Level)
|
|
|
|
|
|
.ThenBy(x => x.Node.ParentContentId)
|
|
|
|
|
|
.ThenBy(x => x.Node.SortOrder)
|
2019-12-10 08:37:19 +01:00
|
|
|
|
.Select(x => x.Clone(PublishedModelFactory));
|
2018-04-29 20:02:38 +02:00
|
|
|
|
|
|
|
|
|
|
public ContentNodeKit GetMediaSource(IScope scope, int id)
|
|
|
|
|
|
{
|
2019-08-19 22:07:22 +10:00
|
|
|
|
return default;
|
2018-04-29 20:02:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ContentNodeKit> GetAllMediaSources(IScope scope)
|
|
|
|
|
|
{
|
2019-08-19 22:07:22 +10:00
|
|
|
|
return Enumerable.Empty<ContentNodeKit>();
|
2018-04-29 20:02:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ContentNodeKit> GetBranchMediaSources(IScope scope, int id)
|
|
|
|
|
|
{
|
2019-08-19 22:07:22 +10:00
|
|
|
|
return Enumerable.Empty<ContentNodeKit>();
|
2018-04-29 20:02:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ContentNodeKit> GetTypeMediaSources(IScope scope, IEnumerable<int> ids)
|
|
|
|
|
|
{
|
2019-08-19 22:07:22 +10:00
|
|
|
|
return Enumerable.Empty<ContentNodeKit>();
|
2018-04-29 20:02:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|