diff --git a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs index 21acc5c543..978c81d169 100644 --- a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using NUnit.Framework; using Umbraco.Core.Models; @@ -64,5 +65,58 @@ namespace Umbraco.Tests.Services Assert.That(contentType.Alias, Is.EqualTo("umbTextpage")); Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(1)); } + + [Test] + public void DataTypeService_Can_Persist_Dictionary_Based_Pre_Values() + { + // Arrange + var dataTypeService = ServiceContext.DataTypeService; + var textfieldId = new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"); + + // Act + IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textfieldId) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.SaveDataTypeAndPreValues(dataTypeDefinition, new Dictionary + { + {"preVal1", new PreValue("Hello")}, + {"preVal2", new PreValue("World")} + }); + //re-get + dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + + // Assert + Assert.That(dataTypeDefinition, Is.Not.Null); + Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.AreEqual(true, preVals.IsDictionaryBased); + Assert.AreEqual(2, preVals.PreValuesAsDictionary.Keys.Count); + Assert.AreEqual("preVal1", preVals.PreValuesAsDictionary.Keys.First()); + Assert.AreEqual("preVal2", preVals.PreValuesAsDictionary.Keys.Last()); + Assert.AreEqual("Hello", preVals.PreValuesAsDictionary["preVal1"].Value); + Assert.AreEqual("World", preVals.PreValuesAsDictionary["preVal2"].Value); + } + + [Test] + public void DataTypeService_Can_Persist_Array_Based_Pre_Values() + { + // Arrange + var dataTypeService = ServiceContext.DataTypeService; + var textfieldId = new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"); + + // Act + IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textfieldId) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.Save(dataTypeDefinition); + dataTypeService.SavePreValues(dataTypeDefinition.Id, new[] {"preVal1", "preVal2"}); + + //re-get + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + + // Assert + Assert.That(dataTypeDefinition, Is.Not.Null); + Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.AreEqual(false, preVals.IsDictionaryBased); + Assert.AreEqual(2, preVals.PreValuesAsArray.Count()); + Assert.AreEqual("preVal1", preVals.PreValuesAsArray.First().Value); + Assert.AreEqual("preVal2", preVals.PreValuesAsArray.Last().Value); + } } } \ No newline at end of file