Fixes tests - Nucache tests were not disposing the snapshot service so was binding to all events!! renames the test snapshot service to avoid confusion

This commit is contained in:
Shannon
2019-10-16 15:49:19 +11:00
parent 6d38f946a4
commit 4e51a2d184
8 changed files with 25 additions and 12 deletions

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
/// <summary>
/// Implements a published snapshot service.
/// </summary>
internal class PublishedSnapshotService : PublishedSnapshotServiceBase
internal class XmlPublishedSnapshotService : PublishedSnapshotServiceBase
{
private readonly XmlStore _xmlStore;
private readonly RoutesCache _routesCache;
@@ -41,7 +41,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Constructors
// used in WebBootManager + tests
public PublishedSnapshotService(ServiceContext serviceContext,
public XmlPublishedSnapshotService(ServiceContext serviceContext,
IPublishedContentTypeFactory publishedContentTypeFactory,
IScopeProvider scopeProvider,
IAppCache requestCache,
@@ -65,7 +65,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
// used in some tests
internal PublishedSnapshotService(ServiceContext serviceContext,
internal XmlPublishedSnapshotService(ServiceContext serviceContext,
IPublishedContentTypeFactory publishedContentTypeFactory,
IScopeProvider scopeProvider,
IAppCache requestCache,

View File

@@ -32,7 +32,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
/// Represents the Xml storage for the Xml published cache.
/// </summary>
/// <remarks>
/// <para>One instance of <see cref="XmlStore"/> is instantiated by the <see cref="PublishedSnapshotService"/> and
/// <para>One instance of <see cref="XmlStore"/> is instantiated by the <see cref="XmlPublishedSnapshotService"/> and
/// then passed to all <see cref="PublishedContentCache"/> instances that are created (one per request).</para>
/// <para>This class should *not* be public.</para>
/// </remarks>

View File

@@ -41,6 +41,12 @@ namespace Umbraco.Tests.PublishedContent
private ContentType _contentTypeVariant;
private TestDataSource _source;
[TearDown]
public void Teardown()
{
_snapshotService?.Dispose();
}
private void Init(IEnumerable<ContentNodeKit> kits)
{
Current.Reset();

View File

@@ -36,6 +36,12 @@ namespace Umbraco.Tests.PublishedContent
private ContentType _contentType;
private PropertyType _propertyType;
[TearDown]
public void Teardown()
{
_snapshotService?.Dispose();
}
private void Init()
{
Current.Reset();
@@ -303,5 +309,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsFalse(c2.IsPublished("dk-DA"));
Assert.IsTrue(c2.IsPublished("de-DE"));
}
}
}

View File

@@ -73,7 +73,7 @@ namespace Umbraco.Tests.Scoping
// xmlStore.Xml - the actual main xml document
// publishedContentCache.GetXml() - the captured xml
private static XmlStore XmlStore => (Current.Factory.GetInstance<IPublishedSnapshotService>() as PublishedSnapshotService).XmlStore;
private static XmlStore XmlStore => (Current.Factory.GetInstance<IPublishedSnapshotService>() as XmlPublishedSnapshotService).XmlStore;
private static XmlDocument XmlMaster => XmlStore.Xml;
private static XmlDocument XmlInContext => ((PublishedContentCache) Umbraco.Web.Composing.Current.UmbracoContext.Content).GetXml(false);

View File

@@ -259,7 +259,7 @@ namespace Umbraco.Tests.TestHelpers
var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Umbraco.Web.Composing.Current.UmbracoContextAccessor);
var variationContextAccessor = new TestVariationContextAccessor();
var service = new PublishedSnapshotService(
var service = new XmlPublishedSnapshotService(
ServiceContext,
Factory.GetInstance<IPublishedContentTypeFactory>(),
ScopeProvider,
@@ -357,14 +357,14 @@ namespace Umbraco.Tests.TestHelpers
protected UmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable<IUrlProvider> urlProviders = null, IEnumerable<IMediaUrlProvider> mediaUrlProviders = null, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null)
{
// ensure we have a PublishedCachesService
var service = snapshotService ?? PublishedSnapshotService as PublishedSnapshotService;
var service = snapshotService ?? PublishedSnapshotService as XmlPublishedSnapshotService;
if (service == null)
throw new Exception("Not a proper XmlPublishedCache.PublishedCachesService.");
if (service is PublishedSnapshotService)
if (service is XmlPublishedSnapshotService)
{
// re-initialize PublishedCacheService content with an Xml source with proper template id
((PublishedSnapshotService)service).XmlStore.GetXmlDocument = () =>
((XmlPublishedSnapshotService)service).XmlStore.GetXmlDocument = () =>
{
var doc = new XmlDocument();
doc.LoadXml(GetXmlContent(templateId));

View File

@@ -511,7 +511,7 @@
<Compile Include="LegacyXmlPublishedCache\PublishedMediaCache.cs" />
<Compile Include="LegacyXmlPublishedCache\PublishedMemberCache.cs" />
<Compile Include="LegacyXmlPublishedCache\PublishedSnapshot.cs" />
<Compile Include="LegacyXmlPublishedCache\PublishedSnapshotService.cs" />
<Compile Include="LegacyXmlPublishedCache\XmlPublishedSnapshotService.cs" />
<Compile Include="LegacyXmlPublishedCache\RoutesCache.cs" />
<Compile Include="LegacyXmlPublishedCache\SafeXmlReaderWriter.cs" />
<Compile Include="LegacyXmlPublishedCache\UmbracoContextCache.cs" />

View File

@@ -29,7 +29,7 @@ namespace Umbraco.Tests.Web.Mvc
[UmbracoTest(WithApplication = true)]
public class UmbracoViewPageTests : UmbracoTestBase
{
private PublishedSnapshotService _service;
private XmlPublishedSnapshotService _service;
[TearDown]
public override void TearDown()
@@ -421,7 +421,7 @@ namespace Umbraco.Tests.Web.Mvc
var scopeProvider = TestObjects.GetScopeProvider(Mock.Of<ILogger>());
var factory = Mock.Of<IPublishedContentTypeFactory>();
var umbracoContextAccessor = Mock.Of<IUmbracoContextAccessor>();
_service = new PublishedSnapshotService(svcCtx, factory, scopeProvider, cache,
_service = new XmlPublishedSnapshotService(svcCtx, factory, scopeProvider, cache,
null, null,
umbracoContextAccessor, null, null, null,
new TestDefaultCultureAccessor(),