From 8517a8e088800c5bb7dcec01b52a8902f19e556a Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 31 Jul 2018 12:19:12 +1000 Subject: [PATCH] fixes tests --- src/Umbraco.Core/Models/PropertyTagsExtensions.cs | 12 ++++++++++-- src/Umbraco.Tests/Services/ContentServiceTests.cs | 10 +++++----- src/Umbraco.Tests/Services/TagServiceTests.cs | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs index 3121da85bd..b0e0d0bd9c 100644 --- a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs +++ b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs @@ -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(property.GetValue().ToString()).Select(x => x.ToString().Trim()); + try + { + //fixme doesn't take into account variants + return JsonConvert.DeserializeObject(value).Select(x => x.ToString().Trim()); + } + catch (JsonException) + { + //cannot parse, malformed + return Enumerable.Empty(); + } default: throw new NotSupportedException($"Value \"{storageType}\" is not a valid TagsStorageType."); diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index d5003674af..0fcbb4b22c 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -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); diff --git a/src/Umbraco.Tests/Services/TagServiceTests.cs b/src/Umbraco.Tests/Services/TagServiceTests.cs index 49aad03efb..0665210430 100644 --- a/src/Umbraco.Tests/Services/TagServiceTests.cs +++ b/src/Umbraco.Tests/Services/TagServiceTests.cs @@ -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(tagsValue); Assert.AreEqual(3, tagsValues.Length); Assert.Contains("pig", tagsValues); Assert.Contains("goat", tagsValues);