Files
Umbraco-CMS/src/Umbraco.Tests/Testing/Objects/TestDataSource.cs

73 lines
2.5 KiB
C#
Raw Normal View History

2018-04-29 20:02:38 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Scoping;
using Umbraco.Web.PublishedCache.NuCache;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
namespace Umbraco.Tests.Testing.Objects
{
internal class TestDataSource : IDataSource
{
public TestDataSource(params ContentNodeKit[] kits)
: this((IEnumerable<ContentNodeKit>) kits)
{ }
public TestDataSource(IEnumerable<ContentNodeKit> kits)
{
Kits = kits.ToDictionary(x => x.Node.Id, x => x);
2018-04-29 20:02:38 +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)
=> Kits.TryGetValue(id, out var kit) ? kit.Clone() : default;
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetAllContentSources(IScope scope)
=> 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)
.Select(x => x.Clone());
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetBranchContentSources(IScope scope, int id)
=> 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)
.Select(x => x.Clone());
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetTypeContentSources(IScope scope, IEnumerable<int> ids)
=> 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)
.Select(x => x.Clone());
2018-04-29 20:02:38 +02:00
public ContentNodeKit GetMediaSource(IScope scope, int id)
{
return default;
2018-04-29 20:02:38 +02:00
}
public IEnumerable<ContentNodeKit> GetAllMediaSources(IScope scope)
{
return Enumerable.Empty<ContentNodeKit>();
2018-04-29 20:02:38 +02:00
}
public IEnumerable<ContentNodeKit> GetBranchMediaSources(IScope scope, int id)
{
return Enumerable.Empty<ContentNodeKit>();
2018-04-29 20:02:38 +02:00
}
public IEnumerable<ContentNodeKit> GetTypeMediaSources(IScope scope, IEnumerable<int> ids)
{
return Enumerable.Empty<ContentNodeKit>();
2018-04-29 20:02:38 +02:00
}
}
}