From 4ea0fa0a19f436117e38959a7204bc2e181e24ac Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 23 Jan 2015 12:34:51 +1100 Subject: [PATCH 1/6] Fixes: U4-6163 Remove LanguageLocale column from cmsContentVersion --- .../RemoveLanguageLocaleColumn.cs | 23 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + .../Repositories/MediaRepositoryTest.cs | 12 +++------- .../businesslogic/translation/Translation.cs | 1 + src/umbraco.cms/umbraco.cms.csproj | 4 +--- 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/RemoveLanguageLocaleColumn.cs diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/RemoveLanguageLocaleColumn.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/RemoveLanguageLocaleColumn.cs new file mode 100644 index 0000000000..9e28994ca4 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/RemoveLanguageLocaleColumn.cs @@ -0,0 +1,23 @@ +using System.Linq; +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero +{ + [Migration("7.3.0", 4, GlobalSettings.UmbracoMigrationName)] + public class RemoveLanguageLocaleColumn : MigrationBase + { + public override void Up() + { + var columns = SqlSyntax.GetColumnsInSchema(Context.Database).Distinct().ToArray(); + + if (columns.Any(x => x.ColumnName.InvariantEquals("LanguageLocale") && x.TableName.InvariantEquals("cmsContentVersion"))) + { + Delete.Column("LanguageLocale").FromTable("cmsContentVersion"); + } + } + + public override void Down() + { + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 4c904fc3e3..59f9f0a7fa 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -326,6 +326,7 @@ + diff --git a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs index 5267cb1ca8..348f2015f7 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs @@ -3,21 +3,15 @@ using System.Linq; using System.Xml.Linq; using Moq; using NUnit.Framework; -using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence; - using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.Repositories; -using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; -using umbraco.editorControls.tinyMCE3; -using umbraco.interfaces; using Umbraco.Core.Persistence.DatabaseModelDefinitions; namespace Umbraco.Tests.Persistence.Repositories @@ -40,9 +34,9 @@ namespace Umbraco.Tests.Persistence.Repositories private MediaRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out MediaTypeRepository mediaTypeRepository) { - mediaTypeRepository = new MediaTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); - var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); - var repository = new MediaRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, mediaTypeRepository, tagRepository); + mediaTypeRepository = new MediaTypeRepository(unitOfWork, CacheHelper, Mock.Of(), SqlSyntax); + var tagRepository = new TagRepository(unitOfWork, CacheHelper, Mock.Of(), SqlSyntax); + var repository = new MediaRepository(unitOfWork, CacheHelper, Mock.Of(), SqlSyntax, mediaTypeRepository, tagRepository); return repository; } diff --git a/src/umbraco.cms/businesslogic/translation/Translation.cs b/src/umbraco.cms/businesslogic/translation/Translation.cs index 42ca56c574..03348470e2 100644 --- a/src/umbraco.cms/businesslogic/translation/Translation.cs +++ b/src/umbraco.cms/businesslogic/translation/Translation.cs @@ -12,6 +12,7 @@ using Umbraco.Core.IO; namespace umbraco.cms.businesslogic.translation { + [Obsolete("This will be removed in future versions, the translation utility will not work perfectly in v7.x")] public class Translation { public static void MakeNew(CMSNode Node, User User, User Translator, Language Language, string Comment, diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index 8c5b18bac9..f96dde9a43 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -418,9 +418,7 @@ PackageFiles.Designer.cs - - - + False From 50ed207211ab7ef998346c5ce7900a0882d0a149 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 23 Jan 2015 14:32:09 +1100 Subject: [PATCH 2/6] error check during stylesheet upgrade --- src/Umbraco.Core/ApplicationContext.cs | 2 +- .../MigrateStylesheetDataToFile.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs index f42e4723fc..3634ae58ad 100644 --- a/src/Umbraco.Core/ApplicationContext.cs +++ b/src/Umbraco.Core/ApplicationContext.cs @@ -229,7 +229,7 @@ namespace Umbraco.Core if (currentVersion != configStatus) { - ProfilingLogger.Logger.Info("CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'"); + ProfilingLogger.Logger.Debug("CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'"); } diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/MigrateStylesheetDataToFile.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/MigrateStylesheetDataToFile.cs index 1b169d8e68..05a5b54f5f 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/MigrateStylesheetDataToFile.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/MigrateStylesheetDataToFile.cs @@ -23,6 +23,10 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe { public override void Up() { + //Don't exeucte if the stylesheet table is not there + var tables = SqlSyntax.GetTablesInSchema(Context.Database).ToArray(); + if (tables.InvariantContains("cmsStylesheet") == false) return; + //This is all rather nasty but it's how stylesheets used to work in the 2 various ugly ways so we just have to // deal with that to get this migration done From 070fc368b2ba16cf32822309b0704b985031411e Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 23 Jan 2015 16:34:57 +1100 Subject: [PATCH 3/6] Adds new public access db tables, removes refs to languagelocale col, fixes the migration script to create a table with a PK --- src/Umbraco.Core/Models/Rdbms/AccessDto.cs | 27 ++++++++++++++ .../Models/Rdbms/AccessRuleDto.cs | 25 +++++++++++++ .../Models/Rdbms/ContentVersionDto.cs | 5 --- .../Persistence/Factories/ContentFactory.cs | 2 -- .../Persistence/Mappers/ContentMapper.cs | 1 - .../Initial/DatabaseSchemaCreation.cs | 5 ++- .../Expressions/CreateTableExpression.cs | 24 ++++++++++--- .../Syntax/Create/Table/CreateTableBuilder.cs | 23 ++++++++++++ .../AddPublicAccessTables.cs | 36 +++++++++++++++++++ .../Repositories/ContentRepository.cs | 15 -------- .../Interfaces/IContentRepository.cs | 8 ----- src/Umbraco.Core/Umbraco.Core.csproj | 3 ++ .../Repositories/ContentRepositoryTest.cs | 28 --------------- .../Repositories/MemberRepositoryTest.cs | 2 +- 14 files changed, 139 insertions(+), 65 deletions(-) create mode 100644 src/Umbraco.Core/Models/Rdbms/AccessDto.cs create mode 100644 src/Umbraco.Core/Models/Rdbms/AccessRuleDto.cs create mode 100644 src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddPublicAccessTables.cs diff --git a/src/Umbraco.Core/Models/Rdbms/AccessDto.cs b/src/Umbraco.Core/Models/Rdbms/AccessDto.cs new file mode 100644 index 0000000000..486b755095 --- /dev/null +++ b/src/Umbraco.Core/Models/Rdbms/AccessDto.cs @@ -0,0 +1,27 @@ +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.DatabaseAnnotations; + +namespace Umbraco.Core.Models.Rdbms +{ + [TableName("umbracoAccess")] + [PrimaryKey("id")] + [ExplicitColumns] + internal class AccessDto + { + [Column("id")] + [PrimaryKeyColumn(Name = "PK_umbracoAccess")] + public int Id { get; set; } + + [Column("nodeId")] + [ForeignKey(typeof(NodeDto), Name = "FK_umbracoAccess_umbracoNode_id")] + public int NodeId { get; set; } + + [Column("loginNodeId")] + [ForeignKey(typeof(NodeDto), Name = "FK_umbracoAccess_umbracoNode_id1")] + public int LoginNodeId { get; set; } + + [Column("noAccessNodeId")] + [ForeignKey(typeof(NodeDto), Name = "FK_umbracoAccess_umbracoNode_id2")] + public int AccessDeniedNodeId { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/AccessRuleDto.cs b/src/Umbraco.Core/Models/Rdbms/AccessRuleDto.cs new file mode 100644 index 0000000000..6b006fabb7 --- /dev/null +++ b/src/Umbraco.Core/Models/Rdbms/AccessRuleDto.cs @@ -0,0 +1,25 @@ +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.DatabaseAnnotations; + +namespace Umbraco.Core.Models.Rdbms +{ + [TableName("umbracoAccessRule")] + [PrimaryKey("id")] + [ExplicitColumns] + internal class AccessRuleDto + { + [Column("id")] + [PrimaryKeyColumn(Name = "PK_umbracoAccessRule")] + public int Id { get; set; } + + [Column("accessId")] + [ForeignKey(typeof(AccessDto), Name = "FK_umbracoAccessRule_umbracoAccess_id")] + public int AccessId { get; set; } + + [Column("claim")] + public string Claim { get; set; } + + [Column("claimType")] + public string ClaimType { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/ContentVersionDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentVersionDto.cs index 1181f7d70d..9b1fa02dae 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentVersionDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentVersionDto.cs @@ -26,11 +26,6 @@ namespace Umbraco.Core.Models.Rdbms [Constraint(Default = "getdate()")] public DateTime VersionDate { get; set; } - [Column("LanguageLocale")] - [Length(10)] - [NullSetting(NullSetting = NullSettings.Null)] - public string Language { get; set; } - [ResultColumn] public ContentDto ContentDto { get; set; } } diff --git a/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs b/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs index 3e2477594d..0208a7a128 100644 --- a/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs @@ -38,7 +38,6 @@ namespace Umbraco.Core.Persistence.Factories : _id.ToGuid(), Name = dto.Text, NodeName = dto.ContentVersionDto.ContentDto.NodeDto.Text, - Language = dto.ContentVersionDto.Language, Path = dto.ContentVersionDto.ContentDto.NodeDto.Path, CreatorId = dto.ContentVersionDto.ContentDto.NodeDto.UserId.Value, WriterId = dto.WriterUserId, @@ -107,7 +106,6 @@ namespace Umbraco.Core.Persistence.Factories NodeId = entity.Id, VersionDate = entity.UpdateDate, VersionId = entity.Version, - Language = lang, ContentDto = BuildContentDto(entity) }; return contentVersionDto; diff --git a/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs b/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs index 7d2f73bac4..1cc29cf959 100644 --- a/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs @@ -47,7 +47,6 @@ namespace Umbraco.Core.Persistence.Mappers CacheMap(src => src.ContentTypeId, dto => dto.ContentTypeId); CacheMap(src => src.UpdateDate, dto => dto.VersionDate); CacheMap(src => src.Version, dto => dto.VersionId); - CacheMap(src => src.Language, dto => dto.Language); CacheMap(src => src.Name, dto => dto.Text); CacheMap(src => src.ExpireDate, dto => dto.ExpiresDate); CacheMap(src => src.ReleaseDate, dto => dto.ReleaseDate); diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs index 8f75bbb189..b77e0843ea 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs @@ -78,7 +78,10 @@ namespace Umbraco.Core.Persistence.Migrations.Initial {37, typeof (User2AppDto)}, {38, typeof (User2NodeNotifyDto)}, {39, typeof (User2NodePermissionDto)}, - {40, typeof (ServerRegistrationDto)} + {40, typeof (ServerRegistrationDto)}, + + {41, typeof (AccessDto)}, + {42, typeof (AccessRuleDto)} }; #endregion diff --git a/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Expressions/CreateTableExpression.cs b/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Expressions/CreateTableExpression.cs index 4ca4db5989..c048bda198 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Expressions/CreateTableExpression.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Expressions/CreateTableExpression.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.SqlSyntax; @@ -6,12 +7,27 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions { public class CreateTableExpression : MigrationExpressionBase { + [Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")] public CreateTableExpression() { Columns = new List(); } - public CreateTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders) + [Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")] + public CreateTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) + : base(current, databaseProviders) + { + Columns = new List(); + } + + public CreateTableExpression(ISqlSyntaxProvider sqlSyntax) + : base(sqlSyntax) + { + Columns = new List(); + } + + public CreateTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax) + : base(current, databaseProviders, sqlSyntax) { Columns = new List(); } @@ -22,9 +38,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions public override string ToString() { - var table = new TableDefinition{Name = TableName, SchemaName = SchemaName, Columns = Columns}; + var table = new TableDefinition { Name = TableName, SchemaName = SchemaName, Columns = Columns }; - return string.Format(SqlSyntaxContext.SqlSyntaxProvider.Format(table)); + return string.Format(SqlSyntax.Format(table)); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Table/CreateTableBuilder.cs b/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Table/CreateTableBuilder.cs index c62c1ca205..58eef672eb 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Table/CreateTableBuilder.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Syntax/Create/Table/CreateTableBuilder.cs @@ -85,6 +85,17 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table public ICreateTableColumnOptionSyntax PrimaryKey() { CurrentColumn.IsPrimaryKey = true; + + var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey) + { + Constraint = + { + TableName = CurrentColumn.TableName, + Columns = new[] { CurrentColumn.Name } + } + }; + _context.Expressions.Add(expression); + return this; } @@ -92,6 +103,18 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table { CurrentColumn.IsPrimaryKey = true; CurrentColumn.PrimaryKeyName = primaryKeyName; + + var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey) + { + Constraint = + { + ConstraintName = primaryKeyName, + TableName = CurrentColumn.TableName, + Columns = new[] { CurrentColumn.Name } + } + }; + _context.Expressions.Add(expression); + return this; } diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddPublicAccessTables.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddPublicAccessTables.cs new file mode 100644 index 0000000000..e2a5318051 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddPublicAccessTables.cs @@ -0,0 +1,36 @@ +using System.Linq; +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero +{ + [Migration("7.3.0", 5, GlobalSettings.UmbracoMigrationName)] + public class AddPublicAccessTables : MigrationBase + { + public override void Up() + { + //Don't exeucte if the table is already there + var tables = SqlSyntax.GetTablesInSchema(Context.Database).ToArray(); + if (tables.InvariantContains("umbracoAccess")) return; + + Create.Table("umbracoAccess") + .WithColumn("id").AsInt32().NotNullable().Identity().PrimaryKey("PK_umbracoAccess") + .WithColumn("nodeId").AsInt32().NotNullable().ForeignKey("FK_umbracoAccess_umbracoNode_id", "umbracoNode", "id") + .WithColumn("loginNodeId").AsInt32().NotNullable().ForeignKey("FK_umbracoAccess_umbracoNode_id1", "umbracoNode", "id") + .WithColumn("noAccessNodeId").AsInt32().NotNullable().ForeignKey("FK_umbracoAccess_umbracoNode_id2", "umbracoNode", "id"); + + Create.Table("umbracoAccessRule") + .WithColumn("id").AsInt32().NotNullable().Identity().PrimaryKey("PK_umbracoAccessRule") + .WithColumn("accessId").AsInt32().NotNullable().ForeignKey("FK_umbracoAccessRule_umbracoAccess_id", "umbracoAccess", "id") + .WithColumn("claim").AsString().NotNullable() + .WithColumn("claimType").AsString().NotNullable(); + + //Create.PrimaryKey("PK_cmsContentType2ContentType") + // .OnTable("cmsContentType2ContentType") + // .Columns(new[] { "parentContentTypeId", "childContentTypeId" }); + } + + public override void Down() + { + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index 60951f6086..55ec8b3b25 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -629,21 +629,6 @@ namespace Umbraco.Core.Persistence.Repositories } } - public IContent GetByLanguage(int id, string language) - { - var sql = GetBaseQuery(false); - sql.Where(GetBaseWhereClause(), new { Id = id }); - sql.Where(x => x.Language == language); - sql.OrderByDescending(x => x.VersionDate); - - var dto = Database.Fetch(sql).FirstOrDefault(); - - if (dto == null) - return null; - - return GetByVersion(dto.ContentVersionDto.VersionId); - } - /// /// Assigns a single permission to the current content item for the specified user ids /// diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs index 5cb470b7cd..e3311862e9 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs @@ -33,14 +33,6 @@ namespace Umbraco.Core.Persistence.Repositories /// void ClearPublished(IContent content); - /// - /// Gets a specific language version of an - /// - /// Id of the to retrieve version from - /// Culture code for the language to retrieve - /// An item - IContent GetByLanguage(int id, string language); - /// /// Gets all published Content by the specified query /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 59f9f0a7fa..b759c51634 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -320,12 +320,15 @@ + + + diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs index f74f70cce2..2a65297864 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs @@ -681,34 +681,6 @@ namespace Umbraco.Tests.Persistence.Repositories } - [Test] - public void Can_Create_Different_Language_Version() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - ContentTypeRepository contentTypeRepository; - using (var repository = CreateRepository(unitOfWork, out contentTypeRepository)) - { - var content = repository.Get(NodeDto.NodeIdSeed + 2); - - // Act - content.Language = "da-DK"; - content.Name = "Tekst Side 1"; - repository.AddOrUpdate(content); - unitOfWork.Commit(); - - var latest = repository.Get(NodeDto.NodeIdSeed + 2); - var english = repository.GetByLanguage(NodeDto.NodeIdSeed + 2, "en-US"); - var danish = repository.GetByLanguage(NodeDto.NodeIdSeed + 2, "da-DK"); - - // Assert - Assert.That(latest.Name, Is.EqualTo("Tekst Side 1")); - Assert.That(english.Name, Is.EqualTo("Text Page 1")); - Assert.That(danish.Name, Is.EqualTo("Tekst Side 1")); - } - } - public void CreateTestData() { //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) diff --git a/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs index 9769a91cb2..0f0b9ed48f 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs @@ -389,7 +389,7 @@ namespace Umbraco.Tests.Persistence.Repositories var sql = new Sql(); sql.Select("umbracoNode.*", "cmsContent.contentType", "cmsContentType.alias AS ContentTypeAlias", "cmsContentVersion.VersionId", - "cmsContentVersion.VersionDate", "cmsContentVersion.LanguageLocale", "cmsMember.Email", + "cmsContentVersion.VersionDate", "cmsMember.Email", "cmsMember.LoginName", "cmsMember.Password", "cmsPropertyData.id AS PropertyDataId", "cmsPropertyData.propertytypeid", "cmsPropertyData.dataDate", "cmsPropertyData.dataInt", "cmsPropertyData.dataNtext", "cmsPropertyData.dataNvarchar", "cmsPropertyType.id", "cmsPropertyType.Alias", "cmsPropertyType.Description", From bd5833ec5fcb1cb199432183d764f113cfd7530c Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 23 Jan 2015 16:40:17 +1100 Subject: [PATCH 4/6] adds tests --- .../Persistence/BaseTableByTableTest.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs index 8fd0c8230a..2467bf8a54 100644 --- a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs @@ -61,7 +61,7 @@ namespace Umbraco.Tests.Persistence //assign the service context new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(_logger), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, _logger), cacheHelper, - new ProfilingLogger(new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test-log4net.config"))), Mock.Of())) + new ProfilingLogger(_logger, Mock.Of())) { IsReady = true }; @@ -94,6 +94,31 @@ namespace Umbraco.Tests.Persistence } } + [Test] + public void Can_Create_umbracoAccess_Table() + { + using (Transaction transaction = Database.GetTransaction()) + { + DatabaseSchemaHelper.CreateTable(); + DatabaseSchemaHelper.CreateTable(); + + //transaction.Complete(); + } + } + + [Test] + public void Can_Create_umbracoAccessRule_Table() + { + using (Transaction transaction = Database.GetTransaction()) + { + DatabaseSchemaHelper.CreateTable(); + DatabaseSchemaHelper.CreateTable(); + DatabaseSchemaHelper.CreateTable(); + + //transaction.Complete(); + } + } + [Test] public void Can_Create_umbracoApp_Table() { From a5c1b0b2f23e453d8fd6e88aa0aa853e8684c362 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 27 Jan 2015 14:52:24 +1100 Subject: [PATCH 5/6] Fixes tests, decouples the UrlSegmentProviderResolver a little bit --- src/Umbraco.Core/Services/ServiceContext.cs | 42 +++++++++---------- src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs | 2 +- .../Repositories/StylesheetRepositoryTest.cs | 2 + .../Routing/NiceUrlProviderTests.cs | 6 ++- .../TestHelpers/BaseUmbracoApplicationTest.cs | 1 - src/Umbraco.Tests/TestHelpers/MockHelper.cs | 26 ++---------- 6 files changed, 31 insertions(+), 48 deletions(-) diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index b635e33e9b..d04a396666 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -88,27 +88,27 @@ namespace Umbraco.Core.Services IDomainService domainService = null, ITaskService taskService = null) { - if (_auditService != null) _auditService = new Lazy(() => auditService); - if (_localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService); - if (_tagService != null) _tagService = new Lazy(() => tagService); - if (_contentService != null) _contentService = new Lazy(() => contentService); - if (_mediaService != null) _mediaService = new Lazy(() => mediaService); - if (_contentTypeService != null) _contentTypeService = new Lazy(() => contentTypeService); - if (_dataTypeService != null) _dataTypeService = new Lazy(() => dataTypeService); - if (_fileService != null) _fileService = new Lazy(() => fileService); - if (_localizationService != null) _localizationService = new Lazy(() => localizationService); - if (_packagingService != null) _packagingService = new Lazy(() => packagingService); - if (_entityService != null) _entityService = new Lazy(() => entityService); - if (_relationService != null) _relationService = new Lazy(() => relationService); - if (_sectionService != null) _sectionService = new Lazy(() => sectionService); - if (_memberGroupService != null) _memberGroupService = new Lazy(() => memberGroupService); - if (_memberTypeService != null) _memberTypeService = new Lazy(() => memberTypeService); - if (_treeService != null) _treeService = new Lazy(() => treeService); - if (_memberService != null) _memberService = new Lazy(() => memberService); - if (_userService != null) _userService = new Lazy(() => userService); - if (_notificationService != null) _notificationService = new Lazy(() => notificationService); - if (_domainService != null) _domainService = new Lazy(() => domainService); - if (_taskService != null) _taskService = new Lazy(() => taskService); + if (auditService != null) _auditService = new Lazy(() => auditService); + if (localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService); + if (tagService != null) _tagService = new Lazy(() => tagService); + if (contentService != null) _contentService = new Lazy(() => contentService); + if (mediaService != null) _mediaService = new Lazy(() => mediaService); + if (contentTypeService != null) _contentTypeService = new Lazy(() => contentTypeService); + if (dataTypeService != null) _dataTypeService = new Lazy(() => dataTypeService); + if (fileService != null) _fileService = new Lazy(() => fileService); + if (localizationService != null) _localizationService = new Lazy(() => localizationService); + if (packagingService != null) _packagingService = new Lazy(() => packagingService); + if (entityService != null) _entityService = new Lazy(() => entityService); + if (relationService != null) _relationService = new Lazy(() => relationService); + if (sectionService != null) _sectionService = new Lazy(() => sectionService); + if (memberGroupService != null) _memberGroupService = new Lazy(() => memberGroupService); + if (memberTypeService != null) _memberTypeService = new Lazy(() => memberTypeService); + if (treeService != null) _treeService = new Lazy(() => treeService); + if (memberService != null) _memberService = new Lazy(() => memberService); + if (userService != null) _userService = new Lazy(() => userService); + if (notificationService != null) _notificationService = new Lazy(() => notificationService); + if (domainService != null) _domainService = new Lazy(() => domainService); + if (taskService != null) _taskService = new Lazy(() => taskService); } internal ServiceContext( diff --git a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs index 9c76cbefe0..3cac22e448 100644 --- a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs @@ -423,7 +423,7 @@ namespace Umbraco.Tests.Mvc logger, settings, "/dang", 0); - var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider() }); + var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider(settings.RequestHandler) }); var routingContext = new RoutingContext( umbracoContext, Enumerable.Empty(), diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index 8521da23b7..dcbab3dd88 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -223,6 +223,8 @@ p{font-size:2em;}")); [TearDown] public void TearDown() { + base.TearDown(); + //Delete all files var files = _fileSystem.GetFiles("", "*.css"); foreach (var file in files) diff --git a/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs b/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs index 457e215db7..075205ef5c 100644 --- a/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs @@ -140,13 +140,15 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Nice_Url_Relative_Or_Absolute() { - var routingContext = GetRoutingContext("http://example.com/test", 1111); - SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; var requestMock = Mock.Get(_umbracoSettings.RequestHandler); requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); + var routingContext = GetRoutingContext("http://example.com/test", 1111, umbracoSettings: _umbracoSettings); + + + Assert.AreEqual("/home/sub1/custom-sub-1/", routingContext.UrlProvider.GetUrl(1177)); requestMock.Setup(x => x.UseDomainPrefixes).Returns(true); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 29f28e3551..12914c8ecd 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -188,7 +188,6 @@ namespace Umbraco.Tests.TestHelpers Assembly.Load("umbraco.editorControls"), Assembly.Load("umbraco.MacroEngines"), Assembly.Load("umbraco.providers"), - Assembly.Load("Umbraco.Web.UI"), } }; } diff --git a/src/Umbraco.Tests/TestHelpers/MockHelper.cs b/src/Umbraco.Tests/TestHelpers/MockHelper.cs index ae7245b855..c95b9fc8c2 100644 --- a/src/Umbraco.Tests/TestHelpers/MockHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/MockHelper.cs @@ -11,13 +11,8 @@ namespace Umbraco.Tests.TestHelpers { public static class MockHelper { - public static ServiceContext GetMockedServiceContext(IUmbracoSettingsSection settings = null, ILogger logger = null, CacheHelper cacheHelper = null, ISqlSyntaxProvider sqlSyntax = null) + public static ServiceContext GetMockedServiceContext() { - if (settings == null) settings = SettingsForTests.GetDefault(); - if (logger == null) logger = Mock.Of(); - if (cacheHelper == null) cacheHelper = CacheHelper.CreateDisabledCacheHelper(); - if (sqlSyntax == null) sqlSyntax = Mock.Of(); - return new ServiceContext( new Mock().Object, new Mock().Object, @@ -25,24 +20,9 @@ namespace Umbraco.Tests.TestHelpers new Mock().Object, new Mock().Object, new Mock().Object, - new PackagingService( - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new RepositoryFactory(cacheHelper, logger, sqlSyntax, settings), - new Mock().Object), + new Mock().Object, new Mock().Object, - new RelationService( - new Mock().Object, - new RepositoryFactory(cacheHelper, logger, sqlSyntax, settings), - logger, - new Mock().Object), + new Mock().Object, new Mock().Object, new Mock().Object, new Mock().Object, From f8600725b21dec5edc395b804efa11a0be880903 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 27 Jan 2015 14:58:59 +1100 Subject: [PATCH 6/6] Fixes service context ctor to allow IMacroService --- src/Umbraco.Core/Services/ServiceContext.cs | 5 ++++- src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs | 2 +- src/Umbraco.Tests/TestHelpers/MockHelper.cs | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index d04a396666..bf1a7e77e5 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -65,6 +65,7 @@ namespace Umbraco.Core.Services /// /// /// + /// public ServiceContext( IContentService contentService = null, IMediaService mediaService = null, @@ -86,7 +87,8 @@ namespace Umbraco.Core.Services ILocalizedTextService localizedTextService = null, IAuditService auditService = null, IDomainService domainService = null, - ITaskService taskService = null) + ITaskService taskService = null, + IMacroService macroService = null) { if (auditService != null) _auditService = new Lazy(() => auditService); if (localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService); @@ -109,6 +111,7 @@ namespace Umbraco.Core.Services if (notificationService != null) _notificationService = new Lazy(() => notificationService); if (domainService != null) _domainService = new Lazy(() => domainService); if (taskService != null) _taskService = new Lazy(() => taskService); + if (macroService != null) _macroService = new Lazy(() => macroService); } internal ServiceContext( diff --git a/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs b/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs index 089f78ac3e..295bb695e5 100644 --- a/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs +++ b/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Routing protected ServiceContext GetServiceContext(IUmbracoSettingsSection umbracoSettings, ILogger logger) { //get the mocked service context to get the mocked domain service - var svcCtx = MockHelper.GetMockedServiceContext(umbracoSettings, logger); + var svcCtx = MockHelper.GetMockedServiceContext(); var domainService = Mock.Get(svcCtx.DomainService); //setup mock domain service domainService.Setup(service => service.GetAll(It.IsAny())) diff --git a/src/Umbraco.Tests/TestHelpers/MockHelper.cs b/src/Umbraco.Tests/TestHelpers/MockHelper.cs index c95b9fc8c2..f81c7439d7 100644 --- a/src/Umbraco.Tests/TestHelpers/MockHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/MockHelper.cs @@ -33,7 +33,9 @@ namespace Umbraco.Tests.TestHelpers new Mock().Object, new Mock().Object, new Mock().Object, - new Mock().Object); + new Mock().Object, + new Mock().Object, + new Mock().Object); } } } \ No newline at end of file