Fixed up remaining macro service tests

This commit is contained in:
Shannon
2013-09-18 14:05:00 +10:00
parent 67171db955
commit 2a143aec46
4 changed files with 34 additions and 11 deletions

View File

@@ -22,6 +22,10 @@ namespace Umbraco.Core.Services
/// <returns>An enumerable list of <see cref="IMacro"/> objects</returns>
IEnumerable<IMacro> GetAll(params string[] aliases);
IEnumerable<IMacro> GetAll(params int[] ids);
IMacro GetById(int id);
/// <summary>
/// Deletes an <see cref="IMacro"/>
/// </summary>

View File

@@ -6,6 +6,7 @@ using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
namespace Umbraco.Core.Services
@@ -61,19 +62,39 @@ namespace Umbraco.Core.Services
{
if (aliases.Any())
{
var q = new Query<IMacro>();
foreach (var alias in aliases)
{
q.Where(macro => macro.Alias == alias);
}
return repository.GetByQuery(q);
return GetAllByAliases(repository, aliases);
}
return repository.GetAll();
}
}
public IEnumerable<IMacro> GetAll(params int[] ids)
{
using (var repository = _repositoryFactory.CreateMacroRepository(_uowProvider.GetUnitOfWork()))
{
return repository.GetAll(ids);
}
}
public IMacro GetById(int id)
{
using (var repository = _repositoryFactory.CreateMacroRepository(_uowProvider.GetUnitOfWork()))
{
return repository.Get(id);
}
}
private IEnumerable<IMacro> GetAllByAliases(IMacroRepository repo, IEnumerable<string> aliases)
{
foreach (var alias in aliases)
{
var q = new Query<IMacro>();
q.Where(macro => macro.Alias == alias);
yield return repo.GetByQuery(q).FirstOrDefault();
}
}
/// <summary>
/// Deletes an <see cref="IMacro"/>
/// </summary>