Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/UnitOfWorkTests.cs
Paul Johnson 95aa143db0 v10 make migration from v9 less painful WRT IScope (#12293)
* Restore IEventDispatcher

* Fix breaking changes WRT IScopeProvider and IScope

* Update internal usage.

* Update src/Umbraco.Core/Services/UserService.cs

* Better obsolete message

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
2022-04-26 10:22:37 +01:00

80 lines
2.5 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using NUnit.Framework;
using Umbraco.Cms.Core.DistributedLocking;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Persistence.Sqlite.Services;
using Umbraco.Cms.Persistence.SqlServer.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
using Constants = Umbraco.Cms.Core.Constants;
using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider;
using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class UnitOfWorkTests : UmbracoIntegrationTest
{
[Test]
public void ReadLockNonExisting()
{
var lockingMechanism = GetRequiredService<IDistributedLockingMechanismFactory>().DistributedLockingMechanism;
if (lockingMechanism is SqliteDistributedLockingMechanism)
{
Assert.Ignore("SqliteDistributedLockingMechanism doesn't query the umbracoLock table for read locks.");
}
IScopeProvider provider = ScopeProvider;
Assert.Throws<ArgumentException>(() =>
{
using (IScope scope = provider.CreateScope())
{
scope.EagerReadLock(-666);
scope.Complete();
}
});
}
[Test]
public void ReadLockExisting()
{
IScopeProvider provider = ScopeProvider;
using (IScope scope = provider.CreateScope())
{
scope.EagerReadLock(Constants.Locks.Servers);
scope.Complete();
}
}
[Test]
public void WriteLockNonExisting()
{
IScopeProvider provider = ScopeProvider;
Assert.Throws<ArgumentException>(() =>
{
using (IScope scope = provider.CreateScope())
{
scope.EagerWriteLock(-666);
scope.Complete();
}
});
}
[Test]
public void WriteLockExisting()
{
IScopeProvider provider = ScopeProvider;
using (IScope scope = provider.CreateScope())
{
scope.EagerWriteLock(Constants.Locks.Servers);
scope.Complete();
}
}
}
}