Fixes pretty big issue with MediaType's not implementing the same IsDirty property check rules as ContentType when they should have shared the same rules. After removing caching on the unit tests, this bug became known.

This commit is contained in:
Shannon
2013-09-18 12:36:38 +10:00
parent 8fe7c0da9e
commit 23b7e94ce3
6 changed files with 75 additions and 75 deletions

View File

@@ -120,67 +120,7 @@ namespace Umbraco.Core.Models
return result;
}
/// <summary>
/// Indicates whether a specific property on the current <see cref="IContent"/> entity is dirty.
/// </summary>
/// <param name="propertyName">Name of the property to check</param>
/// <returns>True if Property is dirty, otherwise False</returns>
public override bool IsPropertyDirty(string propertyName)
{
bool existsInEntity = base.IsPropertyDirty(propertyName);
bool anyDirtyGroups = PropertyGroups.Any(x => x.IsPropertyDirty(propertyName));
bool anyDirtyTypes = PropertyTypes.Any(x => x.IsPropertyDirty(propertyName));
return existsInEntity || anyDirtyGroups || anyDirtyTypes;
}
/// <summary>
/// Indicates whether the current entity is dirty.
/// </summary>
/// <returns>True if entity is dirty, otherwise False</returns>
public override bool IsDirty()
{
bool dirtyEntity = base.IsDirty();
bool dirtyGroups = PropertyGroups.Any(x => x.IsDirty());
bool dirtyTypes = PropertyTypes.Any(x => x.IsDirty());
return dirtyEntity || dirtyGroups || dirtyTypes;
}
/// <summary>
/// Resets dirty properties by clearing the dictionary used to track changes.
/// </summary>
/// <remarks>
/// Please note that resetting the dirty properties could potentially
/// obstruct the saving of a new or updated entity.
/// </remarks>
public override void ResetDirtyProperties()
{
base.ResetDirtyProperties();
//loop through each property group to reset the property types
var propertiesReset = new List<int>();
foreach (var propertyGroup in PropertyGroups)
{
propertyGroup.ResetDirtyProperties();
foreach (var propertyType in propertyGroup.PropertyTypes)
{
propertyType.ResetDirtyProperties();
propertiesReset.Add(propertyType.Id);
}
}
//then loop through our property type collection since some might not exist on a property group
//but don't re-reset ones we've already done.
foreach (var propertyType in PropertyTypes.Where(x => propertiesReset.Contains(x.Id) == false))
{
propertyType.ResetDirtyProperties();
}
}
/// <summary>
/// Creates a clone of the current entity
/// </summary>

View File

@@ -503,5 +503,65 @@ namespace Umbraco.Core.Models
{
get { return _propertyTypes; }
}
/// <summary>
/// Indicates whether a specific property on the current <see cref="IContent"/> entity is dirty.
/// </summary>
/// <param name="propertyName">Name of the property to check</param>
/// <returns>True if Property is dirty, otherwise False</returns>
public override bool IsPropertyDirty(string propertyName)
{
bool existsInEntity = base.IsPropertyDirty(propertyName);
bool anyDirtyGroups = PropertyGroups.Any(x => x.IsPropertyDirty(propertyName));
bool anyDirtyTypes = PropertyTypes.Any(x => x.IsPropertyDirty(propertyName));
return existsInEntity || anyDirtyGroups || anyDirtyTypes;
}
/// <summary>
/// Indicates whether the current entity is dirty.
/// </summary>
/// <returns>True if entity is dirty, otherwise False</returns>
public override bool IsDirty()
{
bool dirtyEntity = base.IsDirty();
bool dirtyGroups = PropertyGroups.Any(x => x.IsDirty());
bool dirtyTypes = PropertyTypes.Any(x => x.IsDirty());
return dirtyEntity || dirtyGroups || dirtyTypes;
}
/// <summary>
/// Resets dirty properties by clearing the dictionary used to track changes.
/// </summary>
/// <remarks>
/// Please note that resetting the dirty properties could potentially
/// obstruct the saving of a new or updated entity.
/// </remarks>
public override void ResetDirtyProperties()
{
base.ResetDirtyProperties();
//loop through each property group to reset the property types
var propertiesReset = new List<int>();
foreach (var propertyGroup in PropertyGroups)
{
propertyGroup.ResetDirtyProperties();
foreach (var propertyType in propertyGroup.PropertyTypes)
{
propertyType.ResetDirtyProperties();
propertiesReset.Add(propertyType.Id);
}
}
//then loop through our property type collection since some might not exist on a property group
//but don't re-reset ones we've already done.
foreach (var propertyType in PropertyTypes.Where(x => propertiesReset.Contains(x.Id) == false))
{
propertyType.ResetDirtyProperties();
}
}
}
}

View File

@@ -212,18 +212,17 @@ namespace Umbraco.Tests.Persistence.Repositories
{
var contentType = repository.Get(1046);
// Act
var contentType2 = repository.Get(1046);
contentType2.PropertyGroups["Meta"].PropertyTypes.Remove("metaDescription");
repository.AddOrUpdate(contentType2);
// Act
contentType.PropertyGroups["Meta"].PropertyTypes.Remove("metaDescription");
repository.AddOrUpdate(contentType);
unitOfWork.Commit();
var contentType3 = repository.Get(1046);
var result = repository.Get(1046);
// Assert
Assert.That(contentType3.PropertyTypes.Any(x => x.Alias == "metaDescription"), Is.False);
Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(contentType3.PropertyGroups.Count));
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(contentType3.PropertyTypes.Count()));
Assert.That(result.PropertyTypes.Any(x => x.Alias == "metaDescription"), Is.False);
Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(result.PropertyGroups.Count));
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(result.PropertyTypes.Count()));
}
}

View File

@@ -206,8 +206,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Assert
Assert.That(mediaTypeV3.PropertyTypes.Any(x => x.Alias == "title"), Is.False);
Assert.That(mediaType.PropertyGroups.Count, Is.EqualTo(mediaTypeV3.PropertyGroups.Count));
Assert.That(mediaType.PropertyTypes.Count(), Is.EqualTo(mediaTypeV3.PropertyTypes.Count()));
Assert.That(mediaTypeV2.PropertyGroups.Count, Is.EqualTo(mediaTypeV3.PropertyGroups.Count));
Assert.That(mediaTypeV2.PropertyTypes.Count(), Is.EqualTo(mediaTypeV3.PropertyTypes.Count()));
}
}

View File

@@ -24,14 +24,14 @@ namespace Umbraco.Tests.Persistence.Repositories
}
[Test]
public void Can_Instantiate_Repository_From_Resolver()
public void Can_Instantiate_Repository()
{
// Arrange
var provider = new FileUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
// Act
var repository = RepositoryResolver.Current.ResolveByType<IScriptRepository>(unitOfWork);
var repository = new ScriptRepository(unitOfWork, _fileSystem);
// Assert
Assert.That(repository, Is.Not.Null);

View File

@@ -24,14 +24,15 @@ namespace Umbraco.Tests.Persistence.Repositories
}
[Test]
public void Can_Instantiate_Repository_From_Resolver()
public void Can_Instantiate_Repository()
{
// Arrange
var provider = new FileUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
// Act
var repository = RepositoryResolver.Current.ResolveByType<IStylesheetRepository>(unitOfWork);
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
// Assert
Assert.That(repository, Is.Not.Null);