re-organizing some namespaces for tests
This commit is contained in:
@@ -187,12 +187,12 @@
|
||||
<Compile Include="Cache\FullDataSetCachePolicyTests.cs" />
|
||||
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
|
||||
<Compile Include="Collections\DeepCloneableListTests.cs" />
|
||||
<Compile Include="Controllers\BackOfficeControllerUnitTests.cs" />
|
||||
<Compile Include="Web\Controllers\BackOfficeControllerUnitTests.cs" />
|
||||
<Compile Include="DelegateExtensionsTests.cs" />
|
||||
<Compile Include="Logging\AsyncRollingFileAppenderTest.cs" />
|
||||
<Compile Include="Logging\DebugAppender.cs" />
|
||||
<Compile Include="Logging\ParallelForwarderTest.cs" />
|
||||
<Compile Include="Mvc\RenderIndexActionSelectorAttributeTests.cs" />
|
||||
<Compile Include="Web\Mvc\RenderIndexActionSelectorAttributeTests.cs" />
|
||||
<Compile Include="Persistence\Repositories\AuditRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\DomainRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\PartialViewRepositoryTests.cs" />
|
||||
@@ -242,8 +242,8 @@
|
||||
<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="Web\Mvc\SurfaceControllerTests.cs" />
|
||||
<Compile Include="Web\Mvc\UmbracoViewPageTests.cs" />
|
||||
<Compile Include="BootManagers\CoreBootManagerTests.cs" />
|
||||
<Compile Include="BootManagers\WebBootManagerTests.cs" />
|
||||
<Compile Include="Cache\ObjectCacheProviderTests.cs" />
|
||||
@@ -318,9 +318,9 @@
|
||||
<Compile Include="Configurations\UmbracoSettings\ViewstateMoverModuleElementTests.cs" />
|
||||
<Compile Include="Configurations\UmbracoSettings\WebRoutingElementDefaultTests.cs" />
|
||||
<Compile Include="Configurations\UmbracoSettings\WebRoutingElementTests.cs" />
|
||||
<Compile Include="Controllers\WebApiEditors\ContentControllerUnitTests.cs" />
|
||||
<Compile Include="Controllers\WebApiEditors\FilterAllowedOutgoingContentAttributeTests.cs" />
|
||||
<Compile Include="Controllers\WebApiEditors\MediaControllerUnitTests.cs" />
|
||||
<Compile Include="Web\Controllers\WebApiEditors\ContentControllerUnitTests.cs" />
|
||||
<Compile Include="Web\Controllers\WebApiEditors\FilterAllowedOutgoingContentAttributeTests.cs" />
|
||||
<Compile Include="Web\Controllers\WebApiEditors\MediaControllerUnitTests.cs" />
|
||||
<Compile Include="CoreXml\FrameworkXmlTests.cs" />
|
||||
<Compile Include="DynamicsAndReflection\QueryableExtensionTests.cs" />
|
||||
<Compile Include="DynamicsAndReflection\ExtensionMethodFinderTests.cs" />
|
||||
@@ -330,8 +330,8 @@
|
||||
<Compile Include="Migrations\Upgrades\ValidateV7UpgradeTest.cs" />
|
||||
<Compile Include="Models\ContentExtensionsTests.cs" />
|
||||
<Compile Include="Models\UserExtensionsTests.cs" />
|
||||
<Compile Include="Mvc\MergeParentContextViewDataAttributeTests.cs" />
|
||||
<Compile Include="Mvc\ViewDataDictionaryExtensionTests.cs" />
|
||||
<Compile Include="Web\Mvc\MergeParentContextViewDataAttributeTests.cs" />
|
||||
<Compile Include="Web\Mvc\ViewDataDictionaryExtensionTests.cs" />
|
||||
<Compile Include="Persistence\PetaPocoExtensionsTest.cs" />
|
||||
<Compile Include="Persistence\Querying\ContentTypeSqlMappingTests.cs" />
|
||||
<Compile Include="Persistence\Repositories\MacroRepositoryTest.cs" />
|
||||
@@ -427,7 +427,7 @@
|
||||
<Compile Include="PublishedContent\PublishedContentTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedMediaTests.cs" />
|
||||
<Compile Include="HashCodeCombinerTests.cs" />
|
||||
<Compile Include="Mvc\HtmlHelperExtensionMethodsTests.cs" />
|
||||
<Compile Include="Web\Mvc\HtmlHelperExtensionMethodsTests.cs" />
|
||||
<Compile Include="IO\IOHelperTest.cs" />
|
||||
<Compile Include="LibraryTests.cs" />
|
||||
<Compile Include="PropertyEditors\PropertyEditorValueConverterTests.cs" />
|
||||
@@ -512,7 +512,7 @@
|
||||
<DependentUpon>ImportResources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Services\ThreadSafetyServiceTest.cs" />
|
||||
<Compile Include="Controllers\PluginControllerAreaTests.cs" />
|
||||
<Compile Include="Web\Controllers\PluginControllerAreaTests.cs" />
|
||||
<Compile Include="Cache\DistributedCache\DistributedCacheTests.cs" />
|
||||
<Compile Include="Templates\MasterPageHelperTests.cs" />
|
||||
<Compile Include="TestHelpers\BaseDatabaseFactoryTest.cs" />
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
namespace Umbraco.Tests.AngularIntegration
|
||||
namespace Umbraco.Tests.Web.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class AngularAntiForgeryTests
|
||||
@@ -1,80 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Tests.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentModelSerializationTests
|
||||
{
|
||||
[Test]
|
||||
public void Content_Display_To_Json()
|
||||
{
|
||||
//create 3 tabs with 3 properties each
|
||||
var tabs = new List<Tab<ContentPropertyDisplay>>();
|
||||
for (var tabIndex = 0; tabIndex < 3; tabIndex ++)
|
||||
{
|
||||
var props = new List<ContentPropertyDisplay>();
|
||||
for (var propertyIndex = 0; propertyIndex < 3; propertyIndex ++)
|
||||
{
|
||||
props.Add(new ContentPropertyDisplay
|
||||
{
|
||||
Alias = "property" + propertyIndex,
|
||||
Label = "Property " + propertyIndex,
|
||||
Id = propertyIndex,
|
||||
Value = "value" + propertyIndex,
|
||||
Config = new Dictionary<string, object> {{ propertyIndex.ToInvariantString(), "value" }},
|
||||
Description = "Description " + propertyIndex,
|
||||
View = "~/Views/View" + propertyIndex,
|
||||
HideLabel = false
|
||||
});
|
||||
}
|
||||
tabs.Add(new Tab<ContentPropertyDisplay>()
|
||||
{
|
||||
Alias = "Tab" + tabIndex,
|
||||
Label = "Tab" + tabIndex,
|
||||
Properties = props
|
||||
});
|
||||
}
|
||||
|
||||
var displayModel = new ContentItemDisplay
|
||||
{
|
||||
Id = 1234,
|
||||
Name = "Test",
|
||||
Tabs = tabs
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(displayModel);
|
||||
|
||||
var jObject = JObject.Parse(json);
|
||||
|
||||
Assert.AreEqual("1234", jObject["id"].ToString());
|
||||
Assert.AreEqual("Test", jObject["name"].ToString());
|
||||
Assert.AreEqual(3, jObject["tabs"].Count());
|
||||
for (var tab = 0; tab < jObject["tabs"].Count(); tab++)
|
||||
{
|
||||
Assert.AreEqual("Tab" + tab, jObject["tabs"][tab]["alias"].ToString());
|
||||
Assert.AreEqual("Tab" + tab, jObject["tabs"][tab]["label"].ToString());
|
||||
Assert.AreEqual(3, jObject["tabs"][tab]["properties"].Count());
|
||||
for (var prop = 0; prop < jObject["tabs"][tab]["properties"].Count(); prop++)
|
||||
{
|
||||
Assert.AreEqual("property" + prop, jObject["tabs"][tab]["properties"][prop]["alias"].ToString());
|
||||
Assert.AreEqual("Property " + prop, jObject["tabs"][tab]["properties"][prop]["label"].ToString());
|
||||
Assert.AreEqual(prop, jObject["tabs"][tab]["properties"][prop]["id"].Value<int>());
|
||||
Assert.AreEqual("value" + prop, jObject["tabs"][tab]["properties"][prop]["value"].ToString());
|
||||
Assert.AreEqual("{\"" + prop + "\":\"value\"}", jObject["tabs"][tab]["properties"][prop]["config"].ToString(Formatting.None));
|
||||
Assert.AreEqual("Description " + prop, jObject["tabs"][tab]["properties"][prop]["description"].ToString());
|
||||
Assert.AreEqual(false, jObject["tabs"][tab]["properties"][prop]["hideLabel"].Value<bool>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Tests.Web.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentModelSerializationTests
|
||||
{
|
||||
[Test]
|
||||
public void Content_Display_To_Json()
|
||||
{
|
||||
//create 3 tabs with 3 properties each
|
||||
var tabs = new List<Tab<ContentPropertyDisplay>>();
|
||||
for (var tabIndex = 0; tabIndex < 3; tabIndex ++)
|
||||
{
|
||||
var props = new List<ContentPropertyDisplay>();
|
||||
for (var propertyIndex = 0; propertyIndex < 3; propertyIndex ++)
|
||||
{
|
||||
props.Add(new ContentPropertyDisplay
|
||||
{
|
||||
Alias = "property" + propertyIndex,
|
||||
Label = "Property " + propertyIndex,
|
||||
Id = propertyIndex,
|
||||
Value = "value" + propertyIndex,
|
||||
Config = new Dictionary<string, object> {{ propertyIndex.ToInvariantString(), "value" }},
|
||||
Description = "Description " + propertyIndex,
|
||||
View = "~/Views/View" + propertyIndex,
|
||||
HideLabel = false
|
||||
});
|
||||
}
|
||||
tabs.Add(new Tab<ContentPropertyDisplay>()
|
||||
{
|
||||
Alias = "Tab" + tabIndex,
|
||||
Label = "Tab" + tabIndex,
|
||||
Properties = props
|
||||
});
|
||||
}
|
||||
|
||||
var displayModel = new ContentItemDisplay
|
||||
{
|
||||
Id = 1234,
|
||||
Name = "Test",
|
||||
Tabs = tabs
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(displayModel);
|
||||
|
||||
var jObject = JObject.Parse(json);
|
||||
|
||||
Assert.AreEqual("1234", jObject["id"].ToString());
|
||||
Assert.AreEqual("Test", jObject["name"].ToString());
|
||||
Assert.AreEqual(3, jObject["tabs"].Count());
|
||||
for (var tab = 0; tab < jObject["tabs"].Count(); tab++)
|
||||
{
|
||||
Assert.AreEqual("Tab" + tab, jObject["tabs"][tab]["alias"].ToString());
|
||||
Assert.AreEqual("Tab" + tab, jObject["tabs"][tab]["label"].ToString());
|
||||
Assert.AreEqual(3, jObject["tabs"][tab]["properties"].Count());
|
||||
for (var prop = 0; prop < jObject["tabs"][tab]["properties"].Count(); prop++)
|
||||
{
|
||||
Assert.AreEqual("property" + prop, jObject["tabs"][tab]["properties"][prop]["alias"].ToString());
|
||||
Assert.AreEqual("Property " + prop, jObject["tabs"][tab]["properties"][prop]["label"].ToString());
|
||||
Assert.AreEqual(prop, jObject["tabs"][tab]["properties"][prop]["id"].Value<int>());
|
||||
Assert.AreEqual("value" + prop, jObject["tabs"][tab]["properties"][prop]["value"].ToString());
|
||||
Assert.AreEqual("{\"" + prop + "\":\"value\"}", jObject["tabs"][tab]["properties"][prop]["config"].ToString(Formatting.None));
|
||||
Assert.AreEqual("Description " + prop, jObject["tabs"][tab]["properties"][prop]["description"].ToString());
|
||||
Assert.AreEqual(false, jObject["tabs"][tab]["properties"][prop]["hideLabel"].Value<bool>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Web.UI.JavaScript;
|
||||
|
||||
namespace Umbraco.Tests.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class JsInitializationTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Get_Default_Init()
|
||||
{
|
||||
var init = JsInitialization.GetDefaultInitialization();
|
||||
Assert.IsTrue(init.Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_Main()
|
||||
{
|
||||
var result = JsInitialization.ParseMain(new[] {"[World]", "Hello" });
|
||||
|
||||
Assert.AreEqual(@"LazyLoad.js([World], function () {
|
||||
//we need to set the legacy UmbClientMgr path
|
||||
UmbClientMgr.setUmbracoPath('Hello');
|
||||
|
||||
jQuery(document).ready(function () {
|
||||
|
||||
angular.bootstrap(document, ['umbraco']);
|
||||
|
||||
});
|
||||
});", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.UI.JavaScript;
|
||||
|
||||
namespace Umbraco.Tests.Web.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class JsInitializationTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Get_Default_Init()
|
||||
{
|
||||
var init = JsInitialization.GetDefaultInitialization();
|
||||
Assert.IsTrue(init.Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_Main()
|
||||
{
|
||||
var result = JsInitialization.ParseMain(new[] {"[World]", "Hello" });
|
||||
|
||||
Assert.AreEqual(@"LazyLoad.js([World], function () {
|
||||
//we need to set the legacy UmbClientMgr path
|
||||
UmbClientMgr.setUmbracoPath('Hello');
|
||||
|
||||
jQuery(document).ready(function () {
|
||||
|
||||
angular.bootstrap(document, ['umbraco']);
|
||||
|
||||
});
|
||||
});", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.UI.JavaScript;
|
||||
|
||||
namespace Umbraco.Tests.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class ServerVariablesParserTests
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public void Parse()
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
d.Add("test1", "Test 1");
|
||||
d.Add("test2", "Test 2");
|
||||
d.Add("test3", "Test 3");
|
||||
d.Add("test4", "Test 4");
|
||||
d.Add("test5", "Test 5");
|
||||
|
||||
var output = ServerVariablesParser.Parse(d);
|
||||
|
||||
Assert.IsTrue(output.Contains(@"Umbraco.Sys.ServerVariables = {
|
||||
""test1"": ""Test 1"",
|
||||
""test2"": ""Test 2"",
|
||||
""test3"": ""Test 3"",
|
||||
""test4"": ""Test 4"",
|
||||
""test5"": ""Test 5""
|
||||
} ;"));
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.UI.JavaScript;
|
||||
|
||||
namespace Umbraco.Tests.Web.AngularIntegration
|
||||
{
|
||||
[TestFixture]
|
||||
public class ServerVariablesParserTests
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public void Parse()
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
d.Add("test1", "Test 1");
|
||||
d.Add("test2", "Test 2");
|
||||
d.Add("test3", "Test 3");
|
||||
d.Add("test4", "Test 4");
|
||||
d.Add("test5", "Test 5");
|
||||
|
||||
var output = ServerVariablesParser.Parse(d);
|
||||
|
||||
Assert.IsTrue(output.Contains(@"Umbraco.Sys.ServerVariables = {
|
||||
""test1"": ""Test 1"",
|
||||
""test2"": ""Test 2"",
|
||||
""test3"": ""Test 3"",
|
||||
""test4"": ""Test 4"",
|
||||
""test5"": ""Test 5""
|
||||
} ;"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Umbraco.Tests.Controllers
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
[TestFixture]
|
||||
public class BackOfficeControllerUnitTests
|
||||
@@ -4,7 +4,7 @@ using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.Controllers
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
[TestFixture]
|
||||
public class PluginControllerAreaTests : BaseWebTest
|
||||
@@ -1,366 +1,366 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Http;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Umbraco.Tests.Controllers.WebApiEditors
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentControllerUnitTests
|
||||
{
|
||||
[Test]
|
||||
public void Access_Allowed_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, contentService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Throws_Exception_When_No_Content_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(0)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>();
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act/assert
|
||||
Assert.Throws<HttpResponseException>(() => ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F' }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(9876);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>();
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A", "B", "C" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_Allowed_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A", "F", "C" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -20);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -20);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Root_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -1)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -1, new[] { 'A'});
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Root_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -1)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -1, new[] { 'B'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Recycle_Bin_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -20)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -20, new[] { 'A'});
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Recycle_Bin_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -20)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -20, new[] { 'B'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//NOTE: The below self hosted stuff does work so need to get some tests written. Some are not possible atm because
|
||||
// of the legacy SQL calls like checking permissions.
|
||||
|
||||
//[TestFixture]
|
||||
//public class ContentControllerHostedTests : BaseRoutingTest
|
||||
//{
|
||||
|
||||
// protected override DatabaseBehavior DatabaseTestBehavior
|
||||
// {
|
||||
// get { return DatabaseBehavior.NoDatabasePerFixture; }
|
||||
// }
|
||||
|
||||
// public override void TearDown()
|
||||
// {
|
||||
// base.TearDown();
|
||||
// UmbracoAuthorizeAttribute.Enable = true;
|
||||
// UmbracoApplicationAuthorizeAttribute.Enable = true;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Tests to ensure that the response filter works so that any items the user
|
||||
// /// doesn't have access to are removed
|
||||
// /// </summary>
|
||||
// [Test]
|
||||
// public async void Get_By_Ids_Response_Filtered()
|
||||
// {
|
||||
// UmbracoAuthorizeAttribute.Enable = false;
|
||||
// UmbracoApplicationAuthorizeAttribute.Enable = false;
|
||||
|
||||
// var baseUrl = string.Format("http://{0}:9876", Environment.MachineName);
|
||||
// var url = baseUrl + "/api/Content/GetByIds?ids=1&ids=2";
|
||||
|
||||
// var routingCtx = GetRoutingContext(url, 1234, null, true);
|
||||
|
||||
// var config = new HttpSelfHostConfiguration(baseUrl);
|
||||
// using (var server = new HttpSelfHostServer(config))
|
||||
// {
|
||||
// var route = config.Routes.MapHttpRoute("test", "api/Content/GetByIds",
|
||||
// new
|
||||
// {
|
||||
// controller = "Content",
|
||||
// action = "GetByIds",
|
||||
// id = RouteParameter.Optional
|
||||
// });
|
||||
// route.DataTokens["Namespaces"] = new string[] { "Umbraco.Web.Editors" };
|
||||
|
||||
// var client = new HttpClient(server);
|
||||
|
||||
// var request = new HttpRequestMessage
|
||||
// {
|
||||
// RequestUri = new Uri(url),
|
||||
// Method = HttpMethod.Get
|
||||
// };
|
||||
|
||||
// var result = await client.SendAsync(request);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Http;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers.WebApiEditors
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentControllerUnitTests
|
||||
{
|
||||
[Test]
|
||||
public void Access_Allowed_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, contentService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Throws_Exception_When_No_Content_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(0)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>();
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act/assert
|
||||
Assert.Throws<HttpResponseException>(() => ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F' }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(9876);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>();
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A", "B", "C" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_Allowed_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A", "F", "C" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, 1234)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -20);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -20);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, null, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Root_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -1)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -1, new[] { 'A'});
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Root_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -1)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -1, new[] { 'B'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Recycle_Bin_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -20)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -20, new[] { 'A'});
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Recycle_Bin_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1234, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, -20)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, null, -20, new[] { 'B'});
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//NOTE: The below self hosted stuff does work so need to get some tests written. Some are not possible atm because
|
||||
// of the legacy SQL calls like checking permissions.
|
||||
|
||||
//[TestFixture]
|
||||
//public class ContentControllerHostedTests : BaseRoutingTest
|
||||
//{
|
||||
|
||||
// protected override DatabaseBehavior DatabaseTestBehavior
|
||||
// {
|
||||
// get { return DatabaseBehavior.NoDatabasePerFixture; }
|
||||
// }
|
||||
|
||||
// public override void TearDown()
|
||||
// {
|
||||
// base.TearDown();
|
||||
// UmbracoAuthorizeAttribute.Enable = true;
|
||||
// UmbracoApplicationAuthorizeAttribute.Enable = true;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Tests to ensure that the response filter works so that any items the user
|
||||
// /// doesn't have access to are removed
|
||||
// /// </summary>
|
||||
// [Test]
|
||||
// public async void Get_By_Ids_Response_Filtered()
|
||||
// {
|
||||
// UmbracoAuthorizeAttribute.Enable = false;
|
||||
// UmbracoApplicationAuthorizeAttribute.Enable = false;
|
||||
|
||||
// var baseUrl = string.Format("http://{0}:9876", Environment.MachineName);
|
||||
// var url = baseUrl + "/api/Content/GetByIds?ids=1&ids=2";
|
||||
|
||||
// var routingCtx = GetRoutingContext(url, 1234, null, true);
|
||||
|
||||
// var config = new HttpSelfHostConfiguration(baseUrl);
|
||||
// using (var server = new HttpSelfHostServer(config))
|
||||
// {
|
||||
// var route = config.Routes.MapHttpRoute("test", "api/Content/GetByIds",
|
||||
// new
|
||||
// {
|
||||
// controller = "Content",
|
||||
// action = "GetByIds",
|
||||
// id = RouteParameter.Optional
|
||||
// });
|
||||
// route.DataTokens["Namespaces"] = new string[] { "Umbraco.Web.Editors" };
|
||||
|
||||
// var client = new HttpClient(server);
|
||||
|
||||
// var request = new HttpRequestMessage
|
||||
// {
|
||||
// RequestUri = new Uri(url),
|
||||
// Method = HttpMethod.Get
|
||||
// };
|
||||
|
||||
// var result = await client.SendAsync(request);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
@@ -1,136 +1,136 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
namespace Umbraco.Tests.Controllers.WebApiEditors
|
||||
{
|
||||
[TestFixture]
|
||||
public class FilterAllowedOutgoingContentAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void GetValueFromResponse_Already_EnumerableContent()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>));
|
||||
var val = new List<ContentItemBasic>() {new ContentItemBasic()};
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof (IEnumerable<ContentItemBasic>),
|
||||
val,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(val, result);
|
||||
Assert.AreEqual(1, ((IEnumerable<ContentItemBasic>)result).Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueFromResponse_From_Property()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>), "MyList");
|
||||
var val = new List<ContentItemBasic>() { new ContentItemBasic() };
|
||||
var container = new MyTestClass() {MyList = val};
|
||||
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof(MyTestClass),
|
||||
container,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(val, result);
|
||||
Assert.AreEqual(1, ((IEnumerable<ContentItemBasic>)result).Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueFromResponse_Returns_Null_Not_Found_Property()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>), "DontFind");
|
||||
var val = new List<ContentItemBasic>() { new ContentItemBasic() };
|
||||
var container = new MyTestClass() { MyList = val };
|
||||
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof(MyTestClass),
|
||||
container,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(null, result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_On_Start_Node()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>));
|
||||
var list = new List<dynamic>();
|
||||
var path = "";
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
if (i > 0 && path.EndsWith(",") == false)
|
||||
{
|
||||
path += ",";
|
||||
}
|
||||
path += i.ToInvariantString();
|
||||
list.Add(new ContentItemBasic { Id = i, Name = "Test" + i, ParentId = i, Path = path });
|
||||
}
|
||||
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(5);
|
||||
var user = userMock.Object;
|
||||
|
||||
att.FilterBasedOnStartNode(list, user);
|
||||
|
||||
Assert.AreEqual(5, list.Count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_On_Permissions()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>));
|
||||
var list = new List<dynamic>();
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
list.Add(new ContentItemBasic{Id = i, Name = "Test" + i, ParentId = -1});
|
||||
}
|
||||
var ids = list.Select(x => (int)x.Id).ToArray();
|
||||
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
//we're only assigning 3 nodes browse permissions so that is what we expect as a result
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1, new string[]{ "F" }),
|
||||
new EntityPermission(9, 2, new string[]{ "F" }),
|
||||
new EntityPermission(9, 3, new string[]{ "F" }),
|
||||
new EntityPermission(9, 4, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, ids)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
att.FilterBasedOnPermissions(list, user, userService);
|
||||
|
||||
Assert.AreEqual(3, list.Count);
|
||||
Assert.AreEqual(1, list.ElementAt(0).Id);
|
||||
Assert.AreEqual(2, list.ElementAt(1).Id);
|
||||
Assert.AreEqual(3, list.ElementAt(2).Id);
|
||||
}
|
||||
|
||||
private class MyTestClass
|
||||
{
|
||||
public IEnumerable<ContentItemBasic> MyList { get; set; }
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers.WebApiEditors
|
||||
{
|
||||
[TestFixture]
|
||||
public class FilterAllowedOutgoingContentAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void GetValueFromResponse_Already_EnumerableContent()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>));
|
||||
var val = new List<ContentItemBasic>() {new ContentItemBasic()};
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof (IEnumerable<ContentItemBasic>),
|
||||
val,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(val, result);
|
||||
Assert.AreEqual(1, ((IEnumerable<ContentItemBasic>)result).Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueFromResponse_From_Property()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>), "MyList");
|
||||
var val = new List<ContentItemBasic>() { new ContentItemBasic() };
|
||||
var container = new MyTestClass() {MyList = val};
|
||||
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof(MyTestClass),
|
||||
container,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(val, result);
|
||||
Assert.AreEqual(1, ((IEnumerable<ContentItemBasic>)result).Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueFromResponse_Returns_Null_Not_Found_Property()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>), "DontFind");
|
||||
var val = new List<ContentItemBasic>() { new ContentItemBasic() };
|
||||
var container = new MyTestClass() { MyList = val };
|
||||
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof(MyTestClass),
|
||||
container,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(null, result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_On_Start_Node()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>));
|
||||
var list = new List<dynamic>();
|
||||
var path = "";
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
if (i > 0 && path.EndsWith(",") == false)
|
||||
{
|
||||
path += ",";
|
||||
}
|
||||
path += i.ToInvariantString();
|
||||
list.Add(new ContentItemBasic { Id = i, Name = "Test" + i, ParentId = i, Path = path });
|
||||
}
|
||||
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(5);
|
||||
var user = userMock.Object;
|
||||
|
||||
att.FilterBasedOnStartNode(list, user);
|
||||
|
||||
Assert.AreEqual(5, list.Count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_On_Permissions()
|
||||
{
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>));
|
||||
var list = new List<dynamic>();
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
list.Add(new ContentItemBasic{Id = i, Name = "Test" + i, ParentId = -1});
|
||||
}
|
||||
var ids = list.Select(x => (int)x.Id).ToArray();
|
||||
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
//we're only assigning 3 nodes browse permissions so that is what we expect as a result
|
||||
var permissions = new List<EntityPermission>
|
||||
{
|
||||
new EntityPermission(9, 1, new string[]{ "F" }),
|
||||
new EntityPermission(9, 2, new string[]{ "F" }),
|
||||
new EntityPermission(9, 3, new string[]{ "F" }),
|
||||
new EntityPermission(9, 4, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, ids)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
att.FilterBasedOnPermissions(list, user, userService);
|
||||
|
||||
Assert.AreEqual(3, list.Count);
|
||||
Assert.AreEqual(1, list.ElementAt(0).Id);
|
||||
Assert.AreEqual(2, list.ElementAt(1).Id);
|
||||
Assert.AreEqual(3, list.ElementAt(2).Id);
|
||||
}
|
||||
|
||||
private class MyTestClass
|
||||
{
|
||||
public IEnumerable<ContentItemBasic> MyList { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,142 +1,142 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Http;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Umbraco.Tests.Controllers.WebApiEditors
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaControllerUnitTests
|
||||
{
|
||||
[Test]
|
||||
public void Access_Allowed_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
mediaServiceMock.Setup(x => x.GetById(1234)).Returns(media);
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, mediaService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Throws_Exception_When_No_Media_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
mediaServiceMock.Setup(x => x.GetById(0)).Returns(media);
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
|
||||
//act/assert
|
||||
Assert.Throws<HttpResponseException>(() => MediaController.CheckPermissions(new Dictionary<string, object>(), user, mediaService, 1234));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(9876);
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
mediaServiceMock.Setup(x => x.GetById(1234)).Returns(media);
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, mediaService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -21);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -21);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Http;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers.WebApiEditors
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaControllerUnitTests
|
||||
{
|
||||
[Test]
|
||||
public void Access_Allowed_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
mediaServiceMock.Setup(x => x.GetById(1234)).Returns(media);
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, mediaService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Throws_Exception_When_No_Media_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
mediaServiceMock.Setup(x => x.GetById(0)).Returns(media);
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
|
||||
//act/assert
|
||||
Assert.Throws<HttpResponseException>(() => MediaController.CheckPermissions(new Dictionary<string, object>(), user, mediaService, 1234));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(9876);
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
mediaServiceMock.Setup(x => x.GetById(1234)).Returns(media);
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, mediaService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -1);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(-1);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -21);
|
||||
|
||||
//assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaId).Returns(1234);
|
||||
var user = userMock.Object;
|
||||
|
||||
//act
|
||||
var result = MediaController.CheckPermissions(new Dictionary<string, object>(), user, null, -21);
|
||||
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using System.Web.Mvc;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.Mvc
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class HtmlHelperExtensionMethodsTests
|
||||
@@ -1,86 +1,86 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class MergeParentContextViewDataAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void Ensure_All_Ancestor_ViewData_Is_Merged()
|
||||
{
|
||||
var http = new FakeHttpContextFactory("http://localhost");
|
||||
|
||||
//setup an heirarchy
|
||||
var rootViewCtx = new ViewContext {Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary()};
|
||||
var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() };
|
||||
parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx);
|
||||
var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) {RouteData = new RouteData()};
|
||||
controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx);
|
||||
|
||||
//set up the view data
|
||||
controllerCtx.Controller.ViewData["Test1"] = "Test1";
|
||||
controllerCtx.Controller.ViewData["Test2"] = "Test2";
|
||||
controllerCtx.Controller.ViewData["Test3"] = "Test3";
|
||||
parentViewCtx.ViewData["Test4"] = "Test4";
|
||||
parentViewCtx.ViewData["Test5"] = "Test5";
|
||||
parentViewCtx.ViewData["Test6"] = "Test6";
|
||||
rootViewCtx.ViewData["Test7"] = "Test7";
|
||||
rootViewCtx.ViewData["Test8"] = "Test8";
|
||||
rootViewCtx.ViewData["Test9"] = "Test9";
|
||||
|
||||
var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) {RouteData = controllerCtx.RouteData};
|
||||
var att = new MergeParentContextViewDataAttribute();
|
||||
|
||||
Assert.IsTrue(filter.IsChildAction);
|
||||
att.OnResultExecuting(filter);
|
||||
|
||||
Assert.AreEqual(9, controllerCtx.Controller.ViewData.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_All_Ancestor_ViewData_Is_Merged_Without_Data_Loss()
|
||||
{
|
||||
var http = new FakeHttpContextFactory("http://localhost");
|
||||
|
||||
//setup an heirarchy
|
||||
var rootViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary() };
|
||||
var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() };
|
||||
parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx);
|
||||
var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) { RouteData = new RouteData() };
|
||||
controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx);
|
||||
|
||||
//set up the view data with overlapping keys
|
||||
controllerCtx.Controller.ViewData["Test1"] = "Test1";
|
||||
controllerCtx.Controller.ViewData["Test2"] = "Test2";
|
||||
controllerCtx.Controller.ViewData["Test3"] = "Test3";
|
||||
parentViewCtx.ViewData["Test2"] = "Test4";
|
||||
parentViewCtx.ViewData["Test3"] = "Test5";
|
||||
parentViewCtx.ViewData["Test4"] = "Test6";
|
||||
rootViewCtx.ViewData["Test3"] = "Test7";
|
||||
rootViewCtx.ViewData["Test4"] = "Test8";
|
||||
rootViewCtx.ViewData["Test5"] = "Test9";
|
||||
|
||||
var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) { RouteData = controllerCtx.RouteData };
|
||||
var att = new MergeParentContextViewDataAttribute();
|
||||
|
||||
Assert.IsTrue(filter.IsChildAction);
|
||||
att.OnResultExecuting(filter);
|
||||
|
||||
Assert.AreEqual(5, controllerCtx.Controller.ViewData.Count);
|
||||
Assert.AreEqual("Test1", controllerCtx.Controller.ViewData["Test1"]);
|
||||
Assert.AreEqual("Test2", controllerCtx.Controller.ViewData["Test2"]);
|
||||
Assert.AreEqual("Test3", controllerCtx.Controller.ViewData["Test3"]);
|
||||
Assert.AreEqual("Test6", controllerCtx.Controller.ViewData["Test4"]);
|
||||
Assert.AreEqual("Test9", controllerCtx.Controller.ViewData["Test5"]);
|
||||
}
|
||||
|
||||
internal class MyController : Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class MergeParentContextViewDataAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void Ensure_All_Ancestor_ViewData_Is_Merged()
|
||||
{
|
||||
var http = new FakeHttpContextFactory("http://localhost");
|
||||
|
||||
//setup an heirarchy
|
||||
var rootViewCtx = new ViewContext {Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary()};
|
||||
var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() };
|
||||
parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx);
|
||||
var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) {RouteData = new RouteData()};
|
||||
controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx);
|
||||
|
||||
//set up the view data
|
||||
controllerCtx.Controller.ViewData["Test1"] = "Test1";
|
||||
controllerCtx.Controller.ViewData["Test2"] = "Test2";
|
||||
controllerCtx.Controller.ViewData["Test3"] = "Test3";
|
||||
parentViewCtx.ViewData["Test4"] = "Test4";
|
||||
parentViewCtx.ViewData["Test5"] = "Test5";
|
||||
parentViewCtx.ViewData["Test6"] = "Test6";
|
||||
rootViewCtx.ViewData["Test7"] = "Test7";
|
||||
rootViewCtx.ViewData["Test8"] = "Test8";
|
||||
rootViewCtx.ViewData["Test9"] = "Test9";
|
||||
|
||||
var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) {RouteData = controllerCtx.RouteData};
|
||||
var att = new MergeParentContextViewDataAttribute();
|
||||
|
||||
Assert.IsTrue(filter.IsChildAction);
|
||||
att.OnResultExecuting(filter);
|
||||
|
||||
Assert.AreEqual(9, controllerCtx.Controller.ViewData.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_All_Ancestor_ViewData_Is_Merged_Without_Data_Loss()
|
||||
{
|
||||
var http = new FakeHttpContextFactory("http://localhost");
|
||||
|
||||
//setup an heirarchy
|
||||
var rootViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary() };
|
||||
var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() };
|
||||
parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx);
|
||||
var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) { RouteData = new RouteData() };
|
||||
controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx);
|
||||
|
||||
//set up the view data with overlapping keys
|
||||
controllerCtx.Controller.ViewData["Test1"] = "Test1";
|
||||
controllerCtx.Controller.ViewData["Test2"] = "Test2";
|
||||
controllerCtx.Controller.ViewData["Test3"] = "Test3";
|
||||
parentViewCtx.ViewData["Test2"] = "Test4";
|
||||
parentViewCtx.ViewData["Test3"] = "Test5";
|
||||
parentViewCtx.ViewData["Test4"] = "Test6";
|
||||
rootViewCtx.ViewData["Test3"] = "Test7";
|
||||
rootViewCtx.ViewData["Test4"] = "Test8";
|
||||
rootViewCtx.ViewData["Test5"] = "Test9";
|
||||
|
||||
var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) { RouteData = controllerCtx.RouteData };
|
||||
var att = new MergeParentContextViewDataAttribute();
|
||||
|
||||
Assert.IsTrue(filter.IsChildAction);
|
||||
att.OnResultExecuting(filter);
|
||||
|
||||
Assert.AreEqual(5, controllerCtx.Controller.ViewData.Count);
|
||||
Assert.AreEqual("Test1", controllerCtx.Controller.ViewData["Test1"]);
|
||||
Assert.AreEqual("Test2", controllerCtx.Controller.ViewData["Test2"]);
|
||||
Assert.AreEqual("Test3", controllerCtx.Controller.ViewData["Test3"]);
|
||||
Assert.AreEqual("Test6", controllerCtx.Controller.ViewData["Test4"]);
|
||||
Assert.AreEqual("Test9", controllerCtx.Controller.ViewData["Test5"]);
|
||||
}
|
||||
|
||||
internal class MyController : Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Mvc
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class RenderIndexActionSelectorAttributeTests
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@@ -12,7 +11,6 @@ using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Profiling;
|
||||
@@ -20,11 +18,10 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Mvc
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class SurfaceControllerTests
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class ViewDataDictionaryExtensionTests
|
||||
{
|
||||
[Test]
|
||||
public void Merge_View_Data()
|
||||
{
|
||||
var source = new ViewDataDictionary();
|
||||
var dest = new ViewDataDictionary();
|
||||
source.Add("Test1", "Test1");
|
||||
dest.Add("Test2", "Test2");
|
||||
|
||||
dest.MergeViewDataFrom(source);
|
||||
|
||||
Assert.AreEqual(2, dest.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Merge_View_Data_Retains_Destination_Values()
|
||||
{
|
||||
var source = new ViewDataDictionary();
|
||||
var dest = new ViewDataDictionary();
|
||||
source.Add("Test1", "Test1");
|
||||
dest.Add("Test1", "MyValue");
|
||||
dest.Add("Test2", "Test2");
|
||||
|
||||
dest.MergeViewDataFrom(source);
|
||||
|
||||
Assert.AreEqual(2, dest.Count);
|
||||
Assert.AreEqual("MyValue", dest["Test1"]);
|
||||
Assert.AreEqual("Test2", dest["Test2"]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
using System.Web.Mvc;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class ViewDataDictionaryExtensionTests
|
||||
{
|
||||
[Test]
|
||||
public void Merge_View_Data()
|
||||
{
|
||||
var source = new ViewDataDictionary();
|
||||
var dest = new ViewDataDictionary();
|
||||
source.Add("Test1", "Test1");
|
||||
dest.Add("Test2", "Test2");
|
||||
|
||||
dest.MergeViewDataFrom(source);
|
||||
|
||||
Assert.AreEqual(2, dest.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Merge_View_Data_Retains_Destination_Values()
|
||||
{
|
||||
var source = new ViewDataDictionary();
|
||||
var dest = new ViewDataDictionary();
|
||||
source.Add("Test1", "Test1");
|
||||
dest.Add("Test1", "MyValue");
|
||||
dest.Add("Test2", "Test2");
|
||||
|
||||
dest.MergeViewDataFrom(source);
|
||||
|
||||
Assert.AreEqual(2, dest.Count);
|
||||
Assert.AreEqual("MyValue", dest["Test1"]);
|
||||
Assert.AreEqual("Test2", dest["Test2"]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user