* 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>
78 lines
2.5 KiB
C#
78 lines
2.5 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models;
|
|
|
|
[TestFixture]
|
|
public class TemplateTests
|
|
{
|
|
[SetUp]
|
|
public void SetUp() => _builder = new TemplateBuilder();
|
|
|
|
private TemplateBuilder _builder;
|
|
|
|
[Test]
|
|
public void Can_Deep_Clone()
|
|
{
|
|
var template = BuildTemplate();
|
|
|
|
var clone = (Template)template.DeepClone();
|
|
|
|
Assert.AreNotSame(clone, template);
|
|
Assert.AreEqual(clone, template);
|
|
Assert.AreEqual(clone.Path, template.Path);
|
|
Assert.AreEqual(clone.IsMasterTemplate, template.IsMasterTemplate);
|
|
Assert.AreEqual(clone.CreateDate, template.CreateDate);
|
|
Assert.AreEqual(clone.Alias, template.Alias);
|
|
Assert.AreEqual(clone.Id, template.Id);
|
|
Assert.AreEqual(clone.Key, template.Key);
|
|
Assert.AreEqual(clone.MasterTemplateAlias, template.MasterTemplateAlias);
|
|
Assert.AreEqual(clone.MasterTemplateId.Value, ((Template)template).MasterTemplateId.Value);
|
|
Assert.AreEqual(clone.Name, template.Name);
|
|
Assert.AreEqual(clone.UpdateDate, template.UpdateDate);
|
|
|
|
// clone.Content should be null but getting it would lazy-load
|
|
var type = clone.GetType();
|
|
var contentField = type.BaseType.GetField("_content", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
var value = contentField.GetValue(clone);
|
|
Assert.IsNull(value);
|
|
|
|
// this double verifies by reflection
|
|
// need to exclude content else it would lazy-load
|
|
var allProps = clone.GetType().GetProperties();
|
|
foreach (var propertyInfo in allProps.Where(x => x.Name != "Content"))
|
|
{
|
|
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(template, null));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Serialize_Without_Error()
|
|
{
|
|
var template = BuildTemplate();
|
|
|
|
var json = JsonSerializer.Serialize(template);
|
|
Debug.Print(json);
|
|
}
|
|
|
|
private ITemplate BuildTemplate() =>
|
|
_builder
|
|
.WithId(3)
|
|
.WithAlias("test")
|
|
.WithName("Test")
|
|
.WithCreateDate(DateTime.UtcNow)
|
|
.WithUpdateDate(DateTime.UtcNow)
|
|
.WithKey(Guid.NewGuid())
|
|
.WithContent("blah")
|
|
.AsMasterTemplate("master", 88)
|
|
.Build();
|
|
}
|