public void TryRegisterFaultedPlugins_RecoversFaultedPluginRegistrations() { var pluginType = typeof(MessageBrokerCreationTestPlugin); var typeNameLookups = new Dictionary <string, Type> { { pluginType.FullName, pluginType } }; var testAssembly = new TestAssembly(typeNameLookups); var assemblyLookups = new Dictionary <string, Assembly> { { "CustomAssembly", testAssembly } }; var assemblyLoadContext = new FailureAssemblyLoadContext(assemblyLookups); var creationChecker = new PluginTypeCreationChecker(); var serviceLookups = new Dictionary <Type, object> { { typeof(PluginTypeCreationChecker), creationChecker } }; var serviceProvider = new TestServiceProvider(serviceLookups); object rawMessageBrokerData = null; var pluginHandler = new PluginHandler(serviceProvider, (data) => rawMessageBrokerData = data); var registerPluginMessage = new PluginMessage { Data = new JObject { { "AssemblyName", "CustomAssembly" }, { "TypeName", typeof(MessageBrokerCreationTestPlugin).FullName }, }, MessageName = "RegisterPlugin", PluginId = RandomGuidId }; pluginHandler.OnReceive(registerPluginMessage); pluginHandler.ProcessMessages(assemblyLoadContext); var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawMessageBrokerData); Assert.Equal(RandomGuidId, messageBrokerData.PluginId); var responseMessage = Assert.IsType <RegisterPluginResponseMessage>(messageBrokerData.Data); Assert.False(responseMessage.Success); Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal); Assert.NotEmpty(responseMessage.Error); Assert.False(creationChecker.Created); pluginHandler.TryRegisterFaultedPlugins(assemblyLoadContext); messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawMessageBrokerData); Assert.Equal(RandomGuidId, messageBrokerData.PluginId); responseMessage = Assert.IsType <RegisterPluginResponseMessage>(messageBrokerData.Data); Assert.True(responseMessage.Success); Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal); Assert.Equal(1, responseMessage.Protocol); Assert.Null(responseMessage.Error); Assert.True(creationChecker.Created); }
public void TryRegisterFaultedPlugins_NoOpsWithoutMessagesEnqueued() { var assemblyLoadContext = CreateTestAssemblyLoadContext <CreationTestPlugin>(); var serviceProvider = new TestServiceProvider(); object rawMessageBrokerData = null; var pluginHandler = new PluginHandler(serviceProvider, (data) => rawMessageBrokerData = data); pluginHandler.TryRegisterFaultedPlugins(assemblyLoadContext); Assert.Null(rawMessageBrokerData); }