* Persist and expose Umbraco system dates as UTC (#19705) * Updated persistence DTOs defining default dates to use UTC. * Remove ForceToUtc = false from all persistence DTO attributes (default when not specified is true). * Removed use of SpecifyKind setting dates to local. * Removed unnecessary Utc suffixes on properties. * Persist current date time with UtcNow. * Removed further necessary Utc suffixes and fixed failing unit tests. * Added migration for SQL server to update database date default constraints. * Added comment justifying not providing a migration for SQLite default date constraints. * Ensure UTC for datetimes created from persistence DTOs. * Ensure UTC when creating dates for published content rendering in Razor and outputting in delivery API. * Fixed migration SQL syntax. * Introduced AuditItemFactory for creating entries for the backoffice document history, so we can control the UTC setting on the retrieved persisted dates. * Ensured UTC dates are retrieved for document versions. * Ensured UTC is returned for backoffice display of last edited and published for variant content. * Fixed SQLite syntax for default current datetime. * Apply suggestions from code review Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com> * Further updates from code review. --------- Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com> * Migrate system dates from local server time to UTC (#19798) * Add settings for the migration. * Add migration and implement for SQL server. * Implement for SQLite. * Fixes from testing with SQL Server. * Fixes from testing with SQLite. * Code tidy. * Cleaned up usings. * Removed audit log date from conversion. * Removed webhook log date from conversion. * Updated update date initialization on saving dictionary items. * Updated filter on log queries. * Use timezone ID instead of system name to work cross-culture. --------- Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>
95 lines
3.6 KiB
C#
95 lines
3.6 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
|
|
|
[TestFixture]
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
internal sealed class AuditEntryServiceTests : UmbracoIntegrationTest
|
|
{
|
|
[Test]
|
|
public async Task Write_and_GetAll()
|
|
{
|
|
var sut = (AuditEntryService)Services.GetRequiredService<IAuditEntryService>();
|
|
var expected = new AuditEntryBuilder()
|
|
.Build();
|
|
|
|
var result = await sut.WriteAsync(
|
|
expected.PerformingUserKey.Value,
|
|
expected.PerformingDetails,
|
|
expected.PerformingIp,
|
|
expected.EventDate,
|
|
expected.AffectedUserKey.Value,
|
|
expected.AffectedDetails,
|
|
expected.EventType,
|
|
expected.EventDetails);
|
|
Assert.NotNull(result);
|
|
|
|
var actual = result;
|
|
|
|
var entries = sut.GetAll().ToArray();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.AreEqual(expected.PerformingUserId, actual.PerformingUserId);
|
|
Assert.AreEqual(expected.PerformingUserKey, actual.PerformingUserKey);
|
|
Assert.AreEqual(expected.PerformingDetails, actual.PerformingDetails);
|
|
Assert.AreEqual(expected.EventDate, actual.EventDate);
|
|
Assert.AreEqual(expected.AffectedUserId, actual.AffectedUserId);
|
|
Assert.AreEqual(expected.AffectedUserKey, actual.AffectedUserKey);
|
|
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.PerformingUserKey, entries[0].PerformingUserKey);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Write_and_GetAll_With_Keys()
|
|
{
|
|
var sut = (AuditEntryService)Services.GetRequiredService<IAuditEntryService>();
|
|
var eventDateUtc = DateTime.UtcNow;
|
|
var result = await sut.WriteAsync(
|
|
Constants.Security.SuperUserKey,
|
|
"performingDetails",
|
|
"performingIp",
|
|
eventDateUtc,
|
|
null,
|
|
"affectedDetails",
|
|
"umbraco/test",
|
|
"eventDetails");
|
|
Assert.NotNull(result);
|
|
|
|
var actual = result;
|
|
|
|
var entries = sut.GetAll().ToArray();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.AreEqual(Constants.Security.SuperUserId, actual.PerformingUserId);
|
|
Assert.AreEqual(Constants.Security.SuperUserKey, actual.PerformingUserKey);
|
|
Assert.AreEqual("performingDetails", actual.PerformingDetails);
|
|
Assert.AreEqual("performingIp", actual.PerformingIp);
|
|
Assert.AreEqual(eventDateUtc, actual.EventDate);
|
|
Assert.AreEqual(Constants.Security.UnknownUserId, actual.AffectedUserId);
|
|
Assert.AreEqual(null, actual.AffectedUserKey);
|
|
Assert.AreEqual("affectedDetails", actual.AffectedDetails);
|
|
Assert.AreEqual("umbraco/test", actual.EventType);
|
|
Assert.AreEqual("eventDetails", actual.EventDetails);
|
|
Assert.IsNotNull(entries);
|
|
Assert.AreEqual(1, entries.Length);
|
|
Assert.AreEqual(Constants.Security.SuperUserId, entries[0].PerformingUserId);
|
|
});
|
|
}
|
|
}
|