Revert "Temp8 tinymce"
This commit is contained in:
@@ -27,9 +27,9 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
string cookieToken, headerToken;
|
||||
AngularAntiForgeryHelper.GetTokens(out cookieToken, out headerToken);
|
||||
|
||||
Assert.AreEqual(true, AngularAntiForgeryHelper.ValidateTokens(cookieToken, headerToken));
|
||||
Assert.AreEqual(true, AngularAntiForgeryHelper.ValidateTokens(cookieToken, headerToken));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -16,68 +16,61 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
{
|
||||
//create 3 tabs with 3 properties each
|
||||
var tabs = new List<Tab<ContentPropertyDisplay>>();
|
||||
for (var tabIndex = 0; tabIndex < 3; tabIndex++)
|
||||
for (var tabIndex = 0; tabIndex < 3; tabIndex ++)
|
||||
{
|
||||
var props = new List<ContentPropertyDisplay>();
|
||||
for (var propertyIndex = 0; propertyIndex < 3; propertyIndex++)
|
||||
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
|
||||
});
|
||||
{
|
||||
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
|
||||
});
|
||||
{
|
||||
Alias = "Tab" + tabIndex,
|
||||
Label = "Tab" + tabIndex,
|
||||
Properties = props
|
||||
});
|
||||
}
|
||||
|
||||
var displayModel = new ContentItemDisplay
|
||||
{
|
||||
Id = 1234,
|
||||
Variants = new List<ContentVariantDisplay>
|
||||
{
|
||||
new ContentVariantDisplay
|
||||
{
|
||||
Name = "Test",
|
||||
Tabs = tabs
|
||||
}
|
||||
}
|
||||
};
|
||||
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["variants"][0]["name"].ToString());
|
||||
var jsonTabs = jObject["variants"][0]["tabs"];
|
||||
Assert.AreEqual(3, jsonTabs.Count());
|
||||
for (var tab = 0; tab < jsonTabs.Count(); tab++)
|
||||
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, jsonTabs[tab]["alias"].ToString());
|
||||
Assert.AreEqual("Tab" + tab, jsonTabs[tab]["label"].ToString());
|
||||
Assert.AreEqual(3, jsonTabs[tab]["properties"].Count());
|
||||
for (var prop = 0; prop < jsonTabs[tab]["properties"].Count(); prop++)
|
||||
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, jsonTabs[tab]["properties"][prop]["alias"].ToString());
|
||||
Assert.AreEqual("Property " + prop, jsonTabs[tab]["properties"][prop]["label"].ToString());
|
||||
Assert.AreEqual(prop, jsonTabs[tab]["properties"][prop]["id"].Value<int>());
|
||||
Assert.AreEqual("value" + prop, jsonTabs[tab]["properties"][prop]["value"].ToString());
|
||||
Assert.AreEqual("{\"" + prop + "\":\"value\"}", jsonTabs[tab]["properties"][prop]["config"].ToString(Formatting.None));
|
||||
Assert.AreEqual("Description " + prop, jsonTabs[tab]["properties"][prop]["description"].ToString());
|
||||
Assert.AreEqual(false, jsonTabs[tab]["properties"][prop]["hideLabel"].Value<bool>());
|
||||
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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,17 +19,15 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
[Test]
|
||||
public void Parse_Main()
|
||||
{
|
||||
var result = JsInitialization.WriteScript("[World]", "Hello", "Blah");
|
||||
var result = JsInitialization.ParseMain(new[] {"[World]", "Hello" });
|
||||
|
||||
Assert.AreEqual(@"LazyLoad.js([World], function () {
|
||||
//we need to set the legacy UmbClientMgr path
|
||||
if ((typeof UmbClientMgr) !== ""undefined"") {
|
||||
UmbClientMgr.setUmbracoPath('Hello');
|
||||
}
|
||||
UmbClientMgr.setUmbracoPath('Hello');
|
||||
|
||||
jQuery(document).ready(function () {
|
||||
|
||||
angular.bootstrap(document, ['Blah']);
|
||||
angular.bootstrap(document, ['umbraco']);
|
||||
|
||||
});
|
||||
});".StripWhitespace(), result.StripWhitespace());
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
[TestFixture]
|
||||
public class ServerVariablesParserTests
|
||||
{
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void Parse()
|
||||
@@ -31,4 +31,4 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
} ;".StripWhitespace()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,20 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
};
|
||||
|
||||
|
||||
[TestCaseSource("TestLegacyJsActionPaths")]
|
||||
public void Separates_Legacy_JsActions_By_Block_Or_Url(object[] jsActions)
|
||||
{
|
||||
var jsBlocks =
|
||||
BackOfficeController.GetLegacyActionJsForActions(BackOfficeController.LegacyJsActionType.JsBlock,
|
||||
jsActions.Select(n => n.ToString()));
|
||||
|
||||
var jsUrls =
|
||||
BackOfficeController.GetLegacyActionJsForActions(BackOfficeController.LegacyJsActionType.JsUrl,
|
||||
jsActions.Select(n => n.ToString()));
|
||||
|
||||
Assert.That(jsBlocks.Count() == 4);
|
||||
Assert.That(jsUrls.Count() == 3);
|
||||
Assert.That(jsUrls.Last().StartsWith("~/") == false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,411 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Web.Http;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.ControllerTesting;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using System;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.Trees;
|
||||
using System.Globalization;
|
||||
using Umbraco.Web.Actions;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.None)]
|
||||
public class ContentControllerTests : TestWithDatabaseBase
|
||||
{
|
||||
protected override void ComposeApplication(bool withApplication)
|
||||
{
|
||||
base.ComposeApplication(withApplication);
|
||||
|
||||
//Replace with mockable services:
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
userServiceMock.Setup(service => service.GetUserById(It.IsAny<int>()))
|
||||
.Returns((int id) => id == 1234 ? new User(1234, "Test", "test@test.com", "test@test.com", "", new List<IReadOnlyUserGroup>(), new int[0], new int[0]) : null);
|
||||
userServiceMock.Setup(x => x.GetProfileById(It.IsAny<int>()))
|
||||
.Returns((int id) => id == 1234 ? new User(1234, "Test", "test@test.com", "test@test.com", "", new List<IReadOnlyUserGroup>(), new int[0], new int[0]) : null);
|
||||
userServiceMock.Setup(service => service.GetPermissionsForPath(It.IsAny<IUser>(), It.IsAny<string>()))
|
||||
.Returns(new EntityPermissionSet(123, new EntityPermissionCollection(new[]
|
||||
{
|
||||
new EntityPermission(0, 123, new[]
|
||||
{
|
||||
ActionBrowse.ActionLetter.ToString(),
|
||||
ActionUpdate.ActionLetter.ToString(),
|
||||
ActionPublish.ActionLetter.ToString(),
|
||||
ActionNew.ActionLetter.ToString()
|
||||
}),
|
||||
})));
|
||||
|
||||
var entityService = new Mock<IEntityService>();
|
||||
entityService.Setup(x => x.GetAllPaths(UmbracoObjectTypes.Document, It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) => ids.Select(x => new TreeEntityPath { Path = $"-1,{x}", Id = x }).ToList());
|
||||
|
||||
var dataTypeService = new Mock<IDataTypeService>();
|
||||
dataTypeService.Setup(service => service.GetDataType(It.IsAny<int>()))
|
||||
.Returns(Mock.Of<IDataType>(type => type.Id == 9876 && type.Name == "text"));
|
||||
dataTypeService.Setup(service => service.GetDataType(-87)) //the RTE
|
||||
.Returns(Mock.Of<IDataType>(type => type.Id == -87 && type.Name == "Rich text" && type.Configuration == new RichTextConfiguration()));
|
||||
|
||||
var langService = new Mock<ILocalizationService>();
|
||||
langService.Setup(x => x.GetAllLanguages()).Returns(new[] {
|
||||
Mock.Of<ILanguage>(x => x.IsoCode == "en-US"),
|
||||
Mock.Of<ILanguage>(x => x.IsoCode == "es-ES"),
|
||||
Mock.Of<ILanguage>(x => x.IsoCode == "fr-FR")
|
||||
});
|
||||
|
||||
var textService = new Mock<ILocalizedTextService>();
|
||||
textService.Setup(x => x.Localize(It.IsAny<string>(), It.IsAny<CultureInfo>(), It.IsAny<IDictionary<string, string>>())).Returns("");
|
||||
|
||||
Container.RegisterSingleton(f => Mock.Of<IContentService>());
|
||||
Container.RegisterSingleton(f => userServiceMock.Object);
|
||||
Container.RegisterSingleton(f => entityService.Object);
|
||||
Container.RegisterSingleton(f => dataTypeService.Object);
|
||||
Container.RegisterSingleton(f => langService.Object);
|
||||
Container.RegisterSingleton(f => textService.Object);
|
||||
Container.RegisterSingleton(f => Mock.Of<ICultureDictionaryFactory>());
|
||||
Container.RegisterSingleton(f => new UmbracoApiControllerTypeCollection(new[] { typeof(ContentTreeController) }));
|
||||
}
|
||||
|
||||
private MultipartFormDataContent GetMultiPartRequestContent(string json)
|
||||
{
|
||||
var multiPartBoundary = "----WebKitFormBoundary123456789";
|
||||
return new MultipartFormDataContent(multiPartBoundary)
|
||||
{
|
||||
new StringContent(json)
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
||||
{
|
||||
Name = "contentItem"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private IContent GetMockedContent()
|
||||
{
|
||||
var content = MockedContent.CreateSimpleContent(MockedContentTypes.CreateSimpleContentType());
|
||||
content.Id = 123;
|
||||
content.Path = "-1,123";
|
||||
//ensure things have ids
|
||||
var ids = 888;
|
||||
foreach (var g in content.PropertyGroups)
|
||||
{
|
||||
g.Id = ids;
|
||||
ids++;
|
||||
}
|
||||
foreach (var p in content.PropertyTypes)
|
||||
{
|
||||
p.Id = ids;
|
||||
ids++;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private const string PublishJsonInvariant = @"{
|
||||
""id"": 123,
|
||||
""contentTypeAlias"": ""page"",
|
||||
""parentId"": -1,
|
||||
""action"": ""save"",
|
||||
""variants"": [
|
||||
{
|
||||
""name"": ""asdf"",
|
||||
""properties"": [
|
||||
{
|
||||
""id"": 1,
|
||||
""alias"": ""title"",
|
||||
""value"": ""asdf""
|
||||
}
|
||||
],
|
||||
""culture"": null,
|
||||
""save"": true,
|
||||
""publish"": true
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
private const string PublishJsonVariant = @"{
|
||||
""id"": 123,
|
||||
""contentTypeAlias"": ""page"",
|
||||
""parentId"": -1,
|
||||
""action"": ""save"",
|
||||
""variants"": [
|
||||
{
|
||||
""name"": ""asdf"",
|
||||
""properties"": [
|
||||
{
|
||||
""id"": 1,
|
||||
""alias"": ""title"",
|
||||
""value"": ""asdf""
|
||||
}
|
||||
],
|
||||
""culture"": ""en-US"",
|
||||
""save"": true,
|
||||
""publish"": true
|
||||
},
|
||||
{
|
||||
""name"": ""asdf"",
|
||||
""properties"": [
|
||||
{
|
||||
""id"": 1,
|
||||
""alias"": ""title"",
|
||||
""value"": ""asdf""
|
||||
}
|
||||
],
|
||||
""culture"": ""fr-FR"",
|
||||
""save"": true,
|
||||
""publish"": true
|
||||
},
|
||||
{
|
||||
""name"": ""asdf"",
|
||||
""properties"": [
|
||||
{
|
||||
""id"": 1,
|
||||
""alias"": ""title"",
|
||||
""value"": ""asdf""
|
||||
}
|
||||
],
|
||||
""culture"": ""es-ES"",
|
||||
""save"": true,
|
||||
""publish"": true
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
/// <summary>
|
||||
/// Returns 404 if the content wasn't found based on the ID specified
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Existing_Content()
|
||||
{
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
{
|
||||
var contentServiceMock = Mock.Get(Current.Services.ContentService);
|
||||
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => null); //do not find it
|
||||
|
||||
var publishedSnapshot = Mock.Of<IPublishedSnapshotService>();
|
||||
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
var usersController = new ContentController(publishedSnapshot, propertyEditorCollection);
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Content", "PostSave", HttpMethod.Post,
|
||||
content: GetMultiPartRequestContent(PublishJsonInvariant),
|
||||
mediaTypeHeader: new MediaTypeWithQualityHeaderValue("multipart/form-data"),
|
||||
assertOkResponse: false);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, response.Item1.StatusCode);
|
||||
Assert.AreEqual(")]}',\n{\"Message\":\"content was not found\"}", response.Item1.Content.ReadAsStringAsync().Result);
|
||||
|
||||
//var obj = JsonConvert.DeserializeObject<PagedResult<UserDisplay>>(response.Item2);
|
||||
//Assert.AreEqual(0, obj.TotalItems);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostSave_Validate_At_Least_One_Variant_Flagged_For_Saving()
|
||||
{
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
{
|
||||
var contentServiceMock = Mock.Get(Current.Services.ContentService);
|
||||
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => GetMockedContent());
|
||||
|
||||
var publishedSnapshot = Mock.Of<IPublishedSnapshotService>();
|
||||
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
var usersController = new ContentController(publishedSnapshot, propertyEditorCollection);
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
var json = JsonConvert.DeserializeObject<JObject>(PublishJsonInvariant);
|
||||
//remove all save flaggs
|
||||
((JArray)json["variants"])[0]["save"] = false;
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Content", "PostSave", HttpMethod.Post,
|
||||
content: GetMultiPartRequestContent(JsonConvert.SerializeObject(json)),
|
||||
mediaTypeHeader: new MediaTypeWithQualityHeaderValue("multipart/form-data"),
|
||||
assertOkResponse: false);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, response.Item1.StatusCode);
|
||||
Assert.AreEqual(")]}',\n{\"Message\":\"No variants flagged for saving\"}", response.Item1.Content.ReadAsStringAsync().Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns 404 if any of the posted properties dont actually exist
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Properties_Exist()
|
||||
{
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
{
|
||||
var contentServiceMock = Mock.Get(Current.Services.ContentService);
|
||||
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => GetMockedContent());
|
||||
|
||||
var publishedSnapshot = Mock.Of<IPublishedSnapshotService>();
|
||||
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
var usersController = new ContentController(publishedSnapshot, propertyEditorCollection);
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
var json = JsonConvert.DeserializeObject<JObject>(PublishJsonInvariant);
|
||||
//add a non-existent property to a variant being saved
|
||||
var variantProps = (JArray)json["variants"].ElementAt(0)["properties"];
|
||||
variantProps.Add(JObject.FromObject(new
|
||||
{
|
||||
id = 2,
|
||||
alias = "doesntExist",
|
||||
value = "hello"
|
||||
}));
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Content", "PostSave", HttpMethod.Post,
|
||||
content: GetMultiPartRequestContent(JsonConvert.SerializeObject(json)),
|
||||
mediaTypeHeader: new MediaTypeWithQualityHeaderValue("multipart/form-data"),
|
||||
assertOkResponse: false);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, response.Item1.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostSave_Simple_Invariant()
|
||||
{
|
||||
var content = GetMockedContent();
|
||||
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
{
|
||||
|
||||
var contentServiceMock = Mock.Get(Current.Services.ContentService);
|
||||
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => content);
|
||||
contentServiceMock.Setup(x => x.Save(It.IsAny<IContent>(), It.IsAny<int>(), It.IsAny<bool>()))
|
||||
.Returns(new OperationResult(OperationResultType.Success, new Core.Events.EventMessages())); //success
|
||||
|
||||
var publishedSnapshot = Mock.Of<IPublishedSnapshotService>();
|
||||
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
var usersController = new ContentController(publishedSnapshot, propertyEditorCollection);
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Content", "PostSave", HttpMethod.Post,
|
||||
content: GetMultiPartRequestContent(PublishJsonInvariant),
|
||||
mediaTypeHeader: new MediaTypeWithQualityHeaderValue("multipart/form-data"),
|
||||
assertOkResponse: false);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.Item1.StatusCode);
|
||||
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(response.Item2);
|
||||
Assert.AreEqual(1, display.Variants.Count());
|
||||
Assert.AreEqual(content.PropertyGroups.Count(), display.Variants.ElementAt(0).Tabs.Count());
|
||||
Assert.AreEqual(content.PropertyTypes.Count(), display.Variants.ElementAt(0).Tabs.ElementAt(0).Properties.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Empty_Name()
|
||||
{
|
||||
var content = GetMockedContent();
|
||||
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
{
|
||||
|
||||
var contentServiceMock = Mock.Get(Current.Services.ContentService);
|
||||
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => content);
|
||||
contentServiceMock.Setup(x => x.Save(It.IsAny<IContent>(), It.IsAny<int>(), It.IsAny<bool>()))
|
||||
.Returns(new OperationResult(OperationResultType.Success, new Core.Events.EventMessages())); //success
|
||||
|
||||
var publishedSnapshot = Mock.Of<IPublishedSnapshotService>();
|
||||
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
var usersController = new ContentController(publishedSnapshot, propertyEditorCollection);
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
//clear out the name
|
||||
var json = JsonConvert.DeserializeObject<JObject>(PublishJsonInvariant);
|
||||
json["variants"].ElementAt(0)["name"] = null;
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Content", "PostSave", HttpMethod.Post,
|
||||
content: GetMultiPartRequestContent(JsonConvert.SerializeObject(json)),
|
||||
mediaTypeHeader: new MediaTypeWithQualityHeaderValue("multipart/form-data"),
|
||||
assertOkResponse: false);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, response.Item1.StatusCode);
|
||||
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(response.Item2);
|
||||
Assert.AreEqual(1, display.Errors.Count());
|
||||
Assert.IsTrue(display.Errors.ContainsKey("Variants[0].Name"));
|
||||
//ModelState":{"Variants[0].Name":["Required"]}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Variants_Empty_Name()
|
||||
{
|
||||
var content = GetMockedContent();
|
||||
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
{
|
||||
|
||||
var contentServiceMock = Mock.Get(Current.Services.ContentService);
|
||||
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => content);
|
||||
contentServiceMock.Setup(x => x.Save(It.IsAny<IContent>(), It.IsAny<int>(), It.IsAny<bool>()))
|
||||
.Returns(new OperationResult(OperationResultType.Success, new Core.Events.EventMessages())); //success
|
||||
|
||||
var publishedSnapshot = Mock.Of<IPublishedSnapshotService>();
|
||||
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
var usersController = new ContentController(publishedSnapshot, propertyEditorCollection);
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
//clear out one of the names
|
||||
var json = JsonConvert.DeserializeObject<JObject>(PublishJsonVariant);
|
||||
json["variants"].ElementAt(0)["name"] = null;
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Content", "PostSave", HttpMethod.Post,
|
||||
content: GetMultiPartRequestContent(JsonConvert.SerializeObject(json)),
|
||||
mediaTypeHeader: new MediaTypeWithQualityHeaderValue("multipart/form-data"),
|
||||
assertOkResponse: false);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, response.Item1.StatusCode);
|
||||
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(response.Item2);
|
||||
Assert.AreEqual(2, display.Errors.Count());
|
||||
Assert.IsTrue(display.Errors.ContainsKey("Variants[0].Name"));
|
||||
Assert.IsTrue(display.Errors.ContainsKey("_content_variant_en-US_"));
|
||||
}
|
||||
|
||||
//TODO: There are SOOOOO many more tests we should write - a lot of them to do with validation
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,8 @@ using System.Web.Http;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
@@ -34,14 +33,14 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var userService = userServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(1234, user, userService, contentService, entityService, out var foundContent);
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, 1234);
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Granted, result);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Content_Found()
|
||||
public void Throws_Exception_When_No_Content_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
@@ -53,7 +52,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(0)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection();
|
||||
var permissionSet = new EntityPermissionSet(1234, permissions);
|
||||
userServiceMock.Setup(x => x.GetPermissionsForPath(user, "-1,1234,5678")).Returns(permissionSet);
|
||||
@@ -61,11 +60,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(1234, user, userService, contentService, entityService, out var foundContent, new[] { 'F' });
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.NotFound, result);
|
||||
//act/assert
|
||||
Assert.Throws<HttpResponseException>(() => ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, 1234, new[] { 'F' }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -74,7 +70,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 9876 });
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[]{ 9876 });
|
||||
var user = userMock.Object;
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
@@ -82,21 +78,21 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection();
|
||||
var permissionSet = new EntityPermissionSet(1234, permissions);
|
||||
userServiceMock.Setup(x => x.GetPermissionsForPath(user, "-1,1234")).Returns(permissionSet);
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 9876 && entity.Path == "-1,9876") });
|
||||
.Returns(new[] { Mock.Of<EntityPath>(entity => entity.Id == 9876 && entity.Path == "-1,9876") });
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(1234, user, userService, contentService, entityService, out var foundContent, new[] { 'F' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -112,7 +108,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
contentServiceMock.Setup(x => x.GetById(1234)).Returns(content);
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection
|
||||
{
|
||||
new EntityPermission(9876, 1234, new string[]{ "A", "B", "C" })
|
||||
@@ -124,10 +120,10 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(1234, user, userService, contentService, entityService, out var foundContent, new[] { 'F' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -156,10 +152,10 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(1234, user, userService, contentService, entityService, out var foundContent, new[] { 'F' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, 1234, new[] { 'F'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Granted, result);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -168,7 +164,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
userMock.Setup(u => u.Groups).Returns(new[] {new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>())});
|
||||
var user = userMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
@@ -178,10 +174,10 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-1, user, userService, contentService, entityService, out var foundContent);
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -1);
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Granted, result);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -200,10 +196,10 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-20, user, userService, contentService, entityService, out var foundContent);
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -20);
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Granted, result);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -212,7 +208,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 1234 });
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new []{ 1234 });
|
||||
var user = userMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
@@ -220,14 +216,14 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
.Returns(new[] { Mock.Of<EntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-20, user, userService, contentService, entityService, out var foundContent);
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -20);
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -236,7 +232,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 1234 });
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new []{ 1234 });
|
||||
var user = userMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
@@ -244,14 +240,14 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
.Returns(new[] { Mock.Of<EntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-1, user, userService, contentService, entityService, out var foundContent);
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -1);
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -275,13 +271,13 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-1, user, userService, contentService, entityService, out var foundContent, new[] { 'A' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -1, new[] { 'A'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Granted, result);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -303,13 +299,13 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
var entityService = entityServiceMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var contentService = contentServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-1, user, userService, contentService, entityService, out var foundContent, new[] { 'B' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -1, new[] { 'B'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -327,19 +323,19 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
new EntityPermission(9876, 1234, new string[]{ "A" })
|
||||
};
|
||||
var permissionSet = new EntityPermissionSet(-20, permissions);
|
||||
|
||||
|
||||
userServiceMock.Setup(x => x.GetPermissionsForPath(user, "-20")).Returns(permissionSet);
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
var entityService = entityServiceMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var contentService = contentServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-20, user, userService, contentService, entityService, out var foundContent, new[] { 'A' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -20, new[] { 'A'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Granted, result);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -361,14 +357,15 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
var entityService = entityServiceMock.Object;
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var contentService = contentServiceMock.Object;
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-20, user, userService, contentService, entityService, out var foundContent, new[] { 'B' });
|
||||
var result = ContentController.CheckPermissions(new Dictionary<string, object>(), user, userService, contentService, entityService, -20, new[] { 'B'});
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//NOTE: The below self hosted stuff does work so need to get some tests written. Some are not possible atm because
|
||||
@@ -427,7 +424,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
|
||||
// var result = await client.SendAsync(request);
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -30,8 +30,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var val = new List<ContentItemBasic>() {new ContentItemBasic()};
|
||||
var result = att.GetValueFromResponse(
|
||||
new ObjectContent(typeof (IEnumerable<ContentItemBasic>),
|
||||
val,
|
||||
new JsonMediaTypeFormatter(),
|
||||
val,
|
||||
new JsonMediaTypeFormatter(),
|
||||
new MediaTypeHeaderValue("html/text")));
|
||||
|
||||
Assert.AreEqual(val, result);
|
||||
@@ -93,7 +93,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 5 && entity.Path == "-1,5") });
|
||||
.Returns(new[] { Mock.Of<EntityPath>(entity => entity.Id == 5 && entity.Path == "-1,5") });
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable<ContentItemBasic>), userService, entityService);
|
||||
@@ -108,23 +108,23 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
path += i.ToInvariantString();
|
||||
list.Add(new ContentItemBasic { Id = i, Name = "Test" + i, ParentId = i, Path = path });
|
||||
}
|
||||
|
||||
|
||||
att.FilterBasedOnStartNode(list, user);
|
||||
|
||||
Assert.AreEqual(5, list.Count);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_On_Permissions()
|
||||
{
|
||||
{
|
||||
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.StartContentIds).Returns(new int[0]);
|
||||
@@ -133,12 +133,12 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
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 EntityPermissionCollection
|
||||
{
|
||||
new EntityPermission(9876, 1, new string[]{ "F" }),
|
||||
new EntityPermission(9876, 2, new string[]{ "F" }),
|
||||
new EntityPermission(9876, 3, new string[]{ "F" }),
|
||||
new EntityPermission(9876, 4, new string[]{ "A" })
|
||||
};
|
||||
{
|
||||
new EntityPermission(9876, 1, new string[]{ "F" }),
|
||||
new EntityPermission(9876, 2, new string[]{ "F" }),
|
||||
new EntityPermission(9876, 3, new string[]{ "F" }),
|
||||
new EntityPermission(9876, 4, new string[]{ "A" })
|
||||
};
|
||||
userServiceMock.Setup(x => x.GetPermissions(user, ids)).Returns(permissions);
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
@@ -152,10 +152,10 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Assert.AreEqual(2, list.ElementAt(1).Id);
|
||||
Assert.AreEqual(3, list.ElementAt(2).Id);
|
||||
}
|
||||
|
||||
|
||||
private class MyTestClass
|
||||
{
|
||||
public IEnumerable<ContentItemBasic> MyList { get; set; }
|
||||
public IEnumerable<ContentItemBasic> MyList { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.Web.Http;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[] { 9876 });
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[]{ 9876 });
|
||||
var user = userMock.Object;
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 9876 && entity.Path == "-1,9876") });
|
||||
.Returns(new[] {Mock.Of<EntityPath>(entity => entity.Id == 9876 && entity.Path == "-1,9876")});
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
@@ -109,13 +109,13 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[] { 1234 });
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[]{ 1234 });
|
||||
var user = userMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
.Returns(new[] { Mock.Of<EntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
@@ -151,13 +151,13 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//arrange
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[] { 1234 });
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[]{ 1234 });
|
||||
var user = userMock.Object;
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns(new[] { Mock.Of<TreeEntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
.Returns(new[] { Mock.Of<EntityPath>(entity => entity.Id == 1234 && entity.Path == "-1,1234") });
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
//act
|
||||
@@ -167,4 +167,4 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,86 +6,82 @@ using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
[TestFixture]
|
||||
public class PluginControllerAreaTests : BaseWebTest
|
||||
{
|
||||
[TestFixture]
|
||||
public class PluginControllerAreaTests : BaseWebTest
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Ensure_Same_Area1()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new PluginControllerArea(new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin2Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin3Controller)) //not same area
|
||||
}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Same_Area1()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new PluginControllerArea(TestObjects.GetGlobalSettings(),
|
||||
new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin2Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin3Controller)) //not same area
|
||||
}));
|
||||
}
|
||||
[Test]
|
||||
public void Ensure_Same_Area3()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new PluginControllerArea(new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin2Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin4Controller)) //no area assigned
|
||||
}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Same_Area3()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new PluginControllerArea(TestObjects.GetGlobalSettings(),
|
||||
new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin2Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin4Controller)) //no area assigned
|
||||
}));
|
||||
}
|
||||
[Test]
|
||||
public void Ensure_Same_Area2()
|
||||
{
|
||||
var area = new PluginControllerArea(new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin2Controller))
|
||||
});
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Same_Area2()
|
||||
{
|
||||
var area = new PluginControllerArea(TestObjects.GetGlobalSettings(),
|
||||
new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
PluginController.GetMetadata(typeof(Plugin2Controller))
|
||||
});
|
||||
Assert.Pass();
|
||||
}
|
||||
#region Test classes
|
||||
|
||||
#region Test classes
|
||||
[PluginController("Area1")]
|
||||
public class Plugin1Controller : PluginController
|
||||
{
|
||||
public Plugin1Controller(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[PluginController("Area1")]
|
||||
public class Plugin1Controller : PluginController
|
||||
{
|
||||
public Plugin1Controller(UmbracoContext umbracoContext)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
[PluginController("Area1")]
|
||||
public class Plugin2Controller : PluginController
|
||||
{
|
||||
public Plugin2Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[PluginController("Area1")]
|
||||
public class Plugin2Controller : PluginController
|
||||
{
|
||||
public Plugin2Controller(UmbracoContext umbracoContext)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
[PluginController("Area2")]
|
||||
public class Plugin3Controller : PluginController
|
||||
{
|
||||
public Plugin3Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[PluginController("Area2")]
|
||||
public class Plugin3Controller : PluginController
|
||||
{
|
||||
public Plugin3Controller(UmbracoContext umbracoContext)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
public class Plugin4Controller : PluginController
|
||||
{
|
||||
public Plugin4Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class Plugin4Controller : PluginController
|
||||
{
|
||||
public Plugin4Controller(UmbracoContext umbracoContext)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Editors;
|
||||
@@ -127,14 +127,14 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
contentService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
.Returns((int id) => Mock.Of<IContent>(content => content.Path == nodePaths[id]));
|
||||
.Returns((int id) => Mock.Of<IContent>(content => content.Path == nodePaths[id]));
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
var userService = new Mock<IUserService>();
|
||||
var entityService = new Mock<IEntityService>();
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath {Path = nodePaths[x], Id = x});
|
||||
return ids.Select(x => new EntityPath {Path = nodePaths[x], Id = x});
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -172,7 +172,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -210,7 +210,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -248,7 +248,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -277,8 +277,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var currentUser = Mock.Of<IUser>(user => user.StartMediaIds == new[] { 9876 });
|
||||
var savingUser = Mock.Of<IUser>();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
mediaService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
.Returns((int id) => Mock.Of<IMedia>(content => content.Path == nodePaths[id]));
|
||||
var userService = new Mock<IUserService>();
|
||||
@@ -286,7 +286,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -315,7 +315,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var currentUser = Mock.Of<IUser>(user => user.StartMediaIds == new[] { 9876 });
|
||||
var savingUser = Mock.Of<IUser>();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
mediaService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
.Returns((int id) => Mock.Of<IMedia>(content => content.Path == nodePaths[id]));
|
||||
@@ -324,7 +324,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -353,7 +353,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var currentUser = Mock.Of<IUser>(user => user.StartMediaIds == new[] { 9876 });
|
||||
var savingUser = Mock.Of<IUser>(user => user.StartMediaIds == new[] { 1234 });
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
mediaService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
.Returns((int id) => Mock.Of<IMedia>(content => content.Path == nodePaths[id]));
|
||||
@@ -362,7 +362,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
@@ -391,7 +391,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var currentUser = Mock.Of<IUser>(user => user.StartMediaIds == new[] { 9876 });
|
||||
var savingUser = Mock.Of<IUser>(user => user.StartMediaIds == new[] { 1234, 4567 });
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
mediaService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
.Returns((int id) => Mock.Of<IMedia>(content => content.Path == nodePaths[id]));
|
||||
@@ -400,7 +400,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Setup(service => service.GetAllPaths(It.IsAny<UmbracoObjectTypes>(), It.IsAny<int[]>()))
|
||||
.Returns((UmbracoObjectTypes objType, int[] ids) =>
|
||||
{
|
||||
return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x });
|
||||
return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x });
|
||||
});
|
||||
|
||||
var authHelper = new UserEditorAuthorizationHelper(
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.ControllerTesting;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -26,35 +23,25 @@ using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
[DatabaseTestBehavior(DatabaseBehavior.NoDatabasePerFixture)]
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.None)]
|
||||
public class UsersControllerTests : TestWithDatabaseBase
|
||||
public class UsersControllerTests : BaseDatabaseFactoryTest
|
||||
{
|
||||
protected override void ComposeApplication(bool withApplication)
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
base.ComposeApplication(withApplication);
|
||||
//if (!withApplication) return;
|
||||
|
||||
// replace the true IUserService implementation with a mock
|
||||
// so that each test can configure the service to their liking
|
||||
Container.RegisterSingleton(f => Mock.Of<IUserService>());
|
||||
|
||||
// kill the true IEntityService too
|
||||
Container.RegisterSingleton(f => Mock.Of<IEntityService>());
|
||||
|
||||
Container.RegisterSingleton<UmbracoFeatures>();
|
||||
FeaturesResolver.Current = new FeaturesResolver(new UmbracoFeatures());
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async System.Threading.Tasks.Task Save_User()
|
||||
public async void Save_User()
|
||||
{
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
var runner = new TestRunner((message, helper) =>
|
||||
{
|
||||
//setup some mocks
|
||||
Umbraco.Core.Configuration.GlobalSettings.HasSmtpServer = true;
|
||||
|
||||
var userServiceMock = Mock.Get(Current.Services.UserService);
|
||||
|
||||
var userServiceMock = Mock.Get(helper.UmbracoContext.Application.Services.UserService);
|
||||
userServiceMock.Setup(service => service.Save(It.IsAny<IUser>(), It.IsAny<bool>()))
|
||||
.Callback((IUser u, bool raiseEvents) =>
|
||||
{
|
||||
@@ -65,12 +52,13 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
userServiceMock.Setup(service => service.GetUserGroupsByAlias(It.IsAny<string[]>()))
|
||||
.Returns(new[] { Mock.Of<IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") });
|
||||
userServiceMock.Setup(service => service.GetUserById(It.IsAny<int>()))
|
||||
.Returns((int id) => id == 1234 ? new User(1234, "Test", "test@test.com", "test@test.com", "", new List<IReadOnlyUserGroup>(), new int[0], new int[0]) : null);
|
||||
.Returns(new User(1234, "Test", "test@test.com", "test@test.com", "", new List<IReadOnlyUserGroup>(), new int[0], new int[0]));
|
||||
|
||||
//we need to manually apply automapper mappings with the mocked applicationcontext
|
||||
InitializeMappers(helper.UmbracoContext.Application);
|
||||
|
||||
var usersController = new UsersController();
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
return new UsersController(helper.UmbracoContext);
|
||||
});
|
||||
|
||||
var userSave = new UserSave
|
||||
{
|
||||
@@ -81,10 +69,9 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Name = "Test",
|
||||
UserGroups = new[] { "writers" }
|
||||
};
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
var response = await runner.Execute("Users", "PostSaveUser", HttpMethod.Post,
|
||||
new ObjectContent<UserSave>(userSave, new JsonMediaTypeFormatter()));
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<UserDisplay>(response.Item2);
|
||||
|
||||
Assert.AreEqual(userSave.Name, obj.Name);
|
||||
@@ -96,42 +83,18 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Assert.IsTrue(userGroupAliases.Contains(group));
|
||||
}
|
||||
}
|
||||
|
||||
private void MockForGetPagedUsers()
|
||||
{
|
||||
Mock.Get(Current.SqlContext)
|
||||
.Setup(x => x.Query<IUser>())
|
||||
.Returns(new Query<IUser>(Current.SqlContext));
|
||||
|
||||
var syntax = new SqlCeSyntaxProvider();
|
||||
|
||||
Mock.Get(Current.SqlContext)
|
||||
.Setup(x => x.SqlSyntax)
|
||||
.Returns(syntax);
|
||||
|
||||
var mappers = new MapperCollection(new []
|
||||
{
|
||||
new UserMapper()
|
||||
});
|
||||
|
||||
Mock.Get(Current.SqlContext)
|
||||
.Setup(x => x.Mappers)
|
||||
.Returns(mappers);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async System.Threading.Tasks.Task GetPagedUsers_Empty()
|
||||
public async void GetPagedUsers_Empty()
|
||||
{
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
var runner = new TestRunner((message, helper) =>
|
||||
{
|
||||
var usersController = new UsersController();
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
//we need to manually apply automapper mappings with the mocked applicationcontext
|
||||
InitializeMappers(helper.UmbracoContext.Application);
|
||||
|
||||
MockForGetPagedUsers();
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
return new UsersController(helper.UmbracoContext);
|
||||
});
|
||||
var response = await runner.Execute("Users", "GetPagedUsers", HttpMethod.Get);
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<PagedResult<UserDisplay>>(response.Item2);
|
||||
@@ -139,27 +102,24 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async System.Threading.Tasks.Task GetPagedUsers_10()
|
||||
public async void GetPagedUsers_10()
|
||||
{
|
||||
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
|
||||
var runner = new TestRunner((message, helper) =>
|
||||
{
|
||||
//setup some mocks
|
||||
var userServiceMock = Mock.Get(Current.Services.UserService);
|
||||
var userServiceMock = Mock.Get(helper.UmbracoContext.Application.Services.UserService);
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
long outVal = 10;
|
||||
userServiceMock.Setup(service => service.GetAll(
|
||||
It.IsAny<long>(), It.IsAny<int>(), out outVal, It.IsAny<string>(), It.IsAny<Direction>(),
|
||||
It.IsAny<UserState[]>(), It.IsAny<string[]>(), It.IsAny<string[]>(), It.IsAny<IQuery<IUser>>()))
|
||||
It.IsAny<long>(), It.IsAny<int>(), out outVal, It.IsAny<string>(), It.IsAny<Direction>(),
|
||||
It.IsAny<UserState[]>(), It.IsAny<string[]>(), It.IsAny<string[]>(), It.IsAny<IQuery<IUser>>()))
|
||||
.Returns(() => users);
|
||||
|
||||
var usersController = new UsersController();
|
||||
Container.InjectProperties(usersController);
|
||||
return usersController;
|
||||
}
|
||||
//we need to manually apply automapper mappings with the mocked applicationcontext
|
||||
InitializeMappers(helper.UmbracoContext.Application);
|
||||
|
||||
MockForGetPagedUsers();
|
||||
|
||||
var runner = new TestRunner(Factory);
|
||||
return new UsersController(helper.UmbracoContext);
|
||||
});
|
||||
var response = await runner.Execute("Users", "GetPagedUsers", HttpMethod.Get);
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<PagedResult<UserDisplay>>(response.Item2);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
|
||||
@@ -17,7 +19,7 @@ namespace Umbraco.Tests.Web.HealthChecks
|
||||
private readonly string _message;
|
||||
private readonly StatusResultType _resultType;
|
||||
|
||||
public StubHealthCheck(StatusResultType resultType, string message)
|
||||
public StubHealthCheck(StatusResultType resultType, string message) : base(null)
|
||||
{
|
||||
_resultType = resultType;
|
||||
_message = message;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Tests.Web
|
||||
else
|
||||
{
|
||||
Assert.IsNull(valueFromHeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class HtmlHelperExtensionMethodsTests
|
||||
{
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
//create an empty htmlHelper
|
||||
_htmlHelper = new HtmlHelper(new ViewContext(), new ViewPage());
|
||||
}
|
||||
[TestFixture]
|
||||
public class HtmlHelperExtensionMethodsTests
|
||||
{
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
//create an empty htmlHelper
|
||||
_htmlHelper = new HtmlHelper(new ViewContext(), new ViewPage());
|
||||
}
|
||||
|
||||
private HtmlHelper _htmlHelper;
|
||||
private HtmlHelper _htmlHelper;
|
||||
|
||||
[Test]
|
||||
public void Wrap_Simple()
|
||||
{
|
||||
var output = _htmlHelper.Wrap("div", "hello world");
|
||||
Assert.AreEqual("<div>hello world</div>", output.ToHtmlString());
|
||||
}
|
||||
[Test]
|
||||
public void Wrap_Simple()
|
||||
{
|
||||
var output = _htmlHelper.Wrap("div", "hello world");
|
||||
Assert.AreEqual("<div>hello world</div>", output.ToHtmlString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Wrap_Object_Attributes()
|
||||
{
|
||||
var output = _htmlHelper.Wrap("div", "hello world", new {style = "color:red;", onclick = "void();"});
|
||||
Assert.AreEqual("<div style=\"color:red;\" onclick=\"void();\">hello world</div>", output.ToHtmlString());
|
||||
}
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public void Wrap_Object_Attributes()
|
||||
{
|
||||
var output = _htmlHelper.Wrap("div", "hello world", new {style = "color:red;", onclick = "void();"});
|
||||
Assert.AreEqual("<div style=\"color:red;\" onclick=\"void();\">hello world</div>", output.ToHtmlString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
@@ -11,14 +11,14 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
|
||||
_htmlStringUtilities = new HtmlStringUtilities();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReplaceLineBreaksWithHtmlBreak()
|
||||
{
|
||||
var output = _htmlStringUtilities.ReplaceLineBreaksForHtml("<div><h1>hello world</h1><p>hello world\r\nhello world\rhello world\nhello world</p></div>").ToString();
|
||||
var output = _htmlStringUtilities.ReplaceLineBreaksForHtml("<div><h1>hello world</h1><p>hello world\r\nhello world\rhello world\nhello world</p></div>");
|
||||
var expected = "<div><h1>hello world</h1><p>hello world<br />hello world<br />hello world<br />hello world</p></div>";
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
@@ -58,4 +58,4 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) {RouteData = controllerCtx.RouteData};
|
||||
var att = new MergeParentContextViewDataAttribute();
|
||||
|
||||
|
||||
Assert.IsTrue(filter.IsChildAction);
|
||||
att.OnResultExecuting(filter);
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
internal class MyController : Controller
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,19 +8,12 @@ using System.Web.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
@@ -29,20 +22,6 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[TestFixture]
|
||||
public class RenderIndexActionSelectorAttributeTests
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Current.Reset();
|
||||
}
|
||||
|
||||
private TestObjects TestObjects = new TestObjects(null);
|
||||
|
||||
private MethodInfo GetRenderMvcControllerIndexMethodFromCurrentType(Type currType)
|
||||
{
|
||||
return currType.GetMethods().Single(x =>
|
||||
@@ -51,7 +30,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
if (x.ReturnParameter == null || x.ReturnParameter.ParameterType != typeof (ActionResult)) return false;
|
||||
var p = x.GetParameters();
|
||||
if (p.Length != 1) return false;
|
||||
if (p[0].ParameterType != typeof (ContentModel)) return false;
|
||||
if (p[0].ParameterType != typeof (RenderModel)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -59,23 +38,19 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Matches_Default_Index()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var attr = new RenderIndexActionSelectorAttribute();
|
||||
var req = new RequestContext();
|
||||
//var appCtx = new ApplicationContext(
|
||||
// CacheHelper.CreateDisabledCacheHelper(),
|
||||
// new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
var ctrl = new MatchesDefaultIndexController { UmbracoContext = umbCtx };
|
||||
var ctrl = new MatchesDefaultIndexController(umbCtx);
|
||||
var controllerCtx = new ControllerContext(req, ctrl);
|
||||
var result = attr.IsValidForRequest(controllerCtx,
|
||||
GetRenderMvcControllerIndexMethodFromCurrentType(ctrl.GetType()));
|
||||
@@ -86,20 +61,19 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Matches_Overriden_Index()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var attr = new RenderIndexActionSelectorAttribute();
|
||||
var req = new RequestContext();
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
var ctrl = new MatchesOverriddenIndexController { UmbracoContext = umbCtx };
|
||||
var ctrl = new MatchesOverriddenIndexController(umbCtx);
|
||||
var controllerCtx = new ControllerContext(req, ctrl);
|
||||
var result = attr.IsValidForRequest(controllerCtx,
|
||||
GetRenderMvcControllerIndexMethodFromCurrentType(ctrl.GetType()));
|
||||
@@ -110,20 +84,19 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Matches_Custom_Index()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var attr = new RenderIndexActionSelectorAttribute();
|
||||
var req = new RequestContext();
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
var ctrl = new MatchesCustomIndexController { UmbracoContext = umbCtx };
|
||||
var ctrl = new MatchesCustomIndexController(umbCtx);
|
||||
var controllerCtx = new ControllerContext(req, ctrl);
|
||||
var result = attr.IsValidForRequest(controllerCtx,
|
||||
GetRenderMvcControllerIndexMethodFromCurrentType(ctrl.GetType()));
|
||||
@@ -134,20 +107,19 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Matches_Async_Index_Same_Signature()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var attr = new RenderIndexActionSelectorAttribute();
|
||||
var req = new RequestContext();
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
var ctrl = new MatchesAsyncIndexController { UmbracoContext = umbCtx };
|
||||
var ctrl = new MatchesAsyncIndexController(umbCtx);
|
||||
var controllerCtx = new ControllerContext(req, ctrl);
|
||||
var result = attr.IsValidForRequest(controllerCtx,
|
||||
GetRenderMvcControllerIndexMethodFromCurrentType(ctrl.GetType()));
|
||||
@@ -156,11 +128,19 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
}
|
||||
|
||||
public class MatchesDefaultIndexController : RenderMvcController
|
||||
{ }
|
||||
{
|
||||
public MatchesDefaultIndexController(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MatchesOverriddenIndexController : RenderMvcController
|
||||
{
|
||||
public override ActionResult Index(ContentModel model)
|
||||
public MatchesOverriddenIndexController(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
}
|
||||
|
||||
public override ActionResult Index(RenderModel model)
|
||||
{
|
||||
return base.Index(model);
|
||||
}
|
||||
@@ -168,7 +148,11 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
public class MatchesCustomIndexController : RenderMvcController
|
||||
{
|
||||
public ActionResult Index(ContentModel model, int page)
|
||||
public MatchesCustomIndexController(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
}
|
||||
|
||||
public ActionResult Index(RenderModel model, int page)
|
||||
{
|
||||
return base.Index(model);
|
||||
}
|
||||
@@ -176,10 +160,14 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
public class MatchesAsyncIndexController : RenderMvcController
|
||||
{
|
||||
public new async Task<ActionResult> Index(ContentModel model)
|
||||
public MatchesAsyncIndexController(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
}
|
||||
|
||||
public new async Task<ActionResult> Index(RenderModel model)
|
||||
{
|
||||
return await Task.FromResult(base.Index(model));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@@ -7,61 +7,48 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class RenderModelBinderTests
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Current.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Binder_For_IPublishedContent_And_IRenderModel()
|
||||
{
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var binder = new RenderModelBinder();
|
||||
var found = binder.GetBinder(typeof (IPublishedContent));
|
||||
Assert.IsNotNull(found);
|
||||
found = binder.GetBinder(typeof(RenderModel));
|
||||
Assert.IsNotNull(found);
|
||||
found = binder.GetBinder(typeof(ContentModel));
|
||||
found = binder.GetBinder(typeof(DynamicPublishedContent));
|
||||
Assert.IsNotNull(found);
|
||||
found = binder.GetBinder(typeof(MyContent));
|
||||
Assert.IsNotNull(found);
|
||||
found = binder.GetBinder(typeof(ContentModel<MyContent>));
|
||||
found = binder.GetBinder(typeof(RenderModel<MyContent>));
|
||||
Assert.IsNotNull(found);
|
||||
|
||||
found = binder.GetBinder(typeof(MyOtherContent));
|
||||
Assert.IsNull(found);
|
||||
found = binder.GetBinder(typeof(MyCustomContentModel));
|
||||
Assert.IsNull(found);
|
||||
found = binder.GetBinder(typeof(IContentModel));
|
||||
found = binder.GetBinder(typeof(MyCustomRenderModel));
|
||||
Assert.IsNull(found);
|
||||
found = binder.GetBinder(typeof(IRenderModel));
|
||||
Assert.IsNull(found);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindModel_Null_Source_Returns_Null()
|
||||
{
|
||||
Assert.IsNull(ContentModelBinder.BindModel(null, typeof(MyContent)));
|
||||
Assert.IsNull(RenderModelBinder.BindModel(null, typeof(MyContent), CultureInfo.CurrentCulture));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindModel_Returns_If_Same_Type()
|
||||
{
|
||||
var content = new MyContent(Mock.Of<IPublishedContent>());
|
||||
var bound = ContentModelBinder.BindModel(content, typeof (IPublishedContent));
|
||||
var bound = RenderModelBinder.BindModel(content, typeof (IPublishedContent), CultureInfo.CurrentCulture);
|
||||
Assert.AreSame(content, bound);
|
||||
}
|
||||
|
||||
@@ -69,8 +56,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public void BindModel_RenderModel_To_IPublishedContent()
|
||||
{
|
||||
var content = new MyContent(Mock.Of<IPublishedContent>());
|
||||
var renderModel = new ContentModel(content);
|
||||
var bound = ContentModelBinder.BindModel(renderModel, typeof(IPublishedContent));
|
||||
var renderModel = new RenderModel(content, CultureInfo.CurrentCulture);
|
||||
var bound = RenderModelBinder.BindModel(renderModel, typeof(IPublishedContent), CultureInfo.CurrentCulture);
|
||||
Assert.AreSame(content, bound);
|
||||
}
|
||||
|
||||
@@ -78,7 +65,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public void BindModel_IPublishedContent_To_RenderModel()
|
||||
{
|
||||
var content = new MyContent(Mock.Of<IPublishedContent>());
|
||||
var bound = (IContentModel)ContentModelBinder.BindModel(content, typeof(ContentModel));
|
||||
var bound = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture);
|
||||
Assert.AreSame(content, bound.Content);
|
||||
}
|
||||
|
||||
@@ -86,14 +73,14 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public void BindModel_IPublishedContent_To_Generic_RenderModel()
|
||||
{
|
||||
var content = new MyContent(Mock.Of<IPublishedContent>());
|
||||
var bound = (IContentModel)ContentModelBinder.BindModel(content, typeof(ContentModel<MyContent>));
|
||||
var bound = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel<MyContent>), CultureInfo.CurrentCulture);
|
||||
Assert.AreSame(content, bound.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_DataToken_Returns_Null()
|
||||
{
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var binder = new RenderModelBinder();
|
||||
var routeData = new RouteData();
|
||||
var result = binder.BindModel(new ControllerContext(Mock.Of<HttpContextBase>(), routeData, Mock.Of<ControllerBase>()),
|
||||
new ModelBindingContext());
|
||||
@@ -104,7 +91,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Invalid_DataToken_Model_Type_Returns_Null()
|
||||
{
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var binder = new RenderModelBinder();
|
||||
var routeData = new RouteData();
|
||||
routeData.DataTokens[Core.Constants.Web.UmbracoDataToken] = "hello";
|
||||
|
||||
@@ -134,20 +121,20 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public void IPublishedContent_DataToken_Model_Type_Uses_DefaultImplementation()
|
||||
{
|
||||
var content = new MyContent(Mock.Of<IPublishedContent>());
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var binder = new RenderModelBinder();
|
||||
var routeData = new RouteData();
|
||||
routeData.DataTokens[Core.Constants.Web.UmbracoDataToken] = content;
|
||||
|
||||
//the value provider is the default implementation
|
||||
var valueProvider = new Mock<IValueProvider>();
|
||||
var valueProvider = new Mock<IValueProvider>();
|
||||
//also IUnvalidatedValueProvider
|
||||
var invalidatedValueProvider = valueProvider.As<IUnvalidatedValueProvider>();
|
||||
invalidatedValueProvider.Setup(x => x.GetValue(It.IsAny<string>(), It.IsAny<bool>())).Returns(() =>
|
||||
new ValueProviderResult(content, "content", CultureInfo.CurrentCulture));
|
||||
|
||||
var controllerCtx = new ControllerContext(
|
||||
Mock.Of<HttpContextBase>(http => http.Items == new Dictionary<object, object>()),
|
||||
routeData,
|
||||
Mock.Of<HttpContextBase>(http => http.Items == new Dictionary<object, object>()),
|
||||
routeData,
|
||||
Mock.Of<ControllerBase>());
|
||||
var result = binder.BindModel(controllerCtx,
|
||||
new ModelBindingContext
|
||||
@@ -159,16 +146,19 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
Assert.AreEqual(content, result);
|
||||
}
|
||||
|
||||
public class MyCustomContentModel : ContentModel
|
||||
{
|
||||
public MyCustomContentModel(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
public class MyCustomRenderModel : RenderModel
|
||||
{
|
||||
public MyCustomRenderModel(IPublishedContent content, CultureInfo culture) : base(content, culture)
|
||||
{
|
||||
}
|
||||
public MyCustomRenderModel(IPublishedContent content) : base(content)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class MyOtherContent
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class MyContent : PublishedContentWrapped
|
||||
@@ -178,4 +168,4 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@@ -6,50 +6,43 @@ using System.Web.Routing;
|
||||
using System.Web.Security;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class SurfaceControllerTests : UmbracoTestBase
|
||||
public class SurfaceControllerTests
|
||||
{
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Construct_And_Get_Result()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var umbracoContext = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext };
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
var result = ctrl.Index();
|
||||
|
||||
@@ -59,19 +52,21 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Umbraco_Context_Not_Null()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
|
||||
ApplicationContext.EnsureContext(appCtx, true);
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
new Mock<HttpContextBase>().Object,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbCtx };
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
Assert.IsNotNull(ctrl.UmbracoContext);
|
||||
}
|
||||
@@ -79,60 +74,55 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Umbraco_Helper_Not_Null()
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var umbracoContext = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
var appCtx = new ApplicationContext(
|
||||
new DatabaseContext(new Mock<IScopeProviderInternal>().Object, Mock.Of<ILogger>(), Mock.Of<ISqlSyntaxProvider>(), "test"),
|
||||
MockHelper.GetMockedServiceContext(),
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var controller = new TestSurfaceController { UmbracoContext = umbracoContext };
|
||||
Container.Register(_ => umbracoContext);
|
||||
Container.InjectProperties(controller);
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
Assert.IsNotNull(controller.Umbraco);
|
||||
Assert.IsNotNull(ctrl.Umbraco);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Lookup_Content()
|
||||
{
|
||||
var publishedSnapshot = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of<IPublishedMemberCache>());
|
||||
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
|
||||
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedSnapshot.Object);
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
|
||||
var umbracoContext = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
publishedSnapshotService.Object,
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "AutoLegacy")),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var helper = new UmbracoHelper(
|
||||
umbracoContext,
|
||||
umbCtx,
|
||||
Mock.Of<IPublishedContent>(),
|
||||
Mock.Of<IPublishedContentQuery>(query => query.Content(It.IsAny<int>()) ==
|
||||
//return mock of IPublishedContent for any call to GetById
|
||||
Mock.Of<IPublishedContent>(content => content.Id == 2)),
|
||||
Mock.Of<ITypedPublishedContentQuery>(query => query.TypedContent(It.IsAny<int>()) ==
|
||||
//return mock of IPublishedContent for any call to GetById
|
||||
Mock.Of<IPublishedContent>(content => content.Id == 2)),
|
||||
Mock.Of<IDynamicPublishedContentQuery>(),
|
||||
Mock.Of<ITagQuery>(),
|
||||
Mock.Of<IDataTypeService>(),
|
||||
new UrlProvider(umbCtx, Enumerable.Empty<IUrlProvider>()),
|
||||
Mock.Of<ICultureDictionary>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
new MembershipHelper(umbracoContext, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>()),
|
||||
new ServiceContext(),
|
||||
CacheHelper.CreateDisabledCacheHelper());
|
||||
new MembershipHelper(umbCtx, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>()));
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext, Umbraco = helper };
|
||||
var ctrl = new TestSurfaceController(umbCtx, helper);
|
||||
var result = ctrl.GetContent(2) as PublishedContentResult;
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
@@ -142,36 +132,40 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Mock_Current_Page()
|
||||
{
|
||||
var webRoutingSettings = Mock.Of<IWebRoutingSection>(section => section.UrlProviderMode == "AutoLegacy");
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
|
||||
var umbracoContext = UmbracoContext.EnsureContext(
|
||||
Current.UmbracoContextAccessor,
|
||||
var webRoutingSettings = Mock.Of<IWebRoutingSection>(section => section.UrlProviderMode == "AutoLegacy");
|
||||
|
||||
var umbCtx = UmbracoContext.EnsureContext(
|
||||
new Mock<HttpContextBase>().Object,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
appCtx,
|
||||
new Mock<WebSecurity>(null, null).Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == webRoutingSettings),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var content = Mock.Of<IPublishedContent>(publishedContent => publishedContent.Id == 12345);
|
||||
|
||||
var contextBase = umbracoContext.HttpContext;
|
||||
var publishedRouter = BaseWebTest.CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting);
|
||||
var frequest = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/test"));
|
||||
frequest.PublishedContent = content;
|
||||
var contextBase = umbCtx.HttpContext;
|
||||
var pcr = new PublishedContentRequest(new Uri("http://localhost/test"),
|
||||
umbCtx.RoutingContext,
|
||||
webRoutingSettings,
|
||||
s => Enumerable.Empty<string>())
|
||||
{
|
||||
PublishedContent = content
|
||||
};
|
||||
|
||||
var routeDefinition = new RouteDefinition
|
||||
{
|
||||
PublishedRequest = frequest
|
||||
PublishedContentRequest = pcr
|
||||
};
|
||||
|
||||
var routeData = new RouteData();
|
||||
routeData.DataTokens.Add(Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition);
|
||||
routeData.DataTokens.Add(Umbraco.Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition);
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext, Umbraco = new UmbracoHelper() };
|
||||
var ctrl = new TestSurfaceController(umbCtx, new UmbracoHelper());
|
||||
ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl);
|
||||
|
||||
var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult;
|
||||
@@ -181,6 +175,27 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
public class TestSurfaceController : SurfaceController
|
||||
{
|
||||
private readonly UmbracoHelper _umbracoHelper;
|
||||
|
||||
public TestSurfaceController(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
}
|
||||
|
||||
public TestSurfaceController(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
_umbracoHelper = umbracoHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an UmbracoHelper object
|
||||
/// </summary>
|
||||
public override UmbracoHelper Umbraco
|
||||
{
|
||||
get { return _umbracoHelper ?? base.Umbraco; }
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
@@ -188,7 +203,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
public ActionResult GetContent(int id)
|
||||
{
|
||||
var content = Umbraco.Content(id);
|
||||
var content = Umbraco.TypedContent(id);
|
||||
|
||||
return new PublishedContentResult(content);
|
||||
}
|
||||
@@ -216,4 +231,4 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,465 +1,502 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using LightInject;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class UmbracoViewPageTests : UmbracoTestBase
|
||||
{
|
||||
private PublishedSnapshotService _service;
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
if (_service == null) return;
|
||||
_service.Dispose();
|
||||
_service = null;
|
||||
}
|
||||
|
||||
#region RenderModel To ...
|
||||
|
||||
[Test]
|
||||
public void RenderModel_To_RenderModel()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new RenderModelTestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.AreSame(model, view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType2_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new ContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType2_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType2>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_RenderModelOf_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel(content);
|
||||
var view = new RenderModelOfContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderModelOf To ...
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_RenderModel()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel<ContentType1>(content);
|
||||
var view = new RenderModelTestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.AreSame(model, view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel<ContentType1>(content);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType2_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new ContentModel<ContentType2>(content);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel<ContentType1>(content);
|
||||
var view = new ContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel<ContentType1>(content);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType2_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new ContentModel<ContentType2>(content);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType2>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_RenderModelOf_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new ContentModel<ContentType1>(content);
|
||||
var view = new RenderModelOfContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContentType To ...
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_RenderModel()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new RenderModelTestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType2_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_RenderModelOf_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new RenderModelOfContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() =>view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new ContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType2_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test elements
|
||||
|
||||
public class TestPage<TModel> : UmbracoViewPage<TModel>
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetViewDataX(ViewDataDictionary viewData)
|
||||
{
|
||||
SetViewData(viewData);
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderModelTestPage : TestPage<ContentModel>
|
||||
{ }
|
||||
|
||||
public class RenderModelOfContentType1TestPage : TestPage<ContentModel<ContentType1>>
|
||||
{ }
|
||||
|
||||
public class RenderModelOfContentType2TestPage : TestPage<ContentModel<ContentType2>>
|
||||
{ }
|
||||
|
||||
public class ContentType1TestPage : TestPage<ContentType1>
|
||||
{ }
|
||||
|
||||
public class ContentType2TestPage : TestPage<ContentType2>
|
||||
{ }
|
||||
|
||||
public class ContentType1 : PublishedContentWrapped
|
||||
{
|
||||
public ContentType1(IPublishedContent content) : base(content) {}
|
||||
}
|
||||
|
||||
public class ContentType2 : ContentType1
|
||||
{
|
||||
public ContentType2(IPublishedContent content) : base(content) { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test helpers
|
||||
|
||||
ServiceContext GetServiceContext()
|
||||
{
|
||||
return TestObjects.GetServiceContextMock();
|
||||
}
|
||||
|
||||
ViewContext GetViewContext()
|
||||
{
|
||||
var settings = SettingsForTests.GetDefaultUmbracoSettings();
|
||||
var logger = Mock.Of<ILogger>();
|
||||
var umbracoContext = GetUmbracoContext(
|
||||
logger, settings,
|
||||
"/dang", 0);
|
||||
|
||||
var publishedRouter = BaseWebTest.CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting);
|
||||
var frequest = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/dang"));
|
||||
|
||||
frequest.Culture = CultureInfo.InvariantCulture;
|
||||
umbracoContext.PublishedRequest = frequest;
|
||||
|
||||
var context = new ViewContext();
|
||||
context.RouteData = new RouteData();
|
||||
context.RouteData.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbracoContext);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false)
|
||||
{
|
||||
var svcCtx = GetServiceContext();
|
||||
|
||||
var databaseFactory = TestObjects.GetDatabaseFactoryMock();
|
||||
|
||||
//var appCtx = new ApplicationContext(
|
||||
// new DatabaseContext(databaseFactory, logger, Mock.Of<IRuntimeState>(), Mock.Of<IMigrationEntryService>()),
|
||||
// svcCtx,
|
||||
// CacheHelper.CreateDisabledCacheHelper(),
|
||||
// new ProfilingLogger(logger, Mock.Of<IProfiler>())) { /*IsReady = true*/ };
|
||||
|
||||
var cache = NullCacheProvider.Instance;
|
||||
//var provider = new ScopeUnitOfWorkProvider(databaseFactory, new RepositoryFactory(Mock.Of<IServiceContainer>()));
|
||||
var scopeProvider = TestObjects.GetScopeProvider(Mock.Of<ILogger>());
|
||||
var factory = Mock.Of<IPublishedContentTypeFactory>();
|
||||
_service = new PublishedSnapshotService(svcCtx, factory, scopeProvider, cache, Enumerable.Empty<IUrlSegmentProvider>(),
|
||||
null, null,
|
||||
null, null, null,
|
||||
new TestDefaultCultureAccessor(),
|
||||
Current.Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), null, true, false); // no events
|
||||
|
||||
var http = GetHttpContextFactory(url, routeData).HttpContext;
|
||||
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
|
||||
var ctx = new UmbracoContext(
|
||||
http,
|
||||
_service,
|
||||
new WebSecurity(http, Current.Services.UserService, globalSettings),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor());
|
||||
|
||||
//if (setSingleton)
|
||||
//{
|
||||
// UmbracoContext.Current = ctx;
|
||||
//}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
protected FakeHttpContextFactory GetHttpContextFactory(string url, RouteData routeData = null)
|
||||
{
|
||||
var factory = routeData != null
|
||||
? new FakeHttpContextFactory(url, routeData)
|
||||
: new FakeHttpContextFactory(url);
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using umbraco.BusinessLogic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class UmbracoViewPageTests
|
||||
{
|
||||
#region RenderModel To ...
|
||||
|
||||
[Test]
|
||||
public void RenderModel_To_RenderModel()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelTestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.AreSame(model, view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType2_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new ContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType2_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType2>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModel_ContentType1_To_RenderModelOf_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelOfContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderModelOf To ...
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_RenderModel()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel<ContentType1>(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelTestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.AreSame(model, view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel<ContentType1>(content, CultureInfo.InvariantCulture);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType2_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new RenderModel<ContentType2>(content, CultureInfo.InvariantCulture);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel<ContentType1>(content, CultureInfo.InvariantCulture);
|
||||
var view = new ContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel<ContentType1>(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType2_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var model = new RenderModel<ContentType2>(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType2>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderModelOf_ContentType1_To_RenderModelOf_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var model = new RenderModel<ContentType1>(content, CultureInfo.InvariantCulture);
|
||||
var view = new RenderModelOfContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(model);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContentType To ...
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_RenderModel()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new RenderModelTestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType2_To_RenderModelOf_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var view = new RenderModelOfContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<RenderModel<ContentType1>>(view.Model);
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_RenderModelOf_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new RenderModelOfContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() =>view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType1_To_ContentType2()
|
||||
{
|
||||
var content = new ContentType1(null);
|
||||
var view = new ContentType2TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentType2_To_ContentType1()
|
||||
{
|
||||
var content = new ContentType2(null);
|
||||
var view = new ContentType1TestPage();
|
||||
var viewData = new ViewDataDictionary(content);
|
||||
|
||||
view.ViewContext = GetViewContext();
|
||||
view.SetViewDataX(viewData);
|
||||
|
||||
Assert.IsInstanceOf<ContentType1>(view.Model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test elements
|
||||
|
||||
public class TestPage<TModel> : UmbracoViewPage<TModel>
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetViewDataX(ViewDataDictionary viewData)
|
||||
{
|
||||
SetViewData(viewData);
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderModelTestPage : TestPage<RenderModel>
|
||||
{ }
|
||||
|
||||
public class RenderModelOfContentType1TestPage : TestPage<RenderModel<ContentType1>>
|
||||
{ }
|
||||
|
||||
public class RenderModelOfContentType2TestPage : TestPage<RenderModel<ContentType2>>
|
||||
{ }
|
||||
|
||||
public class ContentType1TestPage : TestPage<ContentType1>
|
||||
{ }
|
||||
|
||||
public class ContentType2TestPage : TestPage<ContentType2>
|
||||
{ }
|
||||
|
||||
public class ContentType1 : PublishedContentWrapped
|
||||
{
|
||||
public ContentType1(IPublishedContent content) : base(content) {}
|
||||
}
|
||||
|
||||
public class ContentType2 : ContentType1
|
||||
{
|
||||
public ContentType2(IPublishedContent content) : base(content) { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test helpers
|
||||
|
||||
ServiceContext GetServiceContext(IUmbracoSettingsSection umbracoSettings, ILogger logger)
|
||||
{
|
||||
var svcCtx = new ServiceContext(
|
||||
new Mock<IContentService>().Object,
|
||||
new Mock<IMediaService>().Object,
|
||||
new Mock<IContentTypeService>().Object,
|
||||
new Mock<IDataTypeService>().Object,
|
||||
new Mock<IFileService>().Object,
|
||||
new Mock<ILocalizationService>().Object,
|
||||
new PackagingService(
|
||||
new Mock<ILogger>().Object,
|
||||
new Mock<IContentService>().Object,
|
||||
new Mock<IContentTypeService>().Object,
|
||||
new Mock<IMediaService>().Object,
|
||||
new Mock<IMacroService>().Object,
|
||||
new Mock<IDataTypeService>().Object,
|
||||
new Mock<IFileService>().Object,
|
||||
new Mock<ILocalizationService>().Object,
|
||||
new Mock<IEntityService>().Object,
|
||||
new Mock<IUserService>().Object,
|
||||
new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), logger, Mock.Of<ISqlSyntaxProvider>(), umbracoSettings),
|
||||
new Mock<IScopeUnitOfWorkProvider>().Object),
|
||||
new Mock<IEntityService>().Object,
|
||||
new RelationService(
|
||||
new Mock<IScopeUnitOfWorkProvider>().Object,
|
||||
new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), logger, Mock.Of<ISqlSyntaxProvider>(), umbracoSettings),
|
||||
logger,
|
||||
new TransientMessagesFactory(),
|
||||
new Mock<IEntityService>().Object),
|
||||
new Mock<IMemberGroupService>().Object,
|
||||
new Mock<IMemberTypeService>().Object,
|
||||
new Mock<IMemberService>().Object,
|
||||
new Mock<IUserService>().Object,
|
||||
new Mock<ISectionService>().Object,
|
||||
new Mock<IApplicationTreeService>().Object,
|
||||
new Mock<ITagService>().Object,
|
||||
new Mock<INotificationService>().Object,
|
||||
Mock.Of<ILocalizedTextService>(),
|
||||
Mock.Of<IAuditService>(),
|
||||
Mock.Of<IDomainService>());
|
||||
return svcCtx;
|
||||
}
|
||||
|
||||
ViewContext GetViewContext()
|
||||
{
|
||||
var settings = SettingsForTests.GetDefault();
|
||||
var logger = Mock.Of<ILogger>();
|
||||
var umbracoContext = GetUmbracoContext(
|
||||
logger, settings,
|
||||
"/dang", 0);
|
||||
|
||||
var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider(settings.RequestHandler) });
|
||||
var routingContext = new RoutingContext(
|
||||
umbracoContext,
|
||||
Enumerable.Empty<IContentFinder>(),
|
||||
new FakeLastChanceFinder(),
|
||||
urlProvider);
|
||||
umbracoContext.RoutingContext = routingContext;
|
||||
|
||||
var request = new PublishedContentRequest(
|
||||
new Uri("http://localhost/dang"),
|
||||
routingContext,
|
||||
settings.WebRouting,
|
||||
s => Enumerable.Empty<string>());
|
||||
|
||||
request.Culture = CultureInfo.InvariantCulture;
|
||||
umbracoContext.PublishedContentRequest = request;
|
||||
|
||||
var context = new ViewContext();
|
||||
context.RouteData = new RouteData();
|
||||
context.RouteData.DataTokens.Add(Umbraco.Core.Constants.Web.UmbracoContextDataToken, umbracoContext);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false)
|
||||
{
|
||||
var cache = new PublishedContentCache();
|
||||
|
||||
//cache.GetXmlDelegate = (context, preview) =>
|
||||
//{
|
||||
// var doc = new XmlDocument();
|
||||
// doc.LoadXml(GetXmlContent(templateId));
|
||||
// return doc;
|
||||
//};
|
||||
|
||||
//PublishedContentCache.UnitTesting = true;
|
||||
|
||||
// ApplicationContext.Current = new ApplicationContext(false) { IsReady = true };
|
||||
var svcCtx = GetServiceContext(umbracoSettings, logger);
|
||||
|
||||
var appCtx = new ApplicationContext(
|
||||
new DatabaseContext(Mock.Of<IScopeProviderInternal>(), logger, Mock.Of<ISqlSyntaxProvider>(), "test"),
|
||||
svcCtx,
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(logger, Mock.Of<IProfiler>())) { IsReady = true };
|
||||
|
||||
var http = GetHttpContextFactory(url, routeData).HttpContext;
|
||||
var ctx = new UmbracoContext(
|
||||
GetHttpContextFactory(url, routeData).HttpContext,
|
||||
appCtx,
|
||||
new PublishedCaches(cache, new PublishedMediaCache(appCtx)),
|
||||
new WebSecurity(http, appCtx));
|
||||
|
||||
//if (setSingleton)
|
||||
//{
|
||||
// UmbracoContext.Current = ctx;
|
||||
//}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
protected FakeHttpContextFactory GetHttpContextFactory(string url, RouteData routeData = null)
|
||||
{
|
||||
var factory = routeData != null
|
||||
? new FakeHttpContextFactory(url, routeData)
|
||||
: new FakeHttpContextFactory(url);
|
||||
|
||||
|
||||
//set the state helper
|
||||
StateHelper.HttpContext = factory.HttpContext;
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,31 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using LightInject;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
using Umbraco.Web.Templates;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Tests.Web
|
||||
{
|
||||
[TestFixture]
|
||||
public class TemplateUtilitiesTests
|
||||
public class TemplateUtilitiesTests : BaseUmbracoApplicationTest
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
public void Setup()
|
||||
{
|
||||
Current.Reset();
|
||||
|
||||
// fixme - now UrlProvider depends on EntityService for GetUrl(guid) - this is bad
|
||||
// should not depend on more than IdkMap maybe - fix this!
|
||||
var entityService = new Mock<IEntityService>();
|
||||
entityService.Setup(x => x.GetId(It.IsAny<Guid>(), It.IsAny<UmbracoObjectTypes>())).Returns(Attempt<int>.Fail());
|
||||
var serviceContext = new ServiceContext(entityService: entityService.Object);
|
||||
|
||||
// fixme - bad in a unit test - but Udi has a static ctor that wants it?!
|
||||
var container = new Mock<IServiceContainer>();
|
||||
container.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns(
|
||||
new TypeLoader(NullCacheProvider.Instance, SettingsForTests.GenerateMockGlobalSettings(), new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>())));
|
||||
container.Setup(x => x.GetInstance(typeof (ServiceContext))).Returns(serviceContext);
|
||||
Current.Container = container.Object;
|
||||
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
Udi.ResetUdiTypes();
|
||||
|
||||
UmbracoConfig.For.SetUmbracoSettings(SettingsForTests.GetDefaultUmbracoSettings());
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Current.Reset();
|
||||
}
|
||||
|
||||
[TestCase("", "")]
|
||||
@@ -65,47 +36,34 @@ namespace Umbraco.Tests.Web
|
||||
[TestCase("hello href=\"{localLink:umb^://document-type/9931BDE0-AAC3-4BAB-B838-909A7B47570E}\" world ", "hello href=\"{localLink:umb^://document-type/9931BDE0-AAC3-4BAB-B838-909A7B47570E}\" world ")]
|
||||
public void ParseLocalLinks(string input, string result)
|
||||
{
|
||||
var serviceCtxMock = new TestObjects(null).GetServiceContextMock();
|
||||
var serviceCtxMock = MockHelper.GetMockedServiceContext();
|
||||
|
||||
//setup a mock entity service from the service context to return an integer for a GUID
|
||||
var entityService = Mock.Get(serviceCtxMock.EntityService);
|
||||
//entityService.Setup(x => x.GetId(It.IsAny<Guid>(), It.IsAny<UmbracoObjectTypes>()))
|
||||
// .Returns((Guid id, UmbracoObjectTypes objType) =>
|
||||
// {
|
||||
// return Attempt.Succeed(1234);
|
||||
// });
|
||||
entityService.Setup(x => x.GetIdForKey(It.IsAny<Guid>(), It.IsAny<UmbracoObjectTypes>()))
|
||||
.Returns((Guid id, UmbracoObjectTypes objType) =>
|
||||
{
|
||||
return Attempt.Succeed(1234);
|
||||
});
|
||||
|
||||
//setup a mock url provider which we'll use fo rtesting
|
||||
var testUrlProvider = new Mock<IUrlProvider>();
|
||||
testUrlProvider
|
||||
.Setup(x => x.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlProviderMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns((UmbracoContext umbCtx, IPublishedContent content, UrlProviderMode mode, string culture, Uri url) => "/my-test-url");
|
||||
|
||||
var globalSettings = SettingsForTests.GenerateMockGlobalSettings();
|
||||
|
||||
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing);
|
||||
var publishedContent = Mock.Of<IPublishedContent>();
|
||||
Mock.Get(publishedContent).Setup(x => x.Id).Returns(1234);
|
||||
Mock.Get(publishedContent).Setup(x => x.ContentType).Returns(contentType);
|
||||
var contentCache = Mock.Of<IPublishedContentCache>();
|
||||
Mock.Get(contentCache).Setup(x => x.GetById(It.IsAny<int>())).Returns(publishedContent);
|
||||
Mock.Get(contentCache).Setup(x => x.GetById(It.IsAny<Guid>())).Returns(publishedContent);
|
||||
var snapshot = Mock.Of<IPublishedSnapshot>();
|
||||
Mock.Get(snapshot).Setup(x => x.Content).Returns(contentCache);
|
||||
var snapshotService = Mock.Of<IPublishedSnapshotService>();
|
||||
Mock.Get(snapshotService).Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(snapshot);
|
||||
testUrlProvider.Setup(x => x.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<int>(), It.IsAny<Uri>(), It.IsAny<UrlProviderMode>()))
|
||||
.Returns((UmbracoContext umbCtx, int id, Uri url, UrlProviderMode mode) =>
|
||||
{
|
||||
return "/my-test-url";
|
||||
});
|
||||
|
||||
using (var appCtx = new ApplicationContext(new DatabaseContext(new Mock<IScopeProviderInternal>().Object, Mock.Of<ILogger>(), Mock.Of<ISqlSyntaxProvider>(), "test"),
|
||||
serviceCtxMock,
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>())))
|
||||
using (var umbCtx = UmbracoContext.EnsureContext(
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor,
|
||||
Mock.Of<HttpContextBase>(),
|
||||
snapshotService,
|
||||
new Mock<WebSecurity>(null, null, globalSettings).Object,
|
||||
Mock.Of<HttpContextBase>(), appCtx, new Mock<WebSecurity>(null, null).Object,
|
||||
//setup a quick mock of the WebRouting section
|
||||
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "AutoLegacy")),
|
||||
//pass in the custom url provider
|
||||
new[]{ testUrlProvider.Object },
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
true))
|
||||
{
|
||||
var output = TemplateUtilities.ParseInternalLinks(input, umbCtx.UrlProvider);
|
||||
@@ -114,4 +72,4 @@ namespace Umbraco.Tests.Web
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Tests.Web
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class WebExtensionMethodTests : UmbracoTestBase
|
||||
public class WebExtensionMethodTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void UmbracoContextExtensions_GetUmbracoContext()
|
||||
{
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.CreateContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
appCtx,
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), appCtx),
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
new List<IUrlProvider>(),
|
||||
false);
|
||||
var items = new Dictionary<object, object>()
|
||||
{
|
||||
{UmbracoContext.HttpContextItemName, umbCtx}
|
||||
};
|
||||
var http = new Mock<HttpContextBase>();
|
||||
http.Setup(x => x.Items).Returns(items);
|
||||
|
||||
var result = http.Object.GetUmbracoContext();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreSame(umbCtx, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RouteDataExtensions_GetUmbracoContext()
|
||||
{
|
||||
var umbCtx = new UmbracoContext(
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.CreateContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings()),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), appCtx),
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
new List<IUrlProvider>(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
new TestVariationContextAccessor());
|
||||
false);
|
||||
var r1 = new RouteData();
|
||||
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
|
||||
|
||||
Assert.IsTrue(r1.DataTokens.ContainsKey(Core.Constants.Web.UmbracoContextDataToken));
|
||||
Assert.AreSame(umbCtx, r1.DataTokens[Core.Constants.Web.UmbracoContextDataToken]);
|
||||
var result = r1.GetUmbracoContext();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreSame(umbCtx, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ControllerContextExtensions_GetUmbracoContext_From_RouteValues()
|
||||
{
|
||||
var umbCtx = new UmbracoContext(
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.CreateContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings()),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), appCtx),
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
new List<IUrlProvider>(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
new TestVariationContextAccessor());
|
||||
false);
|
||||
|
||||
var r1 = new RouteData();
|
||||
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
|
||||
@@ -69,30 +103,33 @@ namespace Umbraco.Tests.Web
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ControllerContextExtensions_GetUmbracoContext_From_Current()
|
||||
public void ControllerContextExtensions_GetUmbracoContext_From_HttpContext()
|
||||
{
|
||||
var umbCtx = new UmbracoContext(
|
||||
var appCtx = new ApplicationContext(
|
||||
CacheHelper.CreateDisabledCacheHelper(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
var umbCtx = UmbracoContext.CreateContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings()),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
appCtx,
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), appCtx),
|
||||
Mock.Of<IUmbracoSettingsSection>(),
|
||||
new List<IUrlProvider>(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
new TestVariationContextAccessor());
|
||||
|
||||
var httpContext = Mock.Of<HttpContextBase>();
|
||||
false);
|
||||
var items = new Dictionary<object, object>()
|
||||
{
|
||||
{UmbracoContext.HttpContextItemName, umbCtx}
|
||||
};
|
||||
var http = new Mock<HttpContextBase>();
|
||||
http.Setup(x => x.Items).Returns(items);
|
||||
|
||||
var r1 = new RouteData();
|
||||
var ctx1 = CreateViewContext(new ControllerContext(httpContext, r1, new MyController()));
|
||||
var ctx1 = CreateViewContext(new ControllerContext(http.Object, r1, new MyController()));
|
||||
var r2 = new RouteData();
|
||||
r2.DataTokens.Add("ParentActionViewContext", ctx1);
|
||||
var ctx2 = CreateViewContext(new ControllerContext(httpContext, r2, new MyController()));
|
||||
var ctx2 = CreateViewContext(new ControllerContext(http.Object, r2, new MyController()));
|
||||
var r3 = new RouteData();
|
||||
r3.DataTokens.Add("ParentActionViewContext", ctx2);
|
||||
var ctx3 = CreateViewContext(new ControllerContext(httpContext, r3, new MyController()));
|
||||
|
||||
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
Current.UmbracoContextAccessor.UmbracoContext = umbCtx;
|
||||
var ctx3 = CreateViewContext(new ControllerContext(http.Object, r3, new MyController()));
|
||||
|
||||
var result = ctx3.GetUmbracoContext();
|
||||
|
||||
@@ -105,29 +142,29 @@ namespace Umbraco.Tests.Web
|
||||
{
|
||||
var r1 = new RouteData();
|
||||
r1.DataTokens.Add("hello", "world");
|
||||
r1.DataTokens.Add("r", "1");
|
||||
var ctx1 = CreateViewContext(new ControllerContext(Mock.Of<HttpContextBase>(), r1, new MyController()));
|
||||
var r2 = new RouteData();
|
||||
r2.DataTokens.Add("ParentActionViewContext", ctx1);
|
||||
r2.DataTokens.Add("r", "2");
|
||||
var ctx2 = CreateViewContext(new ControllerContext(Mock.Of<HttpContextBase>(), r2, new MyController()));
|
||||
var r3 = new RouteData();
|
||||
r3.DataTokens.Add("ParentActionViewContext", ctx2);
|
||||
r3.DataTokens.Add("r", "3");
|
||||
var ctx3 = CreateViewContext(new ControllerContext(Mock.Of<HttpContextBase>(), r3, new MyController()));
|
||||
|
||||
var result = ctx3.GetDataTokenInViewContextHierarchy("hello");
|
||||
|
||||
Assert.IsNotNull(result as string);
|
||||
Assert.AreEqual((string) result, "world");
|
||||
Assert.AreEqual((string)result, "world");
|
||||
}
|
||||
|
||||
private static ViewContext CreateViewContext(ControllerContext ctx)
|
||||
private ViewContext CreateViewContext(ControllerContext ctx)
|
||||
{
|
||||
return new ViewContext(ctx, Mock.Of<IView>(), new ViewDataDictionary(), new TempDataDictionary(), new StringWriter());
|
||||
return new ViewContext(ctx, Mock.Of<IView>(),
|
||||
new ViewDataDictionary(), new TempDataDictionary(), new StringWriter());
|
||||
}
|
||||
|
||||
private class MyController : Controller
|
||||
{ }
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user