Skip to content

Commit

Permalink
Code tweaks from PR review - also led to adding logging for Deseriali…
Browse files Browse the repository at this point in the history
…zation issues and therefore needing to mock the logger for the tests
  • Loading branch information
Jeavon committed Nov 13, 2019
1 parent 10622cc commit 88f6dde
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/Umbraco.Examine/MediaValueSetBuilder.cs
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.ValueConverters;
Expand All @@ -16,14 +17,16 @@ public class MediaValueSetBuilder : BaseValueSetBuilder<IMedia>
{
private readonly UrlSegmentProviderCollection _urlSegmentProviders;
private readonly IUserService _userService;
private readonly ILogger _logger;

public MediaValueSetBuilder(PropertyEditorCollection propertyEditors,
UrlSegmentProviderCollection urlSegmentProviders,
IUserService userService)
IUserService userService, ILogger logger)
: base(propertyEditors, false)
{
_urlSegmentProviders = urlSegmentProviders;
_userService = userService;
_logger = logger;
}

/// <inheritdoc />
Expand All @@ -40,7 +43,17 @@ public override IEnumerable<ValueSet> GetValueSets(params IMedia[] media)

if (umbracoFileSource.DetectIsJson())
{
var cropper = JsonConvert.DeserializeObject<ImageCropperValue>(m.GetValue<string>(Constants.Conventions.Media.File));
ImageCropperValue cropper = null;
try
{
cropper = JsonConvert.DeserializeObject<ImageCropperValue>(
m.GetValue<string>(Constants.Conventions.Media.File));
}
catch (Exception ex)
{
_logger.Error<MediaValueSetBuilder>(ex, $"Could not Deserialize ImageCropperValue for item with key {m.Key} ");
}

if (cropper != null)
{
umbracoFilePath = cropper.Src;
Expand Down
7 changes: 6 additions & 1 deletion src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs
Expand Up @@ -45,7 +45,7 @@ public static ContentIndexPopulator GetContentIndexRebuilder(PropertyEditorColle

public static MediaIndexPopulator GetMediaIndexRebuilder(PropertyEditorCollection propertyEditors, IMediaService mediaService)
{
var mediaValueSetBuilder = new MediaValueSetBuilder(propertyEditors, new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }), GetMockUserService());
var mediaValueSetBuilder = new MediaValueSetBuilder(propertyEditors, new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }), GetMockUserService(), GetMockLogger());
var mediaIndexDataSource = new MediaIndexPopulator(null, mediaService, mediaValueSetBuilder);
return mediaIndexDataSource;
}
Expand Down Expand Up @@ -146,6 +146,11 @@ public static IMediaTypeService GetMockMediaTypeService()
return mediaTypeServiceMock.Object;
}

public static IProfilingLogger GetMockLogger()
{
return new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>());
}

public static UmbracoContentIndex GetUmbracoIndexer(
IProfilingLogger profilingLogger,
Directory luceneDir,
Expand Down
3 changes: 1 addition & 2 deletions src/Umbraco.Web/Models/Mapping/EntityMapDefinition.cs
Expand Up @@ -177,9 +177,8 @@ private static void Map(ISearchResult source, SearchResultEntity target, MapperC

target.Name = source.Values.ContainsKey("nodeName") ? source.Values["nodeName"] : "[no name]";

if (source.Values.ContainsKey(UmbracoExamineIndex.UmbracoFileFieldName))
if (source.Values.TryGetValue(UmbracoExamineIndex.UmbracoFileFieldName, out var umbracoFile))
{
var umbracoFile = source.Values[UmbracoExamineIndex.UmbracoFileFieldName];
if (umbracoFile != null)
{
target.Name = $"{target.Name} ({umbracoFile})";
Expand Down

0 comments on commit 88f6dde

Please sign in to comment.