mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Added tests for DatabaseLock.
This commit is contained in:
@@ -182,6 +182,7 @@
|
||||
<Compile Include="Stubs\MessageChannelSelectorStub.cs" />
|
||||
<Compile Include="Stubs\ShapeDisplayStub.cs" />
|
||||
<Compile Include="Tags\Services\TagsServiceTests.cs" />
|
||||
<Compile Include="TaskLease\DatabaseLockTests.cs" />
|
||||
<Compile Include="Themes\Services\ThemeServiceTests.cs" />
|
||||
<Compile Include="Users\Controllers\AccountControllerTests.cs" />
|
||||
<Compile Include="Users\Services\UserServiceTests.cs" />
|
||||
@@ -281,6 +282,10 @@
|
||||
<Project>{5D0F00F0-26C9-4785-AD61-B85710C60EB0}</Project>
|
||||
<Name>Orchard.Tags</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.TaskLease\Orchard.TaskLease.csproj">
|
||||
<Project>{3f72a4e9-7b72-4260-b010-c16ec54f9baf}</Project>
|
||||
<Name>Orchard.TaskLease</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Themes\Orchard.Themes.csproj">
|
||||
<Project>{CDE24A24-01D3-403C-84B9-37722E18DFB7}</Project>
|
||||
<Name>Orchard.Themes</Name>
|
||||
|
66
src/Orchard.Tests.Modules/TaskLease/DatabaseLockTests.cs
Normal file
66
src/Orchard.Tests.Modules/TaskLease/DatabaseLockTests.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Data;
|
||||
using Orchard.TaskLease.Models;
|
||||
using Orchard.TaskLease.Services;
|
||||
|
||||
namespace Orchard.Tests.Modules.TaskLease {
|
||||
[TestFixture]
|
||||
public class DatabaseLockTests : DatabaseEnabledTestsBase {
|
||||
private IRepository<DatabaseLockRecord> _databaseLockRepository;
|
||||
private DatabaseLock _lock;
|
||||
|
||||
protected override IEnumerable<Type> DatabaseTypes {
|
||||
get {
|
||||
yield return typeof(DatabaseLockRecord);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterType<DatabaseLock>().AsSelf();
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
|
||||
_databaseLockRepository = _container.Resolve<IRepository<DatabaseLockRecord>>();
|
||||
_lock = _container.Resolve<DatabaseLock>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AcquiringLockSucceeds() {
|
||||
var lockAcquired = _lock.TryAcquire("Test", TimeSpan.FromSeconds(60));
|
||||
|
||||
Assert.That(lockAcquired, Is.True);
|
||||
Assert.That(_databaseLockRepository.Table.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisposingRemovesLockRecord() {
|
||||
_lock.TryAcquire("Test", TimeSpan.FromSeconds(60));
|
||||
_lock.Dispose();
|
||||
Assert.That(_databaseLockRepository.Table.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AcquiringLockTwiceFails() {
|
||||
var attempt1 = _lock.TryAcquire("Test", TimeSpan.FromSeconds(60));
|
||||
var attempt2 = _lock.TryAcquire("Test", TimeSpan.FromSeconds(60));
|
||||
|
||||
Assert.That(attempt1, Is.True);
|
||||
Assert.That(attempt2, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AcquiringExpiredLockSucceeds() {
|
||||
var attempt1 = _lock.TryAcquire("Test", TimeSpan.FromSeconds(60));
|
||||
var attempt2 = _lock.TryAcquire("Test", TimeSpan.FromSeconds(-1)); // Treat the previosuly stored lock as immediately expired.
|
||||
|
||||
Assert.That(attempt1, Is.True);
|
||||
Assert.That(attempt2, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
@@ -269,6 +269,7 @@
|
||||
<Compile Include="Localization\DateTimePartsTests.cs" />
|
||||
<Compile Include="Localization\DefaultDateLocalizationServicesTests.cs" />
|
||||
<Compile Include="Localization\DefaultDateFormatterTests.cs" />
|
||||
<Compile Include="Stubs\StubMachineNameProvider.cs" />
|
||||
<Compile Include="Stubs\StubCultureSelector.cs" />
|
||||
<Compile Include="Localization\TestHelpers.cs" />
|
||||
<Compile Include="Logging\OrchardFileAppenderTests.cs" />
|
||||
|
9
src/Orchard.Tests/Stubs/StubMachineNameProvider.cs
Normal file
9
src/Orchard.Tests/Stubs/StubMachineNameProvider.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Orchard.Environment;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubMachineNameProvider : IMachineNameProvider {
|
||||
public string GetMachineName() {
|
||||
return "Orchard Machine";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user