Fixing issue in MacroRepository which was causing a test to fail.

Changing the alias of a macro property didn't alias work, so added a fallback to the Id of the property in the cases where the Alias wouldn't work.
This commit is contained in:
Morten Christensen
2014-06-27 12:42:15 +02:00
parent 48143bc0c3
commit 097014454f
2 changed files with 44 additions and 3 deletions

View File

@@ -188,10 +188,22 @@ namespace Umbraco.Core.Persistence.Repositories
}
else
{
//only update if it's dirty
if (macro.Properties[propDto.Alias].IsDirty())
//This will only work if the Alias hasn't been changed
if (macro.Properties.ContainsKey(propDto.Alias))
{
Database.Update(propDto);
//only update if it's dirty
if (macro.Properties[propDto.Alias].IsDirty())
{
Database.Update(propDto);
}
}
else
{
var property = macro.Properties.FirstOrDefault(x => x.Id == propDto.Id);
if (property != null && property.IsDirty())
{
Database.Update(propDto);
}
}
}
}

View File

@@ -150,6 +150,35 @@ namespace Umbraco.Tests.Services
}
[Test]
public void Can_Update_Remove_Property()
{
// Arrange
var macroService = ServiceContext.MacroService;
IMacro macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1"));
macro.Properties.Add(new MacroProperty("blah2", "Blah2", 1, "blah2"));
macro.Properties.Add(new MacroProperty("blah3", "Blah3", 2, "blah3"));
macroService.Save(macro);
// Act
macro.Properties["blah1"].Alias = "newAlias";
macro.Properties["blah1"].Name = "new Name";
macro.Properties["blah1"].SortOrder = 1;
macro.Properties["blah1"].EditorAlias = "new";
macro.Properties.Remove("blah3");
macroService.Save(macro);
macro = macroService.GetById(macro.Id);
//assert
Assert.AreEqual(2, macro.Properties.Count());
Assert.AreEqual("newAlias", macro.Properties["newAlias"].Alias);
Assert.AreEqual("new Name", macro.Properties["newAlias"].Name);
Assert.AreEqual(1, macro.Properties["newAlias"].SortOrder);
Assert.AreEqual("new", macro.Properties["newAlias"].EditorAlias);
}
[Test]
public void Can_Add_And_Remove_Properties()
{