using System; using System.Linq; using System.Threading; using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Request; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Tests.Testing.Objects.Accessors; using Umbraco.Web; using Umbraco.Web.Composing; using Umbraco.Web.Models.PublishedContent; using Umbraco.Web.Routing; using Umbraco.Web.Security; namespace Umbraco.Tests.TestHelpers { [TestFixture] [Apartment(ApartmentState.STA)] public abstract class BaseWebTest : TestWithDatabaseBase { protected override void Compose() { base.Compose(); base.Compose(); Composition.RegisterUnique(); Composition.RegisterUnique(); } protected override void Initialize() { base.Initialize(); // need to specify a custom callback for unit tests // AutoPublishedContentTypes generates properties automatically var type = new AutoPublishedContentType(0, "anything", new PublishedPropertyType[] { }); ContentTypesCache.GetPublishedContentTypeByAlias = alias => GetPublishedContentTypeByAlias(alias) ?? type; } protected virtual PublishedContentType GetPublishedContentTypeByAlias(string alias) => null; protected override string GetXmlContent(int templateId) { return @" ]> 1 This is some content]]> "; } internal PublishedRouter CreatePublishedRouter(IFactory container = null, ContentFinderCollection contentFinders = null) { return CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting, container ?? Factory, contentFinders); } internal static PublishedRouter CreatePublishedRouter(IWebRoutingSection webRoutingSection, IFactory container = null, ContentFinderCollection contentFinders = null) { return new PublishedRouter( webRoutingSection, contentFinders ?? new ContentFinderCollection(Enumerable.Empty()), new TestLastChanceFinder(), new TestVariationContextAccessor(), new ProfilingLogger(Mock.Of(), Mock.Of()), container?.TryGetInstance() ?? Current.Factory.GetInstance(), Mock.Of(), Mock.Of(), container?.GetInstance() ?? Current.Factory.GetInstance(), container?.GetInstance()?? Current.Factory.GetInstance(), container?.GetInstance()?? Current.Factory.GetInstance(), container?.GetInstance() ?? Current.Factory.GetInstance(), container?.GetInstance() ?? Current.Factory.GetInstance() ); } } }