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/Builders/AuditEntryBuilder.cs b/src/Umbraco.Tests.Common/Builders/AuditEntryBuilder.cs new file mode 100644 index 0000000000..cf31c2a14f --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/AuditEntryBuilder.cs @@ -0,0 +1,107 @@ +using System; +using System.Globalization; +using Umbraco.Core.Models; +using Umbraco.Tests.Common.Builders.Interfaces; + +namespace Umbraco.Tests.Common.Builders +{ + public class AuditEntryBuilder : AuditEntryBuilder + { + public AuditEntryBuilder() : base(null) + { + } + } + + public class AuditEntryBuilder + : ChildBuilderBase, + IWithIdBuilder, + IWithKeyBuilder, + IWithCreateDateBuilder, + IWithUpdateDateBuilder, + IWithDeleteDateBuilder + { + private DateTime? _createDate; + private DateTime? _deleteDate; + private int? _id; + private Guid? _key; + private DateTime? _updateDate; + private string _affectedDetails; + private int? _affectedUserId; + private string _eventDetails; + private string _eventType; + private string _performingDetails; + private string _performingIp; + private DateTime? _eventDateUtc; + private int? _performingUserId; + + public AuditEntryBuilder(TParent parentBuilder) : base(parentBuilder) + { + } + + DateTime? IWithCreateDateBuilder.CreateDate + { + get => _createDate; + set => _createDate = value; + } + + DateTime? IWithDeleteDateBuilder.DeleteDate + { + get => _deleteDate; + set => _deleteDate = value; + } + + int? IWithIdBuilder.Id + { + get => _id; + set => _id = value; + } + + Guid? IWithKeyBuilder.Key + { + get => _key; + set => _key = value; + } + + DateTime? IWithUpdateDateBuilder.UpdateDate + { + get => _updateDate; + set => _updateDate = value; + } + + + + public override IAuditEntry Build() + { + var id = _id ?? 0; + var key = _key ?? Guid.NewGuid(); + var createDate = _createDate ?? DateTime.Now; + var updateDate = _updateDate ?? DateTime.Now; + var deleteDate = _deleteDate ?? null; + var affectedDetails = _affectedDetails ?? Guid.NewGuid().ToString(); + var affectedUserId = _affectedUserId ?? -1; + var eventDetails = _eventDetails ?? Guid.NewGuid().ToString(); + var eventType = _eventType ?? "umbraco/user"; + var performingDetails = _performingDetails ?? Guid.NewGuid().ToString(); + var performingIp = _performingIp ?? "127.0.0.1"; + var eventDateUtc = _eventDateUtc ?? DateTime.UtcNow; + var performingUserId = _performingUserId ?? -1; + + return new AuditEntry + { + Id = id, + Key = key, + CreateDate = createDate, + UpdateDate = updateDate, + DeleteDate = deleteDate, + AffectedDetails = affectedDetails, + AffectedUserId = affectedUserId, + EventDetails = eventDetails, + EventType = eventType, + PerformingDetails = performingDetails, + PerformingIp = performingIp, + EventDateUtc = eventDateUtc, + PerformingUserId = performingUserId, + }; + } + } +} 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/Services/AuditServiceTests.cs b/src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs new file mode 100644 index 0000000000..9a0ba54082 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs @@ -0,0 +1,108 @@ +using System; +using System.Linq; +using Microsoft.Extensions.DependencyInjection; +using NUnit.Framework; +using Umbraco.Core.Models; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Integration.Testing; +using Umbraco.Tests.Testing; + +namespace Umbraco.Tests.Services +{ + [TestFixture] + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] + public class AuditServiceTests : UmbracoIntegrationTest + { + [Test] + public void GetPage() + { + var sut = (AuditService) GetRequiredService(); + var expected = new AuditEntryBuilder().Build(); + + + for (var i = 0; i < 10; i++) + { + sut.Write( + expected.PerformingUserId + i, + expected.PerformingDetails, + expected.PerformingIp, + expected.EventDateUtc.AddMinutes(i), + expected.AffectedUserId+ i, + expected.AffectedDetails, + expected.EventType, + expected.EventDetails); + } + + var entries = sut.GetPage(2, 2, out var count).ToArray(); + + Assert.Multiple(() => + { + Assert.AreEqual(2, entries.Length); + Assert.AreEqual(expected.PerformingUserId + 5, entries[0].PerformingUserId); + Assert.AreEqual(expected.PerformingUserId + 4, entries[1].PerformingUserId); + }); + } + + [Test] + public void GetUserLogs() + { + var sut = (AuditService) Services.GetRequiredService(); + + var eventDateUtc = DateTime.UtcNow.AddDays(-1); + + var numberOfEntries = 10; + for (var i = 0; i < numberOfEntries; i++) + { + eventDateUtc = eventDateUtc.AddMinutes(1); + sut.Add(AuditType.Unpublish, -1, 33, "", "blah"); + } + + sut.Add(AuditType.Publish, -1, 33, "", "blah"); + + var logs = sut.GetUserLogs(-1, AuditType.Unpublish).ToArray(); + + Assert.Multiple(() => + { + Assert.IsNotNull(logs); + CollectionAssert.AllItemsAreNotNull(logs); + Assert.AreEqual(numberOfEntries, logs.Length); + Assert.AreEqual(numberOfEntries, logs.Count(x => x.AuditType == AuditType.Unpublish)); + }); + } + + [Test] + public void Write_and_GetAll() + { + var sut = (AuditService) Services.GetRequiredService(); + var expected = new AuditEntryBuilder().Build(); + + var actual = sut.Write( + expected.PerformingUserId, + expected.PerformingDetails, + expected.PerformingIp, + expected.EventDateUtc, + expected.AffectedUserId, + expected.AffectedDetails, + expected.EventType, + expected.EventDetails); + + var entries = sut.GetAll().ToArray(); + + Assert.Multiple(() => + { + Assert.AreEqual(expected.PerformingUserId, actual.PerformingUserId); + Assert.AreEqual(expected.PerformingDetails, actual.PerformingDetails); + Assert.AreEqual(expected.EventDateUtc, actual.EventDateUtc); + Assert.AreEqual(expected.AffectedUserId, actual.AffectedUserId); + Assert.AreEqual(expected.AffectedDetails, actual.AffectedDetails); + Assert.AreEqual(expected.EventType, actual.EventType); + Assert.AreEqual(expected.EventDetails, actual.EventDetails); + Assert.IsNotNull(entries); + Assert.AreEqual(1, entries.Length); + Assert.AreEqual(expected.PerformingUserId, entries[0].PerformingUserId); + }); + } + } +} 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..a9a272ac59 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,8 @@ 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)] + [Explicit("Need to figure out whats wrong with these tests when executed all in one run.")] public class ContentControllerTests : UmbracoTestServerTestBase { @@ -150,7 +150,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..e2d66373ec 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] @@ -182,7 +180,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers var user = new UserBuilder() .AddUserGroup() - .WithAlias("writer") // Needs to be an existing alias + .WithAlias("writer") // Needs to be an existing alias .Done() .WithIsLockedOut(true, DateTime.UtcNow) .Build(); diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 66635c12ce..b666cc40f2 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(); - } /// diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoWebApplicationFactory.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoWebApplicationFactory.cs index d2f95a42cf..e74cb15ba0 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoWebApplicationFactory.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoWebApplicationFactory.cs @@ -53,7 +53,8 @@ namespace Umbraco.Tests.Integration.TestServerTest { x.AddInMemoryCollection(new Dictionary() { - ["ConnectionStrings:"+ Constants.System.UmbracoConnectionName] = _testDbConnectionString + ["ConnectionStrings:"+ Constants.System.UmbracoConnectionName] = _testDbConnectionString, + ["Umbraco:CMS:Hosting:Debug"] = "true", }); }); diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 86759a780e..9988362d3b 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -249,7 +249,6 @@ namespace Umbraco.Tests.Integration.Testing Debugger.Launch(); throw; } - } } } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 26df0bbfb0..89cbfa992d 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,10 +137,15 @@ namespace Umbraco.Tests.Integration.Testing app.UseTestLocalDb(testHelper.WorkingDirectory, this, out var connectionString); TestDBConnectionString = connectionString; - app.UseUmbracoCore(); + if (testOptions.Boot) + { + app.UseUmbracoCore(); + } } + protected T GetRequiredService() => Services.GetRequiredService(); + #region Common services protected string TestDBConnectionString { get; private set; } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj index 09a4558a84..ba986ebd86 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj +++ b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index adec2ac95a..568704583d 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -4,13 +4,12 @@ using AutoFixture.AutoMoq; using AutoFixture.Kernel; using AutoFixture.NUnit3; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; using Moq; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Web.BackOffice.Controllers; -namespace Umbraco.Tests.Common.AutoFixture +namespace Umbraco.Tests.UnitTests.AutoFixture { [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor)] public class AutoMoqDataAttribute : AutoDataAttribute diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerUnitTests.cs index f068108b90..4c038a58e6 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerUnitTests.cs @@ -1,11 +1,10 @@ using System.Threading; -using System.Threading.Tasks; using AutoFixture.NUnit3; using Microsoft.AspNetCore.Identity; using Moq; using NUnit.Framework; using Umbraco.Core.BackOffice; -using Umbraco.Tests.Common.AutoFixture; +using Umbraco.Tests.UnitTests.AutoFixture; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Common.Exceptions; @@ -15,7 +14,7 @@ namespace Umbraco.Tests.Web.Controllers public class UsersControllerUnitTests { [Test,AutoMoqData] - public async Task PostUnlockUsers_When_User_Lockout_Update_Fails_Expect_Failure_Response( + public void PostUnlockUsers_When_User_Lockout_Update_Fails_Expect_Failure_Response( [Frozen] IUserStore userStore, UsersController sut, BackOfficeIdentityUser user, diff --git a/src/Umbraco.Tests/Services/AuditServiceTests.cs b/src/Umbraco.Tests/Services/AuditServiceTests.cs deleted file mode 100644 index bfec246e61..0000000000 --- a/src/Umbraco.Tests/Services/AuditServiceTests.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Linq; -using NUnit.Framework; -using Umbraco.Core.Services.Implement; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.Testing; -using Umbraco.Core.Models; - -namespace Umbraco.Tests.Services -{ - [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] - public class AuditServiceTests : TestWithDatabaseBase - { - [Test] - public void CanCrudAuditEntry() - { - var yesterday = DateTime.UtcNow.AddDays(-1); - var entry = ServiceContext.AuditService.Write(123, "user 123, bob@example.com", null, yesterday, 456, "user 456, alice@example.com", "umbraco/user", "change property whatever value"); - Assert.AreEqual(123, entry.PerformingUserId); - Assert.AreEqual("user 123, bob@example.com", entry.PerformingDetails); - Assert.AreEqual(yesterday, entry.EventDateUtc); - Assert.AreEqual(456, entry.AffectedUserId); - Assert.AreEqual("user 456, alice@example.com", entry.AffectedDetails); - Assert.AreEqual("umbraco/user", entry.EventType); - Assert.AreEqual("change property whatever value", entry.EventDetails); - - var entries = ((AuditService)ServiceContext.AuditService).GetAll().ToArray(); - Assert.IsNotNull(entries); - Assert.AreEqual(1, entries.Length); - Assert.AreEqual(123, entries[0].PerformingUserId); - - for (var i = 0; i < 10; i++) - { - yesterday = yesterday.AddMinutes(1); - entry = ServiceContext.AuditService.Write(123 + i, "user 123, bob@example.com", null, yesterday, 456 + i, "user 456, alice@example.com", "umbraco/user", "change property whatever value"); - } - - // - // page 0 contains 123+9, 123+8 - // page 1 contains 123+7, 123+6 - // page 2 contains 123+5, 123+4 - // ... - - entries = ((AuditService)ServiceContext.AuditService).GetPage(2, 2, out var count).ToArray(); - - Assert.AreEqual(2, entries.Length); - - Assert.AreEqual(123 + 5, entries[0].PerformingUserId); - Assert.AreEqual(123 + 4, entries[1].PerformingUserId); - } - - [Test] - public void CanReadEntries() - { - var yesterday = DateTime.UtcNow.AddDays(-1); - - for (var i = 0; i < 10; i++) - { - yesterday = yesterday.AddMinutes(1); - ServiceContext.AuditService.Add(AuditType.Unpublish, -1, 33, "", "blah"); - } - - var logs = ServiceContext.AuditService.GetUserLogs(-1, AuditType.Unpublish); - } - } -} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 2ef0008873..3135ac0278 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -207,7 +207,6 @@ - diff --git a/src/Umbraco.Web.Common/Filters/AngularJsonOnlyConfigurationAttribute.cs b/src/Umbraco.Web.Common/Filters/AngularJsonOnlyConfigurationAttribute.cs index 122ed18857..05abe6cfbc 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 95ac728f82..b277b7de45 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