public static StubIServiceProvider StubIServiceProvider(StubIOrganizationService service, StubIPluginExecutionContext pluginExecutionContext) { // ITracingService var tracingService = new StubITracingService { TraceStringObjectArray = (f, o) => { Debug.WriteLine(f, o); } }; // IOrganizationServiceFactory var factory = new StubIOrganizationServiceFactory { CreateOrganizationServiceNullableOfGuid = id => service }; // IServiceProvider var serviceProvider = new StubIServiceProvider { GetServiceType = t => { if (t == typeof(IPluginExecutionContext)) { return(pluginExecutionContext); } if (t == typeof(ITracingService)) { return(tracingService); } return(t == typeof(IOrganizationServiceFactory) ? factory : null); } }; return(serviceProvider); }
public void SetupServices() { ////Entity entity = new Entity(); ////entity.Attributes["ava_name"] = "CMSHostURL"; ////entity.Attributes["ava_value"] = "CMSHostURLValue"; ////EntityCollection entityCol = new EntityCollection(); ////entityCol.Entities.Add(entity); this.ServiceFake = new StubIOrganizationService(); ////{ //// RetrieveMultipleQueryBase = (queryBase) => entityCol, //// ExecuteOrganizationRequest = (request) => null ////}; IOrganizationServiceFactory factoryFake = new StubIOrganizationServiceFactory() { CreateOrganizationServiceNullableOfGuid = (userId) => this.ServiceFake }; ITracingService tracingServiceFake = new StubITracingService() { TraceStringObjectArray = (format, args) => { return; } }; this.ServiceProviderFake = new StubIServiceProvider() { GetServiceType = (type) => { if (type == typeof(IOrganizationService)) { return(ServiceFake); } if (type == typeof(IPluginExecutionContext)) { return(PluginContextFake); } if (type == typeof(ITracingService)) { return(tracingServiceFake); } if (type == typeof(IOrganizationServiceFactory)) { return(factoryFake); } if (type == typeof(ISystemNetWebClient)) { return(null); } return(null); } }; }
public static void PluginVariables(StubIServiceProvider serviceProvider, StubIPluginExecutionContext pluginContext, StubIOrganizationService organizationService, int stageNumber, string messageName, EntityImageCollection postImage) { var serviceFactory = new StubIOrganizationServiceFactory(); var tracingService = new StubITracingService(); if (serviceProvider != null) { serviceProvider.GetServiceType = type => { if (type == typeof(IPluginExecutionContext)) { return(pluginContext); } else if (type == typeof(ITracingService)) { return(tracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(serviceFactory); } return(null); }; } pluginContext.DepthGet = () => 1; pluginContext.UserIdGet = () => new Guid(); pluginContext.MessageNameGet = () => messageName; pluginContext.StageGet = () => stageNumber; pluginContext.InitiatingUserIdGet = () => Guid.Parse("F83DA6A6-748E-E412-9412-00155D614A70"); pluginContext.CorrelationIdGet = () => new Guid(); pluginContext.PrimaryEntityIdGet = () => { return(Guid.NewGuid()); }; pluginContext.PostEntityImagesGet = () => { return(postImage); }; pluginContext.PreEntityImagesGet = () => { return(postImage); }; serviceFactory.CreateOrganizationServiceNullableOfGuid = t1 => organizationService; tracingService.TraceStringObjectArray = Trace; }
/// <summary> /// Moles the plugin variables. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="pluginContext">The plugin context.</param> /// <param name="organizationService">The organization service.</param> /// <param name="stageNumber">The stage number.</param> /// <param name="messageName">Name of the message.</param> public static void MolePluginVariables( StubIServiceProvider serviceProvider, StubIPluginExecutionContext pluginContext, StubIOrganizationService organizationService, int stageNumber, string messageName) { var serviceFactory = new StubIOrganizationServiceFactory(); var tracingService = new StubITracingService(); if (serviceProvider != null) { serviceProvider.GetServiceType = type => { if (type == typeof(IPluginExecutionContext)) { return(pluginContext); } else if (type == typeof(ITracingService)) { return(tracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(serviceFactory); } return(null); }; } pluginContext.DepthGet = () => 1; pluginContext.UserIdGet = () => new Guid(); pluginContext.MessageNameGet = () => messageName; pluginContext.StageGet = () => stageNumber; pluginContext.InitiatingUserIdGet = () => new Guid(); pluginContext.CorrelationIdGet = () => new Guid(); pluginContext.PrimaryEntityIdGet = Guid.NewGuid; pluginContext.IsInTransactionGet = () => true; serviceFactory.CreateOrganizationServiceNullableOfGuid = t1 => organizationService; tracingService.TraceStringObjectArray = Trace; }
public void TestMethod1() { Entity lead = new Entity("lead"); Guid userId = Guid.NewGuid(); Guid leadId = Guid.NewGuid(); // IPluginExecutionContext var pluginExecutionContext = new StubIPluginExecutionContext(); pluginExecutionContext.UserIdGet = () => { return(userId); }; pluginExecutionContext.InputParametersGet = () => { ParameterCollection parameters = new ParameterCollection(); parameters["Target"] = lead; //parameters["Assignee"] = teamRef; return(parameters); }; // IOrganizationService var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService(); // IOrganizationServiceFactory var factory = new StubIOrganizationServiceFactory(); factory.CreateOrganizationServiceNullableOfGuid = id => { return(service); }; // IServiceProvider var serviceProvider = new System.Fakes.StubIServiceProvider(); serviceProvider.GetServiceType = t => { if (t == typeof(IPluginExecutionContext)) { return(pluginExecutionContext); } else if (t == typeof(IOrganizationServiceFactory)) { return(factory); } return(null); }; service.CreateEntity = (entity) => { return(lead.Id); }; service.ExecuteOrganizationRequest = (executerequest) => { return(new SendEmailResponse()); }; Class1 target = new Class1(); target.Execute(serviceProvider); }
public PipelineBase(IOrganizationService service = null) { _shimContext = ShimsContext.Create(); { if (service == null) { FakeService = new FakeOrganzationService(); Service = FakeService; } else { Service = service; } PreImages = new EntityImageCollection(); PostImages = new EntityImageCollection(); InputParameters = new ParameterCollection(); OutputParameters = new ParameterCollection(); PluginExecutionContext = new StubIPluginExecutionContext(); PluginExecutionContext.PreEntityImagesGet = () => { return(PreImages); }; PluginExecutionContext.PostEntityImagesGet = () => { return(PreImages); }; PluginExecutionContext.InputParametersGet = () => { return(InputParameters); }; PluginExecutionContext.OutputParametersGet = () => { return(OutputParameters); }; // ITracingService TracingService = new StubITracingService(); TracingService.TraceStringObjectArray = (format, values) => { if (values != null && values.Length > 0) { Trace.WriteLine(string.Format(format, values)); } else { Trace.WriteLine(format); } }; // IOrganizationServiceFactory Factory = new StubIOrganizationServiceFactory { CreateOrganizationServiceNullableOfGuid = id => { return(Service); } }; // IServiceProvider ServiceProvider = new System.Fakes.StubIServiceProvider { GetServiceType = type => { if (type == typeof(IPluginExecutionContext)) { return(PluginExecutionContext); } else if (type == typeof(ITracingService)) { return(TracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(Factory); } return(null); } }; } }