V10: fix build warnings in test projects (#12509)
* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -13,114 +13,112 @@ using Umbraco.Cms.Web.Website.Controllers;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.TestData.Configuration;
|
||||
|
||||
namespace Umbraco.TestData
|
||||
namespace Umbraco.TestData;
|
||||
|
||||
public class SegmentTestController : SurfaceController
|
||||
{
|
||||
public class SegmentTestController : SurfaceController
|
||||
private readonly IOptions<TestDataSettings> _testDataSettings;
|
||||
|
||||
public SegmentTestController(
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IUmbracoDatabaseFactory databaseFactory,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger profilingLogger,
|
||||
IPublishedUrlProvider publishedUrlProvider,
|
||||
IOptions<TestDataSettings> testDataSettings)
|
||||
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider) =>
|
||||
_testDataSettings = testDataSettings;
|
||||
|
||||
public IActionResult EnableDocTypeSegments(string alias, string propertyTypeAlias)
|
||||
{
|
||||
private IOptions<TestDataSettings> _testDataSettings;
|
||||
|
||||
public SegmentTestController(
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IUmbracoDatabaseFactory databaseFactory,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger profilingLogger,
|
||||
IPublishedUrlProvider publishedUrlProvider,
|
||||
IOptions<TestDataSettings> testDataSettings)
|
||||
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
|
||||
if (_testDataSettings.Value.Enabled != true)
|
||||
{
|
||||
_testDataSettings = testDataSettings;
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
public IActionResult EnableDocTypeSegments(string alias, string propertyTypeAlias)
|
||||
var ct = Services.ContentTypeService.Get(alias);
|
||||
if (ct == null)
|
||||
{
|
||||
if(_testDataSettings.Value.Enabled != true)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
IContentType ct = Services.ContentTypeService.Get(alias);
|
||||
if (ct == null)
|
||||
{
|
||||
return Content($"No document type found by alias {alias}");
|
||||
}
|
||||
|
||||
IPropertyType propType = ct.PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);
|
||||
if (propType == null)
|
||||
{
|
||||
return Content($"The document type {alias} does not have a property type {propertyTypeAlias ?? "null"}");
|
||||
}
|
||||
|
||||
if (ct.Variations.VariesBySegment())
|
||||
{
|
||||
return Content($"The document type {alias} already allows segments, nothing has been changed");
|
||||
}
|
||||
|
||||
ct.SetVariesBy(ContentVariation.Segment);
|
||||
propType.SetVariesBy(ContentVariation.Segment);
|
||||
|
||||
Services.ContentTypeService.Save(ct);
|
||||
return Content($"The document type {alias} and property type {propertyTypeAlias} now allows segments");
|
||||
return Content($"No document type found by alias {alias}");
|
||||
}
|
||||
|
||||
private IActionResult HttpNotFound() => throw new NotImplementedException();
|
||||
|
||||
public IActionResult DisableDocTypeSegments(string alias)
|
||||
var propType = ct.PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);
|
||||
if (propType == null)
|
||||
{
|
||||
if (_testDataSettings.Value.Enabled != true)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
IContentType ct = Services.ContentTypeService.Get(alias);
|
||||
if (ct == null)
|
||||
{
|
||||
return Content($"No document type found by alias {alias}");
|
||||
}
|
||||
|
||||
if (!ct.VariesBySegment())
|
||||
{
|
||||
return Content($"The document type {alias} does not allow segments, nothing has been changed");
|
||||
}
|
||||
|
||||
ct.SetVariesBy(ContentVariation.Segment, false);
|
||||
|
||||
Services.ContentTypeService.Save(ct);
|
||||
return Content($"The document type {alias} no longer allows segments");
|
||||
return Content($"The document type {alias} does not have a property type {propertyTypeAlias ?? "null"}");
|
||||
}
|
||||
|
||||
public ActionResult AddSegmentData(int contentId, string propertyAlias, string value, string segment, string? culture = null)
|
||||
if (ct.Variations.VariesBySegment())
|
||||
{
|
||||
IContent content = Services.ContentService.GetById(contentId);
|
||||
if (content == null)
|
||||
{
|
||||
return Content($"No content found by id {contentId}");
|
||||
}
|
||||
|
||||
if (propertyAlias.IsNullOrWhiteSpace() || !content.HasProperty(propertyAlias))
|
||||
{
|
||||
return Content($"The content by id {contentId} does not contain a property with alias {propertyAlias ?? "null"}");
|
||||
}
|
||||
|
||||
if (content.ContentType.VariesByCulture() && culture.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Content($"The content by id {contentId} varies by culture but no culture was specified");
|
||||
}
|
||||
|
||||
if (value.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Content("'value' cannot be null");
|
||||
}
|
||||
|
||||
if (segment.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Content("'segment' cannot be null");
|
||||
}
|
||||
|
||||
content.SetValue(propertyAlias, value, culture, segment);
|
||||
Services.ContentService.Save(content);
|
||||
|
||||
return Content($"Segment value has been set on content {contentId} for property {propertyAlias}");
|
||||
return Content($"The document type {alias} already allows segments, nothing has been changed");
|
||||
}
|
||||
|
||||
ct.SetVariesBy(ContentVariation.Segment);
|
||||
propType.SetVariesBy(ContentVariation.Segment);
|
||||
|
||||
Services.ContentTypeService.Save(ct);
|
||||
return Content($"The document type {alias} and property type {propertyTypeAlias} now allows segments");
|
||||
}
|
||||
|
||||
private IActionResult HttpNotFound() => throw new NotImplementedException();
|
||||
|
||||
public IActionResult DisableDocTypeSegments(string alias)
|
||||
{
|
||||
if (_testDataSettings.Value.Enabled != true)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
var ct = Services.ContentTypeService.Get(alias);
|
||||
if (ct == null)
|
||||
{
|
||||
return Content($"No document type found by alias {alias}");
|
||||
}
|
||||
|
||||
if (!ct.VariesBySegment())
|
||||
{
|
||||
return Content($"The document type {alias} does not allow segments, nothing has been changed");
|
||||
}
|
||||
|
||||
ct.SetVariesBy(ContentVariation.Segment, false);
|
||||
|
||||
Services.ContentTypeService.Save(ct);
|
||||
return Content($"The document type {alias} no longer allows segments");
|
||||
}
|
||||
|
||||
public ActionResult AddSegmentData(int contentId, string propertyAlias, string value, string segment, string? culture = null)
|
||||
{
|
||||
var content = Services.ContentService.GetById(contentId);
|
||||
if (content == null)
|
||||
{
|
||||
return Content($"No content found by id {contentId}");
|
||||
}
|
||||
|
||||
if (propertyAlias.IsNullOrWhiteSpace() || !content.HasProperty(propertyAlias))
|
||||
{
|
||||
return Content(
|
||||
$"The content by id {contentId} does not contain a property with alias {propertyAlias ?? "null"}");
|
||||
}
|
||||
|
||||
if (content.ContentType.VariesByCulture() && culture.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Content($"The content by id {contentId} varies by culture but no culture was specified");
|
||||
}
|
||||
|
||||
if (value.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Content("'value' cannot be null");
|
||||
}
|
||||
|
||||
if (segment.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Content("'segment' cannot be null");
|
||||
}
|
||||
|
||||
content.SetValue(propertyAlias, value, culture, segment);
|
||||
Services.ContentService.Save(content);
|
||||
|
||||
return Content($"Segment value has been set on content {contentId} for property {propertyAlias}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user