예제 #1
0
        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);
                    }
                };
            }
        }
예제 #2
0
        public PipelineBase(IOrganizationService service = null)
        {
            if (service == null)
            {
                FakeService = new FakeOrganzationService();
                Service     = FakeService;
            }
            else
            {
                Service = service;
            }

            CorrelationId      = Guid.NewGuid();
            RequestId          = Guid.NewGuid();
            OperationId        = Guid.NewGuid();
            OperationCreatedOn = DateTime.UtcNow;

            PreImages              = new EntityImageCollection();
            PostImages             = new EntityImageCollection();
            InputParameters        = new ParameterCollection();
            OutputParameters       = new ParameterCollection();
            PluginExecutionContext = A.Fake <IPluginExecutionContext>(a => a.Strict());
            A.CallTo(() => PluginExecutionContext.PreEntityImages).Returns(PreImages);
            A.CallTo(() => PluginExecutionContext.PostEntityImages).Returns(PostImages);
            A.CallTo(() => PluginExecutionContext.InputParameters).Returns(InputParameters);
            A.CallTo(() => PluginExecutionContext.OutputParameters).Returns(OutputParameters);

            // ITracingService
            TracingService = A.Fake <ITracingService>((a) => a.Strict());
            A.CallTo(() => TracingService.Trace(A <string> .Ignored, A <object[]> .Ignored))
            .Invokes((string format, object[] args) =>
            {
                if (args != null && args.Length > 0)
                {
                    Trace.WriteLine(string.Format(format, args));
                }
                else
                {
                    Trace.WriteLine(format);
                }
            });


            // IOrganizationServiceFactory
            Factory = A.Fake <IOrganizationServiceFactory>((a) => a.Strict());
            A.CallTo(() => Factory.CreateOrganizationService(A <Guid?> .Ignored)).Returns(Service);

            // IServiceProvider
            ServiceProvider = A.Fake <IServiceProvider>((a) => a.Strict());
            A.CallTo(() => ServiceProvider.GetService(A <Type> .Ignored))
            .ReturnsLazily((objectcall) =>
            {
                var type = (Type)objectcall.Arguments[0];
                if (type == typeof(IPluginExecutionContext))
                {
                    return(PluginExecutionContext);
                }
                else if (type == typeof(ITracingService))
                {
                    return(TracingService);
                }
                else if (type == typeof(IOrganizationServiceFactory))
                {
                    return(Factory);
                }
                return(null);
            });
        }