public void GetHandlerActions_DiscoversActionsOnTypeWithBothActions() { // Arrange var actions = new HotReloadAgent.UpdateHandlerActions(); var log = new List <string>(); var agent = new HotReloadAgent(message => log.Add(message)); agent.GetHandlerActions(actions, typeof(HandlerWithBothActions)); Assert.Empty(log); Assert.Single(actions.ClearCache); Assert.Single(actions.UpdateApplication); }
public void GetHandlerActions_LogsMessageIfMethodHasIncorrectSignature() { // Arrange var actions = new HotReloadAgent.UpdateHandlerActions(); var log = new List <string>(); var agent = new HotReloadAgent(message => log.Add(message)); var handlerType = typeof(HandlerWithIncorrectSignature); agent.GetHandlerActions(actions, handlerType); var message = Assert.Single(log); Assert.Equal($"Type '{handlerType}' has method 'Void ClearCache()' that does not match the required signature.", message); Assert.Empty(actions.ClearCache); Assert.Single(actions.UpdateApplication); }
public void GetHandlerActions_LogsMessageIfNoActionsAreDiscovered() { // Arrange var actions = new HotReloadAgent.UpdateHandlerActions(); var log = new List <string>(); var agent = new HotReloadAgent(message => log.Add(message)); var handlerType = typeof(HandlerWithNoActions); agent.GetHandlerActions(actions, handlerType); var message = Assert.Single(log); Assert.Equal($"No invokable methods found on metadata handler type '{handlerType}'. " + $"Allowed methods are ClearCache, UpdateApplication", message); Assert.Empty(actions.ClearCache); Assert.Empty(actions.UpdateApplication); }
public void WebAssemblyHotReload_DiscoversMetadataHandlers_FromHot() { // Arrange var hotReloadManager = typeof(Renderer).Assembly.GetType("Microsoft.AspNetCore.Components.HotReload.HotReloadManager"); Assert.NotNull(hotReloadManager); var handlerActions = new HotReloadAgent.UpdateHandlerActions(); var logs = new List <string>(); var hotReloadAgent = new HotReloadAgent(logs.Add); // Act hotReloadAgent.GetHandlerActions(handlerActions, hotReloadManager); // Assert Assert.Empty(handlerActions.ClearCache); Assert.Single(handlerActions.UpdateApplication); }