U4-8640 Deleting a content type with children only emits a deleted event on the parent content type

service now includes all deleted content types including children, in the DeletedContentType event arguments.
tests to ensure the correct number of deleted entities are sent in events.
This commit is contained in:
Claus
2016-06-22 19:30:31 +02:00
parent 980683d25a
commit b75578c889
2 changed files with 78 additions and 5 deletions

View File

@@ -803,10 +803,13 @@ namespace Umbraco.Core.Services
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
{
var deletedContentTypes = new List<IContentType>() {contentType};
deletedContentTypes.AddRange(contentType.Descendants().OfType<IContentType>());
repository.Delete(contentType);
uow.Commit();
DeletedContentType.RaiseEvent(new DeleteEventArgs<IContentType>(contentType, false), this);
DeletedContentType.RaiseEvent(new DeleteEventArgs<IContentType>(deletedContentTypes.DistinctBy(x => x.Id), false), this);
}
Audit(AuditType.Delete, string.Format("Delete ContentType performed by user"), userId, contentType.Id);
@@ -838,14 +841,18 @@ namespace Umbraco.Core.Services
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
{
var deletedContentTypes = new List<IContentType>();
deletedContentTypes.AddRange(asArray);
foreach (var contentType in asArray)
{
deletedContentTypes.AddRange(contentType.Descendants().OfType<IContentType>());
repository.Delete(contentType);
}
uow.Commit();
DeletedContentType.RaiseEvent(new DeleteEventArgs<IContentType>(asArray, false), this);
DeletedContentType.RaiseEvent(new DeleteEventArgs<IContentType>(deletedContentTypes.DistinctBy(x => x.Id), false), this);
}
Audit(AuditType.Delete, string.Format("Delete ContentTypes performed by user"), userId, -1);
@@ -1238,11 +1245,13 @@ namespace Umbraco.Core.Services
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
{
var deletedMediaTypes = new List<IMediaType>() {mediaType};
deletedMediaTypes.AddRange(mediaType.Descendants().OfType<IMediaType>());
repository.Delete(mediaType);
uow.Commit();
DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(mediaType, false), this);
DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(deletedMediaTypes.DistinctBy(x => x.Id), false), this);
}
Audit(AuditType.Delete, string.Format("Delete MediaType performed by user"), userId, mediaType.Id);
@@ -1271,13 +1280,17 @@ namespace Umbraco.Core.Services
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
{
var deletedMediaTypes = new List<IMediaType>();
deletedMediaTypes.AddRange(asArray);
foreach (var mediaType in asArray)
{
deletedMediaTypes.AddRange(mediaType.Descendants().OfType<IMediaType>());
repository.Delete(mediaType);
}
uow.Commit();
DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(asArray, false), this);
DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(deletedMediaTypes.DistinctBy(x => x.Id), false), this);
}
Audit(AuditType.Delete, string.Format("Delete MediaTypes performed by user"), userId, -1);

View File

@@ -7,7 +7,7 @@ using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Services;
using Umbraco.Tests.CodeFirst.TestModels.Composition;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
@@ -275,6 +275,66 @@ namespace Umbraco.Tests.Services
Assert.That(success, Is.False);
}
[Test]
public void Deleting_ContentType_Sends_Correct_Number_Of_DeletedEntities_In_Events()
{
var cts = ServiceContext.ContentTypeService;
var deletedEntities = 0;
var contentType = MockedContentTypes.CreateSimpleContentType("page", "Page");
cts.Save(contentType);
ContentTypeService.DeletedContentType += (sender, args) =>
{
deletedEntities += args.DeletedEntities.Count();
};
cts.Delete(contentType);
Assert.AreEqual(deletedEntities, 1);
}
[Test]
public void Deleting_Multiple_ContentTypes_Sends_Correct_Number_Of_DeletedEntities_In_Events()
{
var cts = ServiceContext.ContentTypeService;
var deletedEntities = 0;
var contentType = MockedContentTypes.CreateSimpleContentType("page", "Page");
cts.Save(contentType);
var contentType2 = MockedContentTypes.CreateSimpleContentType("otherPage", "Other page");
cts.Save(contentType2);
ContentTypeService.DeletedContentType += (sender, args) =>
{
deletedEntities += args.DeletedEntities.Count();
};
cts.Delete(contentType);
cts.Delete(contentType2);
Assert.AreEqual(deletedEntities, 2);
}
[Test]
public void Deleting_ContentType_With_Child_Sends_Correct_Number_Of_DeletedEntities_In_Events()
{
var cts = ServiceContext.ContentTypeService;
var deletedEntities = 0;
var contentType = MockedContentTypes.CreateSimpleContentType("page", "Page");
cts.Save(contentType);
var contentType2 = MockedContentTypes.CreateSimpleContentType("subPage", "Sub page");
contentType2.ParentId = contentType.Id;
cts.Save(contentType2);
ContentTypeService.DeletedContentType += (sender, args) =>
{
deletedEntities += args.DeletedEntities.Count();
};
cts.Delete(contentType);
Assert.AreEqual(deletedEntities, 2);
}
[Test]
public void Can_Remove_ContentType_Composition_From_ContentType()
{