Files
Umbraco-CMS/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs

72 lines
3.5 KiB
C#
Raw Normal View History

2016-11-05 19:23:55 +01:00
using System;
2016-11-07 19:12:09 +01:00
using Umbraco.Core;
2016-11-05 19:23:55 +01:00
2016-12-16 10:40:14 +01:00
namespace Umbraco.Tests.Testing
2016-11-05 19:23:55 +01:00
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, /*AllowMultiple = false,*/ Inherited = false)]
2017-09-19 18:47:07 +02:00
public class UmbracoTestAttribute : TestOptionAttributeBase
2016-11-05 19:23:55 +01:00
{
/// <summary>
/// Gets or sets a value indicating whether tests are "WithApplication".
/// </summary>
/// <remarks>
/// <para>Default is false.</para>
/// <para>This is for tests that inherited from TestWithApplicationBase.</para>
2019-03-26 18:47:35 +01:00
/// <para>Implies Mapper = true (, ResetPluginManager = false).</para>
/// </remarks>
2017-05-12 14:49:44 +02:00
public bool WithApplication { get => _withApplication.ValueOrDefault(false); set => _withApplication.Set(value); }
private readonly Settable<bool> _withApplication = new Settable<bool>();
/// <summary>
2019-03-26 18:47:35 +01:00
/// Gets or sets a value indicating whether to compose and initialize the mapper.
/// </summary>
/// <remarks>Default is false unless WithApplication is true, in which case default is true.</remarks>
2019-03-26 18:47:35 +01:00
public bool Mapper { get => _mapper.ValueOrDefault(WithApplication); set => _mapper.Set(value); }
private readonly Settable<bool> _mapper = new Settable<bool>();
2016-11-05 19:23:55 +01:00
// FIXME: to be completed
/// <summary>
/// Gets or sets a value indicating ...
/// </summary>
2017-10-31 12:48:24 +01:00
public bool PublishedRepositoryEvents { get => _publishedRepositoryEvents.ValueOrDefault(false); set => _publishedRepositoryEvents.Set(value); }
private readonly Settable<bool> _publishedRepositoryEvents = new Settable<bool>();
2016-11-05 19:23:55 +01:00
/// <summary>
/// Gets or sets a value indicating the required logging support.
/// </summary>
/// <remarks>Default is to mock logging.</remarks>
2017-05-12 14:49:44 +02:00
public UmbracoTestOptions.Logger Logger { get => _logger.ValueOrDefault(UmbracoTestOptions.Logger.Mock); set => _logger.Set(value); }
private readonly Settable<UmbracoTestOptions.Logger> _logger = new Settable<UmbracoTestOptions.Logger>();
2016-11-05 19:23:55 +01:00
/// <summary>
/// Gets or sets a value indicating the required database support.
/// </summary>
/// <remarks>Default is no database support.</remarks>
2017-05-12 14:49:44 +02:00
public UmbracoTestOptions.Database Database { get => _database.ValueOrDefault(UmbracoTestOptions.Database.None); set => _database.Set(value); }
private readonly Settable<UmbracoTestOptions.Database> _database = new Settable<UmbracoTestOptions.Database>();
2017-05-30 15:33:13 +02:00
/// <summary>
/// Gets or sets a value indicating the required plugin manager support.
/// </summary>
/// <remarks>Default is to use the global tests plugin manager.</remarks>
public UmbracoTestOptions.TypeLoader TypeLoader { get => _typeLoader.ValueOrDefault(UmbracoTestOptions.TypeLoader.Default); set => _typeLoader.Set(value); }
private readonly Settable<UmbracoTestOptions.TypeLoader> _typeLoader = new Settable<UmbracoTestOptions.TypeLoader>();
2017-05-30 15:33:13 +02:00
2017-09-19 18:47:07 +02:00
protected override TestOptionAttributeBase Merge(TestOptionAttributeBase other)
2016-11-05 19:23:55 +01:00
{
2017-09-19 18:47:07 +02:00
if (!(other is UmbracoTestAttribute attr))
throw new ArgumentException(nameof(other));
2016-11-05 19:23:55 +01:00
2017-09-19 18:47:07 +02:00
base.Merge(other);
2016-11-05 19:23:55 +01:00
2019-03-26 18:47:35 +01:00
_mapper.Set(attr._mapper);
2017-10-31 12:48:24 +01:00
_publishedRepositoryEvents.Set(attr._publishedRepositoryEvents);
2017-09-19 18:47:07 +02:00
_logger.Set(attr._logger);
_database.Set(attr._database);
_typeLoader.Set(attr._typeLoader);
2016-11-05 19:23:55 +01:00
return this;
}
}
}