using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Web.Cache; namespace Umbraco.Tests.Cache { [TestFixture] [UmbracoTest(WithApplication = true)] public class CacheRefresherEventHandlerTests : UmbracoTestBase { [Test] public void Can_Find_All_Event_Handlers() { // fixme - cannot work with mocks // because the events are defined on actual static classes, not on the interfaces, so name matching fails // we should really refactor events entirely - in the meantime, let it be an UmbracoTestBase ;( //var testObjects = new TestObjects(null); //var serviceContext = testObjects.GetServiceContextMock(); var serviceContext = Current.Services; var definitions = new IEventDefinition[] { //I would test these but they are legacy events and we don't need them for deploy, when we migrate to new/better events we can wire up the check //Permission.New += PermissionNew; //Permission.Updated += PermissionUpdated; //Permission.Deleted += PermissionDeleted; //PermissionRepository.AssignedPermissions += CacheRefresherEventHandler_AssignedPermissions; new EventDefinition(null, serviceContext.ApplicationTreeService, new EventArgs(), "Deleted"), new EventDefinition(null, serviceContext.ApplicationTreeService, new EventArgs(), "Updated"), new EventDefinition(null, serviceContext.ApplicationTreeService, new EventArgs(), "New"), new EventDefinition(null, serviceContext.SectionService, new EventArgs(), "Deleted"), new EventDefinition(null, serviceContext.SectionService, new EventArgs(), "New"), new EventDefinition>(null, serviceContext.UserService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.UserService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.UserService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.UserService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.LocalizationService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.LocalizationService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.DataTypeService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.DataTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.FileService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.FileService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.DomainService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.DomainService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.LocalizationService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.LocalizationService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.ContentTypeService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.ContentTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MediaTypeService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MediaTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MemberTypeService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MemberTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.FileService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.FileService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MacroService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MacroService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MemberService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MemberService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MemberGroupService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MemberGroupService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MediaService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MediaService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.MediaService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Moved"), new EventDefinition>(null, serviceContext.MediaService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Trashed"), new EventDefinition(null, serviceContext.MediaService, new RecycleBinEventArgs(Guid.NewGuid(), new Dictionary>(), true)), new EventDefinition>(null, serviceContext.ContentService, new SaveEventArgs(Enumerable.Empty()), "Saved"), new EventDefinition>(null, serviceContext.ContentService, new DeleteEventArgs(Enumerable.Empty()), "Deleted"), // not managed //new EventDefinition>(null, serviceContext.ContentService, new SaveEventArgs(Enumerable.Empty()), "SavedBlueprint"), //new EventDefinition>(null, serviceContext.ContentService, new DeleteEventArgs(Enumerable.Empty()), "DeletedBlueprint"), new EventDefinition>(null, serviceContext.ContentService, new CopyEventArgs(null, null, -1)), new EventDefinition>(null, serviceContext.ContentService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Trashed"), new EventDefinition(null, serviceContext.ContentService, new RecycleBinEventArgs(Guid.NewGuid(), new Dictionary>(), true)), new EventDefinition>(null, serviceContext.ContentService, new PublishEventArgs(Enumerable.Empty()), "Published"), new EventDefinition>(null, serviceContext.ContentService, new PublishEventArgs(Enumerable.Empty()), "UnPublished"), new EventDefinition>(null, serviceContext.PublicAccessService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.PublicAccessService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.RelationService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.RelationService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.RelationService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.RelationService, new DeleteEventArgs(Enumerable.Empty())), }; var ok = true; foreach (var definition in definitions) { var found = CacheRefresherComponent.FindHandler(definition); if (found == null) { Console.WriteLine("Couldn't find method for " + definition.EventName + " on " + definition.Sender.GetType()); ok = false; } } Assert.IsTrue(ok, "see log for details"); } } }