Adds fields to unit test model builder for data editors. (#10363)
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Moq;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.PropertyEditors;
|
||||
using Umbraco.Cms.Core.Serialization;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders
|
||||
{
|
||||
public class DataEditorBuilder<TParent> : ChildBuilderBase<TParent, IDataEditor>
|
||||
public class DataEditorBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, IDataEditor>,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder
|
||||
{
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private readonly ConfigurationEditorBuilder<DataEditorBuilder<TParent>> _explicitConfigurationEditorBuilder;
|
||||
private readonly DataValueEditorBuilder<DataEditorBuilder<TParent>> _explicitValueEditorBuilder;
|
||||
private IDictionary<string, object> _defaultConfiguration;
|
||||
@@ -39,6 +43,9 @@ namespace Umbraco.Cms.Tests.Common.Builders
|
||||
|
||||
public override IDataEditor Build()
|
||||
{
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var alias = _alias ?? name.ToCamelCase();
|
||||
|
||||
IDictionary<string, object> defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
|
||||
IConfigurationEditor explicitConfigurationEditor = _explicitConfigurationEditorBuilder.Build();
|
||||
IDataValueEditor explicitValueEditor = _explicitValueEditorBuilder.Build();
|
||||
@@ -46,10 +53,24 @@ namespace Umbraco.Cms.Tests.Common.Builders
|
||||
return new DataEditor(
|
||||
Mock.Of<IDataValueEditorFactory>())
|
||||
{
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
DefaultConfiguration = defaultConfiguration,
|
||||
ExplicitConfigurationEditor = explicitConfigurationEditor,
|
||||
ExplicitValueEditor = explicitValueEditor
|
||||
};
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
@@ -16,16 +17,31 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 3123;
|
||||
const string testEditorAlias = "testAlias";
|
||||
const string testEditorName = "Test Name";
|
||||
|
||||
var builder = new DataTypeBuilder();
|
||||
|
||||
// Act
|
||||
DataType dataType = builder
|
||||
.WithId(testId)
|
||||
.AddEditor()
|
||||
.WithAlias(testEditorAlias)
|
||||
.WithName(testEditorName)
|
||||
.WithDefaultConfiguration(new Dictionary<string, object>
|
||||
{
|
||||
{ "value1", "value1" },
|
||||
{ "value2", "value2" },
|
||||
})
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, dataType.Id);
|
||||
Assert.AreEqual(testEditorAlias, dataType.Editor.Alias);
|
||||
Assert.AreEqual(testEditorName, dataType.Editor.Name);
|
||||
Assert.AreEqual(2, dataType.Editor.DefaultConfiguration.Count);
|
||||
Assert.AreEqual("value1", dataType.Editor.DefaultConfiguration["value1"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user