* Add new BackOfficeApi project * Add swagger * Add and route new install controller * Add new install steps * Add Setup endpoint * Add missing RequiresExecution methods * Fix nullability of databasemodel * Move user information to separate model * Remove ping method * Add view models install data * Move mapping folder * Move ViewModels * Add settings endpoint * Remove unused binderprovider * Postfix RequiresExecution with async * Update NewDatabaseUpgradeStep to not depend on install step * Add installstep collection * Move registration into backoffice project * Add InstallService * Use service in controller * Add upgrade to install service and use in controller * Correctly check is database is configured * Reorganize * Reorganize into new core and infrastructure * Rename steps * Rename BackofficeApi to MangementApi * Make install step an interface instead of abstract class * Rename InstallStep to create CreateUserStep * Move restart runtime and sign in user into install steps * Move install service into new core project * Map controllers in composer * Restrict access to installcontroller based on runtime level * Use FireAndForget when logging install * Use actionresult instead of iactionresult * Set new projects as not packable * Link to backoffice in 201 response when installed * Register installations * Add custom backoffice routing template token * Move umbraco path trimming out of application convention * Make it easier to route to backoffice api * Make swagger version aware and move behind backoffice path * Obsolete old install classes * Move maps into single file This is all mappint to/from viewmodels in some manner * Remove usage of InstallSetupResult * Move new projects to the src folder * Remove InstallationType from IInstallStep This upgrade steps should implement their own IUpgradeStep interface * Remove upgrade from service and controller This should be its own service and controller * Add xml docs * Remove internals visible to * Disable package validation for new projects Quite the gotcha here, if the projects are brand new, there is no nuget packages to compare with, this causes the build to fail. * Add ValidateDatabase endpoint * Remove project references to new backoffice We don't actually want to depend on this yet, it's just needed for testing/development * Obsolete installationtype * Add DatabaseSettingsFactory tests * Add InstallServiceTests * Fix InstallServiceTests * Test RequireRuntimeLevelAttribute * Implement new backoffice upgrader (#12818) * Add UpgradeSettingsModel and viewmodel * Add upgrade/settings endpoint * Implement upgrade steps * Add upgrade step collection * Add UpgradeService * Add authorize endpoint to UpgradeController * Fix interface * Add upgrade service tests * Remove runtime check in databaseinstallstep * Move RequireRuntimeLevel to controller * Add a readme to the new backoffice part * BackOffice not Backoffice * Add conditional project references * Fixes based on review * Fix up * Move running of steps into its own method in UpgradeService * Make services transient * More fixup * Log exceptions when running steps
194 lines
5.5 KiB
C#
194 lines
5.5 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Cache;
|
|
using Umbraco.Cms.Core.Sync;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache.DistributedCache;
|
|
|
|
/// <summary>
|
|
/// Ensures that calls to DistributedCache methods carry through to the IServerMessenger correctly
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class DistributedCacheTests
|
|
{
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
ServerRegistrar = new TestServerRegistrar();
|
|
ServerMessenger = new TestServerMessenger();
|
|
|
|
var cacheRefresherCollection = new CacheRefresherCollection(() => new[] { new TestCacheRefresher() });
|
|
|
|
_distributedCache = new global::Umbraco.Cms.Core.Cache.DistributedCache(ServerMessenger, cacheRefresherCollection);
|
|
}
|
|
|
|
private global::Umbraco.Cms.Core.Cache.DistributedCache _distributedCache;
|
|
|
|
private IServerRoleAccessor ServerRegistrar { get; set; }
|
|
|
|
private TestServerMessenger ServerMessenger { get; set; }
|
|
|
|
[Test]
|
|
public void RefreshIntId()
|
|
{
|
|
for (var i = 1; i < 11; i++)
|
|
{
|
|
_distributedCache.Refresh(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"), i);
|
|
}
|
|
|
|
Assert.AreEqual(10, ServerMessenger.IntIdsRefreshed.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void RefreshIntIdFromObject()
|
|
{
|
|
for (var i = 0; i < 10; i++)
|
|
{
|
|
_distributedCache.Refresh(
|
|
Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"),
|
|
x => x.Id,
|
|
new TestObjectWithId { Id = i });
|
|
}
|
|
|
|
Assert.AreEqual(10, ServerMessenger.IntIdsRefreshed.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void RefreshGuidId()
|
|
{
|
|
for (var i = 0; i < 11; i++)
|
|
{
|
|
_distributedCache.Refresh(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"), Guid.NewGuid());
|
|
}
|
|
|
|
Assert.AreEqual(11, ServerMessenger.GuidIdsRefreshed.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void RemoveIds()
|
|
{
|
|
for (var i = 1; i < 13; i++)
|
|
{
|
|
_distributedCache.Remove(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"), i);
|
|
}
|
|
|
|
Assert.AreEqual(12, ServerMessenger.IntIdsRemoved.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void FullRefreshes()
|
|
{
|
|
for (var i = 0; i < 13; i++)
|
|
{
|
|
_distributedCache.RefreshAll(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"));
|
|
}
|
|
|
|
Assert.AreEqual(13, ServerMessenger.CountOfFullRefreshes);
|
|
}
|
|
|
|
internal class TestObjectWithId
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
internal class TestCacheRefresher : ICacheRefresher
|
|
{
|
|
public static readonly Guid UniqueId = Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73");
|
|
|
|
public Guid RefresherUniqueId => UniqueId;
|
|
|
|
public string Name => "Test Cache Refresher";
|
|
|
|
public void RefreshAll()
|
|
{
|
|
}
|
|
|
|
public void Refresh(int id)
|
|
{
|
|
}
|
|
|
|
public void Remove(int id)
|
|
{
|
|
}
|
|
|
|
public void Refresh(Guid id)
|
|
{
|
|
}
|
|
}
|
|
|
|
internal class TestServerMessenger : IServerMessenger
|
|
{
|
|
// Used for tests
|
|
public List<int> IntIdsRefreshed { get; } = new();
|
|
|
|
public List<Guid> GuidIdsRefreshed { get; } = new();
|
|
|
|
public List<int> IntIdsRemoved { get; } = new();
|
|
|
|
public List<string> PayloadsRemoved { get; } = new();
|
|
|
|
public List<string> PayloadsRefreshed { get; } = new();
|
|
|
|
public int CountOfFullRefreshes { get; private set; }
|
|
|
|
public void QueueRefresh<TPayload>(ICacheRefresher refresher, TPayload[] payload)
|
|
{
|
|
// doing nothing
|
|
}
|
|
|
|
public void QueueRefresh<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances) =>
|
|
IntIdsRefreshed.AddRange(instances.Select(getNumericId));
|
|
|
|
public void QueueRefresh<T>(ICacheRefresher refresher, Func<T, Guid> getGuidId, params T[] instances) =>
|
|
GuidIdsRefreshed.AddRange(instances.Select(getGuidId));
|
|
|
|
public void QueueRemove<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances) =>
|
|
IntIdsRemoved.AddRange(instances.Select(getNumericId));
|
|
|
|
public void QueueRemove(ICacheRefresher refresher, params int[] numericIds) =>
|
|
IntIdsRemoved.AddRange(numericIds);
|
|
|
|
public void QueueRefresh(ICacheRefresher refresher, params int[] numericIds) =>
|
|
IntIdsRefreshed.AddRange(numericIds);
|
|
|
|
public void QueueRefresh(ICacheRefresher refresher, params Guid[] guidIds) =>
|
|
GuidIdsRefreshed.AddRange(guidIds);
|
|
|
|
public void QueueRefreshAll(ICacheRefresher refresher) => CountOfFullRefreshes++;
|
|
|
|
public void Sync()
|
|
{
|
|
}
|
|
|
|
public void SendMessages()
|
|
{
|
|
}
|
|
|
|
public void PerformRefresh(ICacheRefresher refresher, string jsonPayload) => PayloadsRefreshed.Add(jsonPayload);
|
|
|
|
public void PerformRemove(ICacheRefresher refresher, string jsonPayload) => PayloadsRemoved.Add(jsonPayload);
|
|
}
|
|
|
|
internal class TestServerRegistrar : IServerRoleAccessor
|
|
{
|
|
public IEnumerable<IServerAddress> Registrations => new List<IServerAddress>
|
|
{
|
|
new TestServerAddress("localhost"),
|
|
};
|
|
|
|
public ServerRole CurrentServerRole => throw new NotImplementedException();
|
|
}
|
|
|
|
public class TestServerAddress : IServerAddress
|
|
{
|
|
public TestServerAddress(string address) => ServerAddress = address;
|
|
|
|
public string ServerAddress { get; }
|
|
}
|
|
}
|