fixes tests

This commit is contained in:
Shannon
2018-07-31 12:19:12 +10:00
parent d3c45bc90f
commit 8517a8e088
3 changed files with 17 additions and 8 deletions

View File

@@ -156,8 +156,16 @@ namespace Umbraco.Core.Models
return value.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
case TagsStorageType.Json:
//fixme doesn't take into account variants
return JsonConvert.DeserializeObject<JArray>(property.GetValue().ToString()).Select(x => x.ToString().Trim());
try
{
//fixme doesn't take into account variants
return JsonConvert.DeserializeObject<JArray>(value).Select(x => x.ToString().Trim());
}
catch (JsonException)
{
//cannot parse, malformed
return Enumerable.Empty<string>();
}
default:
throw new NotSupportedException($"Value \"{storageType}\" is not a valid TagsStorageType.");

View File

@@ -1847,7 +1847,7 @@ namespace Umbraco.Tests.Services
object obj =
new
{
tags = "Hello,World"
tags = "[\"Hello\",\"World\"]"
};
var content1 = MockedContent.CreateBasicContent(contentType);
content1.PropertyValues(obj);
@@ -2006,13 +2006,13 @@ namespace Umbraco.Tests.Services
contentService.Save(content);
// value has been set but no tags have been created (not published)
Assert.AreEqual("hello,world", content.GetValue(propAlias));
Assert.AreEqual("[\"hello\",\"world\"]", content.GetValue(propAlias));
var contentTags = ServiceContext.TagService.GetTagsForEntity(content.Id).ToArray();
Assert.AreEqual(0, contentTags.Length);
// reloading the content yields the same result
content = (Content) contentService.GetById(content.Id);
Assert.AreEqual("hello,world", content.GetValue(propAlias));
Assert.AreEqual("[\"hello\",\"world\"]", content.GetValue(propAlias));
contentTags = ServiceContext.TagService.GetTagsForEntity(content.Id).ToArray();
Assert.AreEqual(0, contentTags.Length);
@@ -2020,7 +2020,7 @@ namespace Umbraco.Tests.Services
contentService.SaveAndPublish(content);
// now tags have been set (published)
Assert.AreEqual("hello,world", content.GetValue(propAlias));
Assert.AreEqual("[\"hello\",\"world\"]", content.GetValue(propAlias));
contentTags = ServiceContext.TagService.GetTagsForEntity(content.Id).ToArray();
Assert.AreEqual(2, contentTags.Length);
@@ -2028,7 +2028,7 @@ namespace Umbraco.Tests.Services
var copy = contentService.Copy(content, content.ParentId, false);
// copy is not published, so property has value, but no tags have been created
Assert.AreEqual("hello,world", copy.GetValue(propAlias));
Assert.AreEqual("[\"hello\",\"world\"]", copy.GetValue(propAlias));
var copiedTags = ServiceContext.TagService.GetTagsForEntity(copy.Id).ToArray();
Assert.AreEqual(0, copiedTags.Length);

View File

@@ -1,5 +1,6 @@
using System.Linq;
using System.Threading;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
@@ -52,7 +53,7 @@ namespace Umbraco.Tests.Services
// get it back
content1 = contentService.GetById(content1.Id);
var tagsValue = content1.GetValue("tags").ToString();
var tagsValues = tagsValue.Split(',');
var tagsValues = JsonConvert.DeserializeObject<string[]>(tagsValue);
Assert.AreEqual(3, tagsValues.Length);
Assert.Contains("pig", tagsValues);
Assert.Contains("goat", tagsValues);