@@ -2,7 +2,6 @@
|
||||
using LightInject.Microsoft.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Core.Composing.LightInject;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
@@ -112,16 +112,16 @@ namespace Umbraco.Web.Media
|
||||
if (content == null) throw new ArgumentNullException(nameof(content));
|
||||
if (autoFillConfig == null) throw new ArgumentNullException(nameof(autoFillConfig));
|
||||
|
||||
if (!string.IsNullOrEmpty(autoFillConfig.WidthFieldAlias) && content.Properties.Contains(autoFillConfig.WidthFieldAlias))
|
||||
if (!string.IsNullOrWhiteSpace(autoFillConfig.WidthFieldAlias) && content.Properties.Contains(autoFillConfig.WidthFieldAlias))
|
||||
content.Properties[autoFillConfig.WidthFieldAlias].SetValue(size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty, culture, segment);
|
||||
|
||||
if (!string.IsNullOrEmpty(autoFillConfig.HeightFieldAlias) && content.Properties.Contains(autoFillConfig.HeightFieldAlias))
|
||||
if (!string.IsNullOrWhiteSpace(autoFillConfig.HeightFieldAlias) && content.Properties.Contains(autoFillConfig.HeightFieldAlias))
|
||||
content.Properties[autoFillConfig.HeightFieldAlias].SetValue(size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty, culture, segment);
|
||||
|
||||
if (!string.IsNullOrEmpty(autoFillConfig.LengthFieldAlias) && content.Properties.Contains(autoFillConfig.LengthFieldAlias))
|
||||
if (!string.IsNullOrWhiteSpace(autoFillConfig.LengthFieldAlias) && content.Properties.Contains(autoFillConfig.LengthFieldAlias))
|
||||
content.Properties[autoFillConfig.LengthFieldAlias].SetValue(length, culture, segment);
|
||||
|
||||
if (!string.IsNullOrEmpty(autoFillConfig.ExtensionFieldAlias) && content.Properties.Contains(autoFillConfig.ExtensionFieldAlias))
|
||||
if (!string.IsNullOrWhiteSpace(autoFillConfig.ExtensionFieldAlias) && content.Properties.Contains(autoFillConfig.ExtensionFieldAlias))
|
||||
content.Properties[autoFillConfig.ExtensionFieldAlias].SetValue(extension, culture, segment);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,16 @@ namespace Umbraco.Tests.Integration.TestServerTest
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the service from the underlying container that is also used by the <see cref="Client"/>.
|
||||
/// </summary>
|
||||
protected T GetRequiredService<T>() => Factory.Services.GetRequiredService<T>();
|
||||
|
||||
/// <summary>
|
||||
/// Prepare a url before using <see cref="Client"/>.
|
||||
/// This returns the url but also sets the HttpContext.request into to use this url.
|
||||
/// </summary>
|
||||
/// <returns>The string URL of the controller action.</returns>
|
||||
protected string PrepareUrl<T>(Expression<Func<T, object>> methodSelector)
|
||||
where T : UmbracoApiController
|
||||
{
|
||||
|
||||
@@ -252,7 +252,6 @@
|
||||
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
|
||||
<Compile Include="Web\Controllers\AuthenticationControllerTests.cs" />
|
||||
<Compile Include="Web\Controllers\BackOfficeControllerUnitTests.cs" />
|
||||
<Compile Include="Web\Controllers\ContentControllerTests.cs" />
|
||||
<Compile Include="Web\Controllers\UserEditorAuthorizationHelperTests.cs" />
|
||||
<Compile Include="Web\Controllers\UsersControllerTests.cs" />
|
||||
<Compile Include="Web\HealthChecks\HealthCheckResultsTests.cs" />
|
||||
|
||||
@@ -1,518 +0,0 @@
|
||||
// using System;
|
||||
// using System.Collections.Generic;
|
||||
// using System.Globalization;
|
||||
// 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;
|
||||
// using Umbraco.Core.Cache;
|
||||
// using Umbraco.Core.Configuration;
|
||||
// using Umbraco.Core.Dictionary;
|
||||
// using Umbraco.Core.Logging;
|
||||
// using Umbraco.Core.Models;
|
||||
// using Umbraco.Core.Models.Entities;
|
||||
// using Umbraco.Core.Models.Membership;
|
||||
// using Umbraco.Core.Persistence;
|
||||
// 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.Actions;
|
||||
// using Umbraco.Web.Editors;
|
||||
// using Umbraco.Web.Models.ContentEditing;
|
||||
// using Umbraco.Web.PropertyEditors;
|
||||
// using Umbraco.Web.Trees;
|
||||
// using Umbraco.Web.WebApi;
|
||||
// using Umbraco.Web.Composing;
|
||||
// using Task = System.Threading.Tasks.Task;
|
||||
// using Umbraco.Core.Mapping;
|
||||
// using Umbraco.Web.Routing;
|
||||
//
|
||||
// namespace Umbraco.Tests.Web.Controllers
|
||||
// {
|
||||
// [TestFixture]
|
||||
// [UmbracoTest(Database = UmbracoTestOptions.Database.None)]
|
||||
// public class ContentControllerTests : TestWithDatabaseBase
|
||||
// {
|
||||
// private IContentType _contentTypeForMockedContent;
|
||||
//
|
||||
// public override void SetUp()
|
||||
// {
|
||||
// base.SetUp();
|
||||
// _contentTypeForMockedContent = null;
|
||||
// }
|
||||
//
|
||||
// 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(TestObjects.GetGlobalSettings(), 1234, "Test", "test@test.com", "test@test.com", "", null, 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(TestObjects.GetGlobalSettings(), 1234, "Test", "test@test.com", "test@test.com", "", null, 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());
|
||||
// entityService.Setup(x => x.GetKey(It.IsAny<int>(), UmbracoObjectTypes.DataType))
|
||||
// .Returns((int id, UmbracoObjectTypes objType) =>
|
||||
// {
|
||||
// switch (id)
|
||||
// {
|
||||
// case Constants.DataTypes.Textbox:
|
||||
// return Attempt.Succeed(Constants.DataTypes.Guids.TextstringGuid);
|
||||
// case Constants.DataTypes.RichtextEditor:
|
||||
// return Attempt.Succeed(Constants.DataTypes.Guids.RichtextEditorGuid);
|
||||
// }
|
||||
// return Attempt.Fail<Guid>();
|
||||
// });
|
||||
//
|
||||
//
|
||||
// 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("text");
|
||||
//
|
||||
// Composition.RegisterUnique(f => Mock.Of<IContentService>());
|
||||
// Composition.RegisterUnique(f => Mock.Of<IContentTypeService>());
|
||||
// Composition.RegisterUnique(f => userServiceMock.Object);
|
||||
// Composition.RegisterUnique(f => entityService.Object);
|
||||
// Composition.RegisterUnique(f => dataTypeService.Object);
|
||||
// Composition.RegisterUnique(f => langService.Object);
|
||||
// Composition.RegisterUnique(f => textService.Object);
|
||||
// Composition.RegisterUnique(f => Mock.Of<ICultureDictionaryFactory>());
|
||||
// Composition.RegisterUnique(f => new UmbracoApiControllerTypeCollection(new Type[] { }));
|
||||
// }
|
||||
//
|
||||
// private MultipartFormDataContent GetMultiPartRequestContent(string json)
|
||||
// {
|
||||
// var multiPartBoundary = "----WebKitFormBoundary123456789";
|
||||
// return new MultipartFormDataContent(multiPartBoundary)
|
||||
// {
|
||||
// new StringContent(json)
|
||||
// {
|
||||
// Headers =
|
||||
// {
|
||||
// ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
||||
// {
|
||||
// Name = "contentItem"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// private IContentType GetMockedContentType()
|
||||
// {
|
||||
// var contentType = MockedContentTypes.CreateSimpleContentType();
|
||||
// //ensure things have ids
|
||||
// var ids = 888;
|
||||
// foreach (var g in contentType.CompositionPropertyGroups)
|
||||
// {
|
||||
// g.Id = ids;
|
||||
// ids++;
|
||||
// }
|
||||
// foreach (var p in contentType.CompositionPropertyGroups)
|
||||
// {
|
||||
// p.Id = ids;
|
||||
// ids++;
|
||||
// }
|
||||
//
|
||||
// return contentType;
|
||||
// }
|
||||
//
|
||||
// private IContent GetMockedContent()
|
||||
// {
|
||||
// if (_contentTypeForMockedContent == null)
|
||||
// {
|
||||
// _contentTypeForMockedContent = GetMockedContentType();
|
||||
// Mock.Get(ServiceContext.ContentTypeService)
|
||||
// .Setup(x => x.Get(_contentTypeForMockedContent.Id))
|
||||
// .Returns(_contentTypeForMockedContent);
|
||||
// Mock.Get(ServiceContext.ContentTypeService)
|
||||
// .As<IContentTypeBaseService>()
|
||||
// .Setup(x => x.Get(_contentTypeForMockedContent.Id))
|
||||
// .Returns(_contentTypeForMockedContent);
|
||||
// }
|
||||
//
|
||||
// var content = MockedContent.CreateSimpleContent(_contentTypeForMockedContent);
|
||||
// content.Id = 123;
|
||||
// content.Path = "-1,123";
|
||||
// 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 CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
// {
|
||||
// var contentServiceMock = Mock.Get(ServiceContext.ContentService);
|
||||
// contentServiceMock.Setup(x => x.GetById(123)).Returns(() => null); //do not find it
|
||||
//
|
||||
// var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
//
|
||||
// var controller = new ContentController(
|
||||
// Factory.GetInstance<ICultureDictionary>(),
|
||||
// propertyEditorCollection,
|
||||
// Factory.GetInstance<IGlobalSettings>(),
|
||||
// umbracoContextAccessor,
|
||||
// Factory.GetInstance<ISqlContext>(),
|
||||
// Factory.GetInstance<ServiceContext>(),
|
||||
// Factory.GetInstance<AppCaches>(),
|
||||
// Factory.GetInstance<IProfilingLogger>(),
|
||||
// Factory.GetInstance<IRuntimeState>(),
|
||||
// ShortStringHelper,
|
||||
// Factory.GetInstance<UmbracoMapper>(),
|
||||
// Factory.GetInstance<IPublishedUrlProvider>());
|
||||
//
|
||||
// return controller;
|
||||
// }
|
||||
//
|
||||
// var runner = new TestRunner(CtrlFactory);
|
||||
// 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 CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
// {
|
||||
// var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
// var controller = new ContentController(
|
||||
// Factory.GetInstance<ICultureDictionary>(),
|
||||
// propertyEditorCollection,
|
||||
// Factory.GetInstance<IGlobalSettings>(),
|
||||
// umbracoContextAccessor,
|
||||
// Factory.GetInstance<ISqlContext>(),
|
||||
// Factory.GetInstance<ServiceContext>(),
|
||||
// Factory.GetInstance<AppCaches>(),
|
||||
// Factory.GetInstance<IProfilingLogger>(),
|
||||
// Factory.GetInstance<IRuntimeState>(),
|
||||
// ShortStringHelper,
|
||||
// Factory.GetInstance<UmbracoMapper>(),
|
||||
// Factory.GetInstance<IPublishedUrlProvider>());
|
||||
//
|
||||
// return controller;
|
||||
// }
|
||||
//
|
||||
// var json = JsonConvert.DeserializeObject<JObject>(PublishJsonInvariant);
|
||||
// //remove all save flaggs
|
||||
// ((JArray)json["variants"])[0]["save"] = false;
|
||||
//
|
||||
// var runner = new TestRunner(CtrlFactory);
|
||||
// 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 CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
// {
|
||||
// var contentServiceMock = Mock.Get(ServiceContext.ContentService);
|
||||
// contentServiceMock.Setup(x => x.GetById(123)).Returns(() => GetMockedContent());
|
||||
//
|
||||
// var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
// var controller = new ContentController(
|
||||
// Factory.GetInstance<ICultureDictionary>(),
|
||||
// propertyEditorCollection,
|
||||
// Factory.GetInstance<IGlobalSettings>(),
|
||||
// umbracoContextAccessor,
|
||||
// Factory.GetInstance<ISqlContext>(),
|
||||
// Factory.GetInstance<ServiceContext>(),
|
||||
// Factory.GetInstance<AppCaches>(),
|
||||
// Factory.GetInstance<IProfilingLogger>(),
|
||||
// Factory.GetInstance<IRuntimeState>(),
|
||||
// ShortStringHelper,
|
||||
// Factory.GetInstance<UmbracoMapper>(),
|
||||
// Factory.GetInstance<IPublishedUrlProvider>());
|
||||
//
|
||||
// return controller;
|
||||
// }
|
||||
//
|
||||
// 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(CtrlFactory);
|
||||
// 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 CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
// {
|
||||
// var contentServiceMock = Mock.Get(ServiceContext.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 propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
// var controller = new ContentController(
|
||||
// Factory.GetInstance<ICultureDictionary>(),
|
||||
// propertyEditorCollection,
|
||||
// Factory.GetInstance<IGlobalSettings>(),
|
||||
// umbracoContextAccessor,
|
||||
// Factory.GetInstance<ISqlContext>(),
|
||||
// Factory.GetInstance<ServiceContext>(),
|
||||
// Factory.GetInstance<AppCaches>(),
|
||||
// Factory.GetInstance<IProfilingLogger>(),
|
||||
// Factory.GetInstance<IRuntimeState>(),
|
||||
// ShortStringHelper,
|
||||
// Factory.GetInstance<UmbracoMapper>(),
|
||||
// Factory.GetInstance<IPublishedUrlProvider>());
|
||||
//
|
||||
// return controller;
|
||||
// }
|
||||
//
|
||||
// var runner = new TestRunner(CtrlFactory);
|
||||
// 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());
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public async Task PostSave_Validate_Empty_Name()
|
||||
// {
|
||||
// var content = GetMockedContent();
|
||||
//
|
||||
// ApiController CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
// {
|
||||
// var contentServiceMock = Mock.Get(ServiceContext.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 propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
// var controller = new ContentController(
|
||||
// Factory.GetInstance<ICultureDictionary>(),
|
||||
// propertyEditorCollection,
|
||||
// Factory.GetInstance<IGlobalSettings>(),
|
||||
// umbracoContextAccessor,
|
||||
// Factory.GetInstance<ISqlContext>(),
|
||||
// Factory.GetInstance<ServiceContext>(),
|
||||
// Factory.GetInstance<AppCaches>(),
|
||||
// Factory.GetInstance<IProfilingLogger>(),
|
||||
// Factory.GetInstance<IRuntimeState>(),
|
||||
// ShortStringHelper,
|
||||
// Factory.GetInstance<UmbracoMapper>(),
|
||||
// Factory.GetInstance<IPublishedUrlProvider>()
|
||||
// );
|
||||
//
|
||||
// return controller;
|
||||
// }
|
||||
//
|
||||
// //clear out the name
|
||||
// var json = JsonConvert.DeserializeObject<JObject>(PublishJsonInvariant);
|
||||
// json["variants"].ElementAt(0)["name"] = null;
|
||||
//
|
||||
// var runner = new TestRunner(CtrlFactory);
|
||||
// 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 CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
// {
|
||||
// var contentServiceMock = Mock.Get(ServiceContext.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 propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
|
||||
// var controller = new ContentController(
|
||||
// Factory.GetInstance<ICultureDictionary>(),
|
||||
// propertyEditorCollection,
|
||||
// Factory.GetInstance<IGlobalSettings>(),
|
||||
// umbracoContextAccessor,
|
||||
// Factory.GetInstance<ISqlContext>(),
|
||||
// Factory.GetInstance<ServiceContext>(),
|
||||
// Factory.GetInstance<AppCaches>(),
|
||||
// Factory.GetInstance<IProfilingLogger>(),
|
||||
// Factory.GetInstance<IRuntimeState>(),
|
||||
// ShortStringHelper,
|
||||
// Factory.GetInstance<UmbracoMapper>(),
|
||||
// Factory.GetInstance<IPublishedUrlProvider>()
|
||||
// );
|
||||
//
|
||||
// return controller;
|
||||
// }
|
||||
//
|
||||
// //clear out one of the names
|
||||
// var json = JsonConvert.DeserializeObject<JObject>(PublishJsonVariant);
|
||||
// json["variants"].ElementAt(0)["name"] = null;
|
||||
//
|
||||
// var runner = new TestRunner(CtrlFactory);
|
||||
// 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_null_"));
|
||||
// }
|
||||
//
|
||||
// // TODO: There are SOOOOO many more tests we should write - a lot of them to do with validation
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -15,6 +15,12 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// This method determine ambiguous controller actions by making a tryparse of the string (from request) into the type of the argument.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By using this methods you are allowed to to have multiple controller actions named equally. E.g. GetById(Guid id), GetById(int id),...
|
||||
/// </remarks>
|
||||
public class DetermineAmbiguousActionByPassingParameters : ActionMethodSelectorAttribute
|
||||
{
|
||||
private string _requestBody = null;
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
//[FilterAllowedOutgoingMedia(typeof(IEnumerable<MediaItemDisplay>))] // TODO introduce when moved to .NET Core
|
||||
[FilterAllowedOutgoingMedia(typeof(IEnumerable<MediaItemDisplay>))]
|
||||
public IEnumerable<MediaItemDisplay> GetByIds([FromQuery]int[] ids)
|
||||
{
|
||||
var foundMedia = _mediaService.GetByIds(ids);
|
||||
@@ -259,7 +259,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
/// <summary>
|
||||
/// Returns the root media objects
|
||||
/// </summary>
|
||||
//[FilterAllowedOutgoingMedia(typeof(IEnumerable<ContentItemBasic<ContentPropertyBasic>>))] // TODO introduce when moved to .NET Core
|
||||
[FilterAllowedOutgoingMedia(typeof(IEnumerable<ContentItemBasic<ContentPropertyBasic>>))]
|
||||
public IEnumerable<ContentItemBasic<ContentPropertyBasic>> GetRootMedia()
|
||||
{
|
||||
// TODO: Add permissions check!
|
||||
|
||||
@@ -6,6 +6,9 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Filters
|
||||
{
|
||||
/// <summary>
|
||||
/// Applying this attribute to any controller will ensure that the parameter name (prefix) is not part of the validation error keys.
|
||||
/// </summary>
|
||||
public class PrefixlessBodyModelValidatorAttribute : TypeFilterAttribute
|
||||
{
|
||||
public PrefixlessBodyModelValidatorAttribute() : base(typeof(PrefixlessBodyModelValidatorFilter))
|
||||
|
||||
@@ -10,11 +10,11 @@ namespace Umbraco.Web.BackOffice.ModelBinders
|
||||
{
|
||||
internal class BlueprintItemBinder : ContentItemBinder
|
||||
{
|
||||
private readonly ContentService _contentService;
|
||||
private readonly IContentService _contentService;
|
||||
|
||||
public BlueprintItemBinder(IJsonSerializer jsonSerializer, UmbracoMapper umbracoMapper, IContentService contentService, IContentTypeService contentTypeService, IHostingEnvironment hostingEnvironment, ContentService contentService2) : base(jsonSerializer, umbracoMapper, contentService, contentTypeService, hostingEnvironment)
|
||||
public BlueprintItemBinder(IJsonSerializer jsonSerializer, UmbracoMapper umbracoMapper, IContentService contentService, IContentTypeService contentTypeService, IHostingEnvironment hostingEnvironment) : base(jsonSerializer, umbracoMapper, contentService, contentTypeService, hostingEnvironment)
|
||||
{
|
||||
_contentService = contentService2;
|
||||
_contentService = contentService;
|
||||
}
|
||||
|
||||
protected override IContent GetExisting(ContentItemSave model)
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
||||
<PackageReference Include="System.IO.Pipelines" Version="4.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace Umbraco.Web.Common.ApplicationModels
|
||||
ActionModelConventions = new List<IActionModelConvention>()
|
||||
{
|
||||
new ClientErrorResultFilterConvention(), // Ensures the responses without any body is converted into a simple json object with info instead of a string like "Status Code: 404; Not Found"
|
||||
//new InvalidModelStateFilterConvention(), // automatically 400 responses if ModelState is invalid before hitting the controller
|
||||
new ConsumesConstraintForFormFileParameterConvention(), // If an controller accepts files, it must accept multipart/form-data.
|
||||
new InferParameterBindingInfoConvention(modelMetadataProvider), // no need for [FromBody] everywhere, A complex type parameter is assigned to FromBody
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace Umbraco.Web.Common.Filters
|
||||
{
|
||||
public AngularJsonOnlyConfigurationAttribute() : base(typeof(AngularJsonOnlyConfigurationFilter))
|
||||
{
|
||||
Order = -2400;
|
||||
}
|
||||
|
||||
private class AngularJsonOnlyConfigurationFilter : IResultFilter
|
||||
|
||||
Reference in New Issue
Block a user