// Copyright (c) Umbraco. // See LICENSE for more details. using System; using Umbraco.Cms.Core; namespace Umbraco.Cms.Tests.Common.Testing { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, /*AllowMultiple = false,*/ Inherited = false)] public class UmbracoTestAttribute : TestOptionAttributeBase { /// /// Gets or sets a value indicating whether tests are "WithApplication". /// /// /// Default is false. /// This is for tests that inherited from TestWithApplicationBase. /// Implies Mapper = true (, ResetPluginManager = false). /// public bool WithApplication { get => _withApplication.ValueOrDefault(false); set => _withApplication.Set(value); } private readonly Settable _withApplication = new Settable(); /// /// Gets or sets a value indicating whether to compose and initialize the mapper. /// /// Default is false unless WithApplication is true, in which case default is true. public bool Mapper { get => _mapper.ValueOrDefault(WithApplication); set => _mapper.Set(value); } private readonly Settable _mapper = new Settable(); /// /// Gets or sets a value indicating whether the LEGACY XML Cache used in tests should bind to repository events /// public bool PublishedRepositoryEvents { get => _publishedRepositoryEvents.ValueOrDefault(false); set => _publishedRepositoryEvents.Set(value); } private readonly Settable _publishedRepositoryEvents = new Settable(); /// /// Gets or sets a value indicating the required logging support. /// /// Default is to mock logging. public UmbracoTestOptions.Logger Logger { get => _logger.ValueOrDefault(UmbracoTestOptions.Logger.Mock); set => _logger.Set(value); } private readonly Settable _logger = new Settable(); /// /// Gets or sets a value indicating the required database support. /// /// Default is no database support. public UmbracoTestOptions.Database Database { get => _database.ValueOrDefault(UmbracoTestOptions.Database.None); set => _database.Set(value); } private readonly Settable _database = new Settable(); /// /// Gets or sets a value indicating the required plugin manager support. /// /// Default is to use the global tests plugin manager. public UmbracoTestOptions.TypeLoader TypeLoader { get => _typeLoader.ValueOrDefault(UmbracoTestOptions.TypeLoader.Default); set => _typeLoader.Set(value); } public bool Boot { get => _boot.ValueOrDefault(false); set => _boot.Set(value); } private readonly Settable _boot = new Settable(); private readonly Settable _typeLoader = new Settable(); protected override TestOptionAttributeBase Merge(TestOptionAttributeBase other) { if (!(other is UmbracoTestAttribute attr)) { throw new ArgumentException(nameof(other)); } base.Merge(other); _boot.Set(attr.Boot); _mapper.Set(attr._mapper); _publishedRepositoryEvents.Set(attr._publishedRepositoryEvents); _logger.Set(attr._logger); _database.Set(attr._database); _typeLoader.Set(attr._typeLoader); return this; } } }