Adding a rough-cut owner editor

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043456
This commit is contained in:
loudej
2009-12-08 06:13:08 +00:00
parent ab0fbe20e1
commit 5aae644c6d
15 changed files with 231 additions and 10 deletions

View File

@@ -0,0 +1,80 @@
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));
}
}
}

View File

@@ -31,10 +31,30 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=1.4.4.561, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\autofac\Autofac.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nunit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\sqlite\System.Data.SQLite.DLL</HintPath>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -45,8 +65,23 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\Providers\CommonAspectProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Orchard.Tests.Packages\Orchard.Tests.Packages.csproj">
<Project>{6CB3EB30-F725-45C0-9742-42599BA8E8D2}</Project>
<Name>Orchard.Tests.Packages</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Core\Orchard.Core.csproj">
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard\Orchard.csproj">
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.