2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-05-18 10:55:19 +02:00
|
|
|
using NUnit.Framework;
|
2021-02-15 11:41:12 +01:00
|
|
|
using Umbraco.Cms.Core.Scoping;
|
2021-02-10 14:45:44 +01:00
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
2021-02-11 08:30:27 +01:00
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Constants = Umbraco.Cms.Core.Constants;
|
2016-05-18 10:55:19 +02:00
|
|
|
|
2021-02-11 08:30:27 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2016-11-05 19:23:55 +01:00
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
2020-10-22 13:27:24 +02:00
|
|
|
public class UnitOfWorkTests : UmbracoIntegrationTest
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void ReadLockNonExisting()
|
|
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
IScopeProvider provider = ScopeProvider;
|
2019-10-21 07:26:39 +02:00
|
|
|
Assert.Throws<ArgumentException>(() =>
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
using (IScope scope = provider.CreateScope())
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
2021-09-13 21:09:47 +10:00
|
|
|
scope.EagerReadLock(-666);
|
2017-12-12 15:04:13 +01:00
|
|
|
scope.Complete();
|
2016-05-18 10:55:19 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void ReadLockExisting()
|
|
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
IScopeProvider provider = ScopeProvider;
|
|
|
|
|
using (IScope scope = provider.CreateScope())
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
2021-09-13 21:09:47 +10:00
|
|
|
scope.EagerReadLock(Constants.Locks.Servers);
|
2017-12-12 15:04:13 +01:00
|
|
|
scope.Complete();
|
2016-05-18 10:55:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void WriteLockNonExisting()
|
|
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
IScopeProvider provider = ScopeProvider;
|
2019-10-21 07:26:39 +02:00
|
|
|
Assert.Throws<ArgumentException>(() =>
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
using (IScope scope = provider.CreateScope())
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
2021-09-13 21:09:47 +10:00
|
|
|
scope.EagerWriteLock(-666);
|
2017-12-12 15:04:13 +01:00
|
|
|
scope.Complete();
|
2016-05-18 10:55:19 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void WriteLockExisting()
|
|
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
IScopeProvider provider = ScopeProvider;
|
|
|
|
|
using (IScope scope = provider.CreateScope())
|
2016-05-18 10:55:19 +02:00
|
|
|
{
|
2021-09-13 21:09:47 +10:00
|
|
|
scope.EagerWriteLock(Constants.Locks.Servers);
|
2017-12-12 15:04:13 +01:00
|
|
|
scope.Complete();
|
2016-05-18 10:55:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|