diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroPropertyTable.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroPropertyTable.cs index 4349cd2f13..20480ad534 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroPropertyTable.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroPropertyTable.cs @@ -12,9 +12,21 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven [Migration("7.0.0", 5, GlobalSettings.UmbracoMigrationName)] public class AddIndexToCmsMacroPropertyTable : MigrationBase { + private readonly bool _skipIndexCheck; + + internal AddIndexToCmsMacroPropertyTable(bool skipIndexCheck) + { + _skipIndexCheck = skipIndexCheck; + } + + public AddIndexToCmsMacroPropertyTable() + { + + } + public override void Up() { - var dbIndexes = SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database) + var dbIndexes = _skipIndexCheck ? new DbIndexDefinition[]{} : SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database) .Select(x => new DbIndexDefinition() { TableName = x.Item1, diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroTable.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroTable.cs index 746a0da3bc..1be642b9d1 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroTable.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AddIndexToCmsMacroTable.cs @@ -1,4 +1,5 @@ using System; +using System.CodeDom; using System.Linq; using Umbraco.Core.Configuration; using Umbraco.Core.Persistence.DatabaseModelDefinitions; @@ -12,9 +13,21 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven [Migration("7.0.0", 4, GlobalSettings.UmbracoMigrationName)] public class AddIndexToCmsMacroTable : MigrationBase { + private readonly bool _skipIndexCheck; + + internal AddIndexToCmsMacroTable(bool skipIndexCheck) + { + _skipIndexCheck = skipIndexCheck; + } + + public AddIndexToCmsMacroTable() + { + + } + public override void Up() { - var dbIndexes = SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database) + var dbIndexes = _skipIndexCheck ? new DbIndexDefinition[] { } : SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database) .Select(x => new DbIndexDefinition() { TableName = x.Item1, diff --git a/src/Umbraco.Core/TypeFinder.cs b/src/Umbraco.Core/TypeFinder.cs index eb2443cea9..05292c349f 100644 --- a/src/Umbraco.Core/TypeFinder.cs +++ b/src/Umbraco.Core/TypeFinder.cs @@ -295,7 +295,7 @@ namespace Umbraco.Core "AutoMapper.", "AzureDirectory,", "itextsharp,", - "UrlRewritingNet." + "UrlRewritingNet.", "HtmlAgilityPack,", "MiniProfiler,", "Moq,", diff --git a/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs b/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs index 120b1f9a4f..dfb17bf2fb 100644 --- a/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Text; using NUnit.Framework; using Umbraco.Core.IO; -using Umbraco.Tests.BusinessLogic; namespace Umbraco.Tests.IO { diff --git a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs b/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs index d53f95e838..42415a4abb 100644 --- a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using NUnit.Framework; using Umbraco.Core.IO; -using Umbraco.Tests.BusinessLogic; + namespace Umbraco.Tests.IO { diff --git a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs new file mode 100644 index 0000000000..ea4d1aa213 --- /dev/null +++ b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs @@ -0,0 +1,131 @@ +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Rdbms; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.Caching; +using Umbraco.Core.Persistence.Migrations; +using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven; +using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.TestHelpers.Entities; + +namespace Umbraco.Tests.Migrations.Upgrades +{ + [NUnit.Framework.Ignore("This won't work because it is tested against the v6 database but once we upgrade the TagRelationshipDto to have the new cols the old cols wont exist in this test. Rest assured that this test did pass before I modified TagRelationshipDto. Just not sure how to force a legacy db to be created for a test.")] + [TestFixture] + public class ValidateV7TagsUpgradeTest : BaseDatabaseFactoryTest + { + private ContentRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository) + { + var templateRepository = new TemplateRepository(unitOfWork, NullCacheProvider.Current); + var tagRepository = new TagsRepository(unitOfWork, NullCacheProvider.Current); + contentTypeRepository = new ContentTypeRepository(unitOfWork, NullCacheProvider.Current, templateRepository); + var repository = new ContentRepository(unitOfWork, NullCacheProvider.Current, contentTypeRepository, templateRepository, tagRepository, CacheHelper.CreateDisabledCacheHelper()); + return repository; + } + + [Test] + public void Validate_Data_Upgrade() + { + var provider = new PetaPocoUnitOfWorkProvider(); + var unitOfWork = provider.GetUnitOfWork(); + ContentTypeRepository contentTypeRepository; + var insertedContent = new List(); + using (var repository = CreateRepository(unitOfWork, out contentTypeRepository)) + { + //we need to populate some data to upgrade + var contentTypeWith1Tag = MockedContentTypes.CreateSimpleContentType( + "tags1", "tags1", + new PropertyTypeCollection(new[] + { + new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags1", Name = "tags1", SortOrder = 1, DataTypeDefinitionId = 1041}, + })); + var contentTypeWith2Tags = MockedContentTypes.CreateSimpleContentType( + "tags2", "tags2", + new PropertyTypeCollection(new[] + { + new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags1", Name = "tags1", SortOrder = 1, DataTypeDefinitionId = 1041}, + new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags2", Name = "tags2", SortOrder = 1, DataTypeDefinitionId = 1041} + })); + + contentTypeRepository.AddOrUpdate(contentTypeWith1Tag); + contentTypeRepository.AddOrUpdate(contentTypeWith2Tags); + unitOfWork.Commit(); + + for (var i = 0; i < 10; i++) + { + var content = new Content("test" + i, -1, contentTypeWith1Tag) { Language = "en-US", CreatorId = 0, WriterId = 0 }; + var obj = new + { + tags1 = "tag1,tag2,tag3,tag4,tag5" + }; + content.PropertyValues(obj); + content.ResetDirtyProperties(false); + insertedContent.Add(content); + repository.AddOrUpdate(content); + } + for (var i = 0; i < 10; i++) + { + var content = new Content("test-multi" + i, -1, contentTypeWith2Tags) { Language = "en-US", CreatorId = 0, WriterId = 0 }; + var obj = new + { + //NOTE: These will always be the same during an upgrade since we can only support tags per document not per property + tags1 = "tag1,tag2,tag3,anothertag1,anothertag2", + tags2 = "tag1,tag2,tag3,anothertag1,anothertag2" + }; + content.PropertyValues(obj); + content.ResetDirtyProperties(false); + insertedContent.Add(content); + repository.AddOrUpdate(content); + } + unitOfWork.Commit(); + } + //now that we have to create some test tag data + foreach (var tag in "tag1,tag2,tag3,tag4,tag5,anothertag1,anothertag2".Split(',')) + { + DatabaseContext.Database.Insert(new TagDto {Tag = tag, Group = "default"}); + } + var alltags = DatabaseContext.Database.Fetch("SELECT * FROM cmsTags").ToArray(); + foreach (var content in insertedContent) + { + if (content.ContentType.Alias == "tags1") + { + var tags1Tags = alltags.Where(x => "tag1,tag2,tag3,tag4,tag5".Split(',').Contains(x.Tag)); + foreach (var t in tags1Tags) + { + DatabaseContext.Database.Insert(new TagRelationshipDto {NodeId = content.Id, TagId = t.Id}); + } + } + else + { + var tags1Tags = alltags.Where(x => "tag1,tag2,tag3,anothertag1,anothertag2".Split(',').Contains(x.Tag)); + foreach (var t in tags1Tags) + { + DatabaseContext.Database.Insert(new TagRelationshipDto { NodeId = content.Id, TagId = t.Id }); + } + } + } + + //lastly, we'll insert a tag relation with a relation to only an umbracoNode - + // this will generate a delete clause and a warning + DatabaseContext.Database.Insert(new TagRelationshipDto { NodeId = -1, TagId = alltags.First().Id }); + + + var migration = new AlterTagRelationsTable(); + var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, DatabaseContext.Database); + migration.GetUpExpressions(migrationContext); + + Assert.AreEqual( + (10 * 5) //the docs that only have 1 tag prop per document + + (10 * 5) //the docs that have 2 tag prop per document - these are the update statements + + (10 * 5) //the docs that have 2 tag prop per document - these are the insert statements + + 1//the delete clause + + 7 , //additional db expressions + migrationContext.Expressions.Count); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs index ec771d23bb..b1cfaadee2 100644 --- a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs +++ b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs @@ -1,135 +1,12 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; -using Umbraco.Core.Persistence.Caching; using Umbraco.Core.Persistence.Migrations; using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven; -using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.SqlSyntax; -using Umbraco.Core.Persistence.UnitOfWork; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.TestHelpers.Entities; namespace Umbraco.Tests.Migrations.Upgrades { - [NUnit.Framework.Ignore("This won't work because it is tested against the v6 database but once we upgrade the TagRelationshipDto to have the new cols the old cols wont exist in this test. Rest assured that this test did pass before I modified TagRelationshipDto. Just not sure how to force a legacy db to be created for a test.")] - [TestFixture] - public class ValidateV7TagsUpgradeTest : BaseDatabaseFactoryTest - { - private ContentRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository) - { - var templateRepository = new TemplateRepository(unitOfWork, NullCacheProvider.Current); - var tagRepository = new TagsRepository(unitOfWork, NullCacheProvider.Current); - contentTypeRepository = new ContentTypeRepository(unitOfWork, NullCacheProvider.Current, templateRepository); - var repository = new ContentRepository(unitOfWork, NullCacheProvider.Current, contentTypeRepository, templateRepository, tagRepository, CacheHelper.CreateDisabledCacheHelper()); - return repository; - } - - [Test] - public void Validate_Data_Upgrade() - { - var provider = new PetaPocoUnitOfWorkProvider(); - var unitOfWork = provider.GetUnitOfWork(); - ContentTypeRepository contentTypeRepository; - var insertedContent = new List(); - using (var repository = CreateRepository(unitOfWork, out contentTypeRepository)) - { - //we need to populate some data to upgrade - var contentTypeWith1Tag = MockedContentTypes.CreateSimpleContentType( - "tags1", "tags1", - new PropertyTypeCollection(new[] - { - new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags1", Name = "tags1", SortOrder = 1, DataTypeDefinitionId = 1041}, - })); - var contentTypeWith2Tags = MockedContentTypes.CreateSimpleContentType( - "tags2", "tags2", - new PropertyTypeCollection(new[] - { - new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags1", Name = "tags1", SortOrder = 1, DataTypeDefinitionId = 1041}, - new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags2", Name = "tags2", SortOrder = 1, DataTypeDefinitionId = 1041} - })); - - contentTypeRepository.AddOrUpdate(contentTypeWith1Tag); - contentTypeRepository.AddOrUpdate(contentTypeWith2Tags); - unitOfWork.Commit(); - - for (var i = 0; i < 10; i++) - { - var content = new Content("test" + i, -1, contentTypeWith1Tag) { Language = "en-US", CreatorId = 0, WriterId = 0 }; - var obj = new - { - tags1 = "tag1,tag2,tag3,tag4,tag5" - }; - content.PropertyValues(obj); - content.ResetDirtyProperties(false); - insertedContent.Add(content); - repository.AddOrUpdate(content); - } - for (var i = 0; i < 10; i++) - { - var content = new Content("test-multi" + i, -1, contentTypeWith2Tags) { Language = "en-US", CreatorId = 0, WriterId = 0 }; - var obj = new - { - //NOTE: These will always be the same during an upgrade since we can only support tags per document not per property - tags1 = "tag1,tag2,tag3,anothertag1,anothertag2", - tags2 = "tag1,tag2,tag3,anothertag1,anothertag2" - }; - content.PropertyValues(obj); - content.ResetDirtyProperties(false); - insertedContent.Add(content); - repository.AddOrUpdate(content); - } - unitOfWork.Commit(); - } - //now that we have to create some test tag data - foreach (var tag in "tag1,tag2,tag3,tag4,tag5,anothertag1,anothertag2".Split(',')) - { - DatabaseContext.Database.Insert(new TagDto {Tag = tag, Group = "default"}); - } - var alltags = DatabaseContext.Database.Fetch("SELECT * FROM cmsTags").ToArray(); - foreach (var content in insertedContent) - { - if (content.ContentType.Alias == "tags1") - { - var tags1Tags = alltags.Where(x => "tag1,tag2,tag3,tag4,tag5".Split(',').Contains(x.Tag)); - foreach (var t in tags1Tags) - { - DatabaseContext.Database.Insert(new TagRelationshipDto {NodeId = content.Id, TagId = t.Id}); - } - } - else - { - var tags1Tags = alltags.Where(x => "tag1,tag2,tag3,anothertag1,anothertag2".Split(',').Contains(x.Tag)); - foreach (var t in tags1Tags) - { - DatabaseContext.Database.Insert(new TagRelationshipDto { NodeId = content.Id, TagId = t.Id }); - } - } - } - - //lastly, we'll insert a tag relation with a relation to only an umbracoNode - - // this will generate a delete clause and a warning - DatabaseContext.Database.Insert(new TagRelationshipDto { NodeId = -1, TagId = alltags.First().Id }); - - - var migration = new AlterTagRelationsTable(); - var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, DatabaseContext.Database); - migration.GetUpExpressions(migrationContext); - - Assert.AreEqual( - (10 * 5) //the docs that only have 1 tag prop per document - + (10 * 5) //the docs that have 2 tag prop per document - these are the update statements - + (10 * 5) //the docs that have 2 tag prop per document - these are the insert statements - + 1//the delete clause - + 7 , //additional db expressions - migrationContext.Expressions.Count); - } - } - [TestFixture] public class ValidateV7UpgradeTest { @@ -140,7 +17,7 @@ namespace Umbraco.Tests.Migrations.Upgrades { SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider(); - var migration = new AddIndexToCmsMacroTable(); + var migration = new AddIndexToCmsMacroTable(true); var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, null); migration.GetUpExpressions(migrationContext); @@ -156,7 +33,7 @@ namespace Umbraco.Tests.Migrations.Upgrades { SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider(); - var migration = new AddIndexToCmsMacroPropertyTable(); + var migration = new AddIndexToCmsMacroPropertyTable(true); var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, null); migration.GetUpExpressions(migrationContext); diff --git a/src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs b/src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs index 0699370259..67ef3a2bf5 100644 --- a/src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs +++ b/src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs @@ -10,12 +10,13 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.EntityBase; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; namespace Umbraco.Tests.Models.Collections { [TestFixture] - public class PropertyCollectionTests + public class PropertyCollectionTests : BaseUmbracoConfigurationTest { [Test] public void SimpleOrder_Returns_Null_On_FirstOrDefault_When_Empty() diff --git a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs index 155fa4ac0b..21687d20c6 100644 --- a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs +++ b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs @@ -1,13 +1,16 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core.Models; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; namespace Umbraco.Tests.Models { [TestFixture] - public class ContentExtensionsTests + public class ContentExtensionsTests : BaseUmbracoConfigurationTest { + + [Test] public void Should_Create_New_Version_When_Publishing() { diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 4d62dcf809..ce14404196 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -16,6 +16,8 @@ using umbraco; namespace Umbraco.Tests.Models.Mapping { + [RequiresAutoMapperMappings] + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)] [TestFixture] public class ContentWebModelMappingTests : BaseDatabaseFactoryTest { @@ -25,11 +27,6 @@ namespace Umbraco.Tests.Models.Mapping } - protected override DatabaseBehavior DatabaseTestBehavior - { - get { return DatabaseBehavior.NewSchemaPerFixture; } - } - //protected override void FreezeResolution() //{ // PropertyEditorResolver.Current = new PropertyEditorResolver( diff --git a/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs index 4af1ff0279..5907b6c6be 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs @@ -11,6 +11,7 @@ using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Persistence.Repositories { + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)] [TestFixture] public class MacroRepositoryTest : BaseDatabaseFactoryTest { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index 09b140940a..960b1aee57 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -10,7 +10,7 @@ using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Persistence.Repositories { - [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)] + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)] [TestFixture] public class StylesheetRepositoryTest : BaseDatabaseFactoryTest { diff --git a/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs index 846e059298..0a8c478736 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Tests.TestHelpers.Entities; namespace Umbraco.Tests.Persistence.Repositories { + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)] [TestFixture] public class TagRepositoryTest : BaseDatabaseFactoryTest { @@ -553,7 +554,7 @@ namespace Umbraco.Tests.Persistence.Repositories var content1 = MockedContent.CreateSimpleContent(contentType); contentRepository.AddOrUpdate(content1); unitOfWork.Commit(); - var mediaType = MockedContentTypes.CreateImageMediaType(); + var mediaType = MockedContentTypes.CreateImageMediaType("image2"); mediaTypeRepository.AddOrUpdate(mediaType); unitOfWork.Commit(); var media1 = MockedMedia.CreateMediaImage(mediaType, -1); @@ -609,7 +610,7 @@ namespace Umbraco.Tests.Persistence.Repositories var content1 = MockedContent.CreateSimpleContent(contentType); contentRepository.AddOrUpdate(content1); unitOfWork.Commit(); - var mediaType = MockedContentTypes.CreateImageMediaType(); + var mediaType = MockedContentTypes.CreateImageMediaType("image2"); mediaTypeRepository.AddOrUpdate(mediaType); unitOfWork.Commit(); var media1 = MockedMedia.CreateMediaImage(mediaType, -1); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index 703bfde6b1..e8378df75d 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -18,10 +18,6 @@ namespace Umbraco.Tests.PublishedContent [TestFixture] public class PublishedContentMoreTests : PublishedContentTestBase { - protected override DatabaseBehavior DatabaseTestBehavior - { - get { return DatabaseBehavior.NoDatabasePerFixture; } - } // read http://stackoverflow.com/questions/7713326/extension-method-that-works-on-ienumerablet-and-iqueryablet // and http://msmvps.com/blogs/jon_skeet/archive/2010/10/28/overloading-and-generic-constraints.aspx diff --git a/src/Umbraco.Tests/Services/MacroServiceTests.cs b/src/Umbraco.Tests/Services/MacroServiceTests.cs index 926702c8e4..5ef75d0b14 100644 --- a/src/Umbraco.Tests/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests/Services/MacroServiceTests.cs @@ -3,9 +3,11 @@ using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Services { + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)] [TestFixture, RequiresSTA] public class MacroServiceTests : BaseServiceTest { diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index e79db0e4b0..ec1148e1c3 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -82,7 +82,7 @@ namespace Umbraco.Tests.TestHelpers base.Initialize(); - using (DisposableTimer.TraceDuration("base db init")) + using (DisposableTimer.TraceDuration("init")) { //TODO: Somehow make this faster - takes 5s + @@ -251,17 +251,20 @@ namespace Umbraco.Tests.TestHelpers [TearDown] public override void TearDown() { - _isFirstTestInFixture = false; //ensure this is false before anything! - - if (DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerTest) + using (DisposableTimer.TraceDuration("teardown")) { - RemoveDatabaseFile(); - } - - AppDomain.CurrentDomain.SetData("DataDirectory", null); + _isFirstTestInFixture = false; //ensure this is false before anything! - SqlSyntaxContext.SqlSyntaxProvider = null; + if (DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerTest) + { + RemoveDatabaseFile(); + } + AppDomain.CurrentDomain.SetData("DataDirectory", null); + + SqlSyntaxContext.SqlSyntaxProvider = null; + } + base.TearDown(); } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 2f574df791..74c27562d8 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -1,4 +1,7 @@ -using AutoMapper; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using AutoMapper; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models.Mapping; @@ -28,13 +31,12 @@ namespace Umbraco.Tests.TestHelpers { base.Initialize(); - using (DisposableTimer.TraceDuration("init")) + using (DisposableTimer.TraceDuration("init", "init")) { TestHelper.InitializeContentDirectories(); TestHelper.EnsureUmbracoSettingsConfig(); - //Create the legacy prop-eds mapping - LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors(); + InitializeLegacyMappingsForCoreEditors(); SetupPluginManager(); @@ -52,33 +54,65 @@ namespace Umbraco.Tests.TestHelpers { base.TearDown(); - //reset settings - SettingsForTests.Reset(); - UmbracoContext.Current = null; - TestHelper.CleanContentDirectories(); - TestHelper.CleanUmbracoSettingsConfig(); - //reset the app context, this should reset most things that require resetting like ALL resolvers - ObjectExtensions.DisposeIfDisposable(ApplicationContext.Current); - ApplicationContext.Current = null; - ResetPluginManager(); - LegacyPropertyEditorIdToAliasConverter.Reset(); + using (DisposableTimer.TraceDuration("teardown")) + { + //reset settings + SettingsForTests.Reset(); + UmbracoContext.Current = null; + TestHelper.CleanContentDirectories(); + TestHelper.CleanUmbracoSettingsConfig(); + //reset the app context, this should reset most things that require resetting like ALL resolvers + ObjectExtensions.DisposeIfDisposable(ApplicationContext.Current); + ApplicationContext.Current = null; + ResetPluginManager(); + } + } + private static readonly object Locker = new object(); + private static volatile bool _legacyMappingInit = false; + + private static void InitializeLegacyMappingsForCoreEditors() + { + if (_legacyMappingInit == false) + { + lock (Locker) + { + if (_legacyMappingInit == false) + { + _legacyMappingInit = true; + //Create the legacy prop-eds mapping + LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors(); + } + } + } + } + + /// + /// If this class requires auto-mapper mapping initialization then init them + /// + /// + /// This is an opt-in option because initializing the mappers takes about 500ms which equates to quite a lot + /// of time with every test. + /// private void InitializeMappers() { - Mapper.Initialize(configuration => + if (this.GetType().GetCustomAttribute(false) != null) { - var mappers = PluginManager.Current.FindAndCreateInstances( - specificAssemblies: new[] + Mapper.Initialize(configuration => + { + var mappers = PluginManager.Current.FindAndCreateInstances( + specificAssemblies: new[] { typeof(ContentModelMapper).Assembly, typeof(ApplicationRegistrar).Assembly }); - foreach (var mapper in mappers) - { - mapper.ConfigureMappings(configuration, ApplicationContext); - } - }); + foreach (var mapper in mappers) + { + mapper.ConfigureMappings(configuration, ApplicationContext); + } + }); + } } /// @@ -128,7 +162,20 @@ namespace Umbraco.Tests.TestHelpers { if (PluginManager.Current == null || PluginManagerResetRequired) { - PluginManager.Current = new PluginManager(false); + PluginManager.Current = new PluginManager(false); + PluginManager.Current.AssembliesToScan = new[] + { + Assembly.Load("Umbraco.Core"), + Assembly.Load("umbraco"), + Assembly.Load("Umbraco.Tests"), + Assembly.Load("businesslogic"), + Assembly.Load("cms"), + Assembly.Load("controls"), + Assembly.Load("umbraco.editorControls"), + Assembly.Load("umbraco.MacroEngines"), + Assembly.Load("umbraco.providers"), + Assembly.Load("Umbraco.Web.UI"), + }; } } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs index d1596e8ff3..db4b87ab11 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs @@ -19,14 +19,22 @@ namespace Umbraco.Tests.TestHelpers [SetUp] public virtual void Initialize() { - SettingsForTests.Reset(); + using (DisposableTimer.TraceDuration("init")) + { + SettingsForTests.Reset(); + } + } [TearDown] public virtual void TearDown() { //reset settings - SettingsForTests.Reset(); + using (DisposableTimer.TraceDuration("teardown")) + { + SettingsForTests.Reset(); + } + } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/TestHelpers/RequiresAutoMapperMappingsAttribute.cs b/src/Umbraco.Tests/TestHelpers/RequiresAutoMapperMappingsAttribute.cs new file mode 100644 index 0000000000..3dc28d24e1 --- /dev/null +++ b/src/Umbraco.Tests/TestHelpers/RequiresAutoMapperMappingsAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace Umbraco.Tests.TestHelpers +{ + [AttributeUsage(AttributeTargets.Class)] + public sealed class RequiresAutoMapperMappingsAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs b/src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs index 2c96af1836..dfe64beda2 100644 --- a/src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs +++ b/src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs @@ -13,6 +13,7 @@ namespace Umbraco.Tests.TreesAndSections ///This is a test class for ApplicationTreeTest and is intended ///to contain all ApplicationTreeTest Unit Tests /// + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)] [TestFixture()] public class ApplicationTreeTest : BaseDatabaseFactoryTest { diff --git a/src/Umbraco.Tests/TreesAndSections/SectionTests.cs b/src/Umbraco.Tests/TreesAndSections/SectionTests.cs index e6c1a71516..47564a3d81 100644 --- a/src/Umbraco.Tests/TreesAndSections/SectionTests.cs +++ b/src/Umbraco.Tests/TreesAndSections/SectionTests.cs @@ -12,6 +12,8 @@ namespace Umbraco.Tests.TreesAndSections ///This is a test class for ApplicationTest and is intended ///to contain all ApplicationTest Unit Tests /// + [RequiresAutoMapperMappings] + [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)] [TestFixture()] public class SectionTests : BaseDatabaseFactoryTest { diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 7a8fc916fb..35619c8a36 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -176,6 +176,7 @@ + @@ -403,6 +404,7 @@ +