mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
81 lines
2.9 KiB
C#
81 lines
2.9 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using Autofac.Builder;
|
|||
|
using Moq;
|
|||
|
using NUnit.Framework;
|
|||
|
using Orchard.Core.Common.Models;
|
|||
|
using Orchard.Core.Common.Providers;
|
|||
|
using Orchard.Core.Common.Records;
|
|||
|
using Orchard.Models;
|
|||
|
using Orchard.Models.Driver;
|
|||
|
using Orchard.Models.Records;
|
|||
|
using Orchard.Security;
|
|||
|
using Orchard.Tests.Packages;
|
|||
|
|
|||
|
namespace Orchard.Core.Tests.Common.Providers {
|
|||
|
[TestFixture]
|
|||
|
public class CommonAspectProviderTests : DatabaseEnabledTestsBase {
|
|||
|
private Mock<IAuthenticationService> _authn;
|
|||
|
private Mock<IAuthorizationService> _authz;
|
|||
|
private Mock<IMembershipService> _membership;
|
|||
|
|
|||
|
public override void Register(ContainerBuilder builder) {
|
|||
|
builder.Register<DefaultContentManager>().As<IContentManager>();
|
|||
|
builder.Register<TestProvider>().As<IContentProvider>();
|
|||
|
builder.Register<CommonAspectProvider>().As<IContentProvider>();
|
|||
|
|
|||
|
_authn = new Mock<IAuthenticationService>();
|
|||
|
_authz = new Mock<IAuthorizationService>();
|
|||
|
_membership = new Mock<IMembershipService>();
|
|||
|
builder.Register(_authn.Object);
|
|||
|
builder.Register(_authz.Object);
|
|||
|
builder.Register(_membership.Object);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
protected override IEnumerable<Type> DatabaseTypes {
|
|||
|
get {
|
|||
|
return new[] {typeof (ContentTypeRecord), typeof (ContentItemRecord), typeof (CommonRecord)};
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
class TestProvider : ContentProvider {
|
|||
|
public TestProvider() {
|
|||
|
Filters.Add(new ActivatingFilter<CommonAspect>("test-item"));
|
|||
|
Filters.Add(new ActivatingFilter<TestUser>("user"));
|
|||
|
}
|
|||
|
}
|
|||
|
class TestUser : ContentPart, IUser {
|
|||
|
public int Id { get { return 6655321; } }
|
|||
|
public string UserName {get { return "x"; }}
|
|||
|
public string Email { get { return "y"; } }
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void OwnerShouldBeNullAndZeroByDefault() {
|
|||
|
var contentManager = _container.Resolve<IContentManager>();
|
|||
|
var item = contentManager.Create<CommonAspect>("test-item", init => { });
|
|||
|
ClearSession();
|
|||
|
|
|||
|
Assert.That(item.Owner, Is.Null);
|
|||
|
Assert.That(item.Record.OwnerId, Is.EqualTo(0));
|
|||
|
}
|
|||
|
|
|||
|
[Test,Ignore("This testing is still being worked out")]
|
|||
|
public void OwnerShouldBeAuthenticatedUserIfAvailable() {
|
|||
|
var contentManager = _container.Resolve<IContentManager>();
|
|||
|
|
|||
|
var user = contentManager.New<IUser>("user");
|
|||
|
_authn.Setup(x => x.GetAuthenticatedUser()).Returns(user);
|
|||
|
|
|||
|
var item = contentManager.Create<CommonAspect>("test-item", init => { });
|
|||
|
|
|||
|
ClearSession();
|
|||
|
|
|||
|
Assert.That(item.Record.OwnerId, Is.EqualTo(6655321));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|