Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 12 additions & 13 deletions tests/Umbraco.TestData/Configuration/TestDataSettings.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
namespace Umbraco.TestData.Configuration
namespace Umbraco.TestData.Configuration;

public class TestDataSettings
{
public class TestDataSettings
{
/// <summary>
/// Gets or sets a value indicating whether the test data generation is enabled.
/// </summary>
public bool Enabled { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether the test data generation is enabled.
/// </summary>
public bool Enabled { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether persisted local database cache files for content and media are disabled.
/// </summary>
/// <value>The URL path.</value>
public bool IgnoreLocalDb { get; set; } = false;
}
/// <summary>
/// Gets or sets a value indicating whether persisted local database cache files for content and media are disabled.
/// </summary>
/// <value>The URL path.</value>
public bool IgnoreLocalDb { get; set; } = false;
}
66 changes: 31 additions & 35 deletions tests/Umbraco.TestData/Extensions/UmbracoBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,44 @@
using Umbraco.Cms.Web.Common.ApplicationBuilder;
using Umbraco.TestData.Configuration;

namespace Umbraco.TestData.Extensions
namespace Umbraco.TestData.Extensions;

public static class UmbracoBuilderExtensions
{
public static class UmbracoBuilderExtensions
public static IUmbracoBuilder AddUmbracoTestData(this IUmbracoBuilder builder)
{
public static IUmbracoBuilder AddUmbracoTestData(this IUmbracoBuilder builder)
if (builder.Services.Any(x => x.ServiceType == typeof(LoadTestController)))
{
if (builder.Services.Any(x => x.ServiceType == typeof(LoadTestController)))
{
// We assume the test data project is composed if any implementations of LoadTestController exist.
return builder;
}
// We assume the test data project is composed if any implementations of LoadTestController exist.
return builder;
}

IConfigurationSection testDataSection = builder.Config.GetSection("Umbraco:CMS:TestData");
TestDataSettings config = testDataSection.Get<TestDataSettings>();
if (config == null || config.Enabled == false)
{
return builder;
}
var testDataSection = builder.Config.GetSection("Umbraco:CMS:TestData");
var config = testDataSection.Get<TestDataSettings>();
if (config == null || config.Enabled == false)
{
return builder;
}

builder.Services.Configure<TestDataSettings>(testDataSection);

builder.Services.Configure<TestDataSettings>(testDataSection);
if (config.IgnoreLocalDb)
{
builder.Services.AddSingleton(factory => new PublishedSnapshotServiceOptions { IgnoreLocalDb = true });
}

if (config.IgnoreLocalDb)
builder.Services.Configure<UmbracoPipelineOptions>(options =>
options.AddFilter(new UmbracoPipelineFilter(nameof(LoadTestController))
{
builder.Services.AddSingleton(factory => new PublishedSnapshotServiceOptions
{
IgnoreLocalDb = true
});
}

builder.Services.Configure<UmbracoPipelineOptions>(options =>
options.AddFilter(new UmbracoPipelineFilter(nameof(LoadTestController))
{
Endpoints = app => app.UseEndpoints(endpoints =>
endpoints.MapControllerRoute(
"LoadTest",
"/LoadTest/{action}",
new { controller = "LoadTest", Action = "Index" }))
}));

builder.Services.AddScoped(typeof(LoadTestController));
Endpoints = app => app.UseEndpoints(endpoints =>
endpoints.MapControllerRoute(
"LoadTest",
"/LoadTest/{action}",
new { controller = "LoadTest", Action = "Index" }))
}));

return builder;
}
builder.Services.AddScoped(typeof(LoadTestController));

return builder;
}
}
9 changes: 4 additions & 5 deletions tests/Umbraco.TestData/LoadTestComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting

namespace Umbraco.TestData
namespace Umbraco.TestData;

public class LoadTestComposer : IComposer
{
public class LoadTestComposer : IComposer
{
public void Compose(IUmbracoBuilder builder) => builder.AddUmbracoTestData();
}
public void Compose(IUmbracoBuilder builder) => builder.AddUmbracoTestData();
}
Loading