Merge remote-tracking branch 'origin/temp8' into temp8-logviewer

This commit is contained in:
Warren Buckley
2019-01-03 13:52:14 +00:00
50 changed files with 1186 additions and 1229 deletions

View File

@@ -1,21 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using Umbraco.Web.Cache;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
namespace Umbraco.Tests.Cache
{
[TestFixture]
[UmbracoTest(WithApplication = true)]
public class CacheRefresherEventHandlerTests : UmbracoTestBase
public class DistributedCacheBinderTests : UmbracoTestBase
{
[Test]
public void Can_Find_All_Event_Handlers()
@@ -114,7 +116,7 @@ namespace Umbraco.Tests.Cache
var ok = true;
foreach (var definition in definitions)
{
var found = CacheRefresherComponent.FindHandler(definition);
var found = DistributedCacheBinder.FindHandler(definition);
if (found == null)
{
Console.WriteLine("Couldn't find method for " + definition.EventName + " on " + definition.Sender.GetType());
@@ -123,5 +125,35 @@ namespace Umbraco.Tests.Cache
}
Assert.IsTrue(ok, "see log for details");
}
[Test]
public void CanHandleEvent()
{
// refreshers.HandleEvents wants a UmbracoContext
// which wants an HttpContext, which we build using a SimpleWorkerRequest
// which requires these to be non-null
var domain = Thread.GetDomain();
if (domain.GetData(".appPath") == null)
domain.SetData(".appPath", "");
if (domain.GetData(".appVPath") == null)
domain.SetData(".appVPath", "");
// refreshers.HandleEvents wants a UmbracoContext
// which wants these
Container.RegisterSingleton(_ => Mock.Of<IPublishedSnapshotService>());
Container.RegisterCollectionBuilder<UrlProviderCollectionBuilder>();
// create some event definitions
var definitions = new IEventDefinition[]
{
// works because that event definition maps to an empty handler
new EventDefinition<IContentTypeService, SaveEventArgs<IContentType>>(null, Current.Services.ContentTypeService, new SaveEventArgs<IContentType>(Enumerable.Empty<IContentType>()), "Saved"),
};
// just assert it does not throw
var refreshers = new DistributedCacheBinder(null, null);
refreshers.HandleEvents(definitions);
}
}
}

View File

