Skip to content

Commit

Permalink
manual merge pass #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Oct 2, 2018
1 parent edc9744 commit 0c5cf52
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 41 deletions.
24 changes: 24 additions & 0 deletions src/Umbraco.Core/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,30 @@ public static bool CsvContains(this string csv, string value)
return idCheckList.Contains(value);
}

/// <summary>
/// Converts a file name to a friendly name for a content item
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string ToFriendlyName(this string fileName)
{
// strip the file extension
fileName = fileName.StripFileExtension();

// underscores and dashes to spaces
fileName = fileName.ReplaceMany(new[] { '_', '-' }, ' ');

// any other conversions ?

// Pascalcase (to be done last)
fileName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(fileName);

// Replace multiple consecutive spaces with a single space
fileName = string.Join(" ", fileName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

return fileName;
}

// From: http://stackoverflow.com/a/961504/5018
// filters control characters but allows only properly-formed surrogate sequences
private static readonly Lazy<Regex> InvalidXmlChars = new Lazy<Regex>(() =>
Expand Down
34 changes: 19 additions & 15 deletions src/Umbraco.Tests/Persistence/Repositories/AuditRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.Dtos;
using Umbraco.Core.Persistence.Querying;
Expand Down Expand Up @@ -63,43 +64,46 @@ public void Get_Paged_Items()
[Test]
public void Get_Paged_Items_By_User_Id_With_Query_And_Filter()
{
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
using (var repo = new AuditRepository(unitOfWork, CacheHelper, Logger, SqlSyntax))
var sp = TestObjects.GetScopeProvider(Logger);
using (var scope = sp.CreateScope())
{
for (int i = 0; i < 100; i++)
var repo = new AuditRepository((IScopeAccessor)sp, CacheHelper, Logger);

for (var i = 0; i < 100; i++)
{
repo.AddOrUpdate(new AuditItem(i, string.Format("Content {0} created", i), AuditType.New, 0));
repo.AddOrUpdate(new AuditItem(i, string.Format("Content {0} published", i), AuditType.Publish, 0));
repo.Save(new AuditItem(i, $"Content {i} created", AuditType.New, 0));
repo.Save(new AuditItem(i, $"Content {i} published", AuditType.Publish, 0));
}
unitOfWork.Commit();

scope.Complete();
}

using (var repo = new AuditRepository(unitOfWork, CacheHelper, Logger, SqlSyntax))
using (var scope = sp.CreateScope())
{
var query = Query<IAuditItem>.Builder.Where(x => x.UserId == 0);
var repo = new AuditRepository((IScopeAccessor)sp, CacheHelper, Logger);

var query = sp.SqlContext.Query<IAuditItem>().Where(x => x.UserId == 0);

try
{
DatabaseContext.Database.EnableSqlTrace = true;
DatabaseContext.Database.EnableSqlCount();
scope.Database.AsUmbracoDatabase().EnableSqlTrace = true;
scope.Database.AsUmbracoDatabase().EnableSqlCount = true;

var page = repo.GetPagedResultsByQuery(query, 0, 10, out var total, Direction.Descending,
new[] { AuditType.Publish },
Query<IAuditItem>.Builder.Where(x => x.UserId > -1));
sp.SqlContext.Query<IAuditItem>().Where(x => x.UserId > -1));

Assert.AreEqual(10, page.Count());
Assert.AreEqual(100, total);
}
finally
{
DatabaseContext.Database.EnableSqlTrace = false;
DatabaseContext.Database.DisableSqlCount();
scope.Database.AsUmbracoDatabase().EnableSqlTrace = false;
scope.Database.AsUmbracoDatabase().EnableSqlCount = false;
}
}
}


[Test]
public void Get_Paged_Items_With_AuditType_Filter()
{
Expand Down
44 changes: 23 additions & 21 deletions src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.Testing;
using Umbraco.Core.Persistence;

namespace Umbraco.Tests.Persistence.Repositories
{
Expand Down Expand Up @@ -346,63 +347,64 @@ public void Can_Perform_Count_On_UserRepository()
[Test]
public void Can_Get_Paged_Results_By_Query_And_Filter_And_Groups()
{
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
var provider = TestObjects.GetScopeProvider(Logger);
using (var scope = provider.CreateScope())
{
var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
var query = Query<IUser>.Builder.Where(x => x.Username == "TestUser1" || x.Username == "TestUser2");
var repository = CreateRepository(provider);

var users = CreateAndCommitMultipleUsers(repository);
var query = provider.SqlContext.Query<IUser>().Where(x => x.Username == "TestUser1" || x.Username == "TestUser2");

try
{
DatabaseContext.Database.EnableSqlTrace = true;
DatabaseContext.Database.EnableSqlCount();
scope.Database.AsUmbracoDatabase().EnableSqlTrace = true;
scope.Database.AsUmbracoDatabase().EnableSqlCount = true;

// Act
var result = repository.GetPagedResultsByQuery(query, 0, 10, out var totalRecs, user => user.Id, Direction.Ascending,
excludeUserGroups: new[] { Constants.Security.TranslatorGroupAlias },
filter: Query<IUser>.Builder.Where(x => x.Id > -1));
filter: provider.SqlContext.Query<IUser>().Where(x => x.Id > -1));

// Assert
Assert.AreEqual(2, totalRecs);
}
finally
{
DatabaseContext.Database.EnableSqlTrace = false;
DatabaseContext.Database.DisableSqlCount();
scope.Database.AsUmbracoDatabase().EnableSqlTrace = false;
scope.Database.AsUmbracoDatabase().EnableSqlCount = false;
}
}

}

[Test]
public void Can_Get_Paged_Results_With_Filter_And_Groups()
{
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
var provider = TestObjects.GetScopeProvider(Logger);
using (var scope = provider.CreateScope())
{
var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
var repository = CreateRepository(provider);

var users = CreateAndCommitMultipleUsers(repository);

try
{
DatabaseContext.Database.EnableSqlTrace = true;
DatabaseContext.Database.EnableSqlCount();
scope.Database.AsUmbracoDatabase().EnableSqlTrace = true;
scope.Database.AsUmbracoDatabase().EnableSqlCount = true;

// Act
var result = repository.GetPagedResultsByQuery(null, 0, 10, out var totalRecs, user => user.Id, Direction.Ascending,
includeUserGroups: new[] { Constants.Security.AdminGroupAlias, Constants.Security.SensitiveDataGroupAlias },
excludeUserGroups: new[] { Constants.Security.TranslatorGroupAlias },
filter: Query<IUser>.Builder.Where(x => x.Id == 0));
filter: provider.SqlContext.Query<IUser>().Where(x => x.Id == 0));

// Assert
Assert.AreEqual(1, totalRecs);
}
finally
{
DatabaseContext.Database.EnableSqlTrace = false;
DatabaseContext.Database.DisableSqlCount();
scope.Database.AsUmbracoDatabase().EnableSqlTrace = false;
scope.Database.AsUmbracoDatabase().EnableSqlCount = false;
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/Umbraco.Tests/Strings/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Strings;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
Expand All @@ -30,6 +32,14 @@ public void CurrentHelper()
Assert.IsInstanceOf<MockShortStringHelper>(helper);
}

[TestCase("hello-world.png", "Hello World")]
[TestCase("hello-world .png", "Hello World")]
[TestCase("_hello-world __1.png", "Hello World 1")]
public void To_Friendly_Name(string first, string second)
{
Assert.AreEqual(first.ToFriendlyName(), second);
}

[TestCase("hello", "world", false)]
[TestCase("hello", "hello", true)]
[TestCase("hellohellohellohellohellohellohello", "hellohellohellohellohellohellohelloo", false)]
Expand Down
2 changes: 2 additions & 0 deletions src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Umbraco.Web.Templates;
using System.Linq;
using Umbraco.Core.Services;

namespace Umbraco.Tests.Web
{
Expand Down
10 changes: 5 additions & 5 deletions src/Umbraco.Web/Scheduling/ScheduledTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ private async Task ProcessTasksAsync(CancellationToken token)
private async Task<bool> GetTaskByHttpAync(string url, CancellationToken token)
{
if (_httpClient == null)
_httpClient = new HttpClient();

if (Uri.TryCreate(_runtime.ApplicationUrl, UriKind.Absolute, out var baseUri))
_httpClient.BaseAddress = baseUri;

_httpClient = new HttpClient
{
BaseAddress = _runtime.ApplicationUrl
};
var request = new HttpRequestMessage(HttpMethod.Get, url);

//TODO: pass custom the authorization header, currently these aren't really secured!
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Web/Trees/DataTypeTreeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti
});

if (container.HasChildren == false)
{
//can delete data type
menu.Items.Add<ActionDelete>(Services.TextService.Localize($"actions/{ActionDelete.Instance.Alias}"));
}
Expand Down

0 comments on commit 0c5cf52

Please sign in to comment.