using System; using System.Collections.Generic; using System.Linq; using System.Threading; using LightInject; using Moq; using NUnit.Framework; 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.Services; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Web.Routing; namespace Umbraco.Tests.TestHelpers { [TestFixture] [Apartment(ApartmentState.STA)] public abstract class BaseWebTest : TestWithDatabaseBase { protected override void Initialize() { base.Initialize(); // need to specify a custom callback for unit tests // AutoPublishedContentTypes generates properties automatically var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(Mock.Of())) { Id = 1 }); var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeService); var type = new AutoPublishedContentType(0, "anything", new PublishedPropertyType[] { }); ContentTypesCache.GetPublishedContentTypeByAlias = alias => type; } protected override string GetXmlContent(int templateId) { return @" ]> 1 This is some content]]> "; } internal PublishedRouter CreatePublishedRouter(IServiceContainer container = null, ContentFinderCollection contentFinders = null) { return CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting, container, contentFinders); } internal static PublishedRouter CreatePublishedRouter(IWebRoutingSection webRoutingSection, IServiceContainer container = null, ContentFinderCollection contentFinders = null) { return new PublishedRouter( webRoutingSection, contentFinders ?? new ContentFinderCollection(Enumerable.Empty()), new TestLastChanceFinder(), container?.TryGetInstance() ?? new ServiceContext(), new ProfilingLogger(Mock.Of(), Mock.Of())); } } }