@@ -2,19 +2,17 @@
using System.Collections.Generic;
using System.Linq;
using LightInject;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Sync;
using Umbraco.Tests.Cache.DistributedCache;
using Umbraco.Tests.Services;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Tests.Testing;
using Umbraco.Web.Cache;
using static Umbraco.Tests.Cache.DistributedCache.DistributedCacheTests;
@@ -34,8 +32,8 @@ namespace Umbraco.Tests.Integration
{
base.SetUp();
_h1 = new CacheRefresherComponent(true);
_h1.Initialize(new DistributedCache());
_h1 = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_h1.BindEvents(true);
_events = new List<EventInstance>();
@@ -76,7 +74,7 @@ namespace Umbraco.Tests.Integration
{
base.TearDown();
_h1?.Unbind();
_h1?.UnbindEvents();
// clear ALL events
@@ -86,7 +84,7 @@ namespace Umbraco.Tests.Integration
ContentCacheRefresher.CacheUpdated -= ContentCacheUpdated;
}
private CacheRefresherComponent _h1;
private DistributedCacheBinder _h1;
private IList<EventInstance> _events;
private int _msgCount;
private IContentType _contentType;

View File

@@ -11,6 +11,7 @@ using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence.Repositories;
@@ -36,7 +37,7 @@ namespace Umbraco.Tests.Scoping
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)]
public class ScopedNuCacheTests : TestWithDatabaseBase
{
private CacheRefresherComponent _cacheRefresher;
private DistributedCacheBinder _distributedCacheBinder;
protected override void Compose()
{
@@ -56,8 +57,8 @@ namespace Umbraco.Tests.Scoping
{
base.TearDown();
_cacheRefresher?.Unbind();
_cacheRefresher = null;
_distributedCacheBinder?.UnbindEvents();
_distributedCacheBinder = null;
_onPublishedAssertAction = null;
ContentService.Published -= OnPublishedAssert;
@@ -129,8 +130,8 @@ namespace Umbraco.Tests.Scoping
var umbracoContext = GetUmbracoContextNu("http://example.com/", setSingleton: true);
// wire cache refresher
_cacheRefresher = new CacheRefresherComponent(true);
_cacheRefresher.Initialize(new DistributedCache());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_distributedCacheBinder.BindEvents(true);
// create document type, document
var contentType = new ContentType(-1) { Alias = "CustomDocument", Name = "Custom Document" };

View File

@@ -13,6 +13,7 @@ using Umbraco.Web.Cache;
using LightInject;
using Moq;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Sync;
namespace Umbraco.Tests.Scoping
@@ -21,7 +22,7 @@ namespace Umbraco.Tests.Scoping
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, WithApplication = true)]
public class ScopedRepositoryTests : TestWithDatabaseBase
{
private CacheRefresherComponent _cacheRefresher;
private DistributedCacheBinder _distributedCacheBinder;
protected override void Compose()
{
@@ -52,8 +53,8 @@ namespace Umbraco.Tests.Scoping
[TearDown]
public void Teardown()
{
_cacheRefresher?.Unbind();
_cacheRefresher = null;
_distributedCacheBinder?.UnbindEvents();
_distributedCacheBinder = null;
}
[TestCase(true)]
@@ -76,8 +77,8 @@ namespace Umbraco.Tests.Scoping
// get user again - else we'd modify the one that's in the cache
user = service.GetUserById(user.Id);
_cacheRefresher = new CacheRefresherComponent(true);
_cacheRefresher.Initialize(new DistributedCache());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_distributedCacheBinder.BindEvents(true);
Assert.IsNull(scopeProvider.AmbientScope);
using (var scope = scopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped))
@@ -157,8 +158,8 @@ namespace Umbraco.Tests.Scoping
Assert.AreEqual(lang.Id, globalCached.Id);
Assert.AreEqual("fr-FR", globalCached.IsoCode);
_cacheRefresher = new CacheRefresherComponent(true);
_cacheRefresher.Initialize(new DistributedCache());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_distributedCacheBinder.BindEvents(true);
Assert.IsNull(scopeProvider.AmbientScope);
using (var scope = scopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped))
@@ -249,8 +250,8 @@ namespace Umbraco.Tests.Scoping
Assert.AreEqual(item.Id, globalCached.Id);
Assert.AreEqual("item-key", globalCached.ItemKey);
_cacheRefresher = new CacheRefresherComponent(true);
_cacheRefresher.Initialize(new DistributedCache());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_distributedCacheBinder.BindEvents(true);
Assert.IsNull(scopeProvider.AmbientScope);
using (var scope = scopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped))

View File

@@ -7,6 +7,7 @@ using LightInject;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
@@ -23,7 +24,7 @@ namespace Umbraco.Tests.Scoping
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)]
public class ScopedXmlTests : TestWithDatabaseBase
{
private CacheRefresherComponent _cacheRefresher;
private DistributedCacheBinder _distributedCacheBinder;
protected override void Compose()
{
@@ -42,8 +43,8 @@ namespace Umbraco.Tests.Scoping
[TearDown]
public void Teardown()
{
_cacheRefresher?.Unbind();
_cacheRefresher = null;
_distributedCacheBinder?.UnbindEvents();
_distributedCacheBinder = null;
_onPublishedAssertAction = null;
ContentService.Published -= OnPublishedAssert;
@@ -90,8 +91,8 @@ namespace Umbraco.Tests.Scoping
var item = new Content("name", -1, contentType);
// wire cache refresher
_cacheRefresher = new CacheRefresherComponent(true);
_cacheRefresher.Initialize(new DistributedCache());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_distributedCacheBinder.BindEvents(true);
// check xml in context = "before"
var xml = XmlInContext;
@@ -209,8 +210,8 @@ namespace Umbraco.Tests.Scoping
Current.Services.ContentTypeService.Save(contentType);
// wire cache refresher
_cacheRefresher = new CacheRefresherComponent(true);
_cacheRefresher.Initialize(new DistributedCache());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(), Mock.Of<ILogger>());
_distributedCacheBinder.BindEvents(true);
// check xml in context = "before"
var xml = XmlInContext;

View File

@@ -111,7 +111,7 @@
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="Cache\CacheRefresherComponentTests.cs" />
<Compile Include="Cache\DistributedCacheBinderTests.cs" />
<Compile Include="Cache\RefresherTests.cs" />
<Compile Include="Cache\SnapDictionaryTests.cs" />
<Compile Include="Clr\ReflectionUtilitiesTests.cs" />