Fix tests with issues
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
|
||||
@@ -16,8 +17,16 @@ namespace Umbraco.Tests.PublishedContent
|
||||
private UmbracoContext ctx;
|
||||
private string xmlContent = "";
|
||||
private bool createContentTypes = true;
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// make sure we get them from the content service
|
||||
PublishedContentType.GetPublishedContentTypeCallback = null;
|
||||
}
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
{
|
||||
return xmlContent;
|
||||
}
|
||||
@@ -57,7 +66,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var publishedContent = ctx.ContentCache.GetById(1100);
|
||||
Assert.That(publishedContent.IsDocumentType("base", true));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void IsDocumentType_Recursive_InvalidBaseType_ReturnsFalse()
|
||||
{
|
||||
@@ -73,23 +82,23 @@ namespace Umbraco.Tests.PublishedContent
|
||||
if (createContentTypes)
|
||||
{
|
||||
var contentTypeService = ctx.Application.Services.ContentTypeService;
|
||||
var baseType = new ContentType(-1) {Alias = "base", Name = "Base"};
|
||||
var baseType = new ContentType(-1) { Alias = "base", Name = "Base" };
|
||||
const string contentTypeAlias = "inherited";
|
||||
var inheritedType = new ContentType(baseType, contentTypeAlias) {Alias = contentTypeAlias, Name = "Inherited"};
|
||||
var inheritedType = new ContentType(baseType, contentTypeAlias) { Alias = contentTypeAlias, Name = "Inherited" };
|
||||
contentTypeService.Save(baseType);
|
||||
contentTypeService.Save(inheritedType);
|
||||
createContentTypes = false;
|
||||
}
|
||||
#region setup xml content
|
||||
|
||||
xmlContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<!DOCTYPE root[
|
||||
<!DOCTYPE root[
|
||||
<!ELEMENT inherited ANY>
|
||||
<!ATTLIST inherited id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<inherited id=""1100"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1"" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc=""""/>
|
||||
</root>";
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
[Timeout(30000)]
|
||||
public class BackgroundTaskRunnerTests
|
||||
{
|
||||
private ILogger _logger;
|
||||
private ILogger _logger;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void InitializeFixture()
|
||||
@@ -93,7 +93,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
{
|
||||
runner.Add(new MyTask());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -242,7 +242,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void Create_IsNotRunning()
|
||||
{
|
||||
@@ -252,16 +252,18 @@ namespace Umbraco.Tests.Scheduling
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public async void Create_AutoStart_IsRunning()
|
||||
{
|
||||
using (var runner = new BackgroundTaskRunner<IBackgroundTask>(new BackgroundTaskRunnerOptions
|
||||
{
|
||||
AutoStart = true
|
||||
AutoStart = true,
|
||||
KeepAlive = true // else stops!
|
||||
}, _logger))
|
||||
{
|
||||
Assert.IsTrue(runner.IsRunning); // because AutoStart is true
|
||||
runner.Stop(false); // keepalive = must be stopped
|
||||
await runner.StoppedAwaitable; // runner stops, within test's timeout
|
||||
}
|
||||
}
|
||||
@@ -296,7 +298,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
// so that we don't have a runaway task in tests, etc - but it does NOT terminate
|
||||
// the runner - it really is NOT a nice way to end a runner - it's there for tests
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Startup_KeepAlive_IsRunning()
|
||||
{
|
||||
@@ -359,7 +361,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public async void WaitOnRunner_Tasks()
|
||||
{
|
||||
@@ -504,7 +506,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
|
||||
//wait till the thread is done
|
||||
await tManager.CurrentThreadingTask;
|
||||
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
Assert.IsTrue(task.Ended != default(DateTime));
|
||||
@@ -516,7 +518,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void RecurringTaskTest()
|
||||
{
|
||||
@@ -532,7 +534,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
};
|
||||
|
||||
var task = new MyRecurringTask(runner, 200, 500);
|
||||
|
||||
|
||||
runner.Add(task);
|
||||
|
||||
Assert.IsTrue(runner.IsRunning); // waiting on delay
|
||||
@@ -577,7 +579,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
runner.Add(task);
|
||||
Assert.IsTrue(runner.IsRunning);
|
||||
Thread.Sleep(5000);
|
||||
Assert.IsTrue(runner.IsRunning); // still waiting for the task to release
|
||||
Assert.IsTrue(runner.IsRunning); // still waiting for the task to release
|
||||
Assert.IsFalse(task.HasRun);
|
||||
runner.Shutdown(false, false);
|
||||
await runner.StoppedAwaitable; // wait for the entire runner operation to complete
|
||||
@@ -585,7 +587,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void LatchedRecurring()
|
||||
{
|
||||
@@ -842,7 +844,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
}
|
||||
|
||||
public override bool PerformRun()
|
||||
{
|
||||
{
|
||||
Thread.Sleep(_runMilliseconds);
|
||||
return true; // repeat
|
||||
}
|
||||
@@ -976,7 +978,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
public virtual Task RunAsync(CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//return Task.Delay(500);
|
||||
//return Task.Delay(500);
|
||||
}
|
||||
|
||||
public virtual bool IsAsync
|
||||
|
||||
@@ -639,23 +639,9 @@ namespace Umbraco.Web
|
||||
/// <param name="recursive">When true, recurses up the content type tree to check inheritance; when false just calls IsDocumentType(this IPublishedContent content, string docTypeAlias).</param>
|
||||
/// <returns>True if the content is of the specified content type or a derived content type; otherwise false.</returns>
|
||||
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive)
|
||||
{
|
||||
if (content.IsDocumentType(docTypeAlias))
|
||||
return true;
|
||||
|
||||
if (recursive)
|
||||
return IsDocumentTypeRecursive(content, docTypeAlias);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsDocumentTypeRecursive(IPublishedContent content, string docTypeAlias)
|
||||
{
|
||||
var contentTypeService = UmbracoContext.Current.Application.Services.ContentTypeService;
|
||||
var type = contentTypeService.GetContentType(content.DocumentTypeAlias);
|
||||
if (type.Alias.InvariantEquals(docTypeAlias) || content.IsComposedOf(docTypeAlias))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
{
|
||||
return content.DocumentTypeAlias.InvariantEquals(docTypeAlias) || (recursive && content.IsComposedOf(docTypeAlias));
|
||||
}
|
||||
|
||||
public static bool IsNull(this IPublishedContent content, string alias, bool recurse)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user