Exemplo n.º 1
0
        public void TestMethod1()
        {
            #region 1. Setup / Arrange
            var orgServiceMock = new Mock <IOrganizationService>();
            var orgService     = orgServiceMock.Object;
            var orgTracingMock = new Mock <ITracingService>();
            var orgTracing     = orgTracingMock.Object;

            #region Id Request Entity
            var Request = new Entity()
            {
                Id          = Guid.NewGuid(),
                LogicalName = "gsc_cmn_idrequest",
                Attributes  =
                {
                    { "gsc_branch",                new EntityReference("account", new Guid("b360c58f-c7f8-4b37-af9c-7752d3e4740d"))
                        {
                            Name = "Citimotors"
                        } },
                    { "gsc_originatingrecordtype", "Quote" },
                    { "gsc_originatingrecordid",   "Quote123" },
                    { "gsc_idrequestpn",           "" }
                }
            };
            #endregion

            #endregion

            #region 2. Call/Action

            var IDRequestHandler = new IDRequestHandler(orgService, orgTracing);
            IDRequestHandler.GenerateName(Request);

            #endregion

            #region 3. Verify

            var branch = Request.GetAttributeValue <EntityReference>("gsc_branchid") != null
                ? Request.GetAttributeValue <EntityReference>("gsc_branchid").Name
                : String.Empty;

            var recordId = Request.Contains("gsc_originatingrecordid")
                ? Request.GetAttributeValue <String>("gsc_originatingrecordid")
                : String.Empty;
            var recordType = Request.Contains("gsc_originatingrecordtype")
                ? Request.GetAttributeValue <String>("gsc_originatingrecordtype")
                : String.Empty;

            var name = branch + "-" + recordId + "-" + recordType;

            Assert.AreEqual(name, Request.GetAttributeValue <String>("gsc_idrequestpn"));
            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostIDRequestCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            Entity requestEntity            = (Entity)context.InputParameters["Target"];

            try
            {
                IDRequestHandler requestHandler = new IDRequestHandler(service, trace);
                requestHandler.GenerateName(requestEntity);
            }

            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }