From 797eb34f36aaf691ae482d115e67e78692d98c96 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 3 Feb 2016 13:43:51 +0100 Subject: [PATCH] Fixes merge issues and tests --- .../Cache/FullDataSetRepositoryCachePolicy.cs | 28 +++++-------------- .../Repositories/ContentTypeBaseRepository.cs | 4 +-- src/Umbraco.Core/StringExtensions.cs | 10 +++++++ .../Repositories/TemplateRepositoryTest.cs | 20 ++++++------- .../Strings/StylesheetHelperTests.cs | 7 +++-- 5 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs index a7c37ef939..9b37d1861f 100644 --- a/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs @@ -29,20 +29,6 @@ namespace Umbraco.Core.Cache private bool? _hasZeroCountCache; - public override TEntity[] GetAll(TId[] ids, Func> getFromRepo) - { - //process the base logic without any Ids - we want to cache them all! - var result = base.GetAll(new TId[] { }, getFromRepo); - - //now that the base result has been calculated, they will all be cached. - // Now we can just filter by ids if they have been supplied - - return ids.Any() - ? result.Where(x => ids.Contains(_getEntityId(x))).ToArray() - : result; - } - - protected string GetCacheTypeKey() { return string.Format("uRepo_{0}_", typeof(TEntity).Name); @@ -127,7 +113,7 @@ namespace Umbraco.Core.Cache public override bool Exists(TId id, Func getFromRepo) { //Force get all with cache - var found = GetAll(new TId[] {}, ids => _getAllFromRepo().WhereNotNull()); + var found = GetAll(new TId[] { }, ids => _getAllFromRepo().WhereNotNull()); //we don't have anything in cache (this should never happen), just return from the repo return found == null @@ -142,9 +128,9 @@ namespace Umbraco.Core.Cache //now that the base result has been calculated, they will all be cached. // Now we can just filter by ids if they have been supplied - - return (ids.Any() - ? result.Where(x => ids.Contains(_getEntityId(x))).ToArray() + + return (ids.Any() + ? result.Where(x => ids.Contains(_getEntityId(x))).ToArray() : result) //We must ensure to deep clone each one out manually since the deep clone list only clones one way .Select(x => (TEntity)x.DeepClone()) @@ -167,7 +153,7 @@ namespace Umbraco.Core.Cache } //we need to do the lookup from the repo - var entityCollection = getFromRepo(new TId[] {}) + var entityCollection = getFromRepo(new TId[] { }) //ensure we don't include any null refs in the returned collection! .WhereNotNull() .ToArray(); @@ -232,12 +218,12 @@ namespace Umbraco.Core.Cache protected TEntity[] GetAllFromCache() { var found = Cache.GetCacheItem>(GetCacheTypeKey()); - + //This method will get called before checking for zero count cache, so we'll just set the flag here _hasZeroCountCache = found != null; return found == null ? new TEntity[] { } : found.WhereNotNull().ToArray(); } - + } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs index fc2e49a8e5..907f66435e 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs @@ -839,8 +839,8 @@ AND umbracoNode.id <> @id", //now create the content type object - var factory = new MediaTypeFactory(new Guid(Constants.ObjectTypes.MediaType)); - var mediaType = factory.BuildEntity(contentTypeDto); + var factory = new ContentTypeFactory(); + var mediaType = factory.BuildMediaTypeEntity(contentTypeDto); //map the allowed content types mediaType.AllowedContentTypes = currAllowedContentTypes; diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index b6d6d7ce27..8006741a05 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -41,6 +41,16 @@ namespace Umbraco.Core ToCSharpEscapeChars[escape[0]] = escape[1]; } + /// + /// Removes new lines and tabs + /// + /// + /// + internal static string StripBlockWhitespace(this string txt) + { + return Regex.Replace(txt, @"^\s+|\s+$|\s+(?=\s)|\n|\r\n", string.Empty); + } + internal static string StripFileExtension(this string fileName) { //filenames cannot contain line breaks diff --git a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs index 3f168d4741..09da68c477 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -103,7 +104,7 @@ namespace Umbraco.Tests.Persistence.Repositories -".CrLf(), template.Content); +".StripBlockWhitespace(), template.Content.StripBlockWhitespace()); } } @@ -132,7 +133,7 @@ namespace Umbraco.Tests.Persistence.Repositories Assert.That(_masterPageFileSystem.FileExists("test2.master"), Is.True); Assert.AreEqual(@"<%@ Master Language=""C#"" MasterPageFile=""~/masterpages/test.master"" AutoEventWireup=""true"" %> -".CrLf(), template2.Content); +".StripBlockWhitespace(), template2.Content.StripBlockWhitespace()); } } @@ -176,10 +177,9 @@ namespace Umbraco.Tests.Persistence.Repositories //Assert Assert.That(repository.Get("test"), Is.Not.Null); Assert.That(_viewsFileSystem.FileExists("test.cshtml"), Is.True); - Assert.AreEqual(@"@inherits Umbraco.Web.Mvc.UmbracoTemplatePage -@{ -" + "\t" + @"Layout = null; -}".Lf(), template.Content.Lf()); + Assert.AreEqual( + @"@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = null;}".StripBlockWhitespace(), + template.Content.StripBlockWhitespace()); } } @@ -206,12 +206,10 @@ namespace Umbraco.Tests.Persistence.Repositories //Assert Assert.That(repository.Get("test2"), Is.Not.Null); Assert.That(_viewsFileSystem.FileExists("test2.cshtml"), Is.True); - Assert.AreEqual(@"@inherits Umbraco.Web.Mvc.UmbracoTemplatePage -@{ -" + "\t" + @"Layout = ""test.cshtml""; -}".Lf(), template2.Content.Lf()); + Assert.AreEqual( + "@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = \"test.cshtml\";}".StripBlockWhitespace(), + template2.Content.StripBlockWhitespace()); } - } [Test] diff --git a/src/Umbraco.Tests/Strings/StylesheetHelperTests.cs b/src/Umbraco.Tests/Strings/StylesheetHelperTests.cs index 94c44e8114..c4de4cab17 100644 --- a/src/Umbraco.Tests/Strings/StylesheetHelperTests.cs +++ b/src/Umbraco.Tests/Strings/StylesheetHelperTests.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Text; using NUnit.Framework; +using Umbraco.Core; using Umbraco.Core.Strings.Css; namespace Umbraco.Tests.Strings @@ -22,7 +23,7 @@ namespace Umbraco.Tests.Strings }); Assert.AreEqual(@"body {font-family:Arial;}/**umb_name:My new rule*/ -p{font-size:1em; color:blue;} /** umb_name: Test2 */ li {padding:0px;} table {margin:0;}".CrLf(), result); +p{font-size:1em; color:blue;} /** umb_name: Test2 */ li {padding:0px;} table {margin:0;}".StripBlockWhitespace(), result.StripBlockWhitespace()); } [Test] @@ -40,7 +41,7 @@ p{font-size:1em; color:blue;} /** umb_name: Test2 */ li {padding:0px;} table {m Assert.AreEqual(@"body {font-family:Arial;}/** Umb_Name: Test1 */ p { font-size: 1em; } /** umb_name: Test2 */ li {padding:0px;} table {margin:0;} /**umb_name:My new rule*/ -p{font-size:1em; color:blue;}".CrLf(), result); +p{font-size:1em; color:blue;}".StripBlockWhitespace(), result.StripBlockWhitespace()); } [Test] @@ -95,7 +96,7 @@ font-size: 1em; //Assert.IsTrue(results.First().RuleId.Value.Value.ToString() == file.Id.Value.Value + "/" + name); Assert.AreEqual(name, results.First().Name); Assert.AreEqual(selector, results.First().Selector); - Assert.AreEqual(styles.CrLf(), results.First().Styles); + Assert.AreEqual(styles.StripBlockWhitespace(), results.First().Styles.StripBlockWhitespace()); } // No Name: keyword