diff --git a/src/Umbraco.Tests.Benchmarks/App.config b/src/Umbraco.Tests.Benchmarks/App.config
index 8cfb77478c..dca44c497f 100644
--- a/src/Umbraco.Tests.Benchmarks/App.config
+++ b/src/Umbraco.Tests.Benchmarks/App.config
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Umbraco.Tests/App.config b/src/Umbraco.Tests/App.config
index 08b3793afa..362eed160c 100644
--- a/src/Umbraco.Tests/App.config
+++ b/src/Umbraco.Tests/App.config
@@ -79,6 +79,7 @@
+
@@ -89,9 +90,19 @@
+
+
+
+
+
+
+
+
-
+
+
+
@@ -156,7 +167,7 @@
-
+
diff --git a/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs b/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs
index f169e0eb6c..20d0fe979c 100644
--- a/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs
+++ b/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs
@@ -42,12 +42,10 @@ namespace Umbraco.Tests.Cache
new EventDefinition(null, serviceContext.SectionService, new EventArgs(), "Deleted"),
new EventDefinition(null, serviceContext.SectionService, new EventArgs(), "New"),
- new EventDefinition>(null, serviceContext.UserService, new SaveEventArgs(Enumerable.Empty())),
- new EventDefinition>(null, serviceContext.UserService, new DeleteEventArgs(Enumerable.Empty())),
-
new EventDefinition>(null, serviceContext.UserService, new SaveEventArgs(Enumerable.Empty())),
new EventDefinition>(null, serviceContext.UserService, new DeleteEventArgs(Enumerable.Empty())),
- new EventDefinition>(null, serviceContext.UserService, new DeleteEventArgs(Enumerable.Empty())),
+ new EventDefinition>(null, serviceContext.UserService, new SaveEventArgs(Enumerable.Empty())),
+ new EventDefinition>(null, serviceContext.UserService, new DeleteEventArgs(Enumerable.Empty())),
new EventDefinition>(null, serviceContext.LocalizationService, new SaveEventArgs(Enumerable.Empty())),
new EventDefinition>(null, serviceContext.LocalizationService, new DeleteEventArgs(Enumerable.Empty())),
@@ -90,8 +88,10 @@ namespace Umbraco.Tests.Cache
new EventDefinition>(null, serviceContext.MediaService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Trashed"),
new EventDefinition(null, serviceContext.MediaService, new RecycleBinEventArgs(Guid.NewGuid(), new Dictionary>(), true)),
- new EventDefinition>(null, serviceContext.ContentService, new SaveEventArgs(Enumerable.Empty())),
- new EventDefinition>(null, serviceContext.ContentService, new DeleteEventArgs(Enumerable.Empty())),
+ new EventDefinition>(null, serviceContext.ContentService, new SaveEventArgs(Enumerable.Empty()), "Saved"),
+ new EventDefinition>(null, serviceContext.ContentService, new SaveEventArgs(Enumerable.Empty()), "SavedBlueprint"),
+ new EventDefinition>(null, serviceContext.ContentService, new DeleteEventArgs(Enumerable.Empty()), "Deleted"),
+ new EventDefinition>(null, serviceContext.ContentService, new DeleteEventArgs(Enumerable.Empty()), "DeletedBlueprint"),
new EventDefinition>(null, serviceContext.ContentService, new CopyEventArgs(null, null, -1)),
new EventDefinition>(null, serviceContext.ContentService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Trashed"),
new EventDefinition(null, serviceContext.ContentService, new RecycleBinEventArgs(Guid.NewGuid(), new Dictionary>(), true)),
diff --git a/src/Umbraco.Tests/Configurations/RepositorySettingsTests.cs b/src/Umbraco.Tests/Configurations/RepositorySettingsTests.cs
deleted file mode 100644
index 8291a34fad..0000000000
--- a/src/Umbraco.Tests/Configurations/RepositorySettingsTests.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System.Configuration;
-using NUnit.Framework;
-using Umbraco.Core.Configuration.InfrastructureSettings;
-
-namespace Umbraco.Tests.Configurations
-{
- [TestFixture]
- public class RepositorySettingsTests
- {
- [Test]
- public void Can_Get_Repository_From_Config()
- {
- Infrastructure infrastructure = Infrastructure.Instance;
- Repositories repositories = infrastructure.Repositories;
- Repository repository = repositories.Repository["IContentRepository"];
-
- Assert.That(repository, Is.Not.Null);
- Assert.AreEqual(repository.InterfaceShortTypeName, "IContentRepository");
- Assert.AreEqual(repository.RepositoryFullTypeName, "Umbraco.Core.Persistence.Repositories.ContentRepository, Umbraco.Core");
- Assert.AreEqual(repository.CacheProviderFullTypeName, "Umbraco.Core.Persistence.Caching.RuntimeCacheProvider, Umbraco.Core");
- }
-
- [Test]
- public void Can_Get_PublishingStrategy_From_Config()
- {
- Infrastructure infrastructure = Infrastructure.Instance;
- PublishingProvider strategy = infrastructure.PublishingStrategy;
-
- Assert.That(strategy.Type, Is.EqualTo("Umbraco.Web.Publishing.PublishingStrategy, Umbraco.Web"));
- }
- }
-}
diff --git a/src/Umbraco.Tests/CoreThings/UdiTests.cs b/src/Umbraco.Tests/CoreThings/UdiTests.cs
index 60ac41e87b..349fea22e9 100644
--- a/src/Umbraco.Tests/CoreThings/UdiTests.cs
+++ b/src/Umbraco.Tests/CoreThings/UdiTests.cs
@@ -79,6 +79,29 @@ namespace Umbraco.Tests.CoreThings
Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/path%20to/this%20is%20a%20test.xyz", udi3.ToString());
}
+ [Test]
+ public void StringEncodingTest2()
+ {
+ // reserved = : / ? # [ ] @ ! $ & ' ( ) * + , ; =
+ // unreserved = alpha digit - . _ ~
+
+ Assert.AreEqual("%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2B%2C%3B%3D.-_~%25", Uri.EscapeDataString(":/?#[]@!$&'()+,;=.-_~%"));
+ Assert.AreEqual(":/?#[]@!$&'()+,;=.-_~%25", Uri.EscapeUriString(":/?#[]@!$&'()+,;=.-_~%"));
+
+ // we cannot have reserved chars at random places
+ // we want to keep the / in string udis
+
+ var r = string.Join("/", "path/to/View[1].cshtml".Split('/').Select(Uri.EscapeDataString));
+ Assert.AreEqual("path/to/View%5B1%5D.cshtml", r);
+ Assert.IsTrue(Uri.IsWellFormedUriString("umb://partial-view-macro/" + r, UriKind.Absolute));
+
+ // with the proper fix in StringUdi this should work:
+ var udi1 = new StringUdi("partial-view-macro", "path/to/View[1].cshtml");
+ Assert.AreEqual("umb://partial-view-macro/path/to/View%5B1%5D.cshtml", udi1.ToString());
+ var udi2 = Udi.Parse("umb://partial-view-macro/path/to/View%5B1%5D.cshtml");
+ Assert.AreEqual("path/to/View[1].cshtml", ((StringUdi) udi2).Id);
+ }
+
[Test]
public void GuidEntityCtorTest()
{
diff --git a/src/Umbraco.Tests/DateTimeExtensionsTests.cs b/src/Umbraco.Tests/DateTimeExtensionsTests.cs
new file mode 100644
index 0000000000..83a47b3551
--- /dev/null
+++ b/src/Umbraco.Tests/DateTimeExtensionsTests.cs
@@ -0,0 +1,46 @@
+using System;
+using NUnit.Framework;
+using Umbraco.Core;
+
+namespace Umbraco.Tests
+{
+ [TestFixture]
+ public class DateTimeExtensionsTests
+ {
+ [Test]
+ public void PeriodicMinutesFrom_PostTime_CalculatesMinutesBetween()
+ {
+ var nowDateTime = new DateTime(2017, 1, 1, 10, 30, 0);
+ var scheduledTime = "1145";
+ var minutesBetween = nowDateTime.PeriodicMinutesFrom(scheduledTime);
+ Assert.AreEqual(75, minutesBetween);
+ }
+
+ [Test]
+ public void PeriodicMinutesFrom_PriorTime_CalculatesMinutesBetween()
+ {
+ var nowDateTime = new DateTime(2017, 1, 1, 10, 30, 0);
+ var scheduledTime = "900";
+ var minutesBetween = nowDateTime.PeriodicMinutesFrom(scheduledTime);
+ Assert.AreEqual(1350, minutesBetween);
+ }
+
+ [Test]
+ public void PeriodicMinutesFrom_PriorTime_WithLeadingZero_CalculatesMinutesBetween()
+ {
+ var nowDateTime = new DateTime(2017, 1, 1, 10, 30, 0);
+ var scheduledTime = "0900";
+ var minutesBetween = nowDateTime.PeriodicMinutesFrom(scheduledTime);
+ Assert.AreEqual(1350, minutesBetween);
+ }
+
+ [Test]
+ public void PeriodicMinutesFrom_SameTime_CalculatesMinutesBetween()
+ {
+ var nowDateTime = new DateTime(2017, 1, 1, 10, 30, 0);
+ var scheduledTime = "1030";
+ var minutesBetween = nowDateTime.PeriodicMinutesFrom(scheduledTime);
+ Assert.AreEqual(0, minutesBetween);
+ }
+ }
+}
diff --git a/src/Umbraco.Tests/Membership/MembershipProviderBaseTests.cs b/src/Umbraco.Tests/Membership/MembershipProviderBaseTests.cs
index 743fc4f968..3661d1a4b6 100644
--- a/src/Umbraco.Tests/Membership/MembershipProviderBaseTests.cs
+++ b/src/Umbraco.Tests/Membership/MembershipProviderBaseTests.cs
@@ -168,7 +168,7 @@ namespace Umbraco.Tests.Membership
Assert.AreEqual("test", provider.Name);
Assert.AreEqual(MembershipProviderBase.GetDefaultAppName(), provider.ApplicationName);
Assert.AreEqual(false, provider.EnablePasswordRetrieval);
- Assert.AreEqual(false, provider.EnablePasswordReset);
+ Assert.AreEqual(true, provider.EnablePasswordReset);
Assert.AreEqual(false, provider.RequiresQuestionAndAnswer);
Assert.AreEqual(true, provider.RequiresUniqueEmail);
Assert.AreEqual(5, provider.MaxInvalidPasswordAttempts);
diff --git a/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs b/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs
index b8f1f56675..9dd3047f1d 100644
--- a/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs
+++ b/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Collections.Specialized;
-using System.Configuration.Provider;
+using System.Collections.Specialized;
using System.Web.Security;
using Moq;
using NUnit.Framework;
@@ -87,9 +85,9 @@ namespace Umbraco.Tests.Membership
membershipServiceMock.Setup(service => service.GetByEmail("test@test.com")).Returns(() => null);
membershipServiceMock.Setup(
service => service.CreateWithIdentity(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
- .Callback((string u, string e, string p, string m) =>
+ .Callback((string u, string e, string p, string m, bool isApproved) =>
{
- createdMember = new Member("test", e, u, p, memberType);
+ createdMember = new Member("test", e, u, p, memberType, isApproved);
})
.Returns(() => createdMember);
var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object);
@@ -119,9 +117,9 @@ namespace Umbraco.Tests.Membership
membershipServiceMock.Setup(service => service.GetByEmail("test@test.com")).Returns(() => null);
membershipServiceMock.Setup(
service => service.CreateWithIdentity(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
- .Callback((string u, string e, string p, string m) =>
+ .Callback((string u, string e, string p, string m, bool isApproved) =>
{
- createdMember = new Member("test", e, u, p, memberType);
+ createdMember = new Member("test", e, u, p, memberType, isApproved);
})
.Returns(() => createdMember);
@@ -153,9 +151,9 @@ namespace Umbraco.Tests.Membership
membershipServiceMock.Setup(service => service.GetByEmail("test@test.com")).Returns(() => null);
membershipServiceMock.Setup(
service => service.CreateWithIdentity(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
- .Callback((string u, string e, string p, string m) =>
+ .Callback((string u, string e, string p, string m, bool isApproved) =>
{
- createdMember = new Member("test", e, u, p, memberType);
+ createdMember = new Member("test", e, u, p, memberType, isApproved);
})
.Returns(() => createdMember);
diff --git a/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs
index bd0c2ecabe..a3ee01dc3d 100644
--- a/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs
+++ b/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs
@@ -5,11 +5,9 @@ using NPoco;
using NUnit.Framework;
using Semver;
using Umbraco.Core;
-using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Migrations;
-using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
@@ -61,20 +59,22 @@ namespace Umbraco.Tests.Migrations.Upgrades
logger,
configuredVersion,
targetVersion,
- Constants.System.UmbracoMigrationName,
- //pass in explicit migrations
- new Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero.RemoveUmbracoAppConstraints(context),
- new DeleteAppTables(context),
- new EnsureAppsTreesUpdated(context),
- new MoveMasterContentTypeData(context),
- new NewCmsContentType2ContentTypeTable(context),
- new RemoveMasterContentTypeColumn(context),
- new RenameCmsTabTable(context),
- new RenameTabIdColumn(context),
- new UpdateCmsContentTypeAllowedContentTypeTable(context),
- new UpdateCmsContentTypeTable(context),
- new UpdateCmsContentVersionTable(context),
- new UpdateCmsPropertyTypeGroupTable(context));
+ Constants.System.UmbracoMigrationName
+ //pass in explicit migrations
+ // fixme - all gone in v8 - migrations need to be refactored anyways
+ //new Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero.RemoveUmbracoAppConstraints(context),
+ //new DeleteAppTables(context),
+ //new EnsureAppsTreesUpdated(context),
+ //new MoveMasterContentTypeData(context),
+ //new NewCmsContentType2ContentTypeTable(context),
+ //new RemoveMasterContentTypeColumn(context),
+ //new RenameCmsTabTable(context),
+ //new RenameTabIdColumn(context),
+ //new UpdateCmsContentTypeAllowedContentTypeTable(context),
+ //new UpdateCmsContentTypeTable(context),
+ //new UpdateCmsContentVersionTable(context),
+ //new UpdateCmsPropertyTypeGroupTable(context)
+ );
var upgraded = migrationRunner.Execute(context /*, true*/);
diff --git a/src/Umbraco.Tests/Models/Mapping/UserModelMapperTests.cs b/src/Umbraco.Tests/Models/Mapping/UserModelMapperTests.cs
new file mode 100644
index 0000000000..f1dea9b587
--- /dev/null
+++ b/src/Umbraco.Tests/Models/Mapping/UserModelMapperTests.cs
@@ -0,0 +1,35 @@
+using System.Collections.Generic;
+using AutoMapper;
+using Newtonsoft.Json;
+using NUnit.Framework;
+using Umbraco.Core.Models.Membership;
+using Umbraco.Tests.TestHelpers;
+using Umbraco.Tests.Testing;
+using Umbraco.Web.Models.ContentEditing;
+
+namespace Umbraco.Tests.Models.Mapping
+{
+ [TestFixture]
+ [UmbracoTest(AutoMapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
+ public class UserModelMapperTests : TestWithDatabaseBase
+ {
+ [Test]
+ public void Map_UserGroupSave_To_IUserGroup()
+ {
+ IUserGroup userGroup = new UserGroup(0, "alias", "name", new List { "c" }, "icon");
+ userGroup.Id = 42;
+
+ // userGroup.permissions is System.Collections.Generic.List`1[System.String]
+
+ // userGroup.permissions is System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Char, System.String]
+ // fixed: now System.Collections.Generic.List`1[System.String]
+
+ const string json = "{\"id\":@@@ID@@@,\"alias\":\"perm1\",\"name\":\"Perm1\",\"icon\":\"icon-users\",\"sections\":[\"content\"],\"users\":[],\"defaultPermissions\":[\"F\",\"C\",\"A\"],\"assignedPermissions\":{},\"startContentId\":-1,\"startMediaId\":-1,\"action\":\"save\",\"parentId\":-1}";
+ var userGroupSave = JsonConvert.DeserializeObject(json.Replace("@@@ID@@@", userGroup.Id.ToString()));
+
+ // failed, AutoMapper complained, "Unable to cast object of type 'WhereSelectArrayIterator`2[System.Char,System.String]' to type 'System.Collections.IList'".
+ // fixmed: added ToList() in UserGroupFactory
+ Mapper.Map(userGroupSave, userGroup);
+ }
+ }
+}
diff --git a/src/Umbraco.Tests/Models/UserExtensionsTests.cs b/src/Umbraco.Tests/Models/UserExtensionsTests.cs
index d5e90d1fc4..9c776a3c00 100644
--- a/src/Umbraco.Tests/Models/UserExtensionsTests.cs
+++ b/src/Umbraco.Tests/Models/UserExtensionsTests.cs
@@ -1,29 +1,100 @@
-using Moq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Moq;
using NUnit.Framework;
using Umbraco.Core.Models;
+using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Services;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class UserExtensionsTests
{
- [TestCase(2, "-1,1,2,3,4,5", true)]
- [TestCase(6, "-1,1,2,3,4,5", false)]
- [TestCase(-1, "-1,1,2,3,4,5", true)]
- [TestCase(5, "-1,1,2,3,4,5", true)]
- [TestCase(-1, "-1,-20,1,2,3,4,5", true)]
- [TestCase(1, "-1,-20,1,2,3,4,5", false)]
- public void Determines_Path_Based_Access_To_Content(int userId, string contentPath, bool outcome)
+ [TestCase(-1, "-1", "-1,1,2,3,4,5", true)] // below root start node
+ [TestCase(2, "-1,1,2", "-1,1,2,3,4,5", true)] // below start node
+ [TestCase(5, "-1,1,2,3,4,5", "-1,1,2,3,4,5", true)] // at start node
+
+ [TestCase(6, "-1,1,2,3,4,5,6", "-1,1,2,3,4,5", false)] // above start node
+
+ [TestCase(-1, "-1", "-1,-20,1,2,3,4,5", true)] // below root start node, bin
+ [TestCase(1, "-1,-20,1", "-1,-20,1,2,3,4,5", false)] // below bin start node
+
+ public void Determines_Path_Based_Access_To_Content(int startNodeId, string startNodePath, string contentPath, bool outcome)
{
var userMock = new Mock();
- userMock.Setup(u => u.StartContentId).Returns(userId);
+ userMock.Setup(u => u.StartContentIds).Returns(new[] { startNodeId });
var user = userMock.Object;
- var contentMock = new Mock();
- contentMock.Setup(c => c.Path).Returns(contentPath);
- var content = contentMock.Object;
+ var content = Mock.Of(c => c.Path == contentPath && c.Id == 5);
- Assert.AreEqual(outcome, user.HasPathAccess(content));
+ var esmock = new Mock();
+ esmock
+ .Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny()))
+ .Returns((type, ids) => new[] { new EntityPath { Id = startNodeId, Path = startNodePath } });
+
+ Assert.AreEqual(outcome, user.HasPathAccess(content, esmock.Object));
+ }
+
+ [TestCase("", "1", "1")] // single user start, top level
+ [TestCase("", "4", "4")] // single user start, deeper level
+ [TestCase("", "2,3", "2,3")] // many user starts
+ [TestCase("", "2,3,4", "3,4")] // many user starts, de-duplicate to deepest
+
+ [TestCase("1", "", "1")] // single group start, top level
+ [TestCase("4", "", "4")] // single group start, deeper leve
+ [TestCase("2,3", "", "2,3")] // many group starts
+ [TestCase("2,3,4", "", "2,3")] // many group starts, de-duplicate to upmost
+
+ [TestCase("3", "2", "3,2")] // user and group start, combine
+ [TestCase("3", "2,5", "2,5")] // user and group start, restrict
+ [TestCase("3", "2,1", "2,1")] // user and group start, expand
+
+ [TestCase("3,8", "2,6", "3,2")] // exclude bin
+ [TestCase("", "6", "")] // exclude bin
+
+ public void CombineStartNodes(string groupSn, string userSn, string expected)
+ {
+ // 1
+ // 3
+ // 5
+ // 2
+ // 4
+ // bin
+ // 6
+ // 7
+ // 8
+
+ var paths = new Dictionary
+ {
+ { 1, "-1,1" },
+ { 2, "-1,2" },
+ { 3, "-1,1,3" },
+ { 4, "-1,2,4" },
+ { 5, "-1,1,3,5" },
+ { 6, "-1,-20,6" },
+ { 7, "-1,-20,7" },
+ { 8, "-1,-20,7,8" },
+ };
+
+ var esmock = new Mock();
+ esmock
+ .Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny()))
+ .Returns((type, ids) => paths.Where(x => ids.Contains(x.Key)).Select(x => new EntityPath { Id = x.Key, Path = x.Value }));
+
+ var comma = new[] { ',' };
+
+ var groupSnA = groupSn.Split(comma, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
+ var userSnA = userSn.Split(comma, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
+ var combinedA = UserExtensions.CombineStartNodes(UmbracoObjectTypes.Document, groupSnA, userSnA, esmock.Object).OrderBy(x => x).ToArray();
+ var expectedA = expected.Split(comma, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).OrderBy(x => x).ToArray();
+
+ var ok = combinedA.Length == expectedA.Length;
+ if (ok) ok = expectedA.Where((t, i) => t != combinedA[i]).Any() == false;
+
+ if (ok == false)
+ Assert.Fail("Expected \"" + string.Join(",", expectedA) + "\" but got \"" + string.Join(",", combinedA) + "\".");
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs
index b6924c08cd..5e982633d2 100644
--- a/src/Umbraco.Tests/Models/UserTests.cs
+++ b/src/Umbraco.Tests/Models/UserTests.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Tests.Models
[Test]
public void Can_Deep_Clone()
{
- var item = new User(new UserType(){Id = 3})
+ var item = new User()
{
Id = 3,
Key = Guid.NewGuid(),
@@ -21,7 +21,6 @@ namespace Umbraco.Tests.Models
CreateDate = DateTime.Now,
Name = "Test",
Comments = "comments",
- DefaultPermissions = new[]{"a","b","c"},
DefaultToLiveEditing = false,
Email = "test@test.com",
Language = "en",
@@ -36,42 +35,24 @@ namespace Umbraco.Tests.Models
PasswordQuestion = "question",
//ProviderUserKey = "user key",
SessionTimeout = 5,
- StartContentId = 3,
- StartMediaId = 8,
+ StartContentIds = new[] { 3 },
+ StartMediaIds = new[] { 8 },
Username = "username"
};
- item.AddAllowedSection("test");
-
var clone = (User)item.DeepClone();
Assert.AreNotSame(clone, item);
Assert.AreEqual(clone, item);
- Assert.AreNotSame(clone.UserType, item.UserType);
- Assert.AreEqual(clone.UserType, item.UserType);
Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count());
- Assert.AreNotSame(clone.DefaultPermissions, item.DefaultPermissions);
- Assert.AreEqual(clone.DefaultPermissions.Count(), item.DefaultPermissions.Count());
-
//Verify normal properties with reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
}
-
- //ensure internal collections are differet
- Assert.AreNotSame(item.AddedSections, clone.AddedSections);
- Assert.AreNotSame(item.RemovedSections, clone.RemovedSections);
-
- //ensure event handlers are still wired on clone
- clone.AddAllowedSection("blah");
- Assert.AreEqual(1, clone.AddedSections.Count());
- clone.RemoveAllowedSection("blah");
- Assert.AreEqual(1, clone.RemovedSections.Count());
-
}
[Test]
@@ -79,7 +60,7 @@ namespace Umbraco.Tests.Models
{
var ss = new SerializationService(new JsonNetSerializer());
- var item = new User(new UserType() { Id = 3 })
+ var item = new User
{
Id = 3,
Key = Guid.NewGuid(),
@@ -87,7 +68,6 @@ namespace Umbraco.Tests.Models
CreateDate = DateTime.Now,
Name = "Test",
Comments = "comments",
- DefaultPermissions = new[] { "a", "b", "c" },
DefaultToLiveEditing = false,
Email = "test@test.com",
Language = "en",
@@ -102,8 +82,8 @@ namespace Umbraco.Tests.Models
PasswordQuestion = "question",
//ProviderUserKey = "user key",
SessionTimeout = 5,
- StartContentId = 3,
- StartMediaId = 8,
+ StartContentIds = new[] { 3 },
+ StartMediaIds = new[] { 8 },
Username = "username"
};
diff --git a/src/Umbraco.Tests/Models/UserTypeTests.cs b/src/Umbraco.Tests/Models/UserTypeTests.cs
deleted file mode 100644
index 0406107fb1..0000000000
--- a/src/Umbraco.Tests/Models/UserTypeTests.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Linq;
-using NUnit.Framework;
-using Umbraco.Core.Models.Membership;
-using Umbraco.Core.Serialization;
-
-namespace Umbraco.Tests.Models
-{
- [TestFixture]
- public class UserTypeTests
- {
- [Test]
- public void Can_Deep_Clone()
- {
- var item = new UserType()
- {
- Id = 3,
- Key = Guid.NewGuid(),
- UpdateDate = DateTime.Now,
- CreateDate = DateTime.Now,
- Name = "Test",
- Alias = "test",
- Permissions = new[] {"a", "b", "c"}
- };
-
- var clone = (UserType)item.DeepClone();
-
- Assert.AreNotSame(clone, item);
- Assert.AreEqual(clone, item);
-
- //Verify normal properties with reflection
- var allProps = clone.GetType().GetProperties();
- foreach (var propertyInfo in allProps)
- {
- Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
- }
- }
-
- [Test]
- public void Can_Serialize_Without_Error()
- {
- var ss = new SerializationService(new JsonNetSerializer());
-
- var item = new UserType()
- {
- Id = 3,
- Key = Guid.NewGuid(),
- UpdateDate = DateTime.Now,
- CreateDate = DateTime.Now,
- Name = "Test",
- Alias = "test",
- Permissions = new[] { "a", "b", "c" }
- };
-
- var result = ss.ToStream(item);
- var json = result.ResultStream.ToJsonString();
- Debug.Print(json);
- }
- }
-}
diff --git a/src/Umbraco.Tests/Persistence/DatabaseFactoryTests.cs b/src/Umbraco.Tests/Persistence/DatabaseFactoryTests.cs
deleted file mode 100644
index ceb82624c2..0000000000
--- a/src/Umbraco.Tests/Persistence/DatabaseFactoryTests.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using NUnit.Framework;
-using Umbraco.Core.Persistence;
-
-namespace Umbraco.Tests.Persistence
-{
- [TestFixture]
- public class DatabaseFactoryTests
- {
- [Test]
- public void Can_Verify_Single_Database_Instance()
- {
- var db1 = DatabaseFactory.Current.Database;
- var db2 = DatabaseFactory.Current.Database;
-
- Assert.AreSame(db1, db2);
- }
- }
-}
diff --git a/src/Umbraco.Tests/Persistence/PetaPocoDynamicQueryTests.cs b/src/Umbraco.Tests/Persistence/PetaPocoDynamicQueryTests.cs
deleted file mode 100644
index f5f6d5df44..0000000000
--- a/src/Umbraco.Tests/Persistence/PetaPocoDynamicQueryTests.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-//using System;
-//using System.Linq;
-//using NUnit.Framework;
-//using Umbraco.Core.Models;
-//using Umbraco.Core.Persistence;
-//using Umbraco.Core.Persistence.SqlSyntax;
-//using Umbraco.Tests.TestHelpers;
-//using Umbraco.Tests.TestHelpers.Entities;
-
-//namespace Umbraco.Tests.Persistence
-//{
-// [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)]
-// [TestFixture]
-// public class PetaPocoDynamicQueryTests : BaseDatabaseFactoryTest
-// {
-// [Test]
-// public void Check_Poco_Storage_Growth()
-// {
-// //CreateStuff();
-
-// for (int i = 0; i < 1000; i++)
-// {
-// DatabaseContext.Database.Fetch(
-// "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='" + i + "'");
-// }
-
-// //var oc11 = Database.PocoData.GetCachedPocoData().Count();
-// //var oc12 = Database.PocoData.GetConverters().Count();
-// //var oc13 = Database.GetAutoMappers().Count();
-// //var oc14 = Database.GetMultiPocoFactories().Count();
-
-// //for (int i = 0; i < 2; i++)
-// //{
-// // i1 = DatabaseContext.Database.Fetch("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES");
-// // r1 = i1.Select(x => x.TABLE_NAME).Cast().ToList();
-// //}
-
-// //var oc21 = Database.PocoData.GetCachedPocoData().Count();
-// //var oc22 = Database.PocoData.GetConverters().Count();
-// //var oc23 = Database.GetAutoMappers().Count();
-// //var oc24 = Database.GetMultiPocoFactories().Count();
-
-// //var roots = ServiceContext.ContentService.GetRootContent();
-// //foreach (var content in roots)
-// //{
-// // var d = ServiceContext.ContentService.GetDescendants(content);
-// //}
-
-// //var oc31 = Database.PocoData.GetCachedPocoData().Count();
-// //var oc32 = Database.PocoData.GetConverters().Count();
-// //var oc33 = Database.GetAutoMappers().Count();
-// //var oc34 = Database.GetMultiPocoFactories().Count();
-
-// //for (int i = 0; i < 2; i++)
-// //{
-// // roots = ServiceContext.ContentService.GetRootContent();
-// // foreach (var content in roots)
-// // {
-// // var d = ServiceContext.ContentService.GetDescendants(content);
-// // }
-// //}
-
-// //var oc41 = Database.PocoData.GetCachedPocoData().Count();
-// //var oc42 = Database.PocoData.GetConverters().Count();
-// //var oc43 = Database.GetAutoMappers().Count();
-// //var oc44 = Database.GetMultiPocoFactories().Count();
-
-// //var i2 = DatabaseContext.Database.Fetch("SELECT TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS");
-// //var r2 =
-// // i2.Select(
-// // item =>
-// // new ColumnInfo(item.TABLE_NAME, item.COLUMN_NAME, item.ORDINAL_POSITION, item.COLUMN_DEFAULT,
-// // item.IS_NULLABLE, item.DATA_TYPE)).ToList();
-
-
-// var pocoData = Database.PocoData.GetCachedPocoData();
-// Console.WriteLine("GetCachedPocoData: " + pocoData.Count());
-// foreach (var keyValuePair in pocoData)
-// {
-// Console.WriteLine(keyValuePair.Value.GetFactories().Count());
-// }
-
-// Console.WriteLine("GetConverters: " + Database.PocoData.GetConverters().Count());
-// Console.WriteLine("GetAutoMappers: " + Database.GetAutoMappers().Count());
-// Console.WriteLine("GetMultiPocoFactories: " + Database.GetMultiPocoFactories().Count());
-
-// //Assert.AreEqual(oc11, oc21);
-// //Assert.AreEqual(oc12, oc22);
-// //Assert.AreEqual(oc13, oc23);
-// //Assert.AreEqual(oc14, oc24);
-
-// //Assert.AreEqual(oc31, oc41);
-// //Assert.AreEqual(oc32, oc42);
-// //Assert.AreEqual(oc33, oc43);
-// //Assert.AreEqual(oc34, oc44);
-// }
-
-// public void CreateStuff()
-// {
-// var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "test1");
-// var contentType2 = MockedContentTypes.CreateTextpageContentType("test2", "test2");
-// var contentType3 = MockedContentTypes.CreateTextpageContentType("test3", "test3");
-// ServiceContext.ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 });
-// contentType1.AllowedContentTypes = new[]
-// {
-// new ContentTypeSort(new Lazy(() => contentType2.Id), 0, contentType2.Alias),
-// new ContentTypeSort(new Lazy(() => contentType3.Id), 1, contentType3.Alias)
-// };
-// contentType2.AllowedContentTypes = new[]
-// {
-// new ContentTypeSort(new Lazy(() => contentType1.Id), 0, contentType1.Alias),
-// new ContentTypeSort(new Lazy(() => contentType3.Id), 1, contentType3.Alias)
-// };
-// contentType3.AllowedContentTypes = new[]
-// {
-// new ContentTypeSort(new Lazy(() => contentType1.Id), 0, contentType1.Alias),
-// new ContentTypeSort(new Lazy(() => contentType2.Id), 1, contentType2.Alias)
-// };
-// ServiceContext.ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 });
-
-// var roots = MockedContent.CreateTextpageContent(contentType1, -1, 3);
-// ServiceContext.ContentService.Save(roots);
-// foreach (var root in roots)
-// {
-// var item1 = MockedContent.CreateTextpageContent(contentType1, root.Id, 3);
-// var item2 = MockedContent.CreateTextpageContent(contentType2, root.Id, 3);
-// var item3 = MockedContent.CreateTextpageContent(contentType3, root.Id, 3);
-
-// ServiceContext.ContentService.Save(item1.Concat(item2).Concat(item3));
-// }
-// }
-// }
-//}
diff --git a/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs b/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs
index 9d7a87ca8e..d25d75c016 100644
--- a/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs
+++ b/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs
@@ -24,7 +24,7 @@ namespace Umbraco.Tests.Persistence.Querying
sql.SelectAll();
sql.From("umbracoNode");
- var query = new Query(SqlContext.SqlSyntax, Mappers).Where(x => x.Path.StartsWith("-1"));
+ var query = new Query(SqlContext).Where(x => x.Path.StartsWith("-1"));
// Act
var translator = new SqlTranslator(sql, query);
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.Persistence.Querying
sql.SelectAll();
sql.From("umbracoNode");
- var query = new Query(SqlContext.SqlSyntax, Mappers).Where(x => x.ParentId == -1);
+ var query = new Query(SqlContext).Where(x => x.ParentId == -1);
// Act
var translator = new SqlTranslator(sql, query);
@@ -78,7 +78,7 @@ namespace Umbraco.Tests.Persistence.Querying
sql.SelectAll();
sql.From("umbracoNode");
- var query = new Query(SqlContext.SqlSyntax, Mappers).Where(x => x.Alias == "umbTextpage");
+ var query = new Query(SqlContext).Where(x => x.Alias == "umbTextpage");
// Act
var translator = new SqlTranslator(sql, query);
@@ -115,7 +115,7 @@ namespace Umbraco.Tests.Persistence.Querying
.On(left => left.NodeId, right => right.NodeId)
.Where(x => x.NodeObjectType == nodeObjectTypeId);
- var query = new Query(SqlContext.SqlSyntax, Mappers).Where(x => x.Path.StartsWith(path) && x.Id != id && x.Published == true && x.Trashed == false);
+ var query = new Query(SqlContext).Where(x => x.Path.StartsWith(path) && x.Id != id && x.Published == true && x.Trashed == false);
// Act
var translator = new SqlTranslator(sql, query);
diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
index f690247bf5..2d1dba886e 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
@@ -2,9 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
-using System.Xml.Linq;
using Moq;
-using NPoco;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -17,7 +15,6 @@ using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
-using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.Scoping;
using Umbraco.Tests.Testing;
@@ -63,7 +60,7 @@ namespace Umbraco.Tests.Persistence.Repositories
templateRepository = new TemplateRepository(unitOfWork, CacheHelper, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepository = new TagRepository(unitOfWork, CacheHelper, Logger);
contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper, Logger, templateRepository);
- var repository = new ContentRepository(unitOfWork, CacheHelper, Logger, contentTypeRepository, templateRepository, tagRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
return repository;
}
@@ -302,40 +299,6 @@ namespace Umbraco.Tests.Persistence.Repositories
}
}
- [Test]
- public void Ensures_Permissions_Are_Set_If_Parent_Entity_Permissions_Exist()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- ContentTypeRepository contentTypeRepository;
- var repository = CreateRepository(unitOfWork, out contentTypeRepository);
- var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
- contentType.AllowedContentTypes = new List
- {
- new ContentTypeSort(new Lazy(() => contentType.Id), 0, contentType.Alias)
- };
- var parentPage = MockedContent.CreateSimpleContent(contentType);
- contentTypeRepository.AddOrUpdate(contentType);
- repository.AddOrUpdate(parentPage);
- unitOfWork.Flush();
-
- // Act
- repository.AssignEntityPermission(parentPage, 'A', new int[] { 0 });
- var childPage = MockedContent.CreateSimpleContent(contentType, "child", parentPage);
- repository.AddOrUpdate(childPage);
- unitOfWork.Flush();
-
- // Assert
- var permissions = repository.GetPermissionsForEntity(childPage.Id);
- Assert.AreEqual(1, permissions.Count());
- Assert.AreEqual("A", permissions.Single().AssignedPermissions.First());
-
- unitOfWork.Complete();
- }
- }
-
[Test]
public void Can_Perform_Add_On_ContentRepository()
{
diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs
index d607176035..23676e2233 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs
@@ -36,7 +36,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger);
contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, templateRepository);
- var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, contentTypeRepository, templateRepository, tagRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
return repository;
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs
index f2b8e3f1d1..cf70a5afc5 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs
@@ -23,7 +23,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var templateRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepository = new TagRepository(unitOfWork, DisabledCache, Logger);
contentTypeRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, templateRepository);
- contentRepository = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository);
+ contentRepository = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
languageRepository = new LanguageRepository(unitOfWork, DisabledCache, Logger);
var domainRepository = new DomainRepository(unitOfWork, DisabledCache, Logger);
return domainRepository;
diff --git a/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs
index f6b83f1fe1..37831488fb 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs
@@ -49,7 +49,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var repo = new NotificationsRepository(unitOfWork);
- var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "test", MediaStartId = -1, Password = "test", Type = 1, UserName = "test", UserLanguage = "en" };
+ var userDto = new UserDto { Email = "test", Login = "test", Password = "test", UserName = "test", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now };
unitOfWork.Database.Insert(userDto);
var userNew = Mock.Of(e => e.Id == userDto.Id);
@@ -87,7 +87,7 @@ namespace Umbraco.Tests.Persistence.Repositories
for (var i = 0; i < 10; i++)
{
- var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" };
+ var userDto = new UserDto { Email = "test" + i, Login = "test" + i, Password = "test", UserName = "test" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now };
unitOfWork.Database.Insert(userDto);
var userNew = Mock.Of(e => e.Id == userDto.Id);
var notification = repo.CreateNotification(userNew, (i%2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
@@ -117,7 +117,7 @@ namespace Umbraco.Tests.Persistence.Repositories
for (var i = 0; i < 10; i++)
{
- var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" };
+ var userDto = new UserDto { Email = "test" + i, Login = "test" + i, Password = "test", UserName = "test" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now };
unitOfWork.Database.Insert(userDto);
var userNew = Mock.Of(e => e.Id == userDto.Id);
var notification = repo.CreateNotification(userNew, (i%2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
@@ -138,7 +138,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var repo = new NotificationsRepository(unitOfWork);
- var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "test", MediaStartId = -1, Password = "test", Type = 1, UserName = "test", UserLanguage = "en" };
+ var userDto = new UserDto { Email = "test", Login = "test", Password = "test", UserName = "test", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now };
unitOfWork.Database.Insert(userDto);
var userNew = Mock.Of(e => e.Id == userDto.Id);
diff --git a/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs
index 9c5e938298..788e132baf 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs
@@ -308,7 +308,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var templateRepository = new TemplateRepository(unitOfWork, CacheHelper, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepository = new TagRepository(unitOfWork, CacheHelper, Logger);
contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper, Logger, templateRepository);
- var repository = new ContentRepository(unitOfWork, CacheHelper, Logger, contentTypeRepository, templateRepository, tagRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
return repository;
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs
index bfb8096761..279a693238 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs
@@ -991,7 +991,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var templateRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepository = new TagRepository(unitOfWork, DisabledCache, Logger);
contentTypeRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, templateRepository);
- var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository);
+ var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
return repository;
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs
index 681f1b5215..5ff945f1d4 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs
@@ -404,7 +404,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var tagRepository = new TagRepository(unitOfWork, DisabledCache, Logger);
var contentTypeRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, templateRepository);
- var contentRepo = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository);
+ var contentRepo = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
var textpage = MockedContent.CreateSimpleContent(contentType);
diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs
new file mode 100644
index 0000000000..73bef21bfd
--- /dev/null
+++ b/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs
@@ -0,0 +1,420 @@
+using System.Linq;
+using Moq;
+using NUnit.Framework;
+using Umbraco.Core.Logging;
+using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Persistence.Repositories;
+using Umbraco.Core.Persistence.UnitOfWork;
+using Umbraco.Tests.TestHelpers;
+using Umbraco.Tests.TestHelpers.Entities;
+using Umbraco.Tests.Testing;
+
+namespace Umbraco.Tests.Persistence.Repositories
+{
+ [TestFixture]
+ [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
+ public class UserGroupRepositoryTest : TestWithDatabaseBase
+ {
+ private UserGroupRepository CreateRepository(IScopeUnitOfWork unitOfWork)
+ {
+ return new UserGroupRepository(unitOfWork, Core.Cache.CacheHelper.CreateDisabledCacheHelper(), Mock.Of());
+ }
+
+ [Test]
+ public void Can_Perform_Add_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroup = MockedUserGroup.CreateUserGroup();
+
+ // Act
+ repository.AddOrUpdate(userGroup);
+ unitOfWork.Complete();
+
+ // Assert
+ Assert.That(userGroup.HasIdentity, Is.True);
+ }
+ }
+
+ [Test]
+ public void Can_Perform_Multiple_Adds_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroup1 = MockedUserGroup.CreateUserGroup("1");
+ var userGroup2 = MockedUserGroup.CreateUserGroup("2");
+
+ // Act
+ repository.AddOrUpdate(userGroup1);
+ unitOfWork.Flush();
+ repository.AddOrUpdate(userGroup2);
+ unitOfWork.Complete();
+
+ // Assert
+ Assert.That(userGroup1.HasIdentity, Is.True);
+ Assert.That(userGroup2.HasIdentity, Is.True);
+ }
+ }
+
+ [Test]
+ public void Can_Verify_Fresh_Entity_Is_Not_Dirty()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroup = MockedUserGroup.CreateUserGroup();
+ repository.AddOrUpdate(userGroup);
+ unitOfWork.Complete();
+
+ // Act
+ var resolved = repository.Get(userGroup.Id);
+ bool dirty = ((UserGroup)resolved).IsDirty();
+
+ // Assert
+ Assert.That(dirty, Is.False);
+ }
+ }
+
+ [Test]
+ public void Can_Perform_Update_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroup = MockedUserGroup.CreateUserGroup();
+ repository.AddOrUpdate(userGroup);
+ unitOfWork.Flush();
+
+ // Act
+ var resolved = repository.Get(userGroup.Id);
+ resolved.Name = "New Name";
+ resolved.Permissions = new[] { "Z", "Y", "X" };
+ repository.AddOrUpdate(resolved);
+ unitOfWork.Complete();
+ var updatedItem = repository.Get(userGroup.Id);
+
+ // Assert
+ Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
+ Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
+ Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions));
+ }
+ }
+
+ [Test]
+ public void Can_Perform_Delete_On_UserGroupRepository()
+ {
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroup = MockedUserGroup.CreateUserGroup();
+
+ // Act
+ repository.AddOrUpdate(userGroup);
+ unitOfWork.Flush();
+ var id = userGroup.Id;
+
+ var repository2 = new UserGroupRepository(unitOfWork, Core.Cache.CacheHelper.CreateDisabledCacheHelper(), Logger);
+ repository2.Delete(userGroup);
+ unitOfWork.Complete();
+
+ var resolved = repository2.Get(id);
+
+ // Assert
+ Assert.That(resolved, Is.Null);
+ }
+ }
+
+ [Test]
+ public void Can_Perform_Get_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroup = MockedUserGroup.CreateUserGroup();
+ repository.AddOrUpdate(userGroup);
+ unitOfWork.Complete();
+
+ // Act
+ var resolved = repository.Get(userGroup.Id);
+
+ // Assert
+ Assert.That(resolved.Id, Is.EqualTo(userGroup.Id));
+ //Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue));
+ //Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue));
+ Assert.That(resolved.Name, Is.EqualTo(userGroup.Name));
+ Assert.That(resolved.Alias, Is.EqualTo(userGroup.Alias));
+ Assert.That(resolved.Permissions, Is.EqualTo(userGroup.Permissions));
+ }
+ }
+
+ [Test]
+ public void Can_Perform_GetByQuery_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+ var query = unitOfWork.Query().Where(x => x.Alias == "testUserGroup1");
+ var result = repository.GetByQuery(query);
+
+ // Assert
+ Assert.That(result.Count(), Is.GreaterThanOrEqualTo(1));
+ }
+ }
+
+ [Test]
+ public void Can_Perform_GetAll_By_Param_Ids_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroups = CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+ var result = repository.GetAll(userGroups[0].Id, userGroups[1].Id);
+
+ // Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Any(), Is.True);
+ Assert.That(result.Count(), Is.EqualTo(2));
+ }
+ }
+
+ [Test]
+ public void Can_Perform_GetAll_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+ var result = repository.GetAll();
+
+ // Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Any(), Is.True);
+ Assert.That(result.Count(), Is.GreaterThanOrEqualTo(3));
+ }
+ }
+
+ [Test]
+ public void Can_Perform_Exists_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroups = CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+ var exists = repository.Exists(userGroups[0].Id);
+
+ // Assert
+ Assert.That(exists, Is.True);
+ }
+ }
+
+ [Test]
+ public void Can_Perform_Count_On_UserGroupRepository()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var userGroups = CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+ var query = unitOfWork.Query().Where(x => x.Alias == "testUserGroup1" || x.Alias == "testUserGroup2");
+ var result = repository.Count(query);
+
+ // Assert
+ Assert.That(result, Is.GreaterThanOrEqualTo(2));
+ }
+ }
+
+ [Test]
+ public void Can_Remove_Section_For_Group()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var groups = CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+
+ //add and remove a few times, this tests the internal collection
+ groups[0].RemoveAllowedSection("content");
+ groups[0].RemoveAllowedSection("content");
+ groups[0].AddAllowedSection("content");
+ groups[0].RemoveAllowedSection("content");
+
+ groups[1].RemoveAllowedSection("media");
+ groups[1].RemoveAllowedSection("media");
+
+ repository.AddOrUpdate(groups[0]);
+ repository.AddOrUpdate(groups[1]);
+ unitOfWork.Complete();
+
+ // Assert
+ var result = repository.GetAll((int)groups[0].Id, (int)groups[1].Id).ToArray();
+ Assert.AreEqual(1, result[0].AllowedSections.Count());
+ Assert.AreEqual("media", result[0].AllowedSections.First());
+ Assert.AreEqual(1, result[1].AllowedSections.Count());
+ Assert.AreEqual("content", result[1].AllowedSections.First());
+ }
+ }
+
+ [Test]
+ public void Can_Add_Section_ForGroup()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var groups = CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+
+ //add and remove a few times, this tests the internal collection
+ groups[0].ClearAllowedSections();
+ groups[0].AddAllowedSection("content");
+ groups[0].AddAllowedSection("media");
+ groups[0].RemoveAllowedSection("content");
+ groups[0].AddAllowedSection("content");
+ groups[0].AddAllowedSection("settings");
+
+ //add the same even though it's already there
+ groups[0].AddAllowedSection("content");
+
+ groups[1].ClearAllowedSections();
+ groups[1].AddAllowedSection("developer");
+
+ groups[2].ClearAllowedSections();
+
+ repository.AddOrUpdate(groups[0]);
+ repository.AddOrUpdate(groups[1]);
+ repository.AddOrUpdate(groups[2]);
+ unitOfWork.Complete();
+
+ // Assert
+ var result = repository.GetAll((int)groups[0].Id, (int)groups[1].Id, (int)groups[2].Id).ToArray();
+ Assert.AreEqual(3, result[0].AllowedSections.Count());
+ Assert.IsTrue(result[0].AllowedSections.Contains("content"));
+ Assert.IsTrue(result[0].AllowedSections.Contains("media"));
+ Assert.IsTrue(result[0].AllowedSections.Contains("settings"));
+ Assert.AreEqual(1, result[1].AllowedSections.Count());
+ Assert.IsTrue(result[1].AllowedSections.Contains("developer"));
+ Assert.AreEqual(0, result[2].AllowedSections.Count());
+ }
+ }
+
+ [Test]
+ public void Can_Update_Section_For_Group()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var groups = CreateAndCommitMultipleUserGroups(repository, unitOfWork);
+
+ // Act
+
+ groups[0].RemoveAllowedSection("content");
+ groups[0].AddAllowedSection("settings");
+
+ repository.AddOrUpdate(groups[0]);
+ unitOfWork.Complete();
+
+ // Assert
+ var result = repository.Get((int)groups[0].Id);
+ Assert.AreEqual(2, result.AllowedSections.Count());
+ Assert.IsTrue(result.AllowedSections.Contains("settings"));
+ Assert.IsTrue(result.AllowedSections.Contains("media"));
+ }
+ }
+
+
+ [Test]
+ public void Get_Groups_Assigned_To_Section()
+ {
+ // Arrange
+ var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
+ using (var unitOfWork = provider.CreateUnitOfWork())
+ {
+ var repository = CreateRepository(unitOfWork);
+
+ var user1 = MockedUserGroup.CreateUserGroup("1", allowedSections: new[] { "test1" });
+ var user2 = MockedUserGroup.CreateUserGroup("2", allowedSections: new[] { "test2" });
+ var user3 = MockedUserGroup.CreateUserGroup("3", allowedSections: new[] { "test1" });
+ repository.AddOrUpdate(user1);
+ repository.AddOrUpdate(user2);
+ repository.AddOrUpdate(user3);
+ unitOfWork.Complete();
+
+ // Act
+ var groups = repository.GetGroupsAssignedToSection("test1");
+
+ // Assert
+ Assert.AreEqual(2, groups.Count());
+ var names = groups.Select(x => x.Name).ToArray();
+ Assert.IsTrue(names.Contains("TestUserGroup1"));
+ Assert.IsFalse(names.Contains("TestUserGroup2"));
+ Assert.IsTrue(names.Contains("TestUserGroup3"));
+ }
+ }
+
+ private IUserGroup[] CreateAndCommitMultipleUserGroups(IUserGroupRepository repository, IUnitOfWork unitOfWork)
+ {
+ var userGroup1 = MockedUserGroup.CreateUserGroup("1");
+ var userGroup2 = MockedUserGroup.CreateUserGroup("2");
+ var userGroup3 = MockedUserGroup.CreateUserGroup("3");
+ repository.AddOrUpdate(userGroup1);
+ repository.AddOrUpdate(userGroup2);
+ repository.AddOrUpdate(userGroup3);
+ unitOfWork.Complete();
+ return new IUserGroup[] { userGroup1, userGroup2, userGroup3 };
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
index ea34838bcd..348e4d7301 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
@@ -1,7 +1,10 @@
using System.Linq;
using Moq;
using NUnit.Framework;
+using Umbraco.Core;
using Umbraco.Core.Cache;
+using Umbraco.Core.Configuration.UmbracoSettings;
+using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence.Mappers;
@@ -17,13 +20,39 @@ namespace Umbraco.Tests.Persistence.Repositories
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class UserRepositoryTest : TestWithDatabaseBase
{
- private UserRepository CreateRepository(IScopeUnitOfWork unitOfWork, out UserTypeRepository userTypeRepository)
+ private MediaRepository CreateMediaRepository(IScopeUnitOfWork unitOfWork, out IMediaTypeRepository mediaTypeRepository)
{
- userTypeRepository = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of());
- var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), userTypeRepository, Mock.Of());
+ mediaTypeRepository = new MediaTypeRepository(unitOfWork, CacheHelper, Mock.Of());
+ var tagRepository = new TagRepository(unitOfWork, CacheHelper, Mock.Of());
+ var repository = new MediaRepository(unitOfWork, CacheHelper, Mock.Of(), mediaTypeRepository, tagRepository, Mock.Of());
return repository;
}
+ private ContentRepository CreateContentRepository(IScopeUnitOfWork unitOfWork, out IContentTypeRepository contentTypeRepository)
+ {
+ ITemplateRepository tr;
+ return CreateContentRepository(unitOfWork, out contentTypeRepository, out tr);
+ }
+
+ private ContentRepository CreateContentRepository(IScopeUnitOfWork unitOfWork, out IContentTypeRepository contentTypeRepository, out ITemplateRepository templateRepository)
+ {
+ templateRepository = new TemplateRepository(unitOfWork, CacheHelper, Logger, Mock.Of(), Mock.Of(), Mock.Of());
+ var tagRepository = new TagRepository(unitOfWork, CacheHelper, Logger);
+ contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper, Logger, templateRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
+ return repository;
+ }
+
+ private UserRepository CreateRepository(IScopeUnitOfWork unitOfWork)
+ {
+ var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), Mock.Of());
+ return repository;
+ }
+
+ private UserGroupRepository CreateUserGroupRepository(IScopeUnitOfWork unitOfWork)
+ {
+ return new UserGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of());
+ }
[Test]
public void Can_Perform_Add_On_UserRepository()
@@ -32,10 +61,9 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
- var user = MockedUser.CreateUser(CreateAndCommitUserType());
+ var user = MockedUser.CreateUser();
// Act
repository.AddOrUpdate(user);
@@ -53,11 +81,10 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
- var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1");
- var use2 = MockedUser.CreateUser(CreateAndCommitUserType(), "2");
+ var user1 = MockedUser.CreateUser("1");
+ var use2 = MockedUser.CreateUser("2");
// Act
repository.AddOrUpdate(user1);
@@ -78,10 +105,9 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
- var user = MockedUser.CreateUser(CreateAndCommitUserType());
+ var user = MockedUser.CreateUser();
repository.AddOrUpdate(user);
unitOfWork.Flush();
@@ -97,19 +123,32 @@ namespace Umbraco.Tests.Persistence.Repositories
[Test]
public void Can_Perform_Update_On_UserRepository()
{
+ var ct = MockedContentTypes.CreateBasicContentType("test");
+ var content = MockedContent.CreateBasicContent(ct);
+ var mt = MockedContentTypes.CreateSimpleMediaType("testmedia", "TestMedia");
+ var media = MockedMedia.CreateSimpleMedia(mt, "asdf", -1);
+
// Arrange
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var userRepository = CreateRepository(unitOfWork);
+ var contentRepository = CreateContentRepository(unitOfWork, out var contentTypeRepo);
+ var mediaRepository = CreateMediaRepository(unitOfWork, out var mediaTypeRepo);
+ var userGroupRepository = CreateUserGroupRepository(unitOfWork);
- var user = MockedUser.CreateUser(CreateAndCommitUserType());
- repository.AddOrUpdate(user);
+ contentTypeRepo.AddOrUpdate(ct);
+ mediaTypeRepo.AddOrUpdate(mt);
unitOfWork.Flush();
+ contentRepository.AddOrUpdate(content);
+ mediaRepository.AddOrUpdate(media);
+ unitOfWork.Flush();
+
+ var user = CreateAndCommitUserWithGroup(userRepository, userGroupRepository, unitOfWork);
+
// Act
- var resolved = (User)repository.Get((int)user.Id);
+ var resolved = (User)userRepository.Get((int)user.Id);
resolved.Name = "New Name";
//the db column is not used, default permissions are taken from the user type's permissions, this is a getter only
@@ -118,29 +157,28 @@ namespace Umbraco.Tests.Persistence.Repositories
resolved.IsApproved = false;
resolved.RawPasswordValue = "new";
resolved.IsLockedOut = true;
- resolved.StartContentId = 10;
- resolved.StartMediaId = 11;
+ resolved.StartContentIds = new[] { content.Id };
+ resolved.StartMediaIds = new[] { media.Id };
resolved.Email = "new@new.com";
resolved.Username = "newName";
- resolved.RemoveAllowedSection("content");
- repository.AddOrUpdate(resolved);
+ userRepository.AddOrUpdate(resolved);
unitOfWork.Flush();
- var updatedItem = (User)repository.Get((int)user.Id);
+ var updatedItem = (User)userRepository.Get((int)user.Id);
// Assert
Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
- //Assert.That(updatedItem.DefaultPermissions, Is.EqualTo(resolved.DefaultPermissions));
Assert.That(updatedItem.Language, Is.EqualTo(resolved.Language));
Assert.That(updatedItem.IsApproved, Is.EqualTo(resolved.IsApproved));
Assert.That(updatedItem.RawPasswordValue, Is.EqualTo(resolved.RawPasswordValue));
Assert.That(updatedItem.IsLockedOut, Is.EqualTo(resolved.IsLockedOut));
- Assert.That(updatedItem.StartContentId, Is.EqualTo(resolved.StartContentId));
- Assert.That(updatedItem.StartMediaId, Is.EqualTo(resolved.StartMediaId));
+ Assert.IsTrue(updatedItem.StartContentIds.UnsortedSequenceEqual(resolved.StartContentIds));
+ Assert.IsTrue(updatedItem.StartMediaIds.UnsortedSequenceEqual(resolved.StartMediaIds));
Assert.That(updatedItem.Email, Is.EqualTo(resolved.Email));
Assert.That(updatedItem.Username, Is.EqualTo(resolved.Username));
Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(1));
+ Assert.IsTrue(updatedItem.AllowedSections.Contains("content"));
Assert.IsTrue(updatedItem.AllowedSections.Contains("media"));
}
}
@@ -152,18 +190,16 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
- var user = MockedUser.CreateUser(CreateAndCommitUserType());
+ var user = MockedUser.CreateUser();
// Act
repository.AddOrUpdate(user);
unitOfWork.Flush();
var id = user.Id;
- var utRepo = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger);
- var repository2 = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, utRepo, Mock.Of());
+ var repository2 = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, Mock.Of());
repository2.Delete(user);
unitOfWork.Flush();
@@ -175,36 +211,6 @@ namespace Umbraco.Tests.Persistence.Repositories
}
}
- //[Test]
- //public void Can_Perform_Delete_On_UserRepository_With_Permissions_Assigned()
- //{
- // // Arrange
- // var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- // using (var unitOfWork = provider.GetUnitOfWork())
- // UserTypeRepository userTypeRepository;
- //using (var repository = CreateRepository(unitOfWork, out userTypeRepository))
- //{
-
- // var user = MockedUser.CreateUser(CreateAndCommitUserType());
- // //repository.AssignPermissions()
-
- // // Act
- // repository.AddOrUpdate(user);
- // unitOfWork.Commit();
- // var id = user.Id;
-
- // var repository2 = RepositoryResolver.Current.ResolveByType(unitOfWork);
- // repository2.Delete(user);
- // unitOfWork.Commit();
-
- // var resolved = repository2.Get((int)id);
-
- // // Assert
- // Assert.That(resolved, Is.Null);
- //}
-
- //}
-
[Test]
public void Can_Perform_Get_On_UserRepository()
{
@@ -212,12 +218,10 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
+ var userGroupRepository = CreateUserGroupRepository(unitOfWork);
- var user = MockedUser.CreateUser(CreateAndCommitUserType());
- repository.AddOrUpdate(user);
- unitOfWork.Flush();
+ var user = CreateAndCommitUserWithGroup(repository, userGroupRepository, unitOfWork);
// Act
var updatedItem = repository.Get((int) user.Id);
@@ -234,8 +238,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
CreateAndCommitMultipleUsers(repository, unitOfWork);
@@ -255,8 +258,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
@@ -277,8 +279,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
CreateAndCommitMultipleUsers(repository, unitOfWork);
@@ -299,8 +300,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
@@ -319,8 +319,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
using (var unitOfWork = provider.CreateUnitOfWork())
{
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
+ var repository = CreateRepository(unitOfWork);
var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
@@ -333,180 +332,16 @@ namespace Umbraco.Tests.Persistence.Repositories
}
}
- [Test]
- public void Can_Remove_Section_For_User()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
-
- var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
-
- // Act
-
- //add and remove a few times, this tests the internal collection
- users[0].RemoveAllowedSection("content");
- users[0].RemoveAllowedSection("content");
- users[0].AddAllowedSection("content");
- users[0].RemoveAllowedSection("content");
-
- users[1].RemoveAllowedSection("media");
- users[1].RemoveAllowedSection("media");
-
- repository.AddOrUpdate(users[0]);
- repository.AddOrUpdate(users[1]);
- unitOfWork.Flush();
-
- // Assert
- var result = repository.GetAll((int) users[0].Id, (int) users[1].Id).ToArray();
- Assert.AreEqual(1, result[0].AllowedSections.Count());
- Assert.AreEqual("media", result[0].AllowedSections.First());
- Assert.AreEqual(1, result[1].AllowedSections.Count());
- Assert.AreEqual("content", result[1].AllowedSections.First());
- }
- }
-
- [Test]
- public void Can_Add_Section_For_User()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
-
- var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
-
- // Act
-
- //add and remove a few times, this tests the internal collection
- users[0].AddAllowedSection("settings");
- users[0].AddAllowedSection("settings");
- users[0].RemoveAllowedSection("settings");
- users[0].AddAllowedSection("settings");
-
- users[1].AddAllowedSection("developer");
-
- //add the same even though it's already there
- users[2].AddAllowedSection("content");
-
- repository.AddOrUpdate(users[0]);
- repository.AddOrUpdate(users[1]);
- unitOfWork.Flush();
-
- // Assert
- var result = repository.GetAll((int) users[0].Id, (int) users[1].Id, (int) users[2].Id).ToArray();
- Assert.AreEqual(3, result[0].AllowedSections.Count());
- Assert.IsTrue(result[0].AllowedSections.Contains("content"));
- Assert.IsTrue(result[0].AllowedSections.Contains("media"));
- Assert.IsTrue(result[0].AllowedSections.Contains("settings"));
- Assert.AreEqual(3, result[1].AllowedSections.Count());
- Assert.IsTrue(result[1].AllowedSections.Contains("content"));
- Assert.IsTrue(result[1].AllowedSections.Contains("media"));
- Assert.IsTrue(result[1].AllowedSections.Contains("developer"));
- Assert.AreEqual(2, result[2].AllowedSections.Count());
- Assert.IsTrue(result[1].AllowedSections.Contains("content"));
- Assert.IsTrue(result[1].AllowedSections.Contains("media"));
- }
- }
-
- [Test]
- public void Can_Update_Section_For_User()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
-
- var users = CreateAndCommitMultipleUsers(repository, unitOfWork);
-
- // Act
-
- users[0].RemoveAllowedSection("content");
- users[0].AddAllowedSection("settings");
-
- repository.AddOrUpdate(users[0]);
- unitOfWork.Flush();
-
- // Assert
- var result = repository.Get((int) users[0].Id);
- Assert.AreEqual(2, result.AllowedSections.Count());
- Assert.IsTrue(result.AllowedSections.Contains("settings"));
- Assert.IsTrue(result.AllowedSections.Contains("media"));
- }
- }
-
-
- [Test]
- public void Get_Users_Assigned_To_Section()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- UserTypeRepository userTypeRepository;
- var repository = CreateRepository(unitOfWork, out userTypeRepository);
-
- var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1", "test", "media");
- var user2 = MockedUser.CreateUser(CreateAndCommitUserType(), "2", "media", "settings");
- var user3 = MockedUser.CreateUser(CreateAndCommitUserType(), "3", "test", "settings");
- repository.AddOrUpdate(user1);
- repository.AddOrUpdate(user2);
- repository.AddOrUpdate(user3);
- unitOfWork.Flush();
-
- // Act
-
- var users = repository.GetUsersAssignedToSection("test");
-
- // Assert
- Assert.AreEqual(2, users.Count());
- var names = users.Select(x => x.Username).ToArray();
- Assert.IsTrue(names.Contains("TestUser1"));
- Assert.IsTrue(names.Contains("TestUser3"));
- }
- }
-
- [Test]
- public void Default_User_Permissions_Based_On_User_Type()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var utRepo = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger);
- var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, utRepo, Mock.Of());
-
- // Act
- var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1", "test", "media");
- repository.AddOrUpdate(user1);
- unitOfWork.Flush();
-
- // Assert
- Assert.AreEqual(3, user1.DefaultPermissions.Count());
- Assert.AreEqual("A", user1.DefaultPermissions.ElementAt(0));
- Assert.AreEqual("B", user1.DefaultPermissions.ElementAt(1));
- Assert.AreEqual("C", user1.DefaultPermissions.ElementAt(2));
- }
- }
-
private void AssertPropertyValues(IUser updatedItem, IUser originalUser)
{
Assert.That(updatedItem.Id, Is.EqualTo(originalUser.Id));
Assert.That(updatedItem.Name, Is.EqualTo(originalUser.Name));
- Assert.That(updatedItem.DefaultPermissions, Is.EqualTo(originalUser.DefaultPermissions));
Assert.That(updatedItem.Language, Is.EqualTo(originalUser.Language));
Assert.That(updatedItem.IsApproved, Is.EqualTo(originalUser.IsApproved));
Assert.That(updatedItem.RawPasswordValue, Is.EqualTo(originalUser.RawPasswordValue));
Assert.That(updatedItem.IsLockedOut, Is.EqualTo(originalUser.IsLockedOut));
- Assert.That(updatedItem.StartContentId, Is.EqualTo(originalUser.StartContentId));
- Assert.That(updatedItem.StartMediaId, Is.EqualTo(originalUser.StartMediaId));
+ Assert.IsTrue(updatedItem.StartContentIds.UnsortedSequenceEqual(originalUser.StartContentIds));
+ Assert.IsTrue(updatedItem.StartMediaIds.UnsortedSequenceEqual(originalUser.StartMediaIds));
Assert.That(updatedItem.Email, Is.EqualTo(originalUser.Email));
Assert.That(updatedItem.Username, Is.EqualTo(originalUser.Username));
Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(2));
@@ -514,29 +349,30 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.IsTrue(updatedItem.AllowedSections.Contains("content"));
}
+ private static User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository, IScopeUnitOfWork unitOfWork)
+ {
+
+ var user = MockedUser.CreateUser();
+ repository.AddOrUpdate(user);
+ unitOfWork.Flush();
+
+ var group = MockedUserGroup.CreateUserGroup();
+ userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id });
+ unitOfWork.Flush();
+
+ return user;
+ }
+
private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository, IUnitOfWork unitOfWork)
{
- var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1");
- var user2 = MockedUser.CreateUser(CreateAndCommitUserType(), "2");
- var user3 = MockedUser.CreateUser(CreateAndCommitUserType(), "3");
+ var user1 = MockedUser.CreateUser("1");
+ var user2 = MockedUser.CreateUser("2");
+ var user3 = MockedUser.CreateUser("3");
repository.AddOrUpdate(user1);
repository.AddOrUpdate(user2);
repository.AddOrUpdate(user3);
unitOfWork.Complete();
return new IUser[] { user1, user2, user3 };
}
-
- private IUserType CreateAndCommitUserType()
- {
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger);
- var userType = MockedUserType.CreateUserType();
- repository.AddOrUpdate(userType);
- unitOfWork.Complete();
- return userType;
- }
- }
}
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserTypeRepositoryTest.cs
deleted file mode 100644
index 21b18c913e..0000000000
--- a/src/Umbraco.Tests/Persistence/Repositories/UserTypeRepositoryTest.cs
+++ /dev/null
@@ -1,288 +0,0 @@
-using System.Linq;
-using Moq;
-using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Logging;
-using Umbraco.Core.Models.Membership;
-using Umbraco.Core.Persistence;
-
-using Umbraco.Core.Persistence.Querying;
-using Umbraco.Core.Persistence.Repositories;
-using Umbraco.Core.Persistence.UnitOfWork;
-using Umbraco.Tests.TestHelpers;
-using Umbraco.Tests.TestHelpers.Entities;
-using Umbraco.Tests.Testing;
-
-namespace Umbraco.Tests.Persistence.Repositories
-{
- [TestFixture]
- [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
- public class UserTypeRepositoryTest : TestWithDatabaseBase
- {
- private UserTypeRepository CreateRepository(IScopeUnitOfWork unitOfWork)
- {
- return new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of());
- }
-
- [Test]
- public void Can_Perform_Add_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userType = MockedUserType.CreateUserType();
-
- // Act
- repository.AddOrUpdate(userType);
- unitOfWork.Flush();
-
- // Assert
- Assert.That(userType.HasIdentity, Is.True);
- }
- }
-
- [Test]
- public void Can_Perform_Multiple_Adds_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userType1 = MockedUserType.CreateUserType("1");
- var userType2 = MockedUserType.CreateUserType("2");
-
- // Act
- repository.AddOrUpdate(userType1);
- unitOfWork.Flush();
- repository.AddOrUpdate(userType2);
- unitOfWork.Flush();
-
- // Assert
- Assert.That(userType1.HasIdentity, Is.True);
- Assert.That(userType2.HasIdentity, Is.True);
- }
- }
-
- [Test]
- public void Can_Verify_Fresh_Entity_Is_Not_Dirty()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userType = MockedUserType.CreateUserType();
- repository.AddOrUpdate(userType);
- unitOfWork.Flush();
-
- // Act
- var resolved = repository.Get(userType.Id);
- bool dirty = ((UserType) resolved).IsDirty();
-
- // Assert
- Assert.That(dirty, Is.False);
- }
- }
-
- [Test]
- public void Can_Perform_Update_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userType = MockedUserType.CreateUserType();
- repository.AddOrUpdate(userType);
- unitOfWork.Flush();
-
- // Act
- var resolved = repository.Get(userType.Id);
- resolved.Name = "New Name";
- resolved.Permissions = new[]{"Z", "Y", "X"};
- repository.AddOrUpdate(resolved);
- unitOfWork.Flush();
- var updatedItem = repository.Get(userType.Id);
-
- // Assert
- Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
- Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
- Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions));
- }
- }
-
- [Test]
- public void Can_Perform_Delete_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userType = MockedUserType.CreateUserType();
-
- // Act
- repository.AddOrUpdate(userType);
- unitOfWork.Flush();
- var id = userType.Id;
-
- var repository2 = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger);
- repository2.Delete(userType);
- unitOfWork.Flush();
-
- var resolved = repository2.Get(id);
-
- // Assert
- Assert.That(resolved, Is.Null);
- }
- }
-
- [Test]
- public void Can_Perform_Get_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userType = MockedUserType.CreateUserType();
- repository.AddOrUpdate(userType);
- unitOfWork.Flush();
-
- // Act
- var resolved = repository.Get(userType.Id);
-
- // Assert
- Assert.That(resolved.Id, Is.EqualTo(userType.Id));
- //Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue));
- //Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue));
- Assert.That(resolved.Name, Is.EqualTo(userType.Name));
- Assert.That(resolved.Alias, Is.EqualTo(userType.Alias));
- Assert.That(resolved.Permissions, Is.EqualTo(userType.Permissions));
- }
- }
-
- [Test]
- public void Can_Perform_GetByQuery_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- CreateAndCommitMultipleUserTypes(repository, unitOfWork);
-
- // Act
- var query = unitOfWork.Query().Where(x => x.Alias == "testUserType1");
- var result = repository.GetByQuery(query);
-
- // Assert
- Assert.That(result.Count(), Is.GreaterThanOrEqualTo(1));
- }
- }
-
- [Test]
- public void Can_Perform_GetAll_By_Param_Ids_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userTypes = CreateAndCommitMultipleUserTypes(repository, unitOfWork);
-
- // Act
- var result = repository.GetAll(userTypes[0].Id, userTypes[1].Id);
-
- // Assert
- Assert.That(result, Is.Not.Null);
- Assert.That(result.Any(), Is.True);
- Assert.That(result.Count(), Is.EqualTo(2));
- }
- }
-
- [Test]
- public void Can_Perform_GetAll_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- CreateAndCommitMultipleUserTypes(repository, unitOfWork);
-
- // Act
- var result = repository.GetAll();
-
- // Assert
- Assert.That(result, Is.Not.Null);
- Assert.That(result.Any(), Is.True);
- Assert.That(result.Count(), Is.GreaterThanOrEqualTo(3));
- }
- }
-
- [Test]
- public void Can_Perform_Exists_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userTypes = CreateAndCommitMultipleUserTypes(repository, unitOfWork);
-
- // Act
- var exists = repository.Exists(userTypes[0].Id);
-
- // Assert
- Assert.That(exists, Is.True);
- }
- }
-
- [Test]
- public void Can_Perform_Count_On_UserTypeRepository()
- {
- // Arrange
- var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
- using (var unitOfWork = provider.CreateUnitOfWork())
- {
- var repository = CreateRepository(unitOfWork);
-
- var userTypes = CreateAndCommitMultipleUserTypes(repository, unitOfWork);
-
- // Act
- var query = unitOfWork.Query().Where(x => x.Alias == "testUserType1" || x.Alias == "testUserType2");
- var result = repository.Count(query);
-
- // Assert
- Assert.That(result, Is.GreaterThanOrEqualTo(2));
- }
- }
-
- private IUserType[] CreateAndCommitMultipleUserTypes(IUserTypeRepository repository, IUnitOfWork unitOfWork)
- {
- var userType1 = MockedUserType.CreateUserType("1");
- var userType2 = MockedUserType.CreateUserType("2");
- var userType3 = MockedUserType.CreateUserType("3");
- repository.AddOrUpdate(userType1);
- repository.AddOrUpdate(userType2);
- repository.AddOrUpdate(userType3);
- unitOfWork.Flush();
- return new IUserType[] {userType1, userType2, userType3};
- }
- }
-}
diff --git a/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs b/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs
index 5bd3266029..76849cc95f 100644
--- a/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs
+++ b/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs
@@ -500,7 +500,6 @@ namespace Umbraco.Tests.Persistence
var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
helper.CreateTable();
- helper.CreateTable();
helper.CreateTable();
helper.CreateTable();
helper.CreateTable();
@@ -529,7 +528,6 @@ namespace Umbraco.Tests.Persistence
{
var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
- helper.CreateTable();
helper.CreateTable();
scope.Complete();
@@ -537,28 +535,13 @@ namespace Umbraco.Tests.Persistence
}
[Test]
- public void Can_Create_umbracoUserType_Table()
+ public void Can_Create_umbracoUserGroup_Table()
{
using (var scope = ScopeProvider.CreateScope())
{
var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
- helper.CreateTable();
-
- scope.Complete();
- }
- }
-
- [Test]
- public void Can_Create_umbracoUser2app_Table()
- {
- using (var scope = ScopeProvider.CreateScope())
- {
- var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
-
- helper.CreateTable();
- helper.CreateTable();
- helper.CreateTable();
+ helper.CreateTable();
scope.Complete();
}
@@ -572,7 +555,6 @@ namespace Umbraco.Tests.Persistence
var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
helper.CreateTable();
- helper.CreateTable();
helper.CreateTable();
helper.CreateTable();
@@ -580,17 +562,30 @@ namespace Umbraco.Tests.Persistence
}
}
- [Test]
- public void Can_Create_umbracoUser2NodePermission_Table()
+ public void Can_Create_umbracoGroupUser2app_Table()
{
using (var scope = ScopeProvider.CreateScope())
{
var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
helper.CreateTable();
- helper.CreateTable();
- helper.CreateTable();
- helper.CreateTable();
+ helper.CreateTable();
+ helper.CreateTable();
+
+ scope.Complete();
+ }
+ }
+
+ [Test]
+ public void Can_Create_umbracoUserGroup2NodePermission_Table()
+ {
+ using (var scope = ScopeProvider.CreateScope())
+ {
+ var helper = new DatabaseSchemaHelper(scope.Database, Mock.Of());
+
+ helper.CreateTable();
+ helper.CreateTable();
+ helper.CreateTable();
scope.Complete();
}
diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs
index 6c1a483ee7..aff3291e91 100644
--- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs
+++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs
@@ -97,6 +97,27 @@ namespace Umbraco.Tests.PropertyEditors
var inter = converter.ConvertSourceToInter(null, null, value, false);
var result = converter.ConvertInterToObject(null, null, PropertyCacheLevel.Unknown, inter, false);
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestCase("1", 1)]
+ [TestCase("1", 1)]
+ [TestCase("0", 0)]
+ [TestCase("0", 0)]
+ [TestCase(null, 0)]
+ [TestCase(null, 0)]
+ [TestCase("-1", -1)]
+ [TestCase("-1", -1)]
+ [TestCase("1.65", 1.65)]
+ [TestCase("1.65", 1.65)]
+ [TestCase("-1.65", -1.65)]
+ [TestCase("-1.65", -1.65)]
+ public void CanConvertDecimalAliasPropertyEditor(object value, double expected)
+ {
+ var converter = new DecimalValueConverter();
+ var inter = converter.ConvertSourceToInter(null, null, value, false);
+ var result = converter.ConvertInterToObject(null, null, PropertyCacheLevel.Unknown, inter, false);
+
Assert.AreEqual(expected, result);
}
}
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
index ac9783b0e1..4a77db39e1 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
@@ -1,11 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
+using NUnit.Framework;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
-using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using Umbraco.Web;
@@ -82,7 +77,7 @@ namespace Umbraco.Tests.PublishedContent
contentTypeService.Save(inheritedType);
createContentTypes = false;
}
- #region setup xml content
+
xmlContent = @"
@@ -91,7 +86,6 @@ namespace Umbraco.Tests.PublishedContent
";
- #endregion
}
}
}
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
index a7196f9181..e5c767fa64 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
@@ -98,7 +98,7 @@ namespace Umbraco.Tests.PublishedContent
-
+
1
diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs
index 42dea2f992..c6aaca8056 100644
--- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs
+++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs
@@ -258,10 +258,12 @@ namespace Umbraco.Tests.Scheduling
{
using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions
{
- AutoStart = true
+ AutoStart = true,
+ KeepAlive = true // else stops!
}, _logger))
{
Assert.IsTrue(runner.IsRunning); // because AutoStart is true
+ runner.Stop(false); // keepalive = must be stopped
await runner.StoppedAwaitable; // runner stops, within test's timeout
}
}
diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs
index 5b85b2d626..2b62422bb0 100644
--- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs
+++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs
@@ -64,8 +64,7 @@ namespace Umbraco.Tests.Scoping
var service = Current.Services.UserService;
var globalCache = Current.ApplicationCache.IsolatedRuntimeCache.GetOrCreateCache(typeof(IUser));
- var userType = service.GetUserTypeByAlias("admin");
- var user = (IUser) new User("name", "email", "username", "rawPassword", userType);
+ var user = (IUser)new User("name", "email", "username", "rawPassword");
service.Save(user);
// global cache contains the entity
diff --git a/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs b/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs
index 5ec4dea802..74b74ad1ce 100644
--- a/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs
+++ b/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs
@@ -29,8 +29,8 @@ namespace Umbraco.Tests.Security
//This is the id that 'identity' uses to check for the username
new Claim(ClaimTypes.Name, "testing", ClaimValueTypes.String, TestIssuer, TestIssuer),
new Claim(ClaimTypes.GivenName, "hello world", ClaimValueTypes.String, TestIssuer, TestIssuer),
- new Claim(Constants.Security.StartContentNodeIdClaimType, "-1", ClaimValueTypes.Integer32, TestIssuer, TestIssuer),
- new Claim(Constants.Security.StartMediaNodeIdClaimType, "5543", ClaimValueTypes.Integer32, TestIssuer, TestIssuer),
+ new Claim(Constants.Security.StartContentNodeIdClaimType, "[-1]", ClaimValueTypes.Integer32, TestIssuer, TestIssuer),
+ new Claim(Constants.Security.StartMediaNodeIdClaimType, "[5543]", ClaimValueTypes.Integer32, TestIssuer, TestIssuer),
new Claim(Constants.Security.AllowedApplicationsClaimType, "content", ClaimValueTypes.String, TestIssuer, TestIssuer),
new Claim(Constants.Security.AllowedApplicationsClaimType, "media", ClaimValueTypes.String, TestIssuer, TestIssuer),
new Claim(ClaimTypes.Locality, "en-us", ClaimValueTypes.String, TestIssuer, TestIssuer),
@@ -44,8 +44,8 @@ namespace Umbraco.Tests.Security
Assert.AreEqual(sessionId, backofficeIdentity.SessionId);
Assert.AreEqual("testing", backofficeIdentity.Username);
Assert.AreEqual("hello world", backofficeIdentity.RealName);
- Assert.AreEqual(-1, backofficeIdentity.StartContentNode);
- Assert.AreEqual(5543, backofficeIdentity.StartMediaNode);
+ Assert.AreEqual(1, backofficeIdentity.StartContentNodes.Length);
+ Assert.IsTrue(backofficeIdentity.StartMediaNodes.UnsortedSequenceEqual(new[] { 5543 }));
Assert.IsTrue(new[] {"content", "media"}.SequenceEqual(backofficeIdentity.AllowedApplications));
Assert.AreEqual("en-us", backofficeIdentity.Culture);
Assert.IsTrue(new[] { "admin" }.SequenceEqual(backofficeIdentity.Roles));
@@ -98,8 +98,7 @@ namespace Umbraco.Tests.Security
Id = 1234,
RealName = "hello world",
Roles = new[] {"admin"},
- StartContentNode = -1,
- StartMediaNode = 654,
+ StartMediaNodes = new[] { 654 },
Username = "testing"
};
@@ -119,8 +118,7 @@ namespace Umbraco.Tests.Security
Id = 1234,
RealName = "hello world",
Roles = new[] { "admin" },
- StartContentNode = -1,
- StartMediaNode = 654,
+ StartMediaNodes = new[] { 654 },
Username = "testing"
};
@@ -146,8 +144,7 @@ namespace Umbraco.Tests.Security
Id = 1234,
RealName = "hello world",
Roles = new[] { "admin" },
- StartContentNode = -1,
- StartMediaNode = 654,
+ StartMediaNodes = new[] { 654 },
Username = "testing"
};
@@ -170,8 +167,7 @@ namespace Umbraco.Tests.Security
Id = 1234,
RealName = "hello world",
Roles = new[] { "admin" },
- StartContentNode = -1,
- StartMediaNode = 654,
+ StartMediaNodes = new[] { 654 },
Username = "testing"
};
diff --git a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs
index 411b43f5d0..0e475b3eb7 100644
--- a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs
+++ b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs
@@ -162,7 +162,7 @@ namespace Umbraco.Tests.Services
var tRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepo = new TagRepository(unitOfWork, DisabledCache, Logger);
var ctRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, tRepository);
- var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo);
+ var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo, Mock.Of());
// Act
Stopwatch watch = Stopwatch.StartNew();
@@ -194,7 +194,7 @@ namespace Umbraco.Tests.Services
var tRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepo = new TagRepository(unitOfWork, DisabledCache, Logger);
var ctRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, tRepository);
- var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo);
+ var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo, Mock.Of());
// Act
Stopwatch watch = Stopwatch.StartNew();
@@ -224,7 +224,7 @@ namespace Umbraco.Tests.Services
var tRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepo = new TagRepository(unitOfWork, DisabledCache, Logger);
var ctRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, tRepository);
- var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo);
+ var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo, Mock.Of());
// Act
var contents = repository.GetAll();
@@ -257,7 +257,7 @@ namespace Umbraco.Tests.Services
var tRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepo = new TagRepository(unitOfWork, DisabledCache, Logger);
var ctRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, tRepository);
- var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo);
+ var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, ctRepository, tRepository, tagRepo, Mock.Of());
// Act
var contents = repository.GetAll();
diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs
index 613795c75e..89760d11e9 100644
--- a/src/Umbraco.Tests/Services/ContentServiceTests.cs
+++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs
@@ -54,6 +54,108 @@ namespace Umbraco.Tests.Services
Container.Register(factory => factory.GetInstance().TextService);
}
+ [Test]
+ public void Create_Blueprint()
+ {
+ var contentService = ServiceContext.ContentService;
+ var contentTypeService = ServiceContext.ContentTypeService;
+
+ var contentType = MockedContentTypes.CreateTextpageContentType();
+ contentTypeService.Save(contentType);
+
+ var blueprint = MockedContent.CreateTextpageContent(contentType, "hello", -1);
+ blueprint.SetValue("title", "blueprint 1");
+ blueprint.SetValue("bodyText", "blueprint 2");
+ blueprint.SetValue("keywords", "blueprint 3");
+ blueprint.SetValue("description", "blueprint 4");
+
+ contentService.SaveBlueprint(blueprint);
+
+ var found = contentService.GetBlueprintsForContentTypes().ToArray();
+ Assert.AreEqual(1, found.Length);
+
+ //ensures it's not found by normal content
+ var contentFound = contentService.GetById(found[0].Id);
+ Assert.IsNull(contentFound);
+ }
+
+ [Test]
+ public void Delete_Blueprint()
+ {
+ var contentService = ServiceContext.ContentService;
+ var contentTypeService = ServiceContext.ContentTypeService;
+
+ var contentType = MockedContentTypes.CreateTextpageContentType();
+ contentTypeService.Save(contentType);
+
+ var blueprint = MockedContent.CreateTextpageContent(contentType, "hello", -1);
+ blueprint.SetValue("title", "blueprint 1");
+ blueprint.SetValue("bodyText", "blueprint 2");
+ blueprint.SetValue("keywords", "blueprint 3");
+ blueprint.SetValue("description", "blueprint 4");
+
+ contentService.SaveBlueprint(blueprint);
+
+ contentService.DeleteBlueprint(blueprint);
+
+ var found = contentService.GetBlueprintsForContentTypes().ToArray();
+ Assert.AreEqual(0, found.Length);
+ }
+
+ [Test]
+ public void Create_Content_From_Blueprint()
+ {
+ var contentService = ServiceContext.ContentService;
+ var contentTypeService = ServiceContext.ContentTypeService;
+
+ var contentType = MockedContentTypes.CreateTextpageContentType();
+ contentTypeService.Save(contentType);
+
+ var blueprint = MockedContent.CreateTextpageContent(contentType, "hello", -1);
+ blueprint.SetValue("title", "blueprint 1");
+ blueprint.SetValue("bodyText", "blueprint 2");
+ blueprint.SetValue("keywords", "blueprint 3");
+ blueprint.SetValue("description", "blueprint 4");
+
+ contentService.SaveBlueprint(blueprint);
+
+ var fromBlueprint = contentService.CreateContentFromBlueprint(blueprint, "hello world");
+ contentService.Save(fromBlueprint);
+
+ Assert.IsTrue(fromBlueprint.HasIdentity);
+ Assert.AreEqual("blueprint 1", fromBlueprint.Properties["title"].Value);
+ Assert.AreEqual("blueprint 2", fromBlueprint.Properties["bodyText"].Value);
+ Assert.AreEqual("blueprint 3", fromBlueprint.Properties["keywords"].Value);
+ Assert.AreEqual("blueprint 4", fromBlueprint.Properties["description"].Value);
+ }
+
+ [Test]
+ public void Get_All_Blueprints()
+ {
+ var contentService = ServiceContext.ContentService;
+ var contentTypeService = ServiceContext.ContentTypeService;
+
+ var ct1 = MockedContentTypes.CreateTextpageContentType("ct1");
+ contentTypeService.Save(ct1);
+ var ct2 = MockedContentTypes.CreateTextpageContentType("ct2");
+ contentTypeService.Save(ct2);
+
+ for (int i = 0; i < 10; i++)
+ {
+ var blueprint = MockedContent.CreateTextpageContent(i % 2 == 0 ? ct1 : ct2, "hello" + i, -1);
+ contentService.SaveBlueprint(blueprint);
+ }
+
+ var found = contentService.GetBlueprintsForContentTypes().ToArray();
+ Assert.AreEqual(10, found.Length);
+
+ found = contentService.GetBlueprintsForContentTypes(ct1.Id).ToArray();
+ Assert.AreEqual(5, found.Length);
+
+ found = contentService.GetBlueprintsForContentTypes(ct2.Id).ToArray();
+ Assert.AreEqual(5, found.Length);
+ }
+
///
/// Ensures that we don't unpublish all nodes when a node is deleted that has an invalid path of -1
/// Note: it is actually the MoveToRecycleBin happening on the initial deletion of a node through the UI
@@ -787,7 +889,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Can_Save_New_Content_With_Explicit_User()
{
- var user = new User(ServiceContext.UserService.GetUserTypeByAlias("admin"))
+ var user = new User
{
Name = "Test",
Email = "test@test.com",
@@ -1409,6 +1511,98 @@ namespace Umbraco.Tests.Services
Assert.That(contents.Any(), Is.False);
}
+ [Test]
+ public void Ensures_Permissions_Are_Retained_For_Copied_Descendants_With_Explicit_Permissions()
+ {
+ // Arrange
+ var userGroup = MockedUserGroup.CreateUserGroup("1");
+ ServiceContext.UserService.Save(userGroup);
+
+ var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
+ contentType.AllowedContentTypes = new List
+ {
+ new ContentTypeSort(new Lazy(() => contentType.Id), 0, contentType.Alias)
+ };
+ ServiceContext.ContentTypeService.Save(contentType);
+
+ var parentPage = MockedContent.CreateSimpleContent(contentType);
+ ServiceContext.ContentService.Save(parentPage);
+
+ var childPage = MockedContent.CreateSimpleContent(contentType, "child", parentPage);
+ ServiceContext.ContentService.Save(childPage);
+ //assign explicit permissions to the child
+ ServiceContext.ContentService.AssignContentPermission(childPage, 'A', new[] { userGroup.Id });
+
+ //Ok, now copy, what should happen is the childPage will retain it's own permissions
+ var parentPage2 = MockedContent.CreateSimpleContent(contentType);
+ ServiceContext.ContentService.Save(parentPage2);
+
+ var copy = ServiceContext.ContentService.Copy(childPage, parentPage2.Id, false, true);
+
+ //get the permissions and verify
+ var permissions = ServiceContext.UserService.GetPermissionsForPath(userGroup, copy.Path, fallbackToDefaultPermissions: true);
+ var allPermissions = permissions.GetAllPermissions().ToArray();
+ Assert.AreEqual(1, allPermissions.Length);
+ Assert.AreEqual("A", allPermissions[0]);
+ }
+
+ [Test]
+ public void Ensures_Permissions_Are_Inherited_For_Copied_Descendants()
+ {
+ // Arrange
+ var userGroup = MockedUserGroup.CreateUserGroup("1");
+ ServiceContext.UserService.Save(userGroup);
+
+ var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
+ contentType.AllowedContentTypes = new List
+ {
+ new ContentTypeSort(new Lazy(() => contentType.Id), 0, contentType.Alias)
+ };
+ ServiceContext.ContentTypeService.Save(contentType);
+
+ var parentPage = MockedContent.CreateSimpleContent(contentType);
+ ServiceContext.ContentService.Save(parentPage);
+ ServiceContext.ContentService.AssignContentPermission(parentPage, 'A', new[] { userGroup.Id });
+
+ var childPage1 = MockedContent.CreateSimpleContent(contentType, "child1", parentPage);
+ ServiceContext.ContentService.Save(childPage1);
+ var childPage2 = MockedContent.CreateSimpleContent(contentType, "child2", childPage1);
+ ServiceContext.ContentService.Save(childPage2);
+ var childPage3 = MockedContent.CreateSimpleContent(contentType, "child3", childPage2);
+ ServiceContext.ContentService.Save(childPage3);
+
+ //Verify that the children have the inherited permissions
+ var descendants = ServiceContext.ContentService.GetDescendants(parentPage).ToArray();
+ Assert.AreEqual(3, descendants.Length);
+
+ foreach (var descendant in descendants)
+ {
+ var permissions = ServiceContext.UserService.GetPermissionsForPath(userGroup, descendant.Path, fallbackToDefaultPermissions: true);
+ var allPermissions = permissions.GetAllPermissions().ToArray();
+ Assert.AreEqual(1, allPermissions.Length);
+ Assert.AreEqual("A", allPermissions[0]);
+ }
+
+ //create a new parent with a new permission structure
+ var parentPage2 = MockedContent.CreateSimpleContent(contentType);
+ ServiceContext.ContentService.Save(parentPage2);
+ ServiceContext.ContentService.AssignContentPermission(parentPage2, 'B', new[] { userGroup.Id });
+
+ //Now copy, what should happen is the child pages will now have permissions inherited from the new parent
+ var copy = ServiceContext.ContentService.Copy(childPage1, parentPage2.Id, false, true);
+
+ descendants = ServiceContext.ContentService.GetDescendants(parentPage2).ToArray();
+ Assert.AreEqual(3, descendants.Length);
+
+ foreach (var descendant in descendants)
+ {
+ var permissions = ServiceContext.UserService.GetPermissionsForPath(userGroup, descendant.Path, fallbackToDefaultPermissions: true);
+ var allPermissions = permissions.GetAllPermissions().ToArray();
+ Assert.AreEqual(1, allPermissions.Length);
+ Assert.AreEqual("B", allPermissions[0]);
+ }
+ }
+
[Test]
public void Can_Empty_RecycleBin_With_Content_That_Has_All_Related_Data()
{
@@ -1455,9 +1649,11 @@ namespace Umbraco.Tests.Services
}));
Assert.IsTrue(ServiceContext.PublicAccessService.AddRule(content1, "test2", "test2").Success);
- Assert.IsNotNull(ServiceContext.NotificationService.CreateNotification(ServiceContext.UserService.GetUserById(0), content1, "T"));
+ var user = ServiceContext.UserService.GetUserById(0);
+ var userGroup = ServiceContext.UserService.GetUserGroupByAlias(user.Groups.First().Alias);
+ Assert.IsNotNull(ServiceContext.NotificationService.CreateNotification(user, content1, "test"));
- ServiceContext.ContentService.AssignContentPermission(content1, 'A', new[] { 0 });
+ ServiceContext.ContentService.AssignContentPermission(content1, 'A', new[] { userGroup.Id });
Assert.IsTrue(ServiceContext.DomainService.Save(new UmbracoDomain("www.test.com", "en-AU")
{
@@ -1711,9 +1907,9 @@ namespace Umbraco.Tests.Services
Assert.That(sut.GetValue("date").ToString("G"), Is.EqualTo(content.GetValue("date").ToString("G")));
Assert.That(sut.GetValue("ddl"), Is.EqualTo("1234"));
Assert.That(sut.GetValue("chklist"), Is.EqualTo("randomc"));
- Assert.That(sut.GetValue("contentPicker"), Is.EqualTo(1090));
- Assert.That(sut.GetValue("mediaPicker"), Is.EqualTo(1091));
- Assert.That(sut.GetValue("memberPicker"), Is.EqualTo(1092));
+ Assert.That(sut.GetValue("contentPicker"), Is.EqualTo(Udi.Create(Constants.UdiEntityType.Document, new Guid("74ECA1D4-934E-436A-A7C7-36CC16D4095C"))));
+ Assert.That(sut.GetValue("mediaPicker"), Is.EqualTo(Udi.Create(Constants.UdiEntityType.Media, new Guid("44CB39C8-01E5-45EB-9CF8-E70AAF2D1691"))));
+ Assert.That(sut.GetValue("memberPicker"), Is.EqualTo(Udi.Create(Constants.UdiEntityType.Member, new Guid("9A50A448-59C0-4D42-8F93-4F1D55B0F47D"))));
Assert.That(sut.GetValue("relatedLinks"), Is.EqualTo(""));
Assert.That(sut.GetValue("tags"), Is.EqualTo("this,is,tags"));
}
@@ -1971,7 +2167,7 @@ namespace Umbraco.Tests.Services
var templateRepository = new TemplateRepository(unitOfWork, DisabledCache, Logger, Mock.Of(), Mock.Of(), Mock.Of());
var tagRepository = new TagRepository(unitOfWork, DisabledCache, Logger);
contentTypeRepository = new ContentTypeRepository(unitOfWork, DisabledCache, Logger, templateRepository);
- var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository);
+ var repository = new ContentRepository(unitOfWork, DisabledCache, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of());
return repository;
}
}
diff --git a/src/Umbraco.Tests/Services/SectionServiceTests.cs b/src/Umbraco.Tests/Services/SectionServiceTests.cs
new file mode 100644
index 0000000000..6e6f871dd2
--- /dev/null
+++ b/src/Umbraco.Tests/Services/SectionServiceTests.cs
@@ -0,0 +1,70 @@
+using NUnit.Framework;
+using System.Linq;
+using Umbraco.Core.Models.Membership;
+using Umbraco.Tests.Testing;
+
+namespace Umbraco.Tests.Services
+{
+ ///
+ /// Tests covering the SectionService
+ ///
+ [TestFixture, RequiresSTA]
+ [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
+ public class SectionServiceTests : TestWithSomeContentBase
+ {
+ public override void CreateTestData()
+ {
+ base.CreateTestData();
+
+ ServiceContext.SectionService.MakeNew("Content", "content", "icon-content");
+ ServiceContext.SectionService.MakeNew("Media", "media", "icon-media");
+ ServiceContext.SectionService.MakeNew("Settings", "settings", "icon-settings");
+ ServiceContext.SectionService.MakeNew("Developer", "developer", "icon-developer");
+ }
+
+ [Test]
+ public void SectionService_Can_Get_Allowed_Sections_For_User()
+ {
+ // Arrange
+ var user = CreateTestUser();
+
+ // Act
+ var result = ServiceContext.SectionService.GetAllowedSections(user.Id).ToList();
+
+ // Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ private IUser CreateTestUser()
+ {
+ var user = new User
+ {
+ Name = "Test user",
+ Username = "testUser",
+ Email = "testuser@test.com",
+ };
+ ServiceContext.UserService.Save(user, false);
+
+ var userGroupA = new UserGroup
+ {
+ Alias = "GroupA",
+ Name = "Group A"
+ };
+ userGroupA.AddAllowedSection("media");
+ userGroupA.AddAllowedSection("settings");
+ //TODO: This is failing the test
+ ServiceContext.UserService.Save(userGroupA, new[] { user.Id }, false);
+
+ var userGroupB = new UserGroup
+ {
+ Alias = "GroupB",
+ Name = "Group B"
+ };
+ userGroupB.AddAllowedSection("settings");
+ userGroupB.AddAllowedSection("developer");
+ ServiceContext.UserService.Save(userGroupB, new[] { user.Id }, false);
+
+ return ServiceContext.UserService.GetUserById(user.Id);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/Services/UserServiceTests.cs b/src/Umbraco.Tests/Services/UserServiceTests.cs
index d279f257b8..f47ccfd043 100644
--- a/src/Umbraco.Tests/Services/UserServiceTests.cs
+++ b/src/Umbraco.Tests/Services/UserServiceTests.cs
@@ -1,13 +1,15 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using NUnit.Framework;
-using Umbraco.Core.Exceptions;
+using Umbraco.Core;
using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Core.Persistence.Querying;
-using Umbraco.Tests.TestHelpers;
+using Umbraco.Core.Services;
using Umbraco.Tests.Testing;
using Umbraco.Web._Legacy.Actions;
@@ -21,12 +23,11 @@ namespace Umbraco.Tests.Services
public class UserServiceTests : TestWithSomeContentBase
{
[Test]
- public void UserService_Get_User_Permissions_For_Unassigned_Permission_Nodes()
+ public void Get_User_Permissions_For_Unassigned_Permission_Nodes()
{
// Arrange
var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
- var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
+ var user = CreateTestUser(out var userGroup);
var contentType = MockedContentTypes.CreateSimpleContentType();
ServiceContext.ContentTypeService.Save(contentType);
var content = new[]
@@ -38,22 +39,24 @@ namespace Umbraco.Tests.Services
ServiceContext.ContentService.Save(content);
// Act
- var permissions = userService.GetPermissions(user, content.ElementAt(0).Id, content.ElementAt(1).Id, content.ElementAt(2).Id);
+ var permissions = userService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id)
+ .ToArray();
//assert
- Assert.AreEqual(3, permissions.Count());
- Assert.AreEqual(17, permissions.ElementAt(0).AssignedPermissions.Length);
- Assert.AreEqual(17, permissions.ElementAt(1).AssignedPermissions.Length);
- Assert.AreEqual(17, permissions.ElementAt(2).AssignedPermissions.Length);
+ Assert.AreEqual(3, permissions.Length);
+ Assert.AreEqual(17, permissions[0].AssignedPermissions.Length);
+ Assert.AreEqual(17, permissions[1].AssignedPermissions.Length);
+ Assert.AreEqual(17, permissions[2].AssignedPermissions.Length);
}
[Test]
- public void UserService_Get_User_Permissions_For_Assigned_Permission_Nodes()
+ public void Get_User_Permissions_For_Assigned_Permission_Nodes()
{
// Arrange
var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
- var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
+ IUserGroup userGroup;
+ var user = CreateTestUser(out userGroup);
+
var contentType = MockedContentTypes.CreateSimpleContentType();
ServiceContext.ContentTypeService.Save(contentType);
var content = new[]
@@ -63,32 +66,367 @@ namespace Umbraco.Tests.Services
MockedContent.CreateSimpleContent(contentType)
};
ServiceContext.ContentService.Save(content);
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionBrowse.Instance.Letter, new int[] { user.Id });
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionDelete.Instance.Letter, new int[] { user.Id });
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionMove.Instance.Letter, new int[] { user.Id });
-
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionBrowse.Instance.Letter, new int[] { user.Id });
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionDelete.Instance.Letter, new int[] { user.Id });
-
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(2), ActionBrowse.Instance.Letter, new int[] { user.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionMove.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[2], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
// Act
- var permissions = userService.GetPermissions(user, content.ElementAt(0).Id, content.ElementAt(1).Id, content.ElementAt(2).Id);
+ var permissions = userService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray();
//assert
- Assert.AreEqual(3, permissions.Count());
- Assert.AreEqual(3, permissions.ElementAt(0).AssignedPermissions.Count());
- Assert.AreEqual(2, permissions.ElementAt(1).AssignedPermissions.Count());
- Assert.AreEqual(1, permissions.ElementAt(2).AssignedPermissions.Count());
+ Assert.AreEqual(3, permissions.Length);
+ Assert.AreEqual(3, permissions[0].AssignedPermissions.Length);
+ Assert.AreEqual(2, permissions[1].AssignedPermissions.Length);
+ Assert.AreEqual(1, permissions[2].AssignedPermissions.Length);
+ }
+
+ [Test]
+ public void Get_UserGroup_Assigned_Permissions()
+ {
+ // Arrange
+ var userService = ServiceContext.UserService;
+ var userGroup = CreateTestUserGroup();
+
+ var contentType = MockedContentTypes.CreateSimpleContentType();
+ ServiceContext.ContentTypeService.Save(contentType);
+ var content = new[]
+ {
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType)
+ };
+ ServiceContext.ContentService.Save(content);
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionMove.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(2), ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+
+ // Act
+ var permissions = userService.GetPermissions(userGroup, false, content[0].Id, content[1].Id, content[2].Id).ToArray();
+
+ //assert
+ Assert.AreEqual(3, permissions.Length);
+ Assert.AreEqual(3, permissions[0].AssignedPermissions.Length);
+ Assert.AreEqual(2, permissions[1].AssignedPermissions.Length);
+ Assert.AreEqual(1, permissions[2].AssignedPermissions.Length);
+ }
+
+ [Test]
+ public void Get_UserGroup_Assigned_And_Default_Permissions()
+ {
+ // Arrange
+ var userService = ServiceContext.UserService;
+ var userGroup = CreateTestUserGroup();
+
+ var contentType = MockedContentTypes.CreateSimpleContentType();
+ ServiceContext.ContentTypeService.Save(contentType);
+ var content = new[]
+ {
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType)
+ };
+ ServiceContext.ContentService.Save(content);
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionMove.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+
+ // Act
+ var permissions = userService.GetPermissions(userGroup, true, content[0].Id, content[1].Id, content[2].Id)
+ .ToArray();
+
+ //assert
+ Assert.AreEqual(3, permissions.Length);
+ Assert.AreEqual(3, permissions[0].AssignedPermissions.Length);
+ Assert.AreEqual(2, permissions[1].AssignedPermissions.Length);
+ Assert.AreEqual(17, permissions[2].AssignedPermissions.Length);
+ }
+
+ [Test]
+ public void Get_All_User_Permissions_For_All_Nodes_With_Explicit_Permission()
+ {
+ // Arrange
+ var userService = ServiceContext.UserService;
+ var userGroup1 = CreateTestUserGroup();
+ var userGroup2 = CreateTestUserGroup("test2", "Test 2");
+ var userGroup3 = CreateTestUserGroup("test3", "Test 3");
+ var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io");
+
+ var defaultPermissionCount = userGroup3.Permissions.Count();
+
+ user.AddGroup(userGroup1);
+ user.AddGroup(userGroup2);
+ user.AddGroup(userGroup3);
+ userService.Save(user);
+
+ var contentType = MockedContentTypes.CreateSimpleContentType();
+ ServiceContext.ContentTypeService.Save(contentType);
+ var content = new[]
+ {
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType)
+ };
+ ServiceContext.ContentService.Save(content);
+ //assign permissions - we aren't assigning anything explicit for group3 and nothing explicit for content[2] /w group2
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionBrowse.Instance.Letter, new int[] { userGroup1.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionDelete.Instance.Letter, new int[] { userGroup1.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionMove.Instance.Letter, new int[] { userGroup2.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionBrowse.Instance.Letter, new int[] { userGroup1.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionDelete.Instance.Letter, new int[] { userGroup2.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[2], ActionDelete.Instance.Letter, new int[] { userGroup1.Id });
+
+ // Act
+ //we don't pass in any nodes so it will return all of them
+ var result = userService.GetPermissions(user).ToArray();
+ var permissions = result
+ .GroupBy(x => x.EntityId)
+ .ToDictionary(x => x.Key, x => x.GroupBy(a => a.UserGroupId).ToDictionary(a => a.Key, a => a.ToArray()));
+
+ //assert
+
+ //there will be 3 since that is how many content items there are
+ Assert.AreEqual(3, permissions.Count);
+
+ //test permissions contains content[0]
+ Assert.IsTrue(permissions.ContainsKey(content[0].Id));
+ //test that this permissions set contains permissions for all groups
+ Assert.IsTrue(permissions[content[0].Id].ContainsKey(userGroup1.Id));
+ Assert.IsTrue(permissions[content[0].Id].ContainsKey(userGroup2.Id));
+ Assert.IsTrue(permissions[content[0].Id].ContainsKey(userGroup3.Id));
+ //test that the correct number of permissions are returned for each group
+ Assert.AreEqual(2, permissions[content[0].Id][userGroup1.Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.AreEqual(1, permissions[content[0].Id][userGroup2.Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.AreEqual(defaultPermissionCount, permissions[content[0].Id][userGroup3.Id].SelectMany(x => x.AssignedPermissions).Count());
+
+ //test permissions contains content[1]
+ Assert.IsTrue(permissions.ContainsKey(content[1].Id));
+ //test that this permissions set contains permissions for all groups
+ Assert.IsTrue(permissions[content[1].Id].ContainsKey(userGroup1.Id));
+ Assert.IsTrue(permissions[content[1].Id].ContainsKey(userGroup2.Id));
+ Assert.IsTrue(permissions[content[1].Id].ContainsKey(userGroup3.Id));
+ //test that the correct number of permissions are returned for each group
+ Assert.AreEqual(1, permissions[content[1].Id][userGroup1.Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.AreEqual(1, permissions[content[1].Id][userGroup2.Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.AreEqual(defaultPermissionCount, permissions[content[1].Id][userGroup3.Id].SelectMany(x => x.AssignedPermissions).Count());
+
+ //test permissions contains content[2]
+ Assert.IsTrue(permissions.ContainsKey(content[2].Id));
+ //test that this permissions set contains permissions for all groups
+ Assert.IsTrue(permissions[content[2].Id].ContainsKey(userGroup1.Id));
+ Assert.IsTrue(permissions[content[2].Id].ContainsKey(userGroup2.Id));
+ Assert.IsTrue(permissions[content[2].Id].ContainsKey(userGroup3.Id));
+ //test that the correct number of permissions are returned for each group
+ Assert.AreEqual(1, permissions[content[2].Id][userGroup1.Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.AreEqual(defaultPermissionCount, permissions[content[2].Id][userGroup2.Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.AreEqual(defaultPermissionCount, permissions[content[2].Id][userGroup3.Id].SelectMany(x => x.AssignedPermissions).Count());
+ }
+
+ [Test]
+ public void Get_All_User_Group_Permissions_For_All_Nodes()
+ {
+ // Arrange
+ var userService = ServiceContext.UserService;
+ var userGroup = CreateTestUserGroup();
+
+ var contentType = MockedContentTypes.CreateSimpleContentType();
+ ServiceContext.ContentTypeService.Save(contentType);
+ var content = new[]
+ {
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType),
+ MockedContent.CreateSimpleContent(contentType)
+ };
+ ServiceContext.ContentService.Save(content);
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[0], ActionMove.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[1], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(content[2], ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+
+ // Act
+ //we don't pass in any nodes so it will return all of them
+ var permissions = userService.GetPermissions(userGroup, true)
+ .GroupBy(x => x.EntityId)
+ .ToDictionary(x => x.Key, x => x);
+
+ //assert
+ Assert.AreEqual(3, permissions.Count);
+ Assert.IsTrue(permissions.ContainsKey(content[0].Id));
+ Assert.AreEqual(3, permissions[content[0].Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.IsTrue(permissions.ContainsKey(content[1].Id));
+ Assert.AreEqual(2, permissions[content[1].Id].SelectMany(x => x.AssignedPermissions).Count());
+ Assert.IsTrue(permissions.ContainsKey(content[2].Id));
+ Assert.AreEqual(1, permissions[content[2].Id].SelectMany(x => x.AssignedPermissions).Count());
+ }
+
+ [Test]
+ public void Calculate_Permissions_For_User_For_Path()
+ {
+ //see: http://issues.umbraco.org/issue/U4-10075#comment=67-40085
+ // for an overview of what this is testing
+
+ const string path = "-1,1,2,3,4";
+ var pathIds = path.GetIdsFromPathReversed();
+
+ const int groupA = 7;
+ const int groupB = 8;
+ const int groupC = 9;
+
+ var userGroups = new Dictionary
+ {
+ {groupA, new[] {"S", "D", "F"}},
+ {groupB, new[] {"S", "D", "G", "K"}},
+ {groupC, new[] {"F", "G"}}
+ };
+
+ var permissions = new[]
+ {
+ new EntityPermission(groupA, 1, userGroups[groupA], isDefaultPermissions:true),
+ new EntityPermission(groupA, 2, userGroups[groupA], isDefaultPermissions:true),
+ new EntityPermission(groupA, 3, userGroups[groupA], isDefaultPermissions:true),
+ new EntityPermission(groupA, 4, userGroups[groupA], isDefaultPermissions:true),
+
+ new EntityPermission(groupB, 1, userGroups[groupB], isDefaultPermissions:true),
+ new EntityPermission(groupB, 2, new []{"F", "R"}, isDefaultPermissions:false),
+ new EntityPermission(groupB, 3, userGroups[groupB], isDefaultPermissions:true),
+ new EntityPermission(groupB, 4, userGroups[groupB], isDefaultPermissions:true),
+
+ new EntityPermission(groupC, 1, userGroups[groupC], isDefaultPermissions:true),
+ new EntityPermission(groupC, 2, userGroups[groupC], isDefaultPermissions:true),
+ new EntityPermission(groupC, 3, new []{"Q", "Z"}, isDefaultPermissions:false),
+ new EntityPermission(groupC, 4, userGroups[groupC], isDefaultPermissions:true),
+ };
+
+ //Permissions for Id 4
+ var result = UserService.CalculatePermissionsForPathForUser(permissions, pathIds);
+ Assert.AreEqual(4, result.EntityId);
+ var allPermissions = result.GetAllPermissions().ToArray();
+ Assert.AreEqual(6, allPermissions.Length, string.Join(",", allPermissions));
+ Assert.IsTrue(allPermissions.ContainsAll(new[] { "S", "D", "F", "R", "Q", "Z" }));
+
+ //Permissions for Id 3
+ result = UserService.CalculatePermissionsForPathForUser(permissions, pathIds.Skip(1).ToArray());
+ Assert.AreEqual(3, result.EntityId);
+ allPermissions = result.GetAllPermissions().ToArray();
+ Assert.AreEqual(6, allPermissions.Length, string.Join(",", allPermissions));
+ Assert.IsTrue(allPermissions.ContainsAll(new[] { "S", "D", "F", "R", "Q", "Z" }));
+
+ //Permissions for Id 2
+ result = UserService.CalculatePermissionsForPathForUser(permissions, pathIds.Skip(2).ToArray());
+ Assert.AreEqual(2, result.EntityId);
+ allPermissions = result.GetAllPermissions().ToArray();
+ Assert.AreEqual(5, allPermissions.Length, string.Join(",", allPermissions));
+ Assert.IsTrue(allPermissions.ContainsAll(new[] { "S", "D", "F", "G", "R" }));
+
+ //Permissions for Id 1
+ result = UserService.CalculatePermissionsForPathForUser(permissions, pathIds.Skip(3).ToArray());
+ Assert.AreEqual(1, result.EntityId);
+ allPermissions = result.GetAllPermissions().ToArray();
+ Assert.AreEqual(5, allPermissions.Length, string.Join(",", allPermissions));
+ Assert.IsTrue(allPermissions.ContainsAll(new[] { "S", "D", "F", "G", "K" }));
+
+ }
+
+ [Test]
+ public void Determine_Deepest_Explicit_Permissions_For_Group_For_Path_1()
+ {
+ var path = "-1,1,2,3";
+ var pathIds = path.GetIdsFromPathReversed();
+ var defaults = new[] { "A", "B" };
+ var permissions = new List
+ {
+ new EntityPermission(9876, 1, defaults, isDefaultPermissions:true),
+ new EntityPermission(9876, 2, new []{"B","C", "D"}, isDefaultPermissions:false),
+ new EntityPermission(9876, 3, defaults, isDefaultPermissions:true)
+ };
+ var result = UserService.GetPermissionsForPathForGroup(permissions, pathIds, fallbackToDefaultPermissions: true);
+ Assert.AreEqual(3, result.AssignedPermissions.Length);
+ Assert.IsFalse(result.IsDefaultPermissions);
+ Assert.IsTrue(result.AssignedPermissions.ContainsAll(new[] { "B", "C", "D" }));
+ Assert.AreEqual(2, result.EntityId);
+ Assert.AreEqual(9876, result.UserGroupId);
+ }
+
+ [Test]
+ public void Determine_Deepest_Explicit_Permissions_For_Group_For_Path_2()
+ {
+ var path = "-1,1,2,3";
+ var pathIds = path.GetIdsFromPathReversed();
+ var defaults = new[] { "A", "B", "C" };
+ var permissions = new List
+ {
+ new EntityPermission(9876, 1, defaults, isDefaultPermissions:true),
+ new EntityPermission(9876, 2, defaults, isDefaultPermissions:true),
+ new EntityPermission(9876, 3, defaults, isDefaultPermissions:true)
+ };
+ var result = UserService.GetPermissionsForPathForGroup(permissions, pathIds, fallbackToDefaultPermissions: false);
+ Assert.IsNull(result);
+ }
+
+ [Test]
+ public void Determine_Deepest_Explicit_Permissions_For_Group_For_Path_3()
+ {
+ var path = "-1,1,2,3";
+ var pathIds = path.GetIdsFromPathReversed();
+ var defaults = new[] { "A", "B" };
+ var permissions = new List
+ {
+ new EntityPermission(9876, 1, defaults, isDefaultPermissions:true),
+ new EntityPermission(9876, 2, defaults, isDefaultPermissions:true),
+ new EntityPermission(9876, 3, defaults, isDefaultPermissions:true)
+ };
+ var result = UserService.GetPermissionsForPathForGroup(permissions, pathIds, fallbackToDefaultPermissions: true);
+ Assert.AreEqual(2, result.AssignedPermissions.Length);
+ Assert.IsTrue(result.IsDefaultPermissions);
+ Assert.IsTrue(result.AssignedPermissions.ContainsAll(defaults));
+ Assert.AreEqual(3, result.EntityId);
+ Assert.AreEqual(9876, result.UserGroupId);
+ }
+
+ [Test]
+ public void Get_User_Implicit_Permissions()
+ {
+ // Arrange
+ var userService = ServiceContext.UserService;
+ var userGroup = CreateTestUserGroup();
+
+ var contentType = MockedContentTypes.CreateSimpleContentType();
+ ServiceContext.ContentTypeService.Save(contentType);
+ var parent = MockedContent.CreateSimpleContent(contentType);
+ ServiceContext.ContentService.Save(parent);
+ var child1 = MockedContent.CreateSimpleContent(contentType, "child1", parent);
+ ServiceContext.ContentService.Save(child1);
+ var child2 = MockedContent.CreateSimpleContent(contentType, "child2", child1);
+ ServiceContext.ContentService.Save(child2);
+
+ ServiceContext.ContentService.AssignContentPermission(parent, ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(parent, ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(parent, ActionMove.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(parent, ActionBrowse.Instance.Letter, new int[] { userGroup.Id });
+ ServiceContext.ContentService.AssignContentPermission(parent, ActionDelete.Instance.Letter, new int[] { userGroup.Id });
+
+ // Act
+ var permissions = userService.GetPermissionsForPath(userGroup, child2.Path);
+
+ //assert
+ var allPermissions = permissions.GetAllPermissions().ToArray();
+ Assert.AreEqual(3, allPermissions.Length);
}
[Test]
public void Can_Delete_User()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
-
+ var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
+
ServiceContext.UserService.Delete(user, true);
var deleted = ServiceContext.UserService.GetUserById(user.Id);
@@ -99,9 +437,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Disables_User_Instead_Of_Deleting_If_Flag_Not_Set()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
ServiceContext.UserService.Delete(user);
var deleted = ServiceContext.UserService.GetUserById(user.Id);
@@ -113,10 +449,8 @@ namespace Umbraco.Tests.Services
[Test]
public void Exists_By_Username()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
- var user2 = ServiceContext.UserService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
+ var user2 = ServiceContext.UserService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io");
Assert.IsTrue(ServiceContext.UserService.Exists("JohnDoe"));
Assert.IsFalse(ServiceContext.UserService.Exists("notFound"));
Assert.IsTrue(ServiceContext.UserService.Exists("john2@umbraco.io"));
@@ -125,9 +459,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Get_By_Email()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
Assert.IsNotNull(ServiceContext.UserService.GetByEmail(user.Email));
Assert.IsNull(ServiceContext.UserService.GetByEmail("do@not.find"));
@@ -136,9 +468,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Get_By_Username()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
Assert.IsNotNull(ServiceContext.UserService.GetByUsername(user.Username));
Assert.IsNull(ServiceContext.UserService.GetByUsername("notFound"));
@@ -147,9 +477,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Get_By_Username_With_Backslash()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io");
Assert.IsNotNull(ServiceContext.UserService.GetByUsername(user.Username));
Assert.IsNull(ServiceContext.UserService.GetByUsername("notFound"));
@@ -158,9 +486,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Get_By_Object_Id()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
Assert.IsNotNull(ServiceContext.UserService.GetUserById(user.Id));
Assert.IsNull(ServiceContext.UserService.GetUserById(9876));
@@ -169,17 +495,14 @@ namespace Umbraco.Tests.Services
[Test]
public void Find_By_Email_Starts_With()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10);
+ var users = MockedUser.CreateMulipleUsers(10);
ServiceContext.UserService.Save(users);
//don't find this
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
customUser.Email = "hello@hello.com";
ServiceContext.UserService.Save(customUser);
- long totalRecs;
- var found = ServiceContext.UserService.FindByEmail("tes", 0, 100, out totalRecs, StringPropertyMatchType.StartsWith);
+ var found = ServiceContext.UserService.FindByEmail("tes", 0, 100, out _, StringPropertyMatchType.StartsWith);
Assert.AreEqual(10, found.Count());
}
@@ -187,17 +510,14 @@ namespace Umbraco.Tests.Services
[Test]
public void Find_By_Email_Ends_With()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10);
+ var users = MockedUser.CreateMulipleUsers(10);
ServiceContext.UserService.Save(users);
//include this
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
customUser.Email = "hello@test.com";
ServiceContext.UserService.Save(customUser);
- long totalRecs;
- var found = ServiceContext.UserService.FindByEmail("test.com", 0, 100, out totalRecs, StringPropertyMatchType.EndsWith);
+ var found = ServiceContext.UserService.FindByEmail("test.com", 0, 100, out _, StringPropertyMatchType.EndsWith);
Assert.AreEqual(11, found.Count());
}
@@ -205,17 +525,14 @@ namespace Umbraco.Tests.Services
[Test]
public void Find_By_Email_Contains()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10);
+ var users = MockedUser.CreateMulipleUsers(10);
ServiceContext.UserService.Save(users);
//include this
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
customUser.Email = "hello@test.com";
ServiceContext.UserService.Save(customUser);
- long totalRecs;
- var found = ServiceContext.UserService.FindByEmail("test", 0, 100, out totalRecs, StringPropertyMatchType.Contains);
+ var found = ServiceContext.UserService.FindByEmail("test", 0, 100, out _, StringPropertyMatchType.Contains);
Assert.AreEqual(11, found.Count());
}
@@ -223,17 +540,14 @@ namespace Umbraco.Tests.Services
[Test]
public void Find_By_Email_Exact()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10);
+ var users = MockedUser.CreateMulipleUsers(10);
ServiceContext.UserService.Save(users);
//include this
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
customUser.Email = "hello@test.com";
ServiceContext.UserService.Save(customUser);
- long totalRecs;
- var found = ServiceContext.UserService.FindByEmail("hello@test.com", 0, 100, out totalRecs, StringPropertyMatchType.Exact);
+ var found = ServiceContext.UserService.FindByEmail("hello@test.com", 0, 100, out _, StringPropertyMatchType.Exact);
Assert.AreEqual(1, found.Count());
}
@@ -241,13 +555,10 @@ namespace Umbraco.Tests.Services
[Test]
public void Get_All_Paged_Users()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10);
+ var users = MockedUser.CreateMulipleUsers(10);
ServiceContext.UserService.Save(users);
- long totalRecs;
- var found = ServiceContext.UserService.GetAll(0, 2, out totalRecs);
+ var found = ServiceContext.UserService.GetAll(0, 2, out var totalRecs);
Assert.AreEqual(2, found.Count());
// + 1 because of the built in admin user
@@ -256,14 +567,77 @@ namespace Umbraco.Tests.Services
Assert.AreEqual("test0", found.Last().Username);
}
+ [Test]
+ public void Get_All_Paged_Users_With_Filter()
+ {
+ var users = MockedUser.CreateMulipleUsers(10).ToArray();
+ ServiceContext.UserService.Save(users);
+
+ var found = ServiceContext.UserService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test");
+
+ Assert.AreEqual(2, found.Count());
+ Assert.AreEqual(10, totalRecs);
+ Assert.AreEqual("test0", found.First().Username);
+ Assert.AreEqual("test1", found.Last().Username);
+ }
+
+ [Test]
+ public void Get_All_Paged_Users_For_Group()
+ {
+ var userGroup = MockedUserGroup.CreateUserGroup();
+ ServiceContext.UserService.Save(userGroup);
+
+ var users = MockedUser.CreateMulipleUsers(10).ToArray();
+ for (var i = 0; i < 10;)
+ {
+ users[i].AddGroup(userGroup.ToReadOnlyGroup());
+ i = i + 2;
+ }
+ ServiceContext.UserService.Save(users);
+
+ long totalRecs;
+ var found = ServiceContext.UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias });
+
+ Assert.AreEqual(2, found.Count());
+ Assert.AreEqual(5, totalRecs);
+ Assert.AreEqual("test0", found.First().Username);
+ Assert.AreEqual("test2", found.Last().Username);
+ }
+
+ [Test]
+ public void Get_All_Paged_Users_For_Group_With_Filter()
+ {
+ var userGroup = MockedUserGroup.CreateUserGroup();
+ ServiceContext.UserService.Save(userGroup);
+
+ var users = MockedUser.CreateMulipleUsers(10).ToArray();
+ for (var i = 0; i < 10;)
+ {
+ users[i].AddGroup(userGroup.ToReadOnlyGroup());
+ i = i + 2;
+ }
+ for (var i = 0; i < 10;)
+ {
+ users[i].Name = "blah" + users[i].Name;
+ i = i + 3;
+ }
+ ServiceContext.UserService.Save(users);
+
+ long totalRecs;
+ var found = ServiceContext.UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias }, filter: "blah");
+
+ Assert.AreEqual(2, found.Count());
+ Assert.AreEqual(2, totalRecs);
+ Assert.AreEqual("test0", found.First().Username);
+ Assert.AreEqual("test6", found.Last().Username);
+ }
+
[Test]
public void Count_All_Users()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10);
+ var users = MockedUser.CreateMulipleUsers(10);
ServiceContext.UserService.Save(users);
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
ServiceContext.UserService.Save(customUser);
var found = ServiceContext.UserService.GetCount(MemberCountType.All);
@@ -272,28 +646,24 @@ namespace Umbraco.Tests.Services
Assert.AreEqual(12, found);
}
- [Ignore("fixme - ignored test")]
+ [Ignore("why?")]
[Test]
public void Count_All_Online_Users()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2));
+ var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2));
ServiceContext.UserService.Save(users);
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
throw new NotImplementedException();
}
[Test]
public void Count_All_Locked_Users()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10, (i, member) => member.IsLockedOut = i % 2 == 0);
+ var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0);
ServiceContext.UserService.Save(users);
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
customUser.IsLockedOut = true;
ServiceContext.UserService.Save(customUser);
@@ -305,12 +675,10 @@ namespace Umbraco.Tests.Services
[Test]
public void Count_All_Approved_Users()
{
- var userType = MockedUserType.CreateUserType();
- ServiceContext.UserService.SaveUserType(userType);
- var users = MockedUser.CreateUser(userType, 10, (i, member) => member.IsApproved = i % 2 == 0);
+ var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0);
ServiceContext.UserService.Save(users);
- var customUser = MockedUser.CreateUser(userType);
+ var customUser = MockedUser.CreateUser();
customUser.IsApproved = false;
ServiceContext.UserService.Save(customUser);
@@ -320,36 +688,20 @@ namespace Umbraco.Tests.Services
Assert.AreEqual(6, found);
}
- [Test]
- public void Can_Persist_New_User_Type()
- {
- // Arrange
- var userService = ServiceContext.UserService;
- var userType = MockedUserType.CreateUserType();
-
- // Act
- userService.SaveUserType(userType);
-
- // Assert
- Assert.That(userType.HasIdentity, Is.True);
- }
-
[Test]
public void Can_Persist_New_User()
{
// Arrange
var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
// Act
- var membershipUser = userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType);
+ var membershipUser = userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io");
// Assert
Assert.That(membershipUser.HasIdentity, Is.True);
Assert.That(membershipUser.Id, Is.GreaterThan(0));
IUser user = membershipUser as User;
Assert.That(user, Is.Not.Null);
- Assert.That(user.DefaultPermissions, Is.EqualTo(userType.Permissions));
}
[Test]
@@ -357,7 +709,6 @@ namespace Umbraco.Tests.Services
{
// Arrange
var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
// Act
// NOTE: Normally the hash'ing would be handled in the membership provider, so the service just saves the password
@@ -365,7 +716,7 @@ namespace Umbraco.Tests.Services
var hash = new HMACSHA1();
hash.Key = Encoding.Unicode.GetBytes(password);
var encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));
- var membershipUser = new User("JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword, userType);
+ var membershipUser = new User("JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword);
userService.Save(membershipUser);
// Assert
@@ -374,37 +725,41 @@ namespace Umbraco.Tests.Services
Assert.That(membershipUser.RawPasswordValue, Is.EqualTo(encodedPassword));
IUser user = membershipUser as User;
Assert.That(user, Is.Not.Null);
- Assert.That(user.DefaultPermissions, Is.EqualTo(userType.Permissions));
}
[Test]
- public void Can_Add_And_Remove_Sections_From_User()
+ public void Can_Add_And_Remove_Sections_From_UserGroup()
{
- var userType = ServiceContext.UserService.GetUserTypeByAlias("admin");
+ var userGroup = new UserGroup
+ {
+ Alias = "Group1",
+ Name = "Group 1"
+ };
+ userGroup.AddAllowedSection("content");
+ userGroup.AddAllowedSection("mediat");
+ ServiceContext.UserService.Save(userGroup);
- var user1 = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
+ var result1 = ServiceContext.UserService.GetUserGroupById(userGroup.Id);
- var result1 = ServiceContext.UserService.GetUserById(user1.Id);
- //expect 2 sections by default
- // 3: see commit eb59d33
- Assert.AreEqual(3, result1.AllowedSections.Count());
+ Assert.AreEqual(2, result1.AllowedSections.Count());
//adds some allowed sections
- user1.AddAllowedSection("test1");
- user1.AddAllowedSection("test2");
- user1.AddAllowedSection("test3");
- user1.AddAllowedSection("test4");
- ServiceContext.UserService.Save(user1);
+ userGroup.AddAllowedSection("test1");
+ userGroup.AddAllowedSection("test2");
+ userGroup.AddAllowedSection("test3");
+ userGroup.AddAllowedSection("test4");
+ ServiceContext.UserService.Save(userGroup);
- result1 = ServiceContext.UserService.GetUserById(user1.Id);
- //expect 7 sections including the two default sections
- Assert.AreEqual(7, result1.AllowedSections.Count());
+ result1 = ServiceContext.UserService.GetUserGroupById(userGroup.Id);
+
+ Assert.AreEqual(6, result1.AllowedSections.Count());
//simulate clearing the sections
- foreach (var s in user1.AllowedSections)
+ foreach (var s in userGroup.AllowedSections)
{
result1.RemoveAllowedSection(s);
}
+
//now just re-add a couple
result1.AddAllowedSection("test3");
result1.AddAllowedSection("test4");
@@ -412,80 +767,100 @@ namespace Umbraco.Tests.Services
//assert
//re-get
- result1 = ServiceContext.UserService.GetUserById(user1.Id);
+ result1 = ServiceContext.UserService.GetUserGroupById(userGroup.Id);
Assert.AreEqual(2, result1.AllowedSections.Count());
}
[Test]
- public void Can_Remove_Section_From_All_Assigned_Users()
+ public void Can_Remove_Section_From_All_Assigned_UserGroups()
{
- var userType = ServiceContext.UserService.GetUserTypeByAlias("admin");
-
- var user1 = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
- var user2 = ServiceContext.UserService.CreateUserWithIdentity("test2", "test2@test.com", userType);
+ var userGroup1 = new UserGroup
+ {
+ Alias = "Group1",
+ Name = "Group 1"
+ };
+ var userGroup2 = new UserGroup
+ {
+ Alias = "Group2",
+ Name = "Group 2"
+ };
+ ServiceContext.UserService.Save(userGroup1);
+ ServiceContext.UserService.Save(userGroup2);
//adds some allowed sections
- user1.AddAllowedSection("test");
- user2.AddAllowedSection("test");
- ServiceContext.UserService.Save(user1);
- ServiceContext.UserService.Save(user2);
+ userGroup1.AddAllowedSection("test");
+ userGroup2.AddAllowedSection("test");
+ ServiceContext.UserService.Save(userGroup1);
+ ServiceContext.UserService.Save(userGroup2);
//now clear the section from all users
- ServiceContext.UserService.DeleteSectionFromAllUsers("test");
+ ServiceContext.UserService.DeleteSectionFromAllUserGroups("test");
//assert
- var result1 = ServiceContext.UserService.GetUserById((int)user1.Id);
- var result2 = ServiceContext.UserService.GetUserById((int)user2.Id);
+ var result1 = ServiceContext.UserService.GetUserGroupById(userGroup1.Id);
+ var result2 = ServiceContext.UserService.GetUserGroupById(userGroup2.Id);
Assert.IsFalse(result1.AllowedSections.Contains("test"));
Assert.IsFalse(result2.AllowedSections.Contains("test"));
}
[Test]
- public void Can_Add_Section_To_All_Users()
+ public void Can_Add_Section_To_All_UserGroups()
{
- var userType = ServiceContext.UserService.GetUserTypeByAlias("admin");
+ var userGroup1 = new UserGroup
+ {
+ Alias = "Group1",
+ Name = "Group 1"
+ };
+ userGroup1.AddAllowedSection("test");
- var user1 = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
- var user2 = ServiceContext.UserService.CreateUserWithIdentity("test2", "test2@test.com", userType);
- var user3 = ServiceContext.UserService.CreateUserWithIdentity("test3", "test3@test.com", userType);
- var user4 = ServiceContext.UserService.CreateUserWithIdentity("test4", "test4@test.com", userType);
+ var userGroup2 = new UserGroup
+ {
+ Alias = "Group2",
+ Name = "Group 2"
+ };
+ userGroup2.AddAllowedSection("test");
- //now add the section to specific users
- ServiceContext.UserService.AddSectionToAllUsers("test", (int)user1.Id, (int)user2.Id);
-
- //assert
- var result1 = ServiceContext.UserService.GetUserById((int)user1.Id);
- var result2 = ServiceContext.UserService.GetUserById((int)user2.Id);
- var result3 = ServiceContext.UserService.GetUserById((int)user3.Id);
- var result4 = ServiceContext.UserService.GetUserById((int)user4.Id);
+ var userGroup3 = new UserGroup
+ {
+ Alias = "Group3",
+ Name = "Group 3"
+ };
+ ServiceContext.UserService.Save(userGroup1);
+ ServiceContext.UserService.Save(userGroup2);
+ ServiceContext.UserService.Save(userGroup3);
+
+ //assert
+ var result1 = ServiceContext.UserService.GetUserGroupById(userGroup1.Id);
+ var result2 = ServiceContext.UserService.GetUserGroupById(userGroup2.Id);
+ var result3 = ServiceContext.UserService.GetUserGroupById(userGroup3.Id);
Assert.IsTrue(result1.AllowedSections.Contains("test"));
Assert.IsTrue(result2.AllowedSections.Contains("test"));
Assert.IsFalse(result3.AllowedSections.Contains("test"));
- Assert.IsFalse(result4.AllowedSections.Contains("test"));
- //now add the section to all users
- ServiceContext.UserService.AddSectionToAllUsers("test");
+ //now add the section to all groups
+ foreach (var userGroup in new[] { userGroup1, userGroup2, userGroup3 })
+ {
+ userGroup.AddAllowedSection("test");
+ ServiceContext.UserService.Save(userGroup);
+ }
//assert
- result1 = ServiceContext.UserService.GetUserById((int)user1.Id);
- result2 = ServiceContext.UserService.GetUserById((int)user2.Id);
- result3 = ServiceContext.UserService.GetUserById((int)user3.Id);
- result4 = ServiceContext.UserService.GetUserById((int)user4.Id);
+ result1 = ServiceContext.UserService.GetUserGroupById(userGroup1.Id);
+ result2 = ServiceContext.UserService.GetUserGroupById(userGroup2.Id);
+ result3 = ServiceContext.UserService.GetUserGroupById(userGroup3.Id);
Assert.IsTrue(result1.AllowedSections.Contains("test"));
Assert.IsTrue(result2.AllowedSections.Contains("test"));
Assert.IsTrue(result3.AllowedSections.Contains("test"));
- Assert.IsTrue(result4.AllowedSections.Contains("test"));
}
[Test]
public void Cannot_Create_User_With_Empty_Username()
{
// Arrange
- var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
-
- // Act & Assert
- Assert.Throws(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io", userType));
+ var userService = ServiceContext.UserService;
+
+ // Act & Assert
+ Assert.Throws(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io"));
}
[Test]
@@ -493,8 +868,7 @@ namespace Umbraco.Tests.Services
{
// Arrange
var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
- var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io", userType);
+ var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io");
user.Username = string.Empty;
// Act & Assert
@@ -506,8 +880,7 @@ namespace Umbraco.Tests.Services
{
// Arrange
var userService = ServiceContext.UserService;
- var userType = userService.GetUserTypeByAlias("admin");
- var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io", userType);
+ var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io");
user.Name = string.Empty;
// Act & Assert
@@ -518,8 +891,7 @@ namespace Umbraco.Tests.Services
public void Get_By_Profile_Username()
{
// Arrange
- var userType = ServiceContext.UserService.GetUserTypeByAlias("admin");
- var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
+ var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
// Act
@@ -535,8 +907,7 @@ namespace Umbraco.Tests.Services
public void Get_By_Profile_Id()
{
// Arrange
- var userType = ServiceContext.UserService.GetUserTypeByAlias("admin");
- var user = (IUser)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
+ var user = (IUser)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
// Act
@@ -552,8 +923,8 @@ namespace Umbraco.Tests.Services
public void Get_User_By_Username()
{
// Arrange
- var userType = ServiceContext.UserService.GetUserTypeByAlias("admin");
- var originalUser = (User)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType);
+ IUserGroup userGroup;
+ var originalUser = CreateTestUser(out userGroup);
// Act
@@ -563,16 +934,42 @@ namespace Umbraco.Tests.Services
Assert.IsNotNull(updatedItem);
Assert.That(updatedItem.Id, Is.EqualTo(originalUser.Id));
Assert.That(updatedItem.Name, Is.EqualTo(originalUser.Name));
- Assert.That(updatedItem.DefaultPermissions, Is.EqualTo(originalUser.DefaultPermissions));
Assert.That(updatedItem.Language, Is.EqualTo(originalUser.Language));
Assert.That(updatedItem.IsApproved, Is.EqualTo(originalUser.IsApproved));
Assert.That(updatedItem.RawPasswordValue, Is.EqualTo(originalUser.RawPasswordValue));
Assert.That(updatedItem.IsLockedOut, Is.EqualTo(originalUser.IsLockedOut));
- Assert.That(updatedItem.StartContentId, Is.EqualTo(originalUser.StartContentId));
- Assert.That(updatedItem.StartMediaId, Is.EqualTo(originalUser.StartMediaId));
+ Assert.IsTrue(updatedItem.StartContentIds.UnsortedSequenceEqual(originalUser.StartContentIds));
+ Assert.IsTrue(updatedItem.StartMediaIds.UnsortedSequenceEqual(originalUser.StartMediaIds));
Assert.That(updatedItem.Email, Is.EqualTo(originalUser.Email));
Assert.That(updatedItem.Username, Is.EqualTo(originalUser.Username));
- Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(3)); // 3: see commit eb59d33
+ Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(2));
+ }
+
+ private IUser CreateTestUser(out IUserGroup userGroup)
+ {
+ userGroup = CreateTestUserGroup();
+
+ var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
+ user.AddGroup(userGroup.ToReadOnlyGroup());
+ ServiceContext.UserService.Save(user);
+ return user;
+ }
+
+ private UserGroup CreateTestUserGroup(string alias = "testGroup", string name = "Test Group")
+ {
+ var userGroup = new UserGroup
+ {
+ Alias = alias,
+ Name = name,
+ Permissions = "ABCDEFGHIJ1234567".ToCharArray().Select(x => x.ToString())
+ };
+
+ userGroup.AddAllowedSection("content");
+ userGroup.AddAllowedSection("media");
+
+ ServiceContext.UserService.Save(userGroup);
+
+ return userGroup;
}
}
}
diff --git a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs
index b2be6179fb..67baab695c 100644
--- a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs
+++ b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs
@@ -118,6 +118,33 @@ namespace Umbraco.Tests.Strings
Assert.AreEqual("aeoa-and-aeoa-and-and-and-grosser-bbddzhzh-page", output);
}
+ [Test]
+ public void U4_4056_TryAscii()
+ {
+ var settings = SettingsForTests.GenerateMockSettings();
+ var contentMock = Mock.Get(settings.RequestHandler);
+ contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty());
+ contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false);
+ SettingsForTests.ConfigureSettings(settings);
+
+ const string input1 = "ÆØÅ and æøå and 中文测试 and אודות האתר and größer БбДдЖж page";
+ const string input2 = "ÆØÅ and æøå and größer БбДдЖж page";
+
+ var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings)); // unicode
+ Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input1));
+ Assert.AreEqual("æøå-and-æøå-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input2));
+
+ helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings)
+ .WithConfig(CleanStringType.UrlSegment, new DefaultShortStringHelperConfig.Config
+ {
+ IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_',
+ StringType = CleanStringType.LowerCase | CleanStringType.TryAscii, // try ascii
+ Separator = '-'
+ }));
+ Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input1));
+ Assert.AreEqual("aeoa-and-aeoa-and-grosser-bbddzhzh-page", helper.CleanStringForUrlSegment(input2));
+ }
+
[Test]
public void CleanStringUnderscoreInTerm()
{
diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingExtensions.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingExtensions.cs
new file mode 100644
index 0000000000..f7d457f0d1
--- /dev/null
+++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingExtensions.cs
@@ -0,0 +1,18 @@
+using System;
+using Microsoft.Owin.Extensions;
+using Owin;
+
+namespace Umbraco.Tests.TestHelpers.ControllerTesting
+{
+ public static class AuthenticateEverythingExtensions
+ {
+ public static IAppBuilder AuthenticateEverything(this IAppBuilder app)
+ {
+ if (app == null)
+ throw new ArgumentNullException("app");
+ app.Use(typeof(AuthenticateEverythingMiddleware), (object)app, (object)new AuthenticateEverythingMiddleware.AuthenticateEverythingAuthenticationOptions());
+ app.UseStageMarker(PipelineStage.Authenticate);
+ return app;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingMiddleware.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingMiddleware.cs
new file mode 100644
index 0000000000..0cfcb47ade
--- /dev/null
+++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingMiddleware.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Threading.Tasks;
+using Microsoft.Owin;
+using Microsoft.Owin.Security;
+using Microsoft.Owin.Security.Infrastructure;
+using Owin;
+using Umbraco.Core.Security;
+
+namespace Umbraco.Tests.TestHelpers.ControllerTesting
+{
+ public class AuthenticateEverythingMiddleware : AuthenticationMiddleware
+ {
+ public AuthenticateEverythingMiddleware(OwinMiddleware next, IAppBuilder app, AuthenticationOptions options)
+ : base(next, options)
+ {
+ }
+
+ protected override AuthenticationHandler CreateHandler()
+ {
+ return new AuthenticateEverythingHandler();
+ }
+
+ public class AuthenticateEverythingHandler : AuthenticationHandler
+ {
+ protected override Task AuthenticateCoreAsync()
+ {
+ var identity = new UmbracoBackOfficeIdentity(
+ new UserData(Guid.NewGuid().ToString())
+ {
+ Id = 0,
+ Roles = new[] { "admin" },
+ AllowedApplications = new[] { "content", "media", "members" },
+ Culture = "en-US",
+ RealName = "Admin",
+ Username = "admin"
+ });
+
+ return Task.FromResult(new AuthenticationTicket(identity,
+ new AuthenticationProperties()
+ {
+ ExpiresUtc = DateTime.Now.AddDays(1)
+ }));
+ }
+ }
+
+ public class AuthenticateEverythingAuthenticationOptions : AuthenticationOptions
+ {
+ public AuthenticateEverythingAuthenticationOptions()
+ : base("AuthenticateEverything")
+ {
+ AuthenticationMode = AuthenticationMode.Active;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/SpecificAssemblyResolver.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/SpecificAssemblyResolver.cs
new file mode 100644
index 0000000000..b301952c92
--- /dev/null
+++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/SpecificAssemblyResolver.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+using System.Reflection;
+using System.Web.Http.Dispatcher;
+
+namespace Umbraco.Tests.TestHelpers.ControllerTesting
+{
+ public class SpecificAssemblyResolver : IAssembliesResolver
+ {
+ private readonly Assembly[] _assemblies;
+
+ public SpecificAssemblyResolver(Assembly[] assemblies)
+ {
+ _assemblies = assemblies;
+ }
+
+ public ICollection GetAssemblies()
+ {
+ return _assemblies;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivator.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivator.cs
new file mode 100644
index 0000000000..81cdeccbfe
--- /dev/null
+++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivator.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Net.Http;
+using System.Web.Http;
+using Umbraco.Web;
+
+namespace Umbraco.Tests.TestHelpers.ControllerTesting
+{
+ public class TestControllerActivator : TestControllerActivatorBase
+ {
+ private readonly Func _factory;
+
+ public TestControllerActivator(Func factory)
+ {
+ _factory = factory;
+ }
+
+ protected override ApiController CreateController(Type controllerType, HttpRequestMessage msg, UmbracoHelper helper)
+ {
+ return _factory(msg, helper);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs
new file mode 100644
index 0000000000..65d114793d
--- /dev/null
+++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs
@@ -0,0 +1,144 @@
+using System;
+using System.Collections;
+using System.Linq;
+using System.Net.Http;
+using System.Web;
+using System.Web.Http;
+using System.Web.Http.Controllers;
+using System.Web.Http.Dispatcher;
+using System.Web.Security;
+using Moq;
+using Semver;
+using Umbraco.Core;
+using Umbraco.Core.Cache;
+using Umbraco.Core.Composing;
+using Umbraco.Core.Configuration.UmbracoSettings;
+using Umbraco.Core.Dictionary;
+using Umbraco.Core.Models;
+using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Models.PublishedContent;
+using Umbraco.Core.Security;
+using Umbraco.Core.Services;
+using Umbraco.Tests.TestHelpers.Stubs;
+using Umbraco.Web;
+using Umbraco.Web.PublishedCache;
+using Umbraco.Web.Routing;
+using Umbraco.Web.Security;
+using Umbraco.Web.WebApi;
+
+namespace Umbraco.Tests.TestHelpers.ControllerTesting
+{
+ ///
+ /// Used to mock all of the services required for re-mocking and testing controllers
+ ///
+ ///
+ /// A more complete version of this is found in the Umbraco REST API project but this has the basics covered
+ ///
+ public abstract class TestControllerActivatorBase : DefaultHttpControllerActivator, IHttpControllerActivator
+ {
+ IHttpController IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
+ {
+ if (typeof(UmbracoApiControllerBase).IsAssignableFrom(controllerType))
+ {
+ var owinContext = request.TryGetOwinContext().Result;
+
+ var mockedUserService = Mock.Of();
+
+ var mockedMigrationService = new Mock();
+ //set it up to return anything so that the app ctx is 'Configured'
+ mockedMigrationService.Setup(x => x.FindEntry(It.IsAny(), It.IsAny())).Returns(Mock.Of());
+
+ var serviceContext = new ServiceContext(
+ userService: mockedUserService,
+ migrationEntryService: mockedMigrationService.Object,
+ localizedTextService:Mock.Of(),
+ sectionService:Mock.Of());
+
+ //ensure the configuration matches the current version for tests
+ SettingsForTests.ConfigurationStatus = Current.RuntimeState.SemanticVersion.ToSemanticString();
+
+ // fixme v8?
+ ////new app context
+ //var dbCtx = new Mock(Mock.Of