private void Test(IRegisteredEventsPlugin plugin)
        {
            //
            // Arrange
            //
            TestInitializer.InitializeTestSettings();
            var contact = new Contact {
                MobilePhone = "A-1-B-2-C-3"
            };                                                                                                                       // Create Contact to use as target
            var context = new PluginExecutionContextBuilder().                                                                       // Create Context Which is required by the service provider, which is required by the plugin
                          WithRegisteredEvent(plugin.RegisteredEvents.First(e => e.EntityLogicalName == Contact.EntityLogicalName)). // Specifies the plugin event to use in the context
                          WithTarget(contact).Build();                                                                               // Sets the Target
            var provider = new ServiceProviderBuilder().
                           WithContext(context).Build();

            //
            // Act
            //
            plugin.Execute(provider); // Executes the Plugin

            //
            // Assert
            //

            Assert.AreEqual("123", contact.MobilePhone);
        }
Esempio n. 2
0
 // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
 private void AssertEventFound(IRegisteredEventsPlugin plugin, RegisteredEvent @event, string message)
 {
     if (@event == null)
     {
         throw new Exception($"Plugin {plugin.GetType().FullName} {message}  Unable to set the registered event of the context.");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Sets the first registered post operation event of the plugin for the context.
        /// </summary>
        /// <param name="plugin"></param>
        /// <returns></returns>
        public PluginExecutionContextBuilder WithFirstPostOpEvent(IRegisteredEventsPlugin plugin)
        {
            var first = plugin.RegisteredEvents.FirstOrDefault(e => (int)e.Stage == (int)PipelineStage.PostOperation);

            AssertEventFound(plugin, first, "does not contain any post operation registered events!");
            return(WithRegisteredEvent(first));
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the first registered event of the plugin for the context.
        /// </summary>
        /// <param name="plugin"></param>
        /// <returns></returns>
        public PluginExecutionContextBuilder WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin)
        {
            var first = plugin.RegisteredEvents.FirstOrDefault();

            AssertEventFound(plugin, first, "does not contain any registered events!");
            return(WithRegisteredEvent(first));
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the registered event for the context to the first registered event of the plugin. Throws an exception if more than one event is found.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Plugin  + plugin.GetType().FullName +  does not contain any registered events!  Unable to set the registered event of the context.</exception>
        public TDerived WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin)
        {
            if (!plugin.RegisteredEvents.Any())
            {
                throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
            }

            return(WithRegisteredEvent(plugin.RegisteredEvents.Single()));
        }
Esempio n. 6
0
 public ActionContext(IServiceProvider serviceProvider, IRegisteredEventsPlugin plugin) : base(serviceProvider, plugin)
 {
     Request = new TRequest
     {
         Parameters = PluginExecutionContext.InputParameters
     };
     Response = new TResponse
     {
         Results = PluginExecutionContext.OutputParameters
     };
 }
        public PluginExecutionContextBuilder WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin)
        {
            var first = plugin.RegisteredEvents.FirstOrDefault();

            if (first == null)
            {
                throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
            }

            return(WithRegisteredEvent(first));
        }
Esempio n. 8
0
 /// <summary>
 /// Asserts that the plugin has only a single registered event, and sets it as the registered event for the context.
 /// </summary>
 /// <param name="plugin"></param>
 /// <returns></returns>
 public PluginExecutionContextBuilder WithRegisteredEvent(IRegisteredEventsPlugin plugin)
 {
     if (!plugin.RegisteredEvents.Any())
     {
         throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
     }
     if (plugin.RegisteredEvents.Skip(1).Any())
     {
         throw new Exception("Plugin " + plugin.GetType().FullName + " contains more than one registered event!  Unable to determine what registered event to use for the context.");
     }
     return(WithRegisteredEvent(plugin.RegisteredEvents.Single()));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DLaBExtendedPluginContextBase"/> class.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="plugin">The plugin.</param>
        /// <param name="settings">Settings used to control services of context</param>
        /// <exception cref="System.ArgumentNullException">
        /// serviceProvider
        /// or
        /// plugin
        /// </exception>
        public DLaBExtendedPluginContextBase(IServiceProvider serviceProvider, IRegisteredEventsPlugin plugin, IExtendedPluginContextInitializer settings = null)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            Settings               = settings ?? new DLaBExtendedPluginContextSettings();
            ServiceProvider        = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            PluginExecutionContext = Settings.InitializePluginExecutionContext(serviceProvider, TracingService);
            InitializePluginProperties(plugin);
        }
Esempio n. 10
0
        /// <summary>
        /// Sets the registered event for the context to the first registered event of the plugin. Throws an exception if more than one event is found.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="predicate">Optional predicate based on the RegisteredEvents of the plugin.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Plugin  + plugin.GetType().FullName +  does not contain any registered events!  Unable to set the registered event of the context.</exception>
        public TDerived WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin, Func <RegisteredEvent, bool> predicate = null)
        {
            var first = predicate == null
                ? plugin.RegisteredEvents.FirstOrDefault()
                : plugin.RegisteredEvents.FirstOrDefault(predicate);

            if (first == null)
            {
                throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
            }

            return(WithRegisteredEvent(first));
        }
 /// <summary>
 /// Initializes the plugin properties.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 private void InitializePluginProperties(IRegisteredEventsPlugin plugin)
 {
     Event = PluginExecutionContext.GetEvent(plugin.RegisteredEvents);
     if (Event == null)
     {
         var message = $"No RegisteredEvent found for the current context of Stage: {this.GetPipelineStage()}, Message: {MessageName}, Entity: {PrimaryEntityName}.  Either Unregister the plugin for this event, or include this as a RegisteredEvent in the Plugin's RegisteredEvents.";
         try
         {
             TracingService.Trace(message);
             TracingService.Trace(this.GetContextInfo());
         }
         finally
         {
             throw new InvalidPluginExecutionException(message);
         }
     }
     if (Event.Message == RegisteredEvent.Any)
     {
         Event = new RegisteredEvent(Event.Stage, PluginExecutionContext.GetMessageType(), Event.Execute);
     }
     PluginTypeName = plugin.GetType().FullName;
 }
 public ExtendedPluginContext(IServiceProvider serviceProvider, IRegisteredEventsPlugin plugin) : base(serviceProvider, plugin)
 {
 }