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

72 lines
3.3 KiB
C#
Raw Normal View History

using System;
2018-04-29 20:02:38 +02:00
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Core.Models;
2018-04-29 20:02:38 +02:00
using Umbraco.Core.Scoping;
using Umbraco.Infrastructure.PublishedCache.Persistence;
using Umbraco.Web;
2018-04-29 20:02:38 +02:00
using Umbraco.Web.PublishedCache.NuCache;
namespace Umbraco.Tests.Testing.Objects
{
internal class TestDataSource : INuCacheContentService
2018-04-29 20:02:38 +02: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) => 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
public ContentNodeKit GetContentSource(int id)
=> Kits.TryGetValue(id, out ContentNodeKit kit) ? kit.Clone(PublishedModelFactory) : default;
public IEnumerable<ContentNodeKit> GetAllContentSources()
=> 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(PublishedModelFactory));
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetBranchContentSources(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(PublishedModelFactory));
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetTypeContentSources(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(PublishedModelFactory));
2018-04-29 20:02:38 +02:00
public ContentNodeKit GetMediaSource(int id) => default;
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetAllMediaSources() => Enumerable.Empty<ContentNodeKit>();
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetBranchMediaSources(int id) => Enumerable.Empty<ContentNodeKit>();
2018-04-29 20:02:38 +02:00
public IEnumerable<ContentNodeKit> GetTypeMediaSources(IEnumerable<int> ids) => Enumerable.Empty<ContentNodeKit>();
public void DeleteContentItem(IContentBase item) => throw new NotImplementedException();
public void RefreshContent(IContent content) => throw new NotImplementedException();
public void RefreshEntity(IContentBase content) => throw new NotImplementedException();
public bool VerifyContentDbCache() => throw new NotImplementedException();
public bool VerifyMediaDbCache() => throw new NotImplementedException();
public bool VerifyMemberDbCache() => throw new NotImplementedException();
public void Rebuild(int groupSize = 5000, IReadOnlyCollection<int> contentTypeIds = null, IReadOnlyCollection<int> mediaTypeIds = null, IReadOnlyCollection<int> memberTypeIds = null) => throw new NotImplementedException();
2018-04-29 20:02:38 +02:00
}
}