Test + fix

This commit is contained in:
Elitsa Marinovska
2022-03-16 14:19:25 +01:00
parent 5d08caae8c
commit 5bebf98339
2 changed files with 24 additions and 5 deletions

View File

@@ -77,7 +77,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
public IEnumerable<IMacro> GetAllByAlias(string[] aliases)
{
if (aliases.Any() == false) return base.GetMany();
if (aliases.Any() == false)
{
return base.GetMany();
}
return _macroByAliasCachePolicy.GetAll(aliases, PerformGetAllByAlias);
}
@@ -90,9 +93,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
private IEnumerable<IMacro> PerformGetAllByAlias(params string[] aliases)
{
if (aliases.Any() == false) return base.GetMany();
if (aliases.Any() == false)
{
return base.GetMany();
}
var query = Query<IMacro>().WhereIn(x => x.Alias, aliases);
var query = Query<IMacro>().Where(x => aliases.Contains(x.Alias));
return PerformGetByQuery(query);
}

View File

@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
@@ -24,7 +23,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class MacroServiceTests : UmbracoIntegrationTest
{
private IMacroService MacroService => GetRequiredService<IMacroService>();
[Obsolete("After merging IMacroWithAliasService interface with IMacroService in Umbraco 11, this should go back to just being GetRequiredService<IMacroService>()")]
private IMacroWithAliasService MacroService => GetRequiredService<IMacroService>() as IMacroWithAliasService;
[SetUp]
public void SetupTest()
@@ -52,6 +52,19 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
Assert.AreEqual("Test1", macro.Name);
}
[Test]
public void Can_Get_By_Aliases()
{
// Act
IEnumerable<IMacro> macros = MacroService.GetAll("test1", "test2");
// Assert
Assert.IsNotNull(macros);
Assert.AreEqual(2, macros.Count());
Assert.AreEqual("Test1", macros.ToArray()[0].Name);
Assert.AreEqual("Test2", macros.ToArray()[1].Name);
}
[Test]
public void Can_Get_All()
{