Files
Umbraco-CMS/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs

66 lines
2.7 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
2020-12-23 14:28:03 +11:00
using System;
using NUnit.Framework;
using Umbraco.Core.Models;
2020-10-11 22:31:54 +02:00
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Tests.Common.Builders;
namespace Umbraco.Tests.Integration.Testing
{
public abstract class UmbracoIntegrationTestWithContent : UmbracoIntegrationTest
{
protected IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
2020-12-23 14:28:03 +11:00
2020-10-11 22:31:54 +02:00
protected IFileService FileService => GetRequiredService<IFileService>();
2020-12-23 14:28:03 +11:00
2020-10-11 22:31:54 +02:00
protected ContentService ContentService => (ContentService)GetRequiredService<IContentService>();
[SetUp]
2020-12-23 14:28:03 +11:00
public void Setup() => CreateTestData();
2020-10-11 22:31:54 +02:00
public virtual void CreateTestData()
{
2020-12-23 14:28:03 +11:00
// NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested.
Template template = TemplateBuilder.CreateTextPageTemplate();
2020-10-11 22:31:54 +02:00
FileService.SaveTemplate(template);
// Create and Save ContentType "umbTextpage" -> 1051 (template), 1052 (content type)
ContentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id);
ContentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522");
ContentTypeService.Save(ContentType);
2020-10-11 22:31:54 +02:00
// Create and Save Content "Homepage" based on "umbTextpage" -> 1053
Textpage = ContentBuilder.CreateSimpleContent(ContentType);
Textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0");
ContentService.Save(Textpage, 0);
2020-10-11 22:31:54 +02:00
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054
Subpage = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 1", Textpage.Id);
Subpage.ContentSchedule.Add(DateTime.Now.AddMinutes(-5), null);
ContentService.Save(Subpage, 0);
2020-10-11 22:31:54 +02:00
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1055
Subpage2 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 2", Textpage.Id);
ContentService.Save(Subpage2, 0);
2020-10-11 22:31:54 +02:00
// Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1056
Trashed = ContentBuilder.CreateSimpleContent(ContentType, "Text Page Deleted", -20);
Trashed.Trashed = true;
ContentService.Save(Trashed, 0);
2020-10-11 22:31:54 +02:00
}
protected Content Trashed { get; private set; }
protected Content Subpage2 { get; private set; }
protected Content Subpage { get; private set; }
protected Content Textpage { get; private set; }
protected ContentType ContentType { get; private set; }
2020-10-11 22:31:54 +02:00
}
}