using Moq; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; public abstract class BlockPropertyValueConverterTestsBase { protected abstract string PropertyEditorAlias { get; } protected const string ContentAlias1 = "Test1"; protected const string ContentAlias2 = "Test2"; protected const string SettingAlias1 = "Setting1"; protected const string SettingAlias2 = "Setting2"; protected Guid ContentKey1 { get; } = Guid.NewGuid(); protected Guid ContentKey2 { get; } = Guid.NewGuid(); protected Guid SettingKey1 { get; } = Guid.NewGuid(); protected Guid SettingKey2 { get; } = Guid.NewGuid(); /// /// Setup mocks for IPublishedSnapshotAccessor /// protected IPublishedSnapshotAccessor GetPublishedSnapshotAccessor() { var test1ContentType = Mock.Of(x => x.IsElement == true && x.Key == ContentKey1 && x.Alias == ContentAlias1); var test2ContentType = Mock.Of(x => x.IsElement == true && x.Key == ContentKey2 && x.Alias == ContentAlias2); var test3ContentType = Mock.Of(x => x.IsElement == true && x.Key == SettingKey1 && x.Alias == SettingAlias1); var test4ContentType = Mock.Of(x => x.IsElement == true && x.Key == SettingKey2 && x.Alias == SettingAlias2); var contentCache = new Mock(); contentCache.Setup(x => x.GetContentType(ContentKey1)).Returns(test1ContentType); contentCache.Setup(x => x.GetContentType(ContentKey2)).Returns(test2ContentType); contentCache.Setup(x => x.GetContentType(SettingKey1)).Returns(test3ContentType); contentCache.Setup(x => x.GetContentType(SettingKey2)).Returns(test4ContentType); var publishedSnapshot = Mock.Of(x => x.Content == contentCache.Object); var publishedSnapshotAccessor = Mock.Of(x => x.TryGetPublishedSnapshot(out publishedSnapshot)); return publishedSnapshotAccessor; } protected IPublishedPropertyType GetPropertyType(TPropertyEditorConfig config) { var dataType = new PublishedDataType(1, "test", new Lazy(() => config)); var propertyType = Mock.Of(x => x.EditorAlias == PropertyEditorAlias && x.DataType == dataType); return propertyType; } }