Fixes: U4-6770 When creating editorstyles: No stylesheet property found with name when creating headingstyles with capitals

This commit is contained in:
Shannon
2015-07-23 13:18:53 +02:00
parent f3d9b4a9f3
commit cd578b7b19
3 changed files with 29 additions and 8 deletions

View File

@@ -33,11 +33,11 @@ namespace Umbraco.Core.Models
//re-parse it so we can check what properties are different and adjust the event handlers
var parsed = StylesheetHelper.ParseRules(Content).ToArray();
var names = parsed.Select(x => x.Name).ToArray();
var existing = _properties.Value.Where(x => names.Contains(x.Name)).ToArray();
var existing = _properties.Value.Where(x => names.InvariantContains(x.Name)).ToArray();
//update existing
foreach (var stylesheetProperty in existing)
{
var updateFrom = parsed.Single(x => x.Name == stylesheetProperty.Name);
var updateFrom = parsed.Single(x => x.Name.InvariantEquals(stylesheetProperty.Name));
//remove current event handler while we update, we'll reset it after
stylesheetProperty.PropertyChanged -= Property_PropertyChanged;
stylesheetProperty.Alias = updateFrom.Selector;
@@ -46,14 +46,14 @@ namespace Umbraco.Core.Models
stylesheetProperty.PropertyChanged += Property_PropertyChanged;
}
//remove no longer existing
var nonExisting = _properties.Value.Where(x => names.Contains(x.Name) == false).ToArray();
var nonExisting = _properties.Value.Where(x => names.InvariantContains(x.Name) == false).ToArray();
foreach (var stylesheetProperty in nonExisting)
{
stylesheetProperty.PropertyChanged -= Property_PropertyChanged;
_properties.Value.Remove(stylesheetProperty);
}
//add new ones
var newItems = parsed.Where(x => _properties.Value.Select(p => p.Name).Contains(x.Name) == false);
var newItems = parsed.Where(x => _properties.Value.Select(p => p.Name).InvariantContains(x.Name) == false);
foreach (var stylesheetRule in newItems)
{
var prop = new StylesheetProperty(stylesheetRule.Name, stylesheetRule.Selector, stylesheetRule.Styles);
@@ -128,7 +128,7 @@ namespace Umbraco.Core.Models
/// <param name="property"></param>
public void AddProperty(StylesheetProperty property)
{
if (Properties.Any(x => x.Name == property.Name))
if (Properties.Any(x => x.Name.InvariantEquals(property.Name)))
{
throw new DuplicateNameException("The property with the name " + property.Name + " already exists in the collection");
}
@@ -151,7 +151,7 @@ namespace Umbraco.Core.Models
/// <param name="name"></param>
public void RemoveProperty(string name)
{
if (Properties.Any(x => x.Name == name))
if (Properties.Any(x => x.Name.InvariantEquals(name)))
{
Content = StylesheetHelper.ReplaceRule(Content, name, null);
}

View File

@@ -1,4 +1,5 @@
using System.IO;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using Moq;
@@ -118,6 +119,26 @@ p{font-size:2em;}"));
Assert.AreEqual(1, stylesheet.Properties.Count());
}
[Test]
public void Throws_When_Adding_Duplicate_Properties()
{
// Arrange
var provider = new FileUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
// Act
var stylesheet = new Stylesheet("test-update.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" };
repository.AddOrUpdate(stylesheet);
unitOfWork.Commit();
stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;"));
Assert.Throws<DuplicateNameException>(() => stylesheet.AddProperty(new StylesheetProperty("test", "p", "font-size:2em;")));
}
[Test]
public void Can_Perform_Delete()
{

View File

@@ -45,7 +45,7 @@ namespace umbraco.cms.presentation.settings.stylesheet
var propName = IsPostBack ? OriginalName.Value : Request.QueryString["prop"];
_stylesheetproperty = _sheet.Properties.FirstOrDefault(x => x.Name == propName);
_stylesheetproperty = _sheet.Properties.FirstOrDefault(x => x.Name.InvariantEquals(propName));
if (_stylesheetproperty == null) throw new InvalidOperationException("No stylesheet property found with name: " + Request.QueryString["prop"]);
Panel1.Text = ui.Text("stylesheet", "editstylesheetproperty", UmbracoUser);