예제 #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);
        }