diff --git a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs index f506933631..c69efed5d8 100644 --- a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs +++ b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs @@ -147,15 +147,20 @@ namespace Umbraco.Tests.Services.Importing var xml = XElement.Parse(strXml); var element = xml.Descendants("Templates").First(); var packagingService = ServiceContext.PackagingService; + var init = ServiceContext.FileService.GetTemplates().Count(); // Act var templates = packagingService.ImportTemplates(element); var numberOfTemplates = (from doc in element.Elements("Template") select doc).Count(); + var allTemplates = ServiceContext.FileService.GetTemplates(); // Assert Assert.That(templates, Is.Not.Null); Assert.That(templates.Any(), Is.True); Assert.That(templates.Count(), Is.EqualTo(numberOfTemplates)); + + Assert.AreEqual(init + numberOfTemplates, allTemplates.Count()); + Assert.IsTrue(allTemplates.All(x => x.Content.Contains("UmbracoTemplatePage"))); } [Test] diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 49def25762..8db672f59c 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.TestHelpers SetupApplicationContext(); - InitializeMappers(); + InitializeMappers(); FreezeResolution(); @@ -80,7 +80,7 @@ namespace Umbraco.Tests.TestHelpers public override void TearDown() { base.TearDown(); - + //reset settings SettingsForTests.Reset(); UmbracoContext.Current = null; @@ -97,9 +97,10 @@ namespace Umbraco.Tests.TestHelpers protected virtual void ConfigureContainer() { + // oh no! should not use a container in unit tests? var settings = SettingsForTests.GetDefault(); - //register mappers + //register mappers Container.RegisterFrom(); Container.RegisterFrom(); @@ -109,7 +110,7 @@ namespace Umbraco.Tests.TestHelpers //Default Datalayer/Repositories/SQL/Database/etc... Container.RegisterFrom(); - //register basic stuff that might need to be there for some container resolvers to work, we can + //register basic stuff that might need to be there for some container resolvers to work, we can // add more to this in base classes in resolution freezing Container.RegisterSingleton(factory => Logger); Container.Register(factory => CacheHelper); @@ -127,8 +128,12 @@ namespace Umbraco.Tests.TestHelpers Container.RegisterSingleton(factory => Mock.Of(), "PartialViewFileSystem"); Container.RegisterSingleton(factory => Mock.Of(), "PartialViewMacroFileSystem"); Container.RegisterSingleton(factory => Mock.Of(), "StylesheetFileSystem"); - Container.RegisterSingleton(factory => Mock.Of(), "MasterpageFileSystem"); - Container.RegisterSingleton(factory => Mock.Of(), "ViewFileSystem"); + + // need real file systems here as templates content is on-disk only + //Container.RegisterSingleton(factory => Mock.Of(), "MasterpageFileSystem"); + //Container.RegisterSingleton(factory => Mock.Of(), "ViewFileSystem"); + Container.RegisterSingleton(factory => new PhysicalFileSystem("Views", "/views"), "ViewFileSystem"); + Container.RegisterSingleton(factory => new PhysicalFileSystem("MasterPages", "/masterpages"), "MasterpageFileSystem"); } private static readonly object Locker = new object(); @@ -173,7 +178,7 @@ namespace Umbraco.Tests.TestHelpers } /// - /// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan + /// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan /// all of the assemblies. Inheritors can override this if plugin manager resetting is required, generally needs /// to be set to true if the SetupPluginManager has been overridden. /// @@ -207,7 +212,7 @@ namespace Umbraco.Tests.TestHelpers /// Inheritors can override this if they wish to create a custom application context /// protected virtual void SetupApplicationContext() - { + { var evtMsgs = new TransientMessagesFactory(); ApplicationContext.Current = new ApplicationContext( //assign the db context @@ -215,13 +220,13 @@ namespace Umbraco.Tests.TestHelpers Logger, SqlSyntax, "System.Data.SqlServerCe.4.0"), //assign the service context ServiceContextHelper.GetServiceContext( - Container.GetInstance(), - new NPocoUnitOfWorkProvider(Logger), + Container.GetInstance(), + new NPocoUnitOfWorkProvider(Logger), new FileUnitOfWorkProvider(), - new PublishingStrategy(evtMsgs, Logger), - CacheHelper, - Logger, - evtMsgs, + new PublishingStrategy(evtMsgs, Logger), + CacheHelper, + Logger, + evtMsgs, Enumerable.Empty()), CacheHelper, ProfilingLogger) @@ -273,7 +278,7 @@ namespace Umbraco.Tests.TestHelpers protected ProfilingLogger ProfilingLogger { get; private set; } protected CacheHelper CacheHelper { get; private set; } - //I know tests shouldn't use IoC, but for all these tests inheriting from this class are integration tests + //I know tests shouldn't use IoC, but for all these tests inheriting from this class are integration tests // and the number of these will hopefully start getting greatly reduced now that most things are mockable. internal IServiceContainer Container { get; private set; }