Skip to content

Commit

Permalink
Fixed failing integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyButland committed Dec 21, 2024
1 parent bf1e165 commit 1b86e7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
17 changes: 11 additions & 6 deletions tests/Umbraco.Tests.Common/Builders/DataTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public DataTypeBuilder WithDatabaseType(ValueStorageType databaseType)
return this;
}

public DataTypeBuilder WithConfigurationData(Dictionary<string, object> configurationData)
public DataTypeBuilder AddOrUpdateConfigurationDataValue(string key, object value)
{
_configurationData = configurationData;
_configurationData[key] = value;
return this;
}

Expand All @@ -143,9 +143,8 @@ public override DataType Build()
var databaseType = _databaseType ?? ValueStorageType.Ntext;
var sortOrder = _sortOrder ?? 0;
var serializer = new SystemTextConfigurationEditorJsonSerializer();
var configurationData = _configurationData;

return new DataType(editor, serializer, parentId)
var dataType = new DataType(editor, serializer, parentId)
{
Id = id,
Key = key,
Expand All @@ -158,8 +157,14 @@ public override DataType Build()
Path = path,
CreatorId = creatorId,
DatabaseType = databaseType,
SortOrder = sortOrder,
ConfigurationData = configurationData,
SortOrder = sortOrder
};

foreach (var item in _configurationData)
{
dataType.ConfigurationData[item.Key] = item.Value;
}

return dataType;

Check warning on line 168 in tests/Umbraco.Tests.Common/Builders/DataTypeBuilder.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

❌ Getting worse: Complex Method

Build increases in cyclomatic complexity from 13 to 14, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,7 @@ public void CanConvertDatePickerPropertyEditor(string date, bool expected)
[TestCase(null, true, true)]
public void CanConvertYesNoPropertyEditor(object value, bool? initialStateConfigurationValue, bool expected)
{
var dataTypeConfiguration = new Dictionary<string, object>();
if (initialStateConfigurationValue.HasValue)
{
dataTypeConfiguration.Add("default", initialStateConfigurationValue.Value);
}

var dataType = new DataTypeBuilder()
.WithConfigurationData(dataTypeConfiguration)
.Build();

var publishedDataType = new PublishedDataType(dataType.Id, dataType.EditorAlias, dataType.EditorUiAlias, new Lazy<object>(() => dataTypeConfiguration));
var publishedDataType = CreatePublishedDataType(initialStateConfigurationValue);

var publishedPropertyTypeMock = new Mock<IPublishedPropertyType>();
publishedPropertyTypeMock
Expand All @@ -90,6 +80,26 @@ public void CanConvertYesNoPropertyEditor(object value, bool? initialStateConfig
Assert.AreEqual(expected, result);
}

private static PublishedDataType CreatePublishedDataType(bool? initialStateConfigurationValue)
{
var dataTypeConfiguration = new Dictionary<string, object>();
if (initialStateConfigurationValue.HasValue)
{
dataTypeConfiguration.Add("default", initialStateConfigurationValue.Value);
}

var dataTypeBuilder = new DataTypeBuilder();

if (initialStateConfigurationValue.HasValue)
{
dataTypeBuilder = dataTypeBuilder.AddOrUpdateConfigurationDataValue("default", initialStateConfigurationValue.Value);
}

var dataType = dataTypeBuilder.Build();

return new PublishedDataType(dataType.Id, dataType.EditorAlias, dataType.EditorUiAlias, new Lazy<object>(() => dataTypeConfiguration));
}

[TestCase("[\"apples\"]", new[] { "apples" })]
[TestCase("[\"apples\",\"oranges\"]", new[] { "apples", "oranges" })]
[TestCase("[\"apples\",\"oranges\",\"pears\"]", new[] { "apples", "oranges", "pears" })]
Expand Down

0 comments on commit 1b86e7b

Please sign in to comment.