Files
Umbraco-CMS/tests/Umbraco.Tests.Common/Builders/ContentNodeKitBuilder.cs
Shannon Deminick c77dc5dc00 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 <mail@bergmania.dk>
2021-10-19 14:11:54 +02:00

97 lines
3.4 KiB
C#

using System;
using Umbraco.Cms.Infrastructure.PublishedCache;
using Umbraco.Cms.Infrastructure.PublishedCache.DataSource;
namespace Umbraco.Cms.Tests.Common.Builders
{
public class ContentNodeKitBuilder : BuilderBase<ContentNodeKit>
{
private int _contentTypeId;
private ContentNode _contentNode;
private ContentData _draftData;
private ContentData _publishedData;
public ContentNodeKitBuilder WithContentNode(ContentNode contentNode)
{
_contentNode = contentNode;
return this;
}
public ContentNodeKitBuilder WithContentNode(int id, Guid uid, int level, string path, int sortOrder, int parentContentId, DateTime createDate, int creatorId)
{
_contentNode = new ContentNode(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId);
return this;
}
public ContentNodeKitBuilder WithContentTypeId(int contentTypeId)
{
_contentTypeId = contentTypeId;
return this;
}
public ContentNodeKitBuilder WithDraftData(ContentData draftData)
{
_draftData = draftData;
return this;
}
public ContentNodeKitBuilder WithPublishedData(ContentData publishedData)
{
_publishedData = publishedData;
return this;
}
public override ContentNodeKit Build()
{
var data = new ContentNodeKit(_contentNode, _contentTypeId, _draftData, _publishedData);
return data;
}
/// <summary>
/// Creates a ContentNodeKit
/// </summary>
/// <param name="contentTypeId"></param>
/// <param name="id"></param>
/// <param name="path"></param>
/// <param name="sortOrder"></param>
/// <param name="level">
/// Optional. Will get calculated based on the path value if not specified.
/// </param>
/// <param name="parentContentId">
/// Optional. Will get calculated based on the path value if not specified.
/// </param>
/// <param name="creatorId"></param>
/// <param name="uid"></param>
/// <param name="createDate"></param>
/// <param name="draftData"></param>
/// <param name="publishedData"></param>
/// <returns></returns>
public static ContentNodeKit CreateWithContent(
int contentTypeId,
int id,
string path,
int? sortOrder = null,
int? level = null,
int? parentContentId = null,
int creatorId = -1,
Guid? uid = null,
DateTime? createDate = null,
ContentData draftData = null,
ContentData publishedData = null)
{
var pathParts = path.Split(',');
if (pathParts.Length >= 2)
{
parentContentId ??= int.Parse(pathParts[^2]);
}
return new ContentNodeKitBuilder()
.WithContentTypeId(contentTypeId)
.WithContentNode(id, uid ?? Guid.NewGuid(), level ?? pathParts.Length - 1, path, sortOrder ?? 0, parentContentId.Value, createDate ?? DateTime.Now, creatorId)
.WithDraftData(draftData)
.WithPublishedData(publishedData)
.Build();
}
}
}