Пример #1
0
 public PluginServiceProvider(
     IServiceProvider hostServices,
     PluginMessageBroker messageBroker)
 {
     _hostServices  = hostServices;
     _messageBroker = messageBroker;
 }
Пример #2
0
        public void SendMessage_CallsIntoSendMessageMethod()
        {
            var called = false;
            var pluginMessageBroker = 
                new PluginMessageBroker(pluginId: Guid.NewGuid().ToString(), sendMessageMethod: (_) => called = true);

            pluginMessageBroker.SendMessage(string.Empty);

            Assert.True(called);
        }
Пример #3
0
        public void SendMessage_CallsIntoSendMessageMethod()
        {
            var called = false;
            var pluginMessageBroker =
                new PluginMessageBroker(pluginId: Guid.NewGuid().ToString(), sendMessageMethod: (_) => called = true);

            pluginMessageBroker.SendMessage(string.Empty);

            Assert.True(called);
        }
Пример #4
0
        public void SendMessage_WrapsData()
        {
            object calledWithRaw = null;
            var expectedPluginId = "d81b8ad8-306d-474b-b8a9-b25c7f80be7e"; // Random, hardcoded GUID.
            var pluginMessageBroker = new PluginMessageBroker(
                expectedPluginId,
                sendMessageMethod: (data) => calledWithRaw = data);

            pluginMessageBroker.SendMessage("Hello World");

            Assert.NotNull(calledWithRaw);
            var calledWith = Assert.IsType<PluginMessageBroker.PluginMessageWrapperData>(calledWithRaw);
            Assert.Equal(expectedPluginId, calledWith.PluginId);
            Assert.Equal("Hello World", (string)calledWith.Data, StringComparer.Ordinal);
        }
Пример #5
0
        public void SendMessage_WrapsData()
        {
            object calledWithRaw       = null;
            var    expectedPluginId    = "d81b8ad8-306d-474b-b8a9-b25c7f80be7e"; // Random, hardcoded GUID.
            var    pluginMessageBroker = new PluginMessageBroker(
                expectedPluginId,
                sendMessageMethod: (data) => calledWithRaw = data);

            pluginMessageBroker.SendMessage("Hello World");

            Assert.NotNull(calledWithRaw);
            var calledWith = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(calledWithRaw);

            Assert.Equal(expectedPluginId, calledWith.PluginId);
            Assert.Equal("Hello World", (string)calledWith.Data, StringComparer.Ordinal);
        }
Пример #6
0
        public void ProcessMessages_RegisterPlugin_CreatesPluginWithCustomMessageBroker()
        {
            var    assemblyLoadContext  = CreateTestAssemblyLoadContext <MessageBrokerCreationTestPlugin>();
            var    creationChecker      = new PluginTypeCreationChecker();
            object rawMessageBrokerData = null;
            var    pluginMessageBroker  = new PluginMessageBroker(RandomGuidId, (data) => rawMessageBrokerData = data);
            var    serviceLookups       = new Dictionary <Type, object>
            {
                { typeof(PluginTypeCreationChecker), creationChecker },
                { typeof(IPluginMessageBroker), pluginMessageBroker }
            };
            var serviceProvider       = new TestServiceProvider(serviceLookups);
            var pluginHandler         = new PluginHandler(serviceProvider, (_) => { });
            var registerPluginMessage = new PluginMessage
            {
                Data = new JObject
                {
                    { "AssemblyName", "CustomAssembly" },
                    { "TypeName", typeof(MessageBrokerCreationTestPlugin).FullName },
                },
                MessageName = "RegisterPlugin",
                PluginId    = RandomGuidId
            };
            var pluginMessage = new PluginMessage
            {
                Data = new JObject
                {
                    { "Data", "Hello Plugin" },
                },
                MessageName = "PluginMessage",
                PluginId    = RandomGuidId
            };

            pluginHandler.OnReceive(registerPluginMessage);
            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            Assert.True(creationChecker.Created);
            Assert.NotNull(rawMessageBrokerData);
            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawMessageBrokerData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            Assert.Equal("Created", messageBrokerData.Data.ToString(), StringComparer.Ordinal);
        }
Пример #7
0
        private void SendMessage(string pluginId, PluginResponseMessage message)
        {
            var messageBroker = new PluginMessageBroker(pluginId, _sendMessageMethod);

            messageBroker.SendMessage(message);
        }
Пример #8
0
 public PluginServiceProvider(
     IServiceProvider hostServices,
     PluginMessageBroker messageBroker)
 {
     _hostServices = hostServices;
     _messageBroker = messageBroker;
 }
Пример #9
0
        private void SendMessage(string pluginId, PluginResponseMessage message)
        {
            var messageBroker = new PluginMessageBroker(pluginId, _sendMessageMethod);

            messageBroker.SendMessage(message);
        }