diff --git a/src/Umbraco.Examine.Lucene/UmbracoContentIndex.cs b/src/Umbraco.Examine.Lucene/UmbracoContentIndex.cs index 70b44340bd..904bf68623 100644 --- a/src/Umbraco.Examine.Lucene/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine.Lucene/UmbracoContentIndex.cs @@ -21,7 +21,7 @@ namespace Umbraco.Examine /// public class UmbracoContentIndex : UmbracoExamineIndex, IUmbracoContentIndex { - + protected ILocalizationService LanguageService { get; } #region Constructors diff --git a/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs b/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs index b33a0ad69a..3a0ce39493 100644 --- a/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs +++ b/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.Testing // FIXME: to be completed /// - /// Gets or sets a value indicating ... + /// Gets or sets a value indicating ... /// public bool PublishedRepositoryEvents { get => _publishedRepositoryEvents.ValueOrDefault(false); set => _publishedRepositoryEvents.Set(value); } private readonly Settable _publishedRepositoryEvents = new Settable(); @@ -50,6 +50,10 @@ namespace Umbraco.Tests.Testing /// /// Default is to use the global tests plugin manager. public UmbracoTestOptions.TypeLoader TypeLoader { get => _typeLoader.ValueOrDefault(UmbracoTestOptions.TypeLoader.Default); set => _typeLoader.Set(value); } + public bool Boot { get => _boot.ValueOrDefault(true); set => _boot.Set(value); } + private readonly Settable _boot = new Settable(); + + private readonly Settable _typeLoader = new Settable(); protected override TestOptionAttributeBase Merge(TestOptionAttributeBase other) diff --git a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/BackOfficeAssetsControllerTests.cs b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/BackOfficeAssetsControllerTests.cs index ad7fcb7b53..7c9ab2daf3 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/BackOfficeAssetsControllerTests.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/BackOfficeAssetsControllerTests.cs @@ -7,7 +7,6 @@ using Umbraco.Web.BackOffice.Controllers; namespace Umbraco.Tests.Integration.TestServerTest.Controllers { [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class BackOfficeAssetsControllerTests: UmbracoTestServerTestBase { [Test] diff --git a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/ContentControllerTests.cs b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/ContentControllerTests.cs index 3da9168311..9a1b335c62 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/ContentControllerTests.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/ContentControllerTests.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Tests.Common.Builders; @@ -16,9 +17,7 @@ using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Tests.Integration.TestServerTest.Controllers { - [Explicit("We need to fix the tests on buildserver and when running multiple tests in one run")] [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class ContentControllerTests : UmbracoTestServerTestBase { @@ -150,7 +149,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers Assert.Multiple(() => { Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); - Assert.AreEqual(")]}',\n{\"message\":\"No variants flagged for saving\"}", body); + Assert.AreEqual(")]}',\n{\"Message\":\"No variants flagged for saving\"}", body); }); } diff --git a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/TemplateQueryControllerTests.cs b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/TemplateQueryControllerTests.cs index f2e4935a96..747e99191b 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/TemplateQueryControllerTests.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/TemplateQueryControllerTests.cs @@ -14,9 +14,7 @@ using Umbraco.Web.Models.TemplateQuery; namespace Umbraco.Tests.Integration.TestServerTest.Controllers { - [Explicit("We need to fix the tests on buildserver and when running multiple tests in one run")] [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class TemplateQueryControllerTests : UmbracoTestServerTestBase { [Test] @@ -43,7 +41,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers { var alias = nameof(ContentTypeModel.Alias); var camelCaseAlias = alias.ToCamelCase(); - Assert.IsNotNull(jToken.Value(camelCaseAlias), $"'{jToken}' do not contain the key '{camelCaseAlias}'"); + Assert.IsNotNull(jToken.Value(camelCaseAlias), $"'{jToken}' do not contain the key '{camelCaseAlias}' in the expected casing"); Assert.IsNull(jToken.Value(alias), $"'{jToken}' do contain the key '{alias}', which was not expect in that casing"); } }); diff --git a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/UsersControllerTests.cs b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/UsersControllerTests.cs index 07ba387b4d..7451740a15 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/Controllers/UsersControllerTests.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/Controllers/UsersControllerTests.cs @@ -22,9 +22,7 @@ using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Tests.Integration.TestServerTest.Controllers { - [Explicit("We need to fix the tests on buildserver and when running multiple tests in one run")] [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class UsersControllerTests : UmbracoTestServerTestBase { [Test] diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index d366ea49ee..9efbe976d3 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -11,6 +11,7 @@ using NUnit.Framework; using Umbraco.Composing; using Umbraco.Extensions; using Umbraco.Tests.Integration.Testing; +using Umbraco.Tests.Testing; using Umbraco.Web; using Umbraco.Web.Common.Controllers; using Umbraco.Web.Editors; @@ -19,6 +20,7 @@ using Umbraco.Web.Editors; namespace Umbraco.Tests.Integration.TestServerTest { [TestFixture] + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console, Boot = false)] public abstract class UmbracoTestServerTestBase : UmbracoIntegrationTest { [SetUp] @@ -29,7 +31,6 @@ namespace Umbraco.Tests.Integration.TestServerTest AllowAutoRedirect = false }); LinkGenerator = Factory.Services.GetRequiredService(); - } protected T GetRequiredService() => Factory.Services.GetRequiredService(); diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 86759a780e..62d6db0a8b 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -237,7 +237,7 @@ namespace Umbraco.Tests.Integration.Testing action(); return; } - catch (SqlException e) + catch (Exception e) { Console.Error.WriteLine($"SqlException occured, but we try again {i+1}/{maxIterations}.\n{e}"); diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 26df0bbfb0..6780744c3e 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using NUnit.Framework; using Umbraco.Core.Cache; using Umbraco.Core.Composing; @@ -18,7 +19,9 @@ using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Extensions; using Umbraco.Tests.Integration.Implementations; using Umbraco.Extensions; +using Umbraco.Tests.Testing; using Umbraco.Web; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Tests.Integration.Testing { @@ -98,6 +101,8 @@ namespace Umbraco.Tests.Integration.Testing { var umbracoContainer = GetUmbracoContainer(out var serviceProviderFactory); var testHelper = new TestHelper(); + // get the currently set db options + var testOptions = TestOptionAttributeBase.GetTestOptions(); var hostBuilder = new HostBuilder() .UseUmbraco(serviceProviderFactory) @@ -117,6 +122,9 @@ namespace Umbraco.Tests.Integration.Testing services.AddMvc(); + + services.AddSingleton(new ConsoleLogger(new MessageTemplates())); + CustomTestSetup(services); }); @@ -129,7 +137,10 @@ namespace Umbraco.Tests.Integration.Testing app.UseTestLocalDb(testHelper.WorkingDirectory, this, out var connectionString); TestDBConnectionString = connectionString; - app.UseUmbracoCore(); + if (testOptions.Boot) + { + app.UseUmbracoCore(); + } } diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 358378ca35..e3cb75a3dc 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -228,7 +228,7 @@ namespace Umbraco.Extensions factory = coreRuntime.Configure(container); return services; - } + } private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, ITypeFinderSettings typeFinderSettings) { diff --git a/src/Umbraco.Web.Common/Filters/AngularJsonOnlyConfigurationAttribute.cs b/src/Umbraco.Web.Common/Filters/AngularJsonOnlyConfigurationAttribute.cs index e185491f0e..d2e89c5a27 100644 --- a/src/Umbraco.Web.Common/Filters/AngularJsonOnlyConfigurationAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/AngularJsonOnlyConfigurationAttribute.cs @@ -2,6 +2,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; using Umbraco.Web.Common.Formatters; namespace Umbraco.Web.Common.Filters @@ -18,13 +21,11 @@ namespace Umbraco.Web.Common.Filters private class AngularJsonOnlyConfigurationFilter : IResultFilter { - private readonly IOptions _mvcNewtonsoftJsonOptions; private readonly ArrayPool _arrayPool; private readonly IOptions _options; - public AngularJsonOnlyConfigurationFilter(IOptions mvcNewtonsoftJsonOptions, ArrayPool arrayPool, IOptions options) + public AngularJsonOnlyConfigurationFilter(ArrayPool arrayPool, IOptions options) { - _mvcNewtonsoftJsonOptions = mvcNewtonsoftJsonOptions; _arrayPool = arrayPool; _options = options; } @@ -37,8 +38,14 @@ namespace Umbraco.Web.Common.Filters { if (context.Result is ObjectResult objectResult) { + var serializerSettings = new JsonSerializerSettings() + { + ContractResolver = new DefaultContractResolver(), + Converters = {new VersionConverter()} + }; + objectResult.Formatters.Clear(); - objectResult.Formatters.Add(new AngularJsonMediaTypeFormatter(_mvcNewtonsoftJsonOptions.Value.SerializerSettings, _arrayPool, _options.Value)); + objectResult.Formatters.Add(new AngularJsonMediaTypeFormatter(serializerSettings, _arrayPool, _options.Value)); } } } diff --git a/src/Umbraco.Web.Common/Formatters/AngularJsonMediaTypeFormatter.cs b/src/Umbraco.Web.Common/Formatters/AngularJsonMediaTypeFormatter.cs index bd79dd7c4e..d3e5882688 100644 --- a/src/Umbraco.Web.Common/Formatters/AngularJsonMediaTypeFormatter.cs +++ b/src/Umbraco.Web.Common/Formatters/AngularJsonMediaTypeFormatter.cs @@ -21,8 +21,7 @@ namespace Umbraco.Web.Common.Formatters public AngularJsonMediaTypeFormatter(JsonSerializerSettings serializerSettings, ArrayPool charPool, MvcOptions mvcOptions) : base(serializerSettings, charPool, mvcOptions) { - serializerSettings.Converters.Add(new VersionConverter()); - serializerSettings.ContractResolver = new DefaultContractResolver(); + } protected override JsonWriter CreateJsonWriter(TextWriter writer) diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index 0453c692df..317b556197 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -3,6 +3,7 @@ netcoreapp3.1 Umbraco.Web.UI.NetCore + latest