Merge remote-tracking branch 'origin/6.2.1' into 7.1.5
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
using System.CodeDom;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class SurfaceControllerTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Construct_And_Get_Result()
|
||||
{
|
||||
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
|
||||
ApplicationContext.EnsureContext(appCtx, true);
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
appCtx,
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
var result = ctrl.Index();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Umbraco_Context_Not_Null()
|
||||
{
|
||||
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
|
||||
ApplicationContext.EnsureContext(appCtx, true);
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
appCtx,
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
Assert.IsNotNull(ctrl.UmbracoContext);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Umbraco_Helper_Not_Null()
|
||||
{
|
||||
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
|
||||
ApplicationContext.EnsureContext(appCtx, true);
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
appCtx,
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
Assert.IsNotNull(ctrl.Umbraco);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Lookup_Content()
|
||||
{
|
||||
//init app context
|
||||
|
||||
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
|
||||
|
||||
//TODO: Need to either make this public or make all methods on the UmbracoHelper or
|
||||
// in v7 the PublishedContentQuery object virtual so we can just mock the methods
|
||||
|
||||
var contentCaches = new Mock<IPublishedCaches>();
|
||||
|
||||
//init content resolver
|
||||
//TODO: This is not public so people cannot actually do this!
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(contentCaches.Object);
|
||||
|
||||
//init umb context
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
appCtx,
|
||||
true);
|
||||
|
||||
//setup the mock
|
||||
|
||||
contentCaches.Setup(caches => caches.CreateContextualContentCache(It.IsAny<UmbracoContext>()))
|
||||
.Returns(new ContextualPublishedContentCache(
|
||||
Mock.Of<IPublishedContentCache>(cache =>
|
||||
cache.GetById(It.IsAny<UmbracoContext>(), false, It.IsAny<int>()) ==
|
||||
//return mock of IPublishedContent for any call to GetById
|
||||
Mock.Of<IPublishedContent>(content => content.Id == 2)),
|
||||
umbCtx));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using (var uTest = new DisposableUmbracoTest(appCtx))
|
||||
{
|
||||
var ctrl = new TestSurfaceController(uTest.UmbracoContext);
|
||||
var result = ctrl.GetContent(2) as PublishedContentResult;
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(2, result.Content.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestSurfaceController : SurfaceController
|
||||
{
|
||||
public TestSurfaceController(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult GetContent(int id)
|
||||
{
|
||||
var content = Umbraco.TypedContent(id);
|
||||
|
||||
return new PublishedContentResult(content);
|
||||
}
|
||||
}
|
||||
|
||||
public class PublishedContentResult : ActionResult
|
||||
{
|
||||
public IPublishedContent Content { get; set; }
|
||||
|
||||
public PublishedContentResult(IPublishedContent content)
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public override void ExecuteResult(ControllerContext context)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Web;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
//NOTE: This is just a POC! Looking at the simplest way to expose some code so people can very easily test
|
||||
// their Umbraco controllers, etc....
|
||||
public class DisposableUmbracoTest : DisposableObject
|
||||
{
|
||||
public ApplicationContext ApplicationContext { get; set; }
|
||||
public UmbracoContext UmbracoContext { get; set; }
|
||||
|
||||
public DisposableUmbracoTest(ApplicationContext applicationContext)
|
||||
{
|
||||
//init umb context
|
||||
var umbctx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
applicationContext,
|
||||
true);
|
||||
|
||||
Init(applicationContext, umbctx);
|
||||
}
|
||||
|
||||
public DisposableUmbracoTest(ApplicationContext applicationContext, UmbracoContext umbracoContext)
|
||||
{
|
||||
Init(applicationContext, umbracoContext);
|
||||
}
|
||||
|
||||
private void Init(ApplicationContext applicationContext, UmbracoContext umbracoContext)
|
||||
{
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
|
||||
ApplicationContext = applicationContext;
|
||||
UmbracoContext = umbracoContext;
|
||||
|
||||
ApplicationContext.Current = applicationContext;
|
||||
UmbracoContext.Current = umbracoContext;
|
||||
|
||||
Resolution.Freeze();
|
||||
}
|
||||
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
ApplicationContext.Current = null;
|
||||
UmbracoContext.Current = null;
|
||||
Resolution.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -202,6 +202,7 @@
|
||||
<Compile Include="Models\UmbracoEntityTests.cs" />
|
||||
<Compile Include="Models\UserTests.cs" />
|
||||
<Compile Include="Models\UserTypeTests.cs" />
|
||||
<Compile Include="Mvc\SurfaceControllerTests.cs" />
|
||||
<Compile Include="Mvc\UmbracoViewPageTests.cs" />
|
||||
<Compile Include="Persistence\Auditing\AuditTests.cs" />
|
||||
<Compile Include="BootManagers\CoreBootManagerTests.cs" />
|
||||
@@ -491,6 +492,7 @@
|
||||
<Compile Include="TestHelpers\Entities\MockedContentTypes.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedEntity.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedMedia.cs" />
|
||||
<Compile Include="TestHelpers\DisposableUmbracoTest.cs" />
|
||||
<Compile Include="Trees\BaseContentTreeTests.cs" />
|
||||
<Compile Include="Trees\BaseMediaTreeTests.cs" />
|
||||
<Compile Include="UmbracoExamine\ContentServiceTest.cs" />
|
||||
|
||||
@@ -34,3 +34,5 @@ using System.Security;
|
||||
[assembly: InternalsVisibleTo("umbraco.webservices")]
|
||||
[assembly: InternalsVisibleTo("Concorde.Sync")]
|
||||
[assembly: InternalsVisibleTo("Umbraco.Belle")]
|
||||
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
Reference in New Issue
Block a user