* Rename Umbraco.Core namespace to Umbraco.Cms.Core * Move extension methods in core project to Umbraco.Extensions * Move extension methods in core project to Umbraco.Extensions * Rename Umbraco.Examine namespace to Umbraco.Cms.Examine * Move examine extensions to Umbraco.Extensions namespace * Reflect changed namespaces in Builder and fix unit tests * Adjust namespace in Umbraco.ModelsBuilder.Embedded * Adjust namespace in Umbraco.Persistence.SqlCe * Adjust namespace in Umbraco.PublishedCache.NuCache * Align namespaces in Umbraco.Web.BackOffice * Align namespaces in Umbraco.Web.Common * Ensure that SqlCeSupport is still enabled after changing the namespace * Align namespaces in Umbraco.Web.Website * Align namespaces in Umbraco.Web.UI.NetCore * Align namespaces in Umbraco.Tests.Common * Align namespaces in Umbraco.Tests.UnitTests * Align namespaces in Umbraco.Tests.Integration * Fix errors caused by changed namespaces * Fix integration tests * Undo the Umbraco.Examine.Lucene namespace change This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows. * Fix merge * Fix Merge
163 lines
5.7 KiB
C#
163 lines
5.7 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
|
|
{
|
|
[TestFixture]
|
|
[Apartment(ApartmentState.STA)]
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
public class PublicAccessServiceTests : UmbracoIntegrationTest
|
|
{
|
|
private IContentService ContentService => GetRequiredService<IContentService>();
|
|
|
|
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
|
|
|
private IFileService FileService => GetRequiredService<IFileService>();
|
|
|
|
private IPublicAccessService PublicAccessService => GetRequiredService<IPublicAccessService>();
|
|
|
|
private Content _content;
|
|
|
|
[SetUp]
|
|
public void CreateTestData()
|
|
{
|
|
Template template = TemplateBuilder.CreateTextPageTemplate();
|
|
FileService.SaveTemplate(template); // else, FK violation on contentType!
|
|
|
|
ContentType ct = ContentTypeBuilder.CreateSimpleContentType("blah", "Blah", defaultTemplateId: template.Id);
|
|
ContentTypeService.Save(ct);
|
|
|
|
_content = ContentBuilder.CreateSimpleContent(ct, "Test", -1);
|
|
ContentService.Save(_content);
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Add_New_Entry()
|
|
{
|
|
// Arrange
|
|
PublicAccessRule[] rules = new[]
|
|
{
|
|
new PublicAccessRule()
|
|
{
|
|
RuleType = "TestType",
|
|
RuleValue = "TestVal"
|
|
},
|
|
};
|
|
var entry = new PublicAccessEntry(_content, _content, _content, rules);
|
|
|
|
// Act
|
|
Attempt<OperationResult> result = PublicAccessService.Save(entry);
|
|
|
|
// Assert
|
|
Assert.IsTrue(result.Success);
|
|
Assert.AreEqual(OperationResultType.Success, result.Result.Result);
|
|
Assert.IsTrue(entry.HasIdentity);
|
|
Assert.AreNotEqual(entry.Key, Guid.Empty);
|
|
Assert.AreEqual(_content.Id, entry.LoginNodeId);
|
|
Assert.AreEqual(_content.Id, entry.NoAccessNodeId);
|
|
Assert.AreEqual(_content.Id, entry.ProtectedNodeId);
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Add_Rule()
|
|
{
|
|
// Arrange
|
|
PublicAccessRule[] rules = new[]
|
|
{
|
|
new PublicAccessRule()
|
|
{
|
|
RuleType = "TestType",
|
|
RuleValue = "TestVal"
|
|
},
|
|
};
|
|
var entry = new PublicAccessEntry(_content, _content, _content, rules);
|
|
PublicAccessService.Save(entry);
|
|
|
|
// Act
|
|
Attempt<OperationResult<OperationResultType, PublicAccessEntry>> updated = PublicAccessService.AddRule(_content, "TestType2", "AnotherVal");
|
|
|
|
// re-get
|
|
entry = PublicAccessService.GetEntryForContent(_content);
|
|
|
|
// Assert
|
|
Assert.IsTrue(updated.Success);
|
|
Assert.AreEqual(OperationResultType.Success, updated.Result.Result);
|
|
Assert.AreEqual(2, entry.Rules.Count());
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Add_Multiple_Value_For_Same_Rule_Type()
|
|
{
|
|
// Arrange
|
|
PublicAccessRule[] rules = new[]
|
|
{
|
|
new PublicAccessRule()
|
|
{
|
|
RuleType = "TestType",
|
|
RuleValue = "TestVal"
|
|
},
|
|
};
|
|
var entry = new PublicAccessEntry(_content, _content, _content, rules);
|
|
PublicAccessService.Save(entry);
|
|
|
|
// Act
|
|
Attempt<OperationResult<OperationResultType, PublicAccessEntry>> updated1 = PublicAccessService.AddRule(_content, "TestType", "AnotherVal1");
|
|
Attempt<OperationResult<OperationResultType, PublicAccessEntry>> updated2 = PublicAccessService.AddRule(_content, "TestType", "AnotherVal2");
|
|
|
|
// re-get
|
|
entry = PublicAccessService.GetEntryForContent(_content);
|
|
|
|
// Assert
|
|
Assert.IsTrue(updated1.Success);
|
|
Assert.IsTrue(updated2.Success);
|
|
Assert.AreEqual(OperationResultType.Success, updated1.Result.Result);
|
|
Assert.AreEqual(OperationResultType.Success, updated2.Result.Result);
|
|
Assert.AreEqual(3, entry.Rules.Count());
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Remove_Rule()
|
|
{
|
|
// Arrange
|
|
PublicAccessRule[] rules = new[]
|
|
{
|
|
new PublicAccessRule()
|
|
{
|
|
RuleType = "TestType",
|
|
RuleValue = "TestValue1"
|
|
},
|
|
new PublicAccessRule()
|
|
{
|
|
RuleType = "TestType",
|
|
RuleValue = "TestValue2"
|
|
},
|
|
};
|
|
var entry = new PublicAccessEntry(_content, _content, _content, rules);
|
|
PublicAccessService.Save(entry);
|
|
|
|
// Act
|
|
Attempt<OperationResult> removed = PublicAccessService.RemoveRule(_content, "TestType", "TestValue1");
|
|
|
|
// re-get
|
|
entry = PublicAccessService.GetEntryForContent(_content);
|
|
|
|
// Assert
|
|
Assert.IsTrue(removed.Success);
|
|
Assert.AreEqual(OperationResultType.Success, removed.Result.Result);
|
|
Assert.AreEqual(1, entry.Rules.Count());
|
|
Assert.AreEqual("TestValue2", entry.Rules.ElementAt(0).RuleValue);
|
|
}
|
|
}
|
|
}
|