public static void Execute( IPlugin plugin , IOrganizationService service, PluginExecutionContextFake context , ITracingService tracingService = null , IServiceEndpointNotificationService notificationService = null ) { ServiceProviderFake serviceProvider = new ServiceProviderFake(); serviceProvider.MyPluginExecutionContext = context; serviceProvider.MyTracingServiceFake = new TracingServiceFake(); if (tracingService != null) { serviceProvider.MyTracingServiceFake.crmTracingService = tracingService; } serviceProvider.MyOrganizationServiceFactory = new OrganizationServiceFactoryFake(); serviceProvider.MyOrganizationServiceFactory.Service = service; serviceProvider.MyServiceEndpointNotificationServiceFake = new ServiceEndpointNotificationServiceFake(); if (notificationService != null) { serviceProvider.MyServiceEndpointNotificationServiceFake.crmServiceEndpointNotificationService = notificationService; } plugin.Execute(serviceProvider); }
// use this sample if you don't trust Nuget packages and don't want to give client to Nuget Packages static void SamplePluginNoTrustExecute(CrmServiceClient client, Guid userId) { var pluginContext = new PluginExecutionContextFake(); pluginContext.PrimaryEntityId = new Guid("12345678-1234-1234-1234-1234567890AB"); pluginContext.PrimaryEntityName = "account"; pluginContext.UserId = userId; pluginContext.InputParameters.Add("Target", new Entity("account", new Guid("12345678-1234-1234-1234-1234567890AB"))); // workaround - client goes directly to your plugin. PluginExecutor can't touch it. var testPlugin = new TestPluginNoTrust(); var serviceFactory = new ServiceFactoryFake(); serviceFactory.service = client.OrganizationServiceProxy; testPlugin.SetOrganizationServiceFactory(serviceFactory); // end of workaround PluginExecutor.Execute(testPlugin, null, pluginContext); }
static void SamplePluginExecute(CrmServiceClient client, Guid userId) { var pluginContext = new PluginExecutionContextFake(); // if within your plugin you use other stuff of plugincontext, initialize it and put appropriate // e.g. pluginContext.BusinessUnitId = yourBuId // or pluginContext.PreEntityImages.Add("name", someEntity); pluginContext.PrimaryEntityId = new Guid("12345678-1234-1234-1234-1234567890AB"); pluginContext.PrimaryEntityName = "account"; pluginContext.UserId = userId; pluginContext.InitiatingUserId = userId; // set your target record lie this var e = new Entity("account", new Guid("12345678-1234-1234-1234-1234567890AB")); e.Attributes["name"] = "someName"; pluginContext.InputParameters.Add("Target", e); var testPlugin = new TestPlugin(); // sample for plugin constructors requiering secure and unsecure config: // TestPlugin testPlugin = new TestPlugin(yourSecureConfig, yourUnsecureConfig); //- both parameters can be null or empty string PluginExecutor.Execute(testPlugin, client, pluginContext); }