Files
Umbraco-CMS/tests/Umbraco.Tests.Common/Builders/PropertyGroupBuilder.cs
Andy Butland d623476902 Use UTC for system dates in Umbraco (#19822)
* 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>
2025-08-22 11:59:23 +02:00

152 lines
3.9 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
namespace Umbraco.Cms.Tests.Common.Builders;
public class PropertyGroupBuilder : PropertyGroupBuilder<NullPropertyGroupBuilderParent>
{
public PropertyGroupBuilder()
: base(null)
{
}
}
public class NullPropertyGroupBuilderParent : IBuildPropertyGroups
{
}
public class PropertyGroupBuilder<TParent>
: ChildBuilderBase<TParent, PropertyGroup>,
IBuildPropertyTypes,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithAliasBuilder,
IWithNameBuilder,
IWithSortOrderBuilder,
IWithSupportsPublishing
where TParent : IBuildPropertyGroups
{
private readonly List<PropertyTypeBuilder<PropertyGroupBuilder<TParent>>> _propertyTypeBuilders = new();
private string _alias;
private DateTime? _createDate;
private int? _id;
private Guid? _key;
private string _name;
private PropertyTypeCollection _propertyTypeCollection;
private int? _sortOrder;
private bool? _supportsPublishing;
private DateTime? _updateDate;
public PropertyGroupBuilder(TParent parentBuilder)
: base(parentBuilder)
{
}
string IWithAliasBuilder.Alias
{
get => _alias;
set => _alias = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
string IWithNameBuilder.Name
{
get => _name;
set => _name = value;
}
int? IWithSortOrderBuilder.SortOrder
{
get => _sortOrder;
set => _sortOrder = value;
}
bool? IWithSupportsPublishing.SupportsPublishing
{
get => _supportsPublishing;
set => _supportsPublishing = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
public PropertyGroupBuilder<TParent> WithPropertyTypeCollection(PropertyTypeCollection propertyTypeCollection)
{
_propertyTypeCollection = propertyTypeCollection;
return this;
}
public PropertyTypeBuilder<PropertyGroupBuilder<TParent>> AddPropertyType()
{
var builder = new PropertyTypeBuilder<PropertyGroupBuilder<TParent>>(this);
_propertyTypeBuilders.Add(builder);
return builder;
}
public override PropertyGroup Build()
{
var id = _id ?? 0;
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.UtcNow;
var updateDate = _updateDate ?? DateTime.UtcNow;
var alias = _alias ?? Guid.NewGuid().ToString();
var name = _name ?? Guid.NewGuid().ToString();
var sortOrder = _sortOrder ?? 0;
var supportsPublishing = _supportsPublishing ?? false;
PropertyTypeCollection propertyTypeCollection;
if (_propertyTypeCollection != null)
{
propertyTypeCollection = _propertyTypeCollection;
}
else
{
propertyTypeCollection = new PropertyTypeCollection(supportsPublishing);
foreach (var propertyType in _propertyTypeBuilders.Select(x => x.Build()))
{
propertyTypeCollection.Add(propertyType);
}
}
return new PropertyGroup(propertyTypeCollection)
{
Id = id,
Key = key,
Alias = alias,
Name = name,
SortOrder = sortOrder,
CreateDate = createDate,
UpdateDate = updateDate
};
}
}