2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-06-29 14:22:58 +02:00
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models.TemplateQuery;
|
2023-09-12 14:16:27 +02:00
|
|
|
using Umbraco.Cms.Tests.Common.Attributes;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.TestServerTest;
|
|
|
|
|
using Umbraco.Cms.Web.BackOffice.Controllers;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Formatters;
|
|
|
|
|
using Umbraco.Extensions;
|
2020-06-29 14:22:58 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Controllers;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TemplateQueryControllerTests : UmbracoTestServerTestBase
|
2020-06-29 14:22:58 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
2023-09-12 14:16:27 +02:00
|
|
|
[LongRunning]
|
2022-06-21 08:09:38 +02:00
|
|
|
public async Task GetContentTypes__Ensure_camel_case()
|
2020-06-29 14:22:58 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var url = PrepareApiControllerUrl<TemplateQueryController>(x => x.GetContentTypes());
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var response = await Client.GetAsync(url);
|
2020-06-29 14:22:58 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var body = await response.Content.ReadAsStringAsync();
|
2020-06-29 14:22:58 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
2020-06-29 14:22:58 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<ContentTypeModel[]>(body));
|
2020-06-29 14:22:58 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var jtokens = JsonConvert.DeserializeObject<JToken[]>(body);
|
|
|
|
|
foreach (var jToken in jtokens)
|
2020-06-29 14:22:58 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var alias = nameof(ContentTypeModel.Alias);
|
|
|
|
|
var camelCaseAlias = alias.ToCamelCase();
|
|
|
|
|
Assert.IsNotNull(jToken.Value<string>(camelCaseAlias), $"'{jToken}' do not contain the key '{camelCaseAlias}' in the expected casing");
|
|
|
|
|
Assert.IsNull(jToken.Value<string>(alias), $"'{jToken}' do contain the key '{alias}', which was not expect in that casing");
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-06-29 14:22:58 +02:00
|
|
|
}
|
|
|
|
|
}
|