Skip to content

Commit

Permalink
Merge branch 'release/2.1.0' into master
Browse files Browse the repository at this point in the history
# Conflicts:
#	appveyor.yml
  • Loading branch information
dawoe committed Dec 8, 2020
2 parents 5f26ca0 + c767bf9 commit 1d071a8
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 2 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
@@ -1,7 +1,7 @@
image: Visual Studio 2017

# Version format
version: 2.0.1.{build}
version: 2.1.0.{build}

branches:
only:
Expand Down Expand Up @@ -68,7 +68,7 @@ deploy:
- provider: NuGet
server:
api_key:
secure: nbR13qs8xp+iOGpuDFDsz7AtYFcltXswOXo9N8fhqx+oJoRdkzHk3pjubFbfO6dx
secure: f5ijMJdo8hygOHm+RRD4pCBcRqj6uw4AWqDgG4MvA1x5sgdmcuRxvdtN1Cn2NB6I
artifact: /.*\.nupkg/
on:
branch: master
Expand Down
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Our.Umbraco.Nexu.Parsers.Tests.Community
{
using System.Linq;

using global::Umbraco.Core;

using NUnit.Framework;

using Our.Umbraco.Nexu.Common.Constants;
using Our.Umbraco.Nexu.Parsers.Core;

[TestFixture]
public class SEOCheckerParserTests
{
[Test]
public void When_EditorAlias_Is_Not_Correct_IsParserFor_Should_Return_False()
{
// arrange
var parser = new SEOCheckerParser();

// act
var result = parser.IsParserFor(Constants.PropertyEditors.Aliases.Boolean);

// assert
Assert.IsFalse(result);
}

[Test]
public void When_EditorAlias_Is_Correct_IsParserFor_Should_Return_True()
{
// arrange
var parser = new SEOCheckerParser();

// act
var result = parser.IsParserFor("SEOChecker.SEOCheckerSocialPropertyEditor");

// assert
Assert.IsTrue(result);
}

[Test]
public void When_Value_Is_Not_Set_GetRelatedEntities_Return_Empty_List()
{
// arrange
var parser = new SEOCheckerParser();

// act
var result = parser.GetRelatedEntities(null).ToList();

// assert
Assert.IsNotNull(result);
Assert.That(result.Count == 0);
}

[Test]
public void When_Value_Is_Set_GetRelatedEntities_Return_List_With_Related_Entities()
{
// arrange
var seoCheckerXML =
"<SEOCheckerSocial><socialImage>umb://media/6f2d6d1d13a8438789b3cf0cced47344</socialImage><ogTitle></ogTitle><ogDescription></ogDescription><twitterTitle></twitterTitle> <twitterDescription></twitterDescription></SEOCheckerSocial>";

var parser = new SEOCheckerParser();

// act
var result = parser.GetRelatedEntities(seoCheckerXML).ToList();

// assert
Assert.IsNotNull(result);
Assert.That(result.Count == 1);
Assert.That(result.Count(x => x.RelationType == RelationTypes.DocumentToMedia) == 1);

Assert.That(result.Exists(x => x.RelatedEntityUdi.ToString() == "umb://media/6f2d6d1d13a8438789b3cf0cced47344"));
}
}
}
Expand Up @@ -191,6 +191,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Community\SEOCheckerParserTests.cs" />
<Compile Include="Core\ContentPickerParserTests.cs" />
<Compile Include="Core\GridParserTests.cs" />
<Compile Include="Core\MediaPickerParserTests.cs" />
Expand Down
64 changes: 64 additions & 0 deletions src/Our.Umbraco.Nexu.Parsers/Community/SEOCheckerParser.cs
@@ -0,0 +1,64 @@
using Our.Umbraco.Nexu.Parsers.Helpers;

namespace Our.Umbraco.Nexu.Parsers.Core
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using global::Umbraco.Core;

using Our.Umbraco.Nexu.Common.Interfaces.Models;
using Our.Umbraco.Nexu.Common.Models;

/// <summary>
/// Represents content picker parser.
/// </summary>
public class SEOCheckerParser : IPropertyValueParser
{
/// <inheritdoc />
public bool IsParserFor(string propertyEditorAlias)
{
return propertyEditorAlias.Equals("SEOChecker.SEOCheckerSocialPropertyEditor");
}

/// <inheritdoc />
public IEnumerable<IRelatedEntity> GetRelatedEntities(string value)
{
if (!string.IsNullOrWhiteSpace(value))
{
var entities = new List<IRelatedEntity>();
var model = XDocument.Parse(value).Root;
if (model != null)
{
try
{
var socialImage = model.Descendants("socialImage").FirstOrDefault();
if (socialImage == null)
{
return Enumerable.Empty<IRelatedEntity>();
}

if (string.IsNullOrEmpty(socialImage.Value))
{
return Enumerable.Empty<IRelatedEntity>();
}

foreach (var documentUdi in ParserUtilities.GetMediaUdiFromText(socialImage.Value).ToList())
{
entities.Add(new RelatedMediaEntity
{
RelatedEntityUdi = documentUdi,
});
}

return entities;
}
catch { }
}
}

return Enumerable.Empty<IRelatedEntity>();
}
}
}
10 changes: 10 additions & 0 deletions src/Our.Umbraco.Nexu.Parsers/Core/BlockListEditorParser.cs
@@ -0,0 +1,10 @@
namespace Our.Umbraco.Nexu.Parsers.Core
{
public class BlockListEditorParser : BaseTextParser
{
public override bool IsParserFor(string propertyEditorAlias)
{
return propertyEditorAlias.Equals("Umbraco.BlockList");
}
}
}
2 changes: 2 additions & 0 deletions src/Our.Umbraco.Nexu.Parsers/Our.Umbraco.Nexu.Parsers.csproj
Expand Up @@ -146,6 +146,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BaseTextParser.cs" />
<Compile Include="Community\SEOCheckerParser.cs" />
<Compile Include="Core\BlockListEditorParser.cs" />
<Compile Include="Core\ContentPickerParser.cs" />
<Compile Include="Core\GridParser.cs" />
<Compile Include="Core\MediaPickerParser.cs" />
Expand Down

0 comments on commit 1d071a8

Please sign in to comment.