Beispiel #1
0
        public override string ConstructUrl(Microsoft.Xrm.Sdk.ParameterCollection InputParameters, IPluginExecutionContext pluginExecutionContext, IOrganizationService organizationService, ITracingService tracingService = null)
        {
            int    Lcid     = (int)InputParameters[LcidKey];
            string _address = string.Empty;

            if (Lcid == 0)
            {
                var userSettingsQuery = new QueryExpression("usersettings");
                userSettingsQuery.ColumnSet.AddColumns("uilanguageid", "systemuserid");
                userSettingsQuery.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, pluginExecutionContext.InitiatingUserId);
                var userSettings = organizationService.RetrieveMultiple(userSettingsQuery);
                if (userSettings.Entities.Count > 0)
                {
                    Lcid = (int)userSettings.Entities[0]["uilanguageid"];
                }
            }

            // Arrange the address components in a single comma-separated string, according to LCID
            _address = GisUtility.FormatInternationalAddress(Lcid,
                                                             (string)InputParameters[Address1Key],
                                                             (string)InputParameters[PostalCodeKey],
                                                             (string)InputParameters[CityKey],
                                                             (string)InputParameters[StateKey],
                                                             (string)InputParameters[CountryKey]);

            WebClient client = new WebClient();
            var       url    = $"https://{ApiServer}{GeocodePath}/json?address={_address}&key={ApiKey}";

            tracingService.Trace($"Calling {url}\n");

            return(url);
        }
        public void EscalationDuplicate()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "smp_escalation";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity escalation = new Entity("smp_escalation");

            escalation.Id          = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            escalation["smp_name"] = "test escalation";
            paramCollection.Add("Target", escalation);
            pluginContext.InputParametersGet = () => paramCollection;
            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null);
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_escalation")
                {
                    Entity escaltionCollection = new Entity("smp_escalation");
                    escaltionCollection.Id          = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    escaltionCollection["smp_name"] = "test escalation";
                    collection.Entities.Add(escaltionCollection);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "incident")
                {
                    Entity building = new Entity(entity);
                    building.Id = Guid.NewGuid();
                    building["smp_issurveyservicerequest"]       = true;
                    building["smp_cancelledforreclassification"] = true;
                    return(building);
                }

                return(null);
            };

            PreEscalationCreateDuplicateDetection escaltionDetect = new PreEscalationCreateDuplicateDetection();

            escaltionDetect.Execute(serviceProvider);
        }
Beispiel #3
0
        public void SendStatusChangeEmail()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection          = new Microsoft.Xrm.Sdk.ParameterCollection();
            Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(2);
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(1);
            incident.Attributes["smp_duedate"]      = new DateTime(2018, 1, 8);
            incident.Attributes["smp_portalsubmit"] = false;
            incident.Attributes["smp_duedatebybuildingtimezone"]         = "2018-01-08";
            incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08";
            incident["smp_submitteddatetime"]      = new DateTime(2018, 1, 8);
            incident["createdon"]                  = new DateTime(2018, 1, 8);
            incident["smp_problemoccureddatetime"] = new DateTime(2018, 1, 8);
            incident["smp_createdfrom"]            = new OptionSetValue(1);
            incident["smp_integrationstatus"]      = true;
            incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_createddatetimebybuildingtimezone"]   = "2018-01-08";
            incident["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "roomtype"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "TestName"
            };
            incident.Attributes["customerid"] = new EntityReference("contact", new Guid());
            incident.Attributes["smp_allowemailnotification"] = true;
            incident["caseorigincode"] = new OptionSetValue(180620001);
            ////Entity preIncident = new Entity("incident");
            ////preIncident["incidentid"] = Guid.NewGuid();
            incident["statuscode"]      = new OptionSetValue(2);
            incident["smp_requestorid"] = new EntityReference("contact", Guid.NewGuid());
            incident["smp_cc"]          = new EntityReference("contact", Guid.NewGuid());
            incident["smp_approver"]    = new EntityReference("contact", Guid.NewGuid());
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            EntityImageCollection postImage = new EntityImageCollection {
                (new KeyValuePair <string, Entity>("PostImage", incident))
            };

            ////pluginContext.PostEntityImagesGet = () => { return postImage; };

            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", postImage);
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;

                if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_configuration")
                {
                    Entity configuration = new Entity("smp_configuration");
                    configuration.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration["smp_title"] = "8/8RoutingPriorities";
                    configuration["smp_value"] = "P1,P2,PS1,PS2";
                    collection.Entities.Add(configuration);
                    Entity configuration1 = new Entity("smp_configuration");
                    configuration1.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration1["smp_title"] = "EmailSenderDomainName";
                    configuration1["smp_value"] = "*****@*****.**";
                    collection.Entities.Add(configuration1);
                    Entity configuration2 = new Entity("smp_configuration");
                    configuration2.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration2["smp_title"] = "PendingDispatchStatusCode";
                    configuration2["smp_value"] = "2";
                    collection.Entities.Add(configuration2);
                    Entity configuration3 = new Entity("smp_configuration");
                    configuration3.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration3["smp_title"] = "DefaultProviderName";
                    configuration3["smp_value"] = "NotAssigned";
                    collection.Entities.Add(configuration3);
                    Entity configuration4 = new Entity("smp_configuration");
                    configuration4.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration4["smp_title"] = "NoCmmsIntegrationActionCodes";
                    configuration4["smp_value"] = "Draft";
                    collection.Entities.Add(configuration4);
                    Entity configuration5 = new Entity("smp_configuration");
                    configuration5.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration5["smp_title"] = "StatusChangeOnCodes";
                    configuration5["smp_value"] = "Draft";
                    collection.Entities.Add(configuration5);
                    Entity configuration9 = new Entity("smp_configuration");
                    configuration9.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration9["smp_title"] = "Sample One";
                    configuration9["smp_value"] = "*****@*****.**";
                    collection.Entities.Add(configuration9);
                    Entity configuration10 = new Entity("smp_configuration");
                    configuration10.Id           = new Guid();
                    configuration10["smp_title"] = "sample name";
                    configuration10["smp_value"] = "04/10/2018";
                    collection.Entities.Add(configuration10);
                    Entity configuration11 = new Entity("smp_configuration");
                    configuration11.Id           = new Guid();
                    configuration11["smp_title"] = "en-us";
                    configuration11["smp_value"] = "2018-09-09";
                    collection.Entities.Add(configuration11);
                    Entity configuration12 = new Entity("smp_configuration");
                    configuration12.Id           = new Guid();
                    configuration12["smp_title"] = "ServiceRequestConfirmation/ToBeScheduled";
                    configuration12["smp_value"] = "2018-09-09";
                    collection.Entities.Add(configuration12);
                    Entity configuration13 = new Entity("smp_configuration");
                    configuration13.Id           = new Guid();
                    configuration13["smp_title"] = "ServiceRequestPortalLink";
                    configuration13["smp_value"] = "https://test.microsofotcrmportals.com";
                    collection.Entities.Add(configuration13);
                    Entity configuration14 = new Entity("smp_configuration");
                    configuration14.Id           = new Guid();
                    configuration14["smp_title"] = "ServiceRequestSurveyLink";
                    configuration14["smp_value"] = "https://[email protected]";
                    collection.Entities.Add(configuration14);
                    Entity configuration15 = new Entity("smp_configuration");
                    configuration15.Id           = new Guid();
                    configuration15["smp_title"] = "Seemoreinformationaboutyourservicerequest";
                    configuration15["smp_value"] = "seemoreinformation";
                    collection.Entities.Add(configuration15);
                    Entity configuration16 = new Entity("smp_configuration");
                    ////configuration16["smp_entityname"] = "incident";
                    ////configuration16.Attributes["statuscode"] = new OptionSetValue(2);
                    ////configuration16["smp_attributename"] = "smp_duedate";
                    configuration16["smp_title"] = "PrioritiesToDisplayTheDueDate";
                    configuration16["smp_value"] = "2018-09-09";
                    collection.Entities.Add(configuration16);
                }

                if (entityName == "systemuser")
                {
                    Entity systemUser = new Entity(entityName);
                    systemUser.Id = Guid.NewGuid();
                    systemUser["systemuserid"] = systemUser.Id;
                    collection.Entities.Add(systemUser);
                }
                else if (entityName == "smp_servicerequeststatuscode")
                {
                    Entity srStatusCode = new Entity(entityName);
                    srStatusCode.Id          = Guid.NewGuid();
                    srStatusCode["smp_name"] = "test1";
                    srStatusCode["smp_servicerequeststatus"] = new OptionSetValue(2);
                    collection.Entities.Add(srStatusCode);
                }
                else if (entityName == "smp_servicerequestproblemtypedesc")
                {
                    Entity servicerequestproblemtype = new Entity(entityName);
                    servicerequestproblemtype.Id = Guid.NewGuid();
                    servicerequestproblemtype["smp_servicerequestproblemtypedescid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    servicerequestproblemtype["smp_problemtypedescriptionid"]        = new EntityReference("smp_problemtypedescription", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    servicerequestproblemtype["smp_answer"] = "Sample Answer";
                    collection.Entities.Add(servicerequestproblemtype);
                }
                else if (entityName == "annotation")
                {
                    Entity annotation = new Entity(entityName);
                    annotation.Id = Guid.NewGuid();
                    annotation["annotationid"] = annotation.Id;
                    annotation["subject"]      = "Sample subject";
                    annotation["notetext"]     = "Sample text";
                    annotation["filename"]     = "Sample filename4";
                    annotation["isdocument"]   = true;
                    annotation["documentbody"] = "Sample body";
                    annotation["createdon"]    = DateTime.Now.AddDays(-10);
                    collection.Entities.Add(annotation);
                }
                else if (entityName == "template")
                {
                    Entity annotation = new Entity(entityName);
                    annotation.Id            = Guid.NewGuid();
                    annotation["templateid"] = annotation.Id;
                    annotation["subject"]    = "<?xml version=\"1.0\" ?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"text\" indent=\"no\" /><xsl:template match=\"/data\"><![CDATA[We haven't heard from you...]]></xsl:template></xsl:stylesheet>";
                    annotation["body"]       = "<?xml version=\"1.0\" ?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"text\" indent=\"no\"/><xsl:template match=\"/data\"><![CDATA[<P>Dear ]]><xsl:choose><xsl:when test=\"account/name\"><xsl:value-of select=\"account/name\" /></xsl:when><xsl:otherwise>Valued Customer</xsl:otherwise></xsl:choose><![CDATA[,</P> <P>We have not heard from you for a while. We wanted to check in and make sure that you are still having a great experience using our product(s). We have asked ]]><xsl:choose><xsl:when test=\"account/ownerid/@name\"><xsl:value-of select=\"account/ownerid/@name\" /></xsl:when><xsl:otherwise>a customer service representative</xsl:otherwise></xsl:choose><![CDATA[ to contact you next week to get your feedback on the product(s) you are currently using and to give you details about our upcoming products.</P> <P>Thank you.</P>]]></xsl:template></xsl:stylesheet>";
                    collection.Entities.Add(annotation);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "incident")
                {
                    Entity incident1 = new Entity(entity);
                    incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    incident1["smp_issurveyservicerequest"]       = true;
                    incident1["smp_cancelledforreclassification"] = true;

                    return(incident1);
                }

                if (entity == "account")
                {
                    Entity account = new Entity(entity);
                    account.Id      = new Guid("58d19398-b350-490a-9e2d-6b30391304a0");
                    account["name"] = "test";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "https://testurl/cmmsservicerequestmanagerAAD.svc";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    return(account);
                }
                else if (entity == "contact")
                {
                    Entity contact = new Entity(entity);
                    contact.Id = Guid.NewGuid();
                    contact["smp_preferredlanguage"]      = "en-us";
                    contact["smp_isprovideruser"]         = false;
                    contact["smp_costcenter"]             = "11110";
                    contact["smp_allowemailnotification"] = false;
                    contact["smp_alias"]     = "testalias";
                    contact["firstname"]     = "first";
                    contact["lastname"]      = "last";
                    contact["funllname"]     = "last";
                    contact["emailaddress1"] = "*****@*****.**";
                    return(contact);
                }
                else if (entity == "smp_building")
                {
                    Entity building = new Entity(entity);
                    building.Id = Guid.NewGuid();
                    building["smp_timezoneid"]                     = new EntityReference("smp_timezone", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    building["smp_isfinancialstatecampus"]         = true;
                    building["smp_buildinglevelemailnotification"] = true;
                    building["smp_feedstoreid"]                    = "Sample StoreId";
                    building["smp_buildingname"]                   = "sample building";
                    return(building);
                }
                else if (entity == "smp_problemclass")
                {
                    Entity problemClass = new Entity(entity);
                    problemClass.Id = Guid.NewGuid();
                    problemClass["smp_donotallowsurvey"]       = true;
                    problemClass["smp_allowemailnotification"] = true;
                    return(problemClass);
                }
                else if (entity == "smp_problemtype")
                {
                    Entity problemType = new Entity(entity);
                    problemType.Id = Guid.NewGuid();
                    problemType["smp_donotallowsurvey"]       = true;
                    problemType["smp_allowemailnotification"] = true;
                    return(problemType);
                }
                else if (entity == "smp_problemtypedescription")
                {
                    Entity problemType = new Entity(entity);
                    problemType.Id = Guid.NewGuid();
                    problemType["smp_problemtypedescriptionname"] = "sample description";
                    return(problemType);
                }
                else if (entity == "smp_priority")
                {
                    Entity priority = new Entity(entity);
                    priority.Id          = Guid.NewGuid();
                    priority["smp_name"] = "sample name";
                    return(priority);
                }
                else if (entity == "smp_roomtype")
                {
                    Entity problemclass = new Entity(entity);
                    problemclass.Id = Guid.NewGuid();
                    problemclass["smp_roomtype"] = "sample room";
                    return(problemclass);
                }

                return(null);
            };

            PostServiceRequestCreateEmailNotification pluginClass = new PostServiceRequestCreateEmailNotification();

            pluginClass.Execute(serviceProvider);
        }
Beispiel #4
0
        public void SetPriority3()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(2);
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(3);
            incident.Attributes["smp_duedate"]      = "2018-01-08";////Convert.ToDateTime(null, CultureInfo.CurrentCulture);
            incident.Attributes["smp_portalsubmit"] = false;
            incident.Attributes["smp_duedatebybuildingtimezone"] = "2018-01-08";
            ////incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08";
            //// incident["smp_submitteddatetime"] = Convert.ToDateTime(null, CultureInfo.CurrentCulture);//new DateTime(2018, 1, 8);
            incident["createdon"] = "2018-01-08";
            incident["smp_problemoccureddatetime"] = "2018-01-08";
            ////incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            ////incident.Attributes["smp_createddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", Guid.Empty)
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "roomtype"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", Guid.Empty);
            incident.Attributes["smp_contact"]    = new EntityReference("contact", Guid.NewGuid());
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null);

            organizationService.ExecuteOrganizationRequest = QueryBase =>
            {
                if (QueryBase.RequestName == "RetrieveAttribute")
                {
                    PicklistAttributeMetadata picklistAttributeMetadata = new PicklistAttributeMetadata();
                    picklistAttributeMetadata.OptionSet = new OptionSetMetadata();
                    picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("+02:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("+02:30", 1033) })), 0));
                    picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("+03:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("+03:30", 1033) })), 1));
                    picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("-04:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("-04:30", 1033) })), 2));

                    RetrieveAttributeResponse response = new RetrieveAttributeResponse();
                    response.Results.Add("AttributeMetadata", picklistAttributeMetadata);

                    return(response);
                }
                else if (QueryBase.RequestName == "LocalTimeFromUtcTime")
                {
                    LocalTimeFromUtcTimeResponse localTimeResponse = new LocalTimeFromUtcTimeResponse();
                    ////localTimeResponse.Results.Add("", value);
                    DateTime dateTime = Convert.ToDateTime(QueryBase.Parameters["UtcTime"]).AddMinutes(Convert.ToInt32(QueryBase.Parameters["TimeZoneCode"]));
                    localTimeResponse.Results.Add("LocalTime", dateTime);
                    return(localTimeResponse);
                }
                else if (QueryBase.RequestName == "UtcTimeFromLocalTime")
                {
                    UtcTimeFromLocalTimeResponse utcTimeResponse = new UtcTimeFromLocalTimeResponse();
                    DateTime dateTime = Convert.ToDateTime(QueryBase.Parameters["LocalTime"]).AddMinutes(-Convert.ToInt32(QueryBase.Parameters["TimeZoneCode"]));
                    utcTimeResponse.Results.Add("UtcTime", dateTime);
                    return(utcTimeResponse);
                }

                return(null);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "smp_building")
                {
                    Entity building = new Entity(entity);
                    building.Id = Guid.NewGuid();
                    building["smp_timezoneid"]             = new EntityReference("smp_timezone", Guid.NewGuid());
                    building["smp_isfinancialstatecampus"] = true;
                    return(building);
                }
                else if (entity == "smp_timezone")
                {
                    Entity timeZone = new Entity(entity);
                    timeZone["smp_timezonename"] = "test timezone";
                    timeZone["smp_offset"]       = new OptionSetValue(2);
                    return(timeZone);
                }
                else if (entity == "smp_priority")
                {
                    Entity priority = new Entity(entity);
                    priority["smp_noofminutes"] = 100;
                    return(priority);
                }
                else if (entity == "smp_roomtype")
                {
                    Entity roomType = new Entity(entity);
                    roomType["smp_zone"] = new OptionSetValue(1);
                    return(roomType);
                }

                return(null);
            };
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("FetchExpression"))
                {
                    if (((FetchExpression)query).Query.Contains("<entity name='ava_keyvaluepair'>"))
                    {
                        entityName = "ava_keyvaluepair";
                    }
                }
                else if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_providermatrix")
                {
                    Entity matrix = new Entity("smp_providermatrix");
                    matrix.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    matrix["smp_primaryproviderid"] = new EntityReference("account", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"));
                    collection.Entities.Add(matrix);
                }
                else if (entityName == "smp_room")
                {
                    Entity room = new Entity(entityName);
                    room["smp_name"]   = "test room";
                    room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    collection.Entities.Add(room);
                }
                else if (entityName == "account")
                {
                    Entity account = new Entity(entityName);
                    account["accountid"]  = new Guid("884A078B-0467-E711-80F5-3863BB3C1560");
                    account["statuscode"] = 1;
                    collection.Entities.Add(account);
                }
                else if (entityName == "smp_slamatrix")
                {
                    Entity slaMatrix = new Entity(entityName);
                    slaMatrix["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0467-E711-80F5-3863BB3C1489"));
                    slaMatrix["smp_starthours"] = 2;
                    slaMatrix["smp_endhours"]   = 1;
                    collection.Entities.Add(slaMatrix);
                }
                else if (entityName == "smp_buildingworkhours")
                {
                    ////Entity buildWorkHours = new Entity(entityName);
                    ////buildWorkHours["smp_starthours"] = new OptionSetValue(1);
                    ////buildWorkHours["smp_endhours"] = new OptionSetValue(2);
                    ////buildWorkHours.FormattedValues["smp_starthours"] = "08:30";
                    ////buildWorkHours.FormattedValues["smp_endhours"] = "08:30";
                    ////collection.Entities.Add(buildWorkHours);
                }
                else if (entityName == "smp_weekdays")
                {
                    Entity weekdays = new Entity(entityName);
                    weekdays["smp_name"] = Convert.ToDateTime("09-03-2017 02:30 AM");
                    collection.Entities.Add(weekdays);
                }
                else if (entityName == "smp_configuration")
                {
                    Entity configuration = new Entity(entityName);
                    configuration["smp_value"] = "Production";
                    collection.Entities.Add(configuration);
                }
                else if (entityName == "systemuser")
                {
                    Entity systemuser = new Entity(entityName);
                    systemuser.Id = Guid.NewGuid();
                    systemuser["systemuserid"] = systemuser.Id;
                    collection.Entities.Add(systemuser);
                }
                else if (entityName == "usersettings")
                {
                    Entity usersettings = new Entity(entityName);
                    usersettings["timezonecode"] = 85;
                    collection.Entities.Add(usersettings);
                }

                return(collection);
            };

            PreServiceRequestCreateSetPriority prioritySet = new PreServiceRequestCreateSetPriority();

            prioritySet.Execute(serviceProvider);
        }
        public void PostServiceRequestsmp_ReclassifyTestMethod()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            ParameterCollection paramCollection = new ParameterCollection();

            Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["smp_incidentid"]             = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
            incident.Attributes["incidentid"]                 = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
            incident.Attributes["customerid"]                 = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["smp_createdfrom"]            = new OptionSetValue(3);
            incident.Attributes["smp_referencesr"]            = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
            incident.Attributes["smp_flag"]                   = false;
            incident.Attributes["smp_problemoccureddatetime"] = "2018-01-08";
            incident.Attributes["smp_portalsubmit"]           = false;
            paramCollection.Add("Target", new EntityReference(incident.LogicalName, incident.Id));
            pluginContext.InputParametersGet  = () => paramCollection;
            pluginContext.OutputParametersGet = () => paramCollection;
            EntityImageCollection postImage = new EntityImageCollection
            {
                (new KeyValuePair <string, Entity>("PostImage", incident))
            };

            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "smp_Reclassify", postImage);
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("FetchExpression"))
                {
                    if (((FetchExpression)query).Query.Contains("<entity name='annotation'>"))
                    {
                        entityName = "annotation";
                    }
                }
                else if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_servicerequestproblemtypedesc")
                {
                    Entity servicerequestproblemtype = new Entity(entityName);
                    servicerequestproblemtype.Id = Guid.NewGuid();
                    servicerequestproblemtype["smp_servicerequestproblemtypedescid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    servicerequestproblemtype["smp_problemtypedescriptionid"]        = new EntityReference("smp_problemtypedescription", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    servicerequestproblemtype["smp_answer"]           = "Sample Answer";
                    servicerequestproblemtype["smp_servicerequestid"] = new EntityReference("incident", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    collection.Entities.Add(servicerequestproblemtype);
                }
                else if (entityName == "annotation")
                {
                    Entity annotation = new Entity(entityName);
                    annotation.Id = Guid.NewGuid();
                    annotation["annotationid"]   = annotation.Id;
                    annotation["subject"]        = "Sample subject";
                    annotation["notetext"]       = "Sample text";
                    annotation["filename"]       = "Sample filename4";
                    annotation["isdocument"]     = true;
                    annotation["documentbody"]   = "Sample body";
                    annotation["createdon"]      = DateTime.Now.AddDays(-10);
                    annotation["objectid"]       = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
                    annotation["objecttypecode"] = "incident";
                    collection.Entities.Add(annotation);
                }
                else if (entityName == "account")
                {
                    Entity account = new Entity(entityName);
                    account.Id           = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    account["accountid"] = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    account["name"]      = "test";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "https://testurl/cmmsservicerequestmanagerAAD.svc";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    collection.Entities.Add(account);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "incident")
                {
                    Entity incident2 = new Entity(entity);
                    incident2.Id                            = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    incident2["incidentid"]                 = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
                    incident2["customerid"]                 = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident2["smp_createdfrom"]            = new OptionSetValue(3);
                    incident2["smp_referencesr"]            = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
                    incident2["smp_flag"]                   = false;
                    incident2["smp_problemoccureddatetime"] = "2018-01-08";
                    incident2["smp_portalsubmit"]           = false;
                    return(incident2);
                }

                if (entity == "account")
                {
                    Entity account = new Entity(entity);
                    account.Id      = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    account["name"] = "test";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "https://testurl/cmmsservicerequestmanagerAAD.svc";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    return(account);
                }

                return(null);
            };
            Guid   expected     = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Entity clonedEntity = null;

            organizationService.CreateEntity = e =>
            {
                clonedEntity = e;
                return(expected);
            };

            PostServiceRequestsmp_Reclassify reclassify = new PostServiceRequestsmp_Reclassify();

            reclassify.Execute(serviceProvider);
        }
        public void ServiceRequestFromSurvey()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "smp_srsatisfactionsurvey";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection          = new Microsoft.Xrm.Sdk.ParameterCollection();
            Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(2);
            incident.Attributes["smp_incidentid"]      = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(1);
            incident.Attributes["smp_duedate"]      = new DateTime(2018, 1, 8);
            incident.Attributes["smp_portalsubmit"] = false;
            incident.Attributes["smp_duedatebybuildingtimezone"]         = "2018-01-08";
            incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08";
            incident["smp_submitteddatetime"]      = "2018-01-08";
            incident["createdon"]                  = "2018-01-08";
            incident["smp_problemoccureddatetime"] = "2018-01-08";
            incident["smp_createdfrom"]            = new OptionSetValue(1);
            incident.Attributes["smp_7a5070ca45ac4bfb9cf14dc614b2c28b"]  = new OptionSetValue(1);
            incident.Attributes["smp_df933ec69da9441986ea13ad23c16c16"]  = new OptionSetValue(1);
            incident.Attributes["smp_a9dfbbbb5d9540d5bea5954f97a5b57e"]  = new OptionSetValue(1);
            incident.Attributes["smp_74593f38170543a0a6af56948307ff8b"]  = new OptionSetValue(1);
            incident.Attributes["smp_8ae246fa75ed4d47a4bb402c7f6b3339 "] = new OptionSetValue(3);
            incident["smp_integrationstatus"] = true;
            incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_createddatetimebybuildingtimezone"]   = "2018-01-08";
            incident.Attributes["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "roomtype"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident.Attributes["smp_priorityid"]      = new EntityReference("smp_priority", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["customerid"]          = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["smp_requestorid"]     = new EntityReference("contact", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["smp_buildingid"]      = new EntityReference("smp_building", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["smp_requestorphone"]  = "88999";
            incident.Attributes["smp_requestoralias"]  = "test";
            incident.Attributes["smp_requestorroomno"] = "88999";
            incident.Attributes["smp_requestoremail"]  = "*****@*****.**";

            ////incident.Attributes["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;

            EntityImageCollection postImage = new EntityImageCollection {
                (new KeyValuePair <string, Entity>("PostImage", incident))
            };

            PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", postImage);
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("FetchExpression"))
                {
                    if (((FetchExpression)query).Query.Contains("<entity name='smp_8x8mailbox'>"))
                    {
                        entityName = "smp_8x8mailbox";
                    }
                }
                else if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_configuration")
                {
                    Entity configuration = new Entity("smp_configuration");
                    configuration.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration["smp_title"] = "8/8RoutingPriorities";
                    configuration["smp_value"] = "P1,P2,PS1,PS2";
                    collection.Entities.Add(configuration);
                    Entity configuration1 = new Entity("smp_configuration");
                    configuration1.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration1["smp_title"] = "EmailSenderDomainName";
                    configuration1["smp_value"] = "*****@*****.**";
                    collection.Entities.Add(configuration1);
                    Entity configuration2 = new Entity("smp_configuration");
                    configuration2.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration2["smp_title"] = "PendingDispatchStatusCode";
                    configuration2["smp_value"] = "2";
                    collection.Entities.Add(configuration2);
                    Entity configuration3 = new Entity("smp_configuration");
                    configuration3.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration3["smp_title"] = "DefaultProviderName";
                    configuration3["smp_value"] = "NotAssigned";
                    collection.Entities.Add(configuration3);
                    Entity configuration4 = new Entity("smp_configuration");
                    configuration4.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration4["smp_title"] = "NoCmmsIntegrationActionCodes";
                    configuration4["smp_value"] = "Draft";
                    collection.Entities.Add(configuration4);
                    Entity configuration5 = new Entity("smp_configuration");
                    configuration5.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration5["smp_title"] = "StatusChangeOnCodes";
                    configuration5["smp_value"] = "Draft";
                    collection.Entities.Add(configuration5);
                    Entity configuration9 = new Entity("smp_configuration");
                    configuration9.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration9["smp_title"] = "ProviderQuestionOne";
                    configuration9["smp_value"] = "smp_7a5070ca45ac4bfb9cf14dc614b2c28b";
                    collection.Entities.Add(configuration9);
                    Entity configuration10 = new Entity("smp_configuration");
                    configuration10.Id           = new Guid();
                    configuration10["smp_title"] = "ProviderQuestionTwo";
                    configuration10["smp_value"] = "smp_df933ec69da9441986ea13ad23c16c16 ";
                    collection.Entities.Add(configuration10);
                    Entity configuration11 = new Entity("smp_configuration");
                    configuration11.Id           = new Guid();
                    configuration11["smp_title"] = "en-us";
                    configuration11["smp_value"] = "2018-09-09";
                    collection.Entities.Add(configuration11);
                    Entity configuration12 = new Entity("smp_configuration");
                    configuration12.Id           = new Guid();
                    configuration12["smp_title"] = "CallCenterQuestionOne";
                    configuration12["smp_value"] = "smp_a9dfbbbb5d9540d5bea5954f97a5b57e";
                    collection.Entities.Add(configuration12);
                    Entity configuration13 = new Entity("smp_configuration");
                    configuration13.Id           = new Guid();
                    configuration13["smp_title"] = "CallCenterQuestionTwo";
                    configuration13["smp_value"] = "smp_74593f38170543a0a6af56948307ff8b ";
                    collection.Entities.Add(configuration13);
                    Entity configuration14 = new Entity("smp_configuration");
                    configuration14.Id           = new Guid();
                    configuration14["smp_title"] = "SingleResponseQuestion";
                    configuration14["smp_value"] = "smp_8ae246fa75ed4d47a4bb402c7f6b3339";
                    collection.Entities.Add(configuration14);
                    Entity configuration15 = new Entity("smp_configuration");
                    configuration15.Id           = new Guid();
                    configuration15["smp_title"] = "Seemoreinformationaboutyourservicerequest";
                    configuration15["smp_value"] = "seemoreinformation";
                    collection.Entities.Add(configuration15);
                    Entity configuration16 = new Entity("smp_configuration");
                    ////configuration16["smp_entityname"] = "incident";
                    ////configuration16.Attributes["statuscode"] = new OptionSetValue(2);
                    ////configuration16["smp_attributename"] = "smp_duedate";
                    configuration16["smp_title"] = "PrioritiesToDisplayTheDueDate";
                    configuration16["smp_value"] = "2018-09-09";
                    collection.Entities.Add(configuration16);
                    Entity configuration17 = new Entity("smp_configuration");
                    configuration17.Id           = new Guid();
                    configuration17["smp_title"] = "SurveyQuestions";
                    configuration17["smp_value"] = "survery1;survey2;survey3;survey4;survery5";
                    collection.Entities.Add(configuration17);
                    Entity configuration18 = new Entity("smp_configuration");
                    configuration18.Id           = new Guid();
                    configuration18["smp_title"] = "SurveyProviderRelatedProblemClass";
                    configuration18["smp_value"] = "SurveyProviderRelatedProblemClass";
                    collection.Entities.Add(configuration18);
                    Entity configuration19 = new Entity("smp_configuration");
                    configuration19.Id           = new Guid();
                    configuration19["smp_title"] = "SurveyProviderRelatedProblemType";
                    configuration19["smp_value"] = "SurveyProviderRelatedProblemType";
                    collection.Entities.Add(configuration19);
                    Entity configuration20 = new Entity("smp_configuration");
                    configuration20.Id           = new Guid();
                    configuration20["smp_title"] = "SurveyCallCenterManagementRelatedProblemClass";
                    configuration20["smp_value"] = "SurveyCallCenterManagementRelatedProblemClass";
                    collection.Entities.Add(configuration20);
                    Entity configuration21 = new Entity("smp_configuration");
                    configuration21.Id           = new Guid();
                    configuration21["smp_title"] = "SurveyCallCenterManagementRelatedProblemType";
                    configuration21["smp_value"] = "SurveyCallCenterManagementRelatedProblemType";
                    collection.Entities.Add(configuration21);
                }
                else if (entityName == "smp_servicerequeststatuscode")
                {
                    Entity srStatusCode = new Entity(entityName);
                    srStatusCode["smp_name"] = "test";
                    srStatusCode["smp_servicerequeststatus"] = new OptionSetValue(2);
                    collection.Entities.Add(srStatusCode);
                }
                else if (entityName == "systemuser")
                {
                    Entity user = new Entity(entityName);
                    user["systemuserid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    user["domainname"]   = "*****@*****.**";
                    collection.Entities.Add(user);
                }
                else if (entityName == "smp_8x8mailbox")
                {
                    Entity eightByEight = new Entity(entityName);
                    eightByEight["smp_8x8mailboxid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    collection.Entities.Add(eightByEight);
                }
                else if (entityName == "account")
                {
                    Entity account = new Entity(entityName);
                    account.Id      = new Guid("58d19398-b350-490a-9e2d-6b30391304a0");
                    account["name"] = "test";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "https://testurl/cmmsservicerequestmanagerAAD.svc";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    collection.Entities.Add(account);
                }
                else if (entityName == "smp_problemclass")
                {
                    Entity problemClass = new Entity(entityName);
                    problemClass.Id = Guid.NewGuid();
                    problemClass["smp_donotallowsurvey"]       = true;
                    problemClass["smp_allowemailnotification"] = true;
                    collection.Entities.Add(problemClass);
                }
                else if (entityName == "smp_problemtype")
                {
                    Entity problemType = new Entity(entityName);
                    problemType.Id = Guid.NewGuid();
                    problemType["smp_donotallowsurvey"]       = true;
                    problemType["smp_allowemailnotification"] = true;
                    collection.Entities.Add(problemType);
                }

                return(collection);
            };
            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "incident")
                {
                    Entity incident1 = new Entity(entity);
                    incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    incident1["smp_issurveyservicerequest"]       = true;
                    incident1["smp_cancelledforreclassification"] = true;
                    incident1["ticketnumber"] = "CAS-120083-X4D1Q2";
                    incident1["smp_contact"]  = new EntityReference("contact", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
                    incident1.Attributes["smp_requestorid"]     = new EntityReference("contact", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident1.Attributes["smp_buildingid"]      = new EntityReference("smp_building", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident1.Attributes["smp_requestorphone"]  = "88999";
                    incident1.Attributes["smp_requestoralias"]  = "test";
                    incident1.Attributes["smp_requestorroomno"] = "88999";
                    incident1.Attributes["smp_requestoremail"]  = "*****@*****.**";
                    incident1["smp_contactbuilding"]            = new EntityReference("smp_building", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident1["smp_contactemail"]                = "*****@*****.**";
                    incident1["smp_contactalias"]                = "test";
                    incident1["smp_contactroom"]                 = "test";
                    incident1["smp_costcentercode"]              = "11223";
                    incident1["smp_contactphone"]                = "44555";
                    incident1["smp_problembuilding"]             = new EntityReference("smp_building", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident1["smp_problembuildingaddressline2"] = "test";
                    incident1["smp_problembuildingstate"]        = "test";
                    incident1["smp_problembuildingzipcode"]      = "5344";
                    incident1["smp_problemroomtype"]             = new EntityReference("smp_roomtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident1["new_problemroomnumber"]           = new EntityReference("smp_room", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    incident1["smp_problembuildingaddressline1"] = "test";
                    incident1["smp_problembuildingcity"]         = "test";
                    incident1["smp_problemroom"]                 = "test";

                    return(incident1);
                }

                if (entity == "smp_building")
                {
                    Entity building = new Entity("entity");
                    building.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    building["smp_timezoneid"]                  = new EntityReference("smp_timezone", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    building["smp_isfinancialstatecampus"]      = true;
                    building["smp_problembuilding"]             = new EntityReference("smp_building", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    building["smp_problembuildingaddressline2"] = "test";
                    building["smp_problembuildingstate"]        = "test";
                    building["smp_problembuildingzipcode"]      = "5344";
                    building["smp_problemroomtype"]             = new EntityReference("smp_roomtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    building["new_problemroomnumber"]           = new EntityReference("smp_room", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    building["smp_problembuildingaddressline1"] = "test";
                    building["smp_problembuildingcity"]         = "test";
                    building["smp_problemroom"]                 = "test";

                    building["smp_problembuildingtimezone"] = new EntityReference("smp_timezone", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
                    return(incident);
                }
                else if (entity == "smp_timezone")
                {
                    Entity timeZone = new Entity(entity);
                    timeZone["smp_timezonename"] = "test timezone";
                    timeZone["smp_offset"]       = new OptionSetValue(2);
                    return(timeZone);
                }
                else if (entity == "smp_priority")
                {
                    Entity priority = new Entity(entity);
                    priority["smp_noofminutes"] = 100;
                    return(priority);
                }
                else if (entity == "smp_roomtype")
                {
                    Entity roomType = new Entity(entity);
                    roomType["smp_zone"] = new OptionSetValue(1);
                    return(roomType);
                }
                else if (entity == "account")
                {
                    Entity account = new Entity(entity);
                    account["name"] = "test Provider";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "testurl";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    return(account);
                }
                else if (entity == "contact")
                {
                    Entity contact = new Entity(entity);
                    contact.Id = new Guid("884a078b-0467-e711-80f5-3863bb3c0660");
                    contact["smp_preferredlanguage"]      = "en-US";
                    contact["smp_isprovideruser"]         = false;
                    contact["smp_costcenter"]             = "11110";
                    contact["smp_allowemailnotification"] = false;
                    contact["smp_alias"]     = "testalias";
                    contact["firstname"]     = "first";
                    contact["lastname"]      = "last";
                    contact["funllname"]     = "last";
                    contact["emailaddress1"] = "*****@*****.**";

                    return(contact);
                }

                return(null);
            };
            PostSatisfactionSurveyResponseCreate pluginClass = new PostSatisfactionSurveyResponseCreate();

            pluginClass.Execute(serviceProvider);
        }
        public void CreateSR()
        {
            PreServiceRequestCreate servicerequestCreate = new PreServiceRequestCreate();
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(1);
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(915240000);
            incident.Attributes["smp_duedate"]      = new DateTime(2018, 1, 8);
            incident.Attributes["smp_portalsubmit"] = true;
            incident.Attributes["smp_duedatebybuildingtimezone"]           = "2018-01-08";
            incident.Attributes["smp_occureddatetimebybuildingtimezone"]   = "2018-01-08";
            incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_createddatetimebybuildingtimezone"]   = "2018-01-08";
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident.Attributes["smp_integrationstatus"] = true;
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null);

            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("FetchExpression"))
                {
                    if (((FetchExpression)query).Query.Contains("<entity name='smp_room'>"))
                    {
                        entityName = "smp_room";
                    }
                }
                else if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_providermatrix")
                {
                    Entity matrix = new Entity("smp_providermatrix");
                    matrix.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    matrix["smp_primaryproviderid"] = new EntityReference("account", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"));
                    collection.Entities.Add(matrix);
                }

                if (entityName == "smp_room")
                {
                    Entity room = new Entity(entityName);
                    room.Id            = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    room["smp_name"]   = "test room";
                    room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    collection.Entities.Add(room);
                }

                if (entityName == "account")
                {
                    Entity account = new Entity(entityName);
                    account["accountid"]  = new Guid("884A078B-0467-E711-80F5-3863BB3C1560");
                    account["statuscode"] = 1;
                    collection.Entities.Add(account);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "smp_room")
                {
                    Entity room = new Entity(entity);
                    room.Id            = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    room["smp_name"]   = "test room";
                    room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    return(room);
                }

                return(null);
            };

            servicerequestCreate.Execute(serviceProvider);
        }
        public void CreateSRCaseOriginCode()
        {
            PreServiceRequestCreate servicerequestCreate = new PreServiceRequestCreate();
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(1);
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(3);
            incident.Attributes["smp_duedate"]      = new DateTime(2018, 1, 8);
            incident.Attributes["smp_portalsubmit"] = true;
            incident.Attributes["smp_duedatebybuildingtimezone"]           = "2018-01-08";
            incident.Attributes["smp_occureddatetimebybuildingtimezone"]   = "2018-01-08";
            incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_createddatetimebybuildingtimezone"]   = "2018-01-08";
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident["smp_requestorid"]                    = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
            incident["telephone1"]                         = "777";
            incident["smp_alias"]                          = "testalias";
            incident["emailaddress1"]                      = "*****@*****.**";
            incident.Attributes["smp_buildingid"]          = new EntityReference("smp_building", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["new_requestorroomnumber"] = "1222";
            incident.Attributes["telephone1"]              = "77889990";

            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null);

            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("FetchExpression"))
                {
                    if (((FetchExpression)query).Query.Contains("<entity name='smp_room'>"))
                    {
                        entityName = "smp_room";
                    }
                }
                else if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_providermatrix")
                {
                    Entity matrix = new Entity("smp_providermatrix");
                    matrix.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    matrix["smp_primaryproviderid"]          = new EntityReference("account", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"));
                    matrix.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A178B-0466-E711-80F5-3863BB3C0560"))
                    {
                        Name = "roomtype"
                    };
                    matrix.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A278B-0468-E711-80F5-3863BB3C0560"))
                    {
                        Name = "problemClass"
                    };
                    matrix.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A378B-0469-E711-80F5-3863BB3C0560"))
                    {
                        Name = "problemType"
                    };
                    matrix.Attributes["smp_approvalrequired"] = true;
                    matrix.Attributes["smp_billablecode"]     = "1234";
                    collection.Entities.Add(matrix);
                }

                if (entityName == "smp_room")
                {
                    Entity room = new Entity(entityName);
                    room.Id            = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    room["smp_name"]   = "test room";
                    room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    collection.Entities.Add(room);
                }

                if (entityName == "account")
                {
                    Entity account = new Entity(entityName);
                    account["accountid"]  = new Guid("884A078B-0467-E711-80F5-3863BB3C1560");
                    account["statuscode"] = 1;
                    collection.Entities.Add(account);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "smp_room")
                {
                    Entity room = new Entity(entity);
                    room.Id            = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    room["smp_name"]   = "test room";
                    room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679");
                    return(room);
                }
                else if (entity == "contact")
                {
                    Entity contact = new Entity(entity);
                    contact.Id = Guid.NewGuid();
                    contact["smp_preferredlanguage"]      = "en-us";
                    contact["smp_isprovideruser"]         = false;
                    contact["smp_costcenter"]             = "11110";
                    contact["smp_allowemailnotification"] = false;
                    contact["smp_alias"]     = "testalias";
                    contact["firstname"]     = "first";
                    contact["lastname"]      = "last";
                    contact["funllname"]     = "last";
                    contact["emailaddress1"] = "*****@*****.**";
                    contact["smp_manager"]   = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0679"));

                    return(contact);
                }
                else if (entity == "smp_building")
                {
                    Entity building = new Entity(entity);
                    building.Id = Guid.NewGuid();
                    building["smp_timezoneid"]                     = new EntityReference("smp_timezone", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    building["smp_isfinancialstatecampus"]         = true;
                    building["smp_buildinglevelemailnotification"] = true;
                    building["smp_feedstoreid"]                    = "Sample StoreId";
                    building["smp_buildingname"]                   = "sample building";
                    building["smp_addressline1"]                   = "test addressline1";
                    building["smp_addressline2"]                   = "test addressline2";
                    building["smp_state"]          = "test state";
                    building["smp_country"]        = "test country";
                    building["smp_city"]           = "test city";
                    building["smp_zipcode"]        = "1222333";
                    building["smp_timezoneid"]     = "test zone";
                    building["statuscode"]         = new OptionSetValue(2);
                    building["smp_buildingid"]     = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    building["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    building["smp_problemtypeid"]  = new EntityReference("smp_problemtype", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));

                    return(building);
                }
                else if (entity == "smp_problemclass")
                {
                    Entity problemClass = new Entity(entity);
                    problemClass.Id = Guid.NewGuid();
                    problemClass["smp_donotallowsurvey"]       = true;
                    problemClass["smp_allowemailnotification"] = true;
                    return(problemClass);
                }
                else if (entity == "smp_problemtype")
                {
                    Entity problemType = new Entity(entity);
                    problemType.Id = Guid.NewGuid();
                    problemType["smp_donotallowsurvey"]       = true;
                    problemType["smp_allowemailnotification"] = true;
                    return(problemType);
                }
                else if (entity == "smp_problemtypedescription")
                {
                    Entity problemType = new Entity(entity);
                    problemType.Id = Guid.NewGuid();
                    problemType["smp_problemtypedescriptionname"] = "sample description";
                    return(problemType);
                }
                else if (entity == "smp_priority")
                {
                    Entity priority = new Entity(entity);
                    priority.Id          = Guid.NewGuid();
                    priority["smp_name"] = "sample name";
                    return(priority);
                }
                else if (entity == "smp_roomtype")
                {
                    Entity problemclass = new Entity(entity);
                    problemclass.Id = Guid.NewGuid();
                    problemclass["smp_roomtype"] = "sample room";
                    return(problemclass);
                }

                return(null);
            };
            servicerequestCreate.Execute(serviceProvider);
        }
        public void DoIntegrationWithIsHostedinAzureTrue()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection          = new Microsoft.Xrm.Sdk.ParameterCollection();
            Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(2);
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(1);
            incident.Attributes["smp_duedate"]      = new DateTime(2018, 1, 8);
            incident.Attributes["smp_portalsubmit"] = false;
            incident.Attributes["smp_duedatebybuildingtimezone"]         = "2018-01-08";
            incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08";
            incident["smp_submitteddatetime"]      = new DateTime(2018, 1, 8);
            incident["createdon"]                  = new DateTime(2018, 1, 8);
            incident["smp_problemoccureddatetime"] = new DateTime(2018, 1, 8);
            incident["smp_createdfrom"]            = new OptionSetValue(1);
            incident["smp_integrationstatus"]      = true;
            incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_createddatetimebybuildingtimezone"]   = "2018-01-08";
            incident["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "roomtype"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "TestName"
            };
            incident.Attributes["customerid"]           = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            incident.Attributes["smp_requestedduedate"] = new DateTime(2018, 1, 8); ////"2018-01-08";
            incident.Attributes["title"]      = "sample title";
            incident.Attributes["smp_iocode"] = "sample code";
            incident.Attributes["smp_tier1workcompletiondatebybuildingtimezone"] = "sample timezone";
            incident.Attributes["smp_providerduedatebybuildingtimezone"]         = "sample title";
            incident.Attributes["smp_problembuildingaddressline1"] = "sample address1";
            incident.Attributes["smp_problembuildingaddressline2"] = "sample address1";
            incident.Attributes["smp_problembuildingcity"]         = "sample city";
            incident.Attributes["smp_problembuildingcountry"]      = "sample country";
            incident.Attributes["smp_problembuildingzipcode"]      = "23432423";
            incident.Attributes["smp_problemcode"]            = "sample code";
            incident.Attributes["smp_problemtypedescription"] = "sample description";
            incident.Attributes["smp_requestoralias"]         = "sample alias";
            incident.Attributes["smp_requestorfirstname"]     = "sample first name";
            incident.Attributes["smp_requestorlastname"]      = "sample last name";
            incident.Attributes["smp_requestorphone"]         = "sample phone";
            incident.Attributes["smp_requestorroomno"]        = "sample promo";
            incident.Attributes["smp_requestorroomtype"]      = "sample room type";

            Entity preIncident = new Entity("incident");

            preIncident["incidentid"] = Guid.NewGuid();
            preIncident["statuscode"] = new OptionSetValue(1);
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            EntityImageCollection postImage = new EntityImageCollection {
                (new KeyValuePair <string, Entity>("PostImage", incident))
            };
            EntityImageCollection preImage = new EntityImageCollection {
                new KeyValuePair <string, Entity>("PreImage", preIncident)
            };

            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", postImage, preImage);

            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_configuration")
                {
                    ////query.ExtensionData
                    var v = (((QueryExpression)query).Criteria.Conditions)[0].Values.First().ToString();
                    if (v == "AzureToeknService")
                    {
                        Entity configurationAzure = new Entity("smp_configuration");
                        configurationAzure.Id           = Guid.NewGuid();
                        configurationAzure["smp_title"] = "AzureToeknService";
                        configurationAzure["smp_value"] = "https://gfmstokenservice.azurewebsites.net/CmmsServiceRequestManagerAAD.svc";
                        collection.Entities.Add(configurationAzure);
                        return(collection);
                    }

                    if (v == "TokenEndpointURL")
                    {
                        Entity configurationAzure = new Entity("smp_configuration");
                        configurationAzure.Id           = Guid.NewGuid();
                        configurationAzure["smp_title"] = "TokenEndpointURL";
                        configurationAzure["smp_value"] = "https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/token";
                        collection.Entities.Add(configurationAzure);
                        return(collection);
                    }

                    Entity configuration = new Entity("smp_configuration");
                    configuration.Id           = Guid.NewGuid();
                    configuration["smp_title"] = "8/8RoutingPriorities";
                    configuration["smp_value"] = "P1,P2,PS1,PS2";
                    collection.Entities.Add(configuration);
                    Entity configuration1 = new Entity("smp_configuration");
                    configuration1.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration1["smp_title"] = "EmailSenderDomainName";
                    configuration1["smp_value"] = "*****@*****.**";
                    collection.Entities.Add(configuration1);
                    Entity configuration2 = new Entity("smp_configuration");
                    configuration2.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration2["smp_title"] = "PendingDispatchStatusCode";
                    configuration2["smp_value"] = "2";
                    collection.Entities.Add(configuration2);
                    Entity configuration3 = new Entity("smp_configuration");
                    configuration3.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration3["smp_title"] = "DefaultProviderName";
                    configuration3["smp_value"] = "NotAssigned";
                    collection.Entities.Add(configuration3);
                    Entity configuration4 = new Entity("smp_configuration");
                    configuration4.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration4["smp_title"] = "NoCmmsIntegrationActionCodes";
                    configuration4["smp_value"] = "test";
                    collection.Entities.Add(configuration4);
                    Entity configuration5 = new Entity("smp_configuration");
                    configuration5.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration5["smp_title"] = "StatusChangeOnCodes";
                    configuration5["smp_value"] = "Draft";
                    collection.Entities.Add(configuration5);
                    Entity configuration6 = new Entity("smp_configuration");
                    configuration6.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration6["smp_title"] = "OutBoundIntegrationtimeOutInSeconds";
                    configuration6["smp_value"] = "5";
                    collection.Entities.Add(configuration6);
                    Entity configuration7 = new Entity("smp_configuration");
                    configuration7.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration7["smp_title"] = "DebugOutBoundIntegration";
                    configuration7["smp_value"] = "4";
                    collection.Entities.Add(configuration7);
                    Entity configuration8 = new Entity("smp_configuration");
                    configuration8.Id           = Guid.NewGuid();
                    configuration8["smp_title"] = "ServiceRequestIntegrationFailEmailTemplateName";
                    configuration8["smp_value"] = "*****@*****.**";
                    collection.Entities.Add(configuration8);
                    Entity configuration9 = new Entity("smp_configuration");
                    configuration9.Id           = Guid.NewGuid();
                    configuration9["smp_title"] = "SASToken";
                    configuration9["smp_value"] = "Test";
                    collection.Entities.Add(configuration9);
                    Entity configuration10 = new Entity("smp_configuration");
                    configuration10.Id           = Guid.NewGuid();
                    configuration10["smp_title"] = "AttachmentBlobUrl";
                    configuration10["smp_value"] = "https://refstorage.blob.core.windows.net/msrefpuatblobnotes/";
                    collection.Entities.Add(configuration10);
                    Entity configuration11 = new Entity("smp_configuration");
                    configuration11.Id           = Guid.NewGuid();
                    configuration11["smp_title"] = "Environment";
                    configuration11["smp_value"] = "Non-Prod";
                    collection.Entities.Add(configuration11);
                }
                else if (entityName == "smp_providerintegration")
                {
                    Entity providerintegration = new Entity(entityName);
                    providerintegration.Id                        = Guid.NewGuid();
                    providerintegration["smp_name"]               = "Engineer Team Details";
                    providerintegration["smp_clientid"]           = "";
                    providerintegration["smp_serviceprincipalid"] = "";
                    collection.Entities.Add(providerintegration);
                }
                else if (entityName == "smp_servicerequeststatuscode")
                {
                    Entity srStatusCode = new Entity(entityName);
                    srStatusCode.Id          = Guid.NewGuid();
                    srStatusCode["smp_name"] = "test1";
                    srStatusCode["smp_servicerequeststatus"] = new OptionSetValue(2);
                    collection.Entities.Add(srStatusCode);
                }
                else if (entityName == "smp_servicerequestproblemtypedesc")
                {
                    Entity servicerequestproblemtype = new Entity(entityName);
                    servicerequestproblemtype.Id = Guid.NewGuid();
                    servicerequestproblemtype["smp_servicerequestproblemtypedescid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    servicerequestproblemtype["smp_problemtypedescriptionid"]        = new EntityReference("smp_problemtypedescription", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                    servicerequestproblemtype["smp_answer"] = "Sample Answer";
                    collection.Entities.Add(servicerequestproblemtype);
                }
                else if (entityName == "systemuser")
                {
                    Entity systemUser = new Entity(entityName);
                    systemUser.Id = Guid.NewGuid();
                    systemUser["systemuserid"] = systemUser.Id;
                    collection.Entities.Add(systemUser);
                }
                else if (entityName == "template")
                {
                    Entity annotation = new Entity(entityName);
                    annotation.Id            = Guid.NewGuid();
                    annotation["templateid"] = annotation.Id;
                    annotation["subject"]    = "<?xml version=\"1.0\" ?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"text\" indent=\"no\" /><xsl:template match=\"/data\"><![CDATA[We haven't heard from you...]]></xsl:template></xsl:stylesheet>";
                    annotation["body"]       = "<?xml version=\"1.0\" ?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"text\" indent=\"no\"/><xsl:template match=\"/data\"><![CDATA[<P>Dear ]]><xsl:choose><xsl:when test=\"account/name\"><xsl:value-of select=\"account/name\" /></xsl:when><xsl:otherwise>Valued Customer</xsl:otherwise></xsl:choose><![CDATA[,</P> <P>We have not heard from you for a while. We wanted to check in and make sure that you are still having a great experience using our product(s). We have asked ]]><xsl:choose><xsl:when test=\"account/ownerid/@name\"><xsl:value-of select=\"account/ownerid/@name\" /></xsl:when><xsl:otherwise>a customer service representative</xsl:otherwise></xsl:choose><![CDATA[ to contact you next week to get your feedback on the product(s) you are currently using and to give you details about our upcoming products.</P> <P>Thank you.</P>]]></xsl:template></xsl:stylesheet>";
                    collection.Entities.Add(annotation);
                }
                else if (entityName == "msdyn_azureblobstoragesetting")
                {
                    Entity blobSettings = new Entity(entityName);
                    blobSettings.Id            = Guid.NewGuid();
                    blobSettings["msdyn_name"] = "refstorage";
                    blobSettings["msdyn_annotationcontainer"] = "msrefpuatblobnotes";
                    collection.Entities.Add(blobSettings);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "account")
                {
                    Entity account = new Entity(entity);
                    account.Id      = Guid.NewGuid();
                    account["name"] = "test Provider";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "https://testurl/cmmsservicerequestmanagerAAD.svc";
                    account["smp_hostedonazure"] = true;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    return(account);
                }
                else if (entity == "contact")
                {
                    Entity contact = new Entity(entity);
                    contact.Id = Guid.NewGuid();
                    contact["smp_preferredlanguage"]      = "English";
                    contact["smp_isprovideruser"]         = true;
                    contact["smp_costcenter"]             = "samdple center";
                    contact["smp_allowemailnotification"] = true;
                    contact["smp_alias"]     = "sample alias";
                    contact["firstname"]     = "sample firstname";
                    contact["lastname"]      = "sample lastname";
                    contact["emailaddress1"] = "*****@*****.**";
                    return(contact);
                }
                else if (entity == "smp_problemtypedescription")
                {
                    Entity problemType = new Entity(entity);
                    problemType.Id = Guid.NewGuid();
                    problemType["smp_problemtypedescriptionname"] = "sample description";
                    return(problemType);
                }
                else if (entity == "smp_priority")
                {
                    Entity priority = new Entity(entity);
                    priority.Id          = Guid.NewGuid();
                    priority["smp_name"] = "sample name";
                    return(priority);
                }
                else if (entity == "smp_problemclass")
                {
                    Entity problemclass = new Entity(entity);
                    problemclass.Id = Guid.NewGuid();
                    problemclass["smp_problemclassname"] = "sample class";
                    return(problemclass);
                }
                else if (entity == "smp_building")
                {
                    Entity building = new Entity(entity);
                    building.Id = Guid.NewGuid();
                    building["smp_buildingname"] = "sample building";
                    building["smp_feedstoreid"]  = "Sample StoreId";
                    return(building);
                }
                else if (entity == "smp_roomtype")
                {
                    Entity problemclass = new Entity(entity);
                    problemclass.Id = Guid.NewGuid();
                    problemclass["smp_roomtype"] = "sample room";
                    return(problemclass);
                }
                else if (entity == "smp_problemtype")
                {
                    Entity smp_problemtype = new Entity(entity);
                    smp_problemtype.Id = Guid.NewGuid();
                    smp_problemtype["smp_problemtypename"] = "sample problemtype";
                    return(smp_problemtype);
                }

                return(null);
            };

            PostCreateUpdateDoIntegration doIntegration = new PostCreateUpdateDoIntegration();

            doIntegration.Execute(serviceProvider);
        }
        public void DoIntegration()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection          = new Microsoft.Xrm.Sdk.ParameterCollection();
            Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident.Attributes["statuscode"]          = new OptionSetValue(2);
            incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560"))
            {
                Name = "building"
            };
            incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560"))
            {
                Name = "room"
            };
            incident.Attributes["caseorigincode"]   = new OptionSetValue(1);
            incident.Attributes["smp_duedate"]      = new DateTime(2018, 1, 8);
            incident.Attributes["smp_portalsubmit"] = false;
            incident.Attributes["smp_duedatebybuildingtimezone"]         = "2018-01-08";
            incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08";
            incident["smp_submitteddatetime"]      = new DateTime(2018, 1, 8);
            incident["createdon"]                  = new DateTime(2018, 1, 8);
            incident["smp_problemoccureddatetime"] = new DateTime(2018, 1, 8);
            incident["smp_createdfrom"]            = new OptionSetValue(1);
            incident["smp_integrationstatus"]      = true;
            incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08";
            incident.Attributes["smp_createddatetimebybuildingtimezone"]   = "2018-01-08";
            incident["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "roomtype"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "TestName"
            };
            incident.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"));
            Entity preIncident = new Entity("incident");

            preIncident["incidentid"] = Guid.NewGuid();
            preIncident["statuscode"] = new OptionSetValue(1);
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            EntityImageCollection postImage = new EntityImageCollection {
                (new KeyValuePair <string, Entity>("PostImage", incident))
            };
            EntityImageCollection preImage = new EntityImageCollection {
                new KeyValuePair <string, Entity>("PreImage", preIncident)
            };

            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", postImage, preImage);
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_configuration")
                {
                    Entity configuration = new Entity("smp_configuration");
                    configuration.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration["smp_title"] = "8/8RoutingPriorities";
                    configuration["smp_value"] = "P1,P2,PS1,PS2";
                    collection.Entities.Add(configuration);
                    Entity configuration1 = new Entity("smp_configuration");
                    configuration1.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration1["smp_title"] = "EmailSenderDomainName";
                    configuration1["smp_value"] = "*****@*****.**";
                    collection.Entities.Add(configuration1);
                    Entity configuration2 = new Entity("smp_configuration");
                    configuration2.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration2["smp_title"] = "PendingDispatchStatusCode";
                    configuration2["smp_value"] = "2";
                    collection.Entities.Add(configuration2);
                    Entity configuration3 = new Entity("smp_configuration");
                    configuration3.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration3["smp_title"] = "DefaultProviderName";
                    configuration3["smp_value"] = "NotAssigned";
                    collection.Entities.Add(configuration3);
                    Entity configuration4 = new Entity("smp_configuration");
                    configuration4.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration4["smp_title"] = "NoCmmsIntegrationActionCodes";
                    configuration4["smp_value"] = "test";
                    collection.Entities.Add(configuration4);
                    Entity configuration5 = new Entity("smp_configuration");
                    configuration5.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration5["smp_title"] = "StatusChangeOnCodes";
                    configuration5["smp_value"] = "Draft";
                    collection.Entities.Add(configuration5);
                    Entity configuration6 = new Entity("smp_configuration");
                    configuration6.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration6["smp_title"] = "OutBoundIntegrationtimeOutInSeconds";
                    configuration6["smp_value"] = "5";
                    collection.Entities.Add(configuration6);
                    Entity configuration7 = new Entity("smp_configuration");
                    configuration7.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration7["smp_title"] = "DebugOutBoundIntegration";
                    configuration7["smp_value"] = "4";
                    collection.Entities.Add(configuration7);
                }
                else if (entityName == "smp_servicerequeststatuscode")
                {
                    Entity srStatusCode = new Entity(entityName);
                    srStatusCode["smp_name"] = "test";
                    srStatusCode["smp_servicerequeststatus"] = new OptionSetValue(2);
                    collection.Entities.Add(srStatusCode);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "account")
                {
                    Entity account = new Entity(entity);
                    account["name"] = "test Provider";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "https://testurl/cmmsservicerequestmanagerAAD.svc";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    return(account);
                }

                return(null);
            };

            PostCreateUpdateDoIntegration doIntegration = new PostCreateUpdateDoIntegration();

            doIntegration.Execute(serviceProvider);
        }
Beispiel #11
0
        public void SetDynamicNotesFromPortal()
        {
            var serviceProvider     = new StubIServiceProvider();
            var pluginContext       = new StubIPluginExecutionContext();
            var organizationService = new StubIOrganizationService();

            pluginContext.PrimaryEntityNameGet = () => "incident";
            pluginContext.PrimaryEntityIdGet   = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            Microsoft.Xrm.Sdk.ParameterCollection paramCollection          = new Microsoft.Xrm.Sdk.ParameterCollection();
            Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
            Entity incident = new Entity("incident");

            incident.Id                  = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            incident["smp_answer"]       = @"{""data"":[{""id"":""ba43e8a7-c9ec-e211-ad57-78e3b511b663"",""answer"":""please ignore this request""},{""id"":""b643e8a7-c9ec-e211-ad57-78e3b511b663"",""answer"":""please ignore this request""},{""id"":""b443e8a7-c9ec-e211-ad57-78e3b511b663"",""answer"":""please ignore this request""}]}";
            incident["smp_portalsubmit"] = true;
            incident["smp_contact"]      = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "contact"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "priority"
            };
            incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"))
            {
                Name = "roomtype"
            };
            incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560"))
            {
                Name = "problemClass"
            };
            incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "problemType"
            };
            incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "TestName"
            };
            incident.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560"))
            {
                Name = "Test Record"
            };
            paramCollection.Add("Target", incident);
            pluginContext.InputParametersGet = () => paramCollection;
            EntityImageCollection postImage = new EntityImageCollection {
                (new KeyValuePair <string, Entity>("PostImage", incident))
            };

            Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", postImage);
            organizationService.RetrieveMultipleQueryBase = (query) =>
            {
                EntityCollection collection = new EntityCollection();
                string           entityName = string.Empty;
                if (query.GetType().Name.Equals("FetchExpression"))
                {
                    if (((FetchExpression)query).Query.Contains("<entity name='smp_8x8mailbox'>"))
                    {
                        entityName = "smp_8x8mailbox";
                    }
                }
                else if (query.GetType().Name.Equals("QueryExpression"))
                {
                    entityName = ((QueryExpression)query).EntityName;
                }
                else
                {
                    entityName = ((QueryByAttribute)query).EntityName;
                }

                if (entityName == "smp_configuration")
                {
                    Entity configuration = new Entity("smp_configuration");
                    configuration.Id           = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    configuration["smp_title"] = "8/8RoutingPriorities";
                    configuration["smp_value"] = "P1,P2,PS1,PS2";
                    configuration["smp_title"] = "EmailSenderDomainName";
                    configuration["smp_value"] = "*****@*****.**";
                    configuration["smp_title"] = "PendingDispatchStatusCode";
                    configuration["smp_value"] = "2";
                    configuration["smp_title"] = "DefaultProviderName";
                    configuration["smp_value"] = "NotAssigned";
                    collection.Entities.Add(configuration);
                }
                else if (entityName == "smp_servicerequeststatuscode")
                {
                    Entity srStatusCode = new Entity(entityName);
                    srStatusCode["smp_name"] = "test";
                    srStatusCode["smp_servicerequeststatus"] = new OptionSetValue(2);
                    collection.Entities.Add(srStatusCode);
                }
                else if (entityName == "systemuser")
                {
                    Entity user = new Entity(entityName);
                    user["systemuserid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    user["domainname"]   = "*****@*****.**";
                    collection.Entities.Add(user);
                }
                else if (entityName == "smp_8x8mailbox")
                {
                    Entity eightByEight = new Entity(entityName);
                    eightByEight["smp_8x8mailboxid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0560");
                    collection.Entities.Add(eightByEight);
                }
                else if (entityName == "smp_problemtypedescription")
                {
                    Entity problemDescription = new Entity(entityName);
                    problemDescription["smp_problemtypedescriptionid"]   = Guid.NewGuid();
                    problemDescription["smp_problemtypedescriptionname"] = "test";
                    collection.Entities.Add(problemDescription);
                }

                return(collection);
            };

            organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet)
            {
                if (entity == "smp_building")
                {
                    Entity building = new Entity("entity");
                    building.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                    building["smp_timezoneid"]             = new EntityReference("smp_timezone", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    building["smp_isfinancialstatecampus"] = true;
                    return(incident);
                }
                else if (entity == "smp_timezone")
                {
                    Entity timeZone = new Entity(entity);
                    timeZone["smp_timezonename"] = "test timezone";
                    timeZone["smp_offset"]       = new OptionSetValue(2);
                    return(timeZone);
                }
                else if (entity == "smp_priority")
                {
                    Entity priority = new Entity(entity);
                    priority["smp_noofminutes"] = 100;
                    return(priority);
                }
                else if (entity == "smp_roomtype")
                {
                    Entity roomType = new Entity(entity);
                    roomType["smp_zone"] = new OptionSetValue(1);
                    return(roomType);
                }
                else if (entity == "account")
                {
                    Entity account = new Entity(entity);
                    account["name"] = "test Provider";
                    account["smp_iscmmsintegrationenabled"] = true;
                    account["smp_cmmsurl"]       = "testurl";
                    account["smp_hostedonazure"] = false;
                    account["smp_providerteam"]  = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652"));
                    return(account);
                }
                else if (entity == "contact")
                {
                    Entity contact = new Entity(entity);
                    contact["smp_preferredlanguage"]      = "en-US";
                    contact["smp_isprovideruser"]         = false;
                    contact["smp_costcenter"]             = "11110";
                    contact["smp_allowemailnotification"] = true;
                    return(contact);
                }

                return(null);
            };

            PostCreateUpdateIncidentInPortal portalIncident = new PostCreateUpdateIncidentInPortal();

            portalIncident.Execute(serviceProvider);
        }
        public void SRUpdate()
        {
            {
                this.pluginContext.PrimaryEntityNameGet = () => "incident";
                this.pluginContext.PrimaryEntityIdGet = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection();
                Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection();
                Entity incident = new Entity("incident");
                incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                incident["smp_createdfrom"] = new OptionSetValue(1);
                incident["smp_portalsubmit"] = true;
                incident.Attributes["caseorigincode"] = new OptionSetValue(3);
                incident.Attributes["smp_reclassifiedsr"] = new EntityReference("smp_reclassifiedsr", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")) { Name = "incident" };
                incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")) { Name = "building" };
                incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560")) { Name = "problemClass" };
                incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")) { Name = "problemType" };
                paramCollection.Add("Target", incident);
                this.pluginContext.InputParametersGet = () => paramCollection;
                EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair<string, Entity>("PostImage", incident)) };
                Helper.Helper.PluginVariables(this.serviceProvider, this.pluginContext, this.organizationService, 40, "Update", postImage);

                this.organizationService.RetrieveMultipleQueryBase = (query) =>
                {
                    EntityCollection collection = new EntityCollection();
                    string entityName = string.Empty;

                    if (query.GetType().Name.Equals("QueryExpression"))
                    {
                        entityName = ((QueryExpression)query).EntityName;
                    }
                    else
                    {
                        entityName = ((QueryByAttribute)query).EntityName;
                    }

                    if (entityName == "smp_problemtypedescription")
                    {
                        Entity configuration = new Entity("smp_configuration");
                        configuration.Id = new Guid("884A078B-0466-E712-80F5-3863BB3C0560");
                        configuration["smp_problemtypedescriptionid"] = new Guid("884A078B-0466-E712-80F5-3863BB3C0560");
                        configuration["smp_problemtypedescriptionname"] = "Sample Name";

                        collection.Entities.Add(configuration);
                    }

                    if (entityName == "smp_servicerequestproblemtypedesc")
                    {
                        Entity servicerequestproblemtype = new Entity(entityName);
                        servicerequestproblemtype.Id = Guid.NewGuid();
                        servicerequestproblemtype["smp_servicerequestproblemtypedescid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                        servicerequestproblemtype["smp_problemtypedescriptionid"] = new EntityReference("smp_problemtypedescription", new Guid("884A078B-0466-E711-80F5-3863BB3C0560"));
                        servicerequestproblemtype["smp_answer"] = "Sample Answer";
                        servicerequestproblemtype["smp_servicerequestid"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660"));
                        collection.Entities.Add(servicerequestproblemtype);
                    }

                    return collection;
                };

                this.organizationService.RetrieveStringGuidColumnSet = delegate (string entity, Guid guid, ColumnSet secondaryUserColumnSet)
                {
                    if (entity == "incident")
                    {
                        Entity incidents = new Entity(entity);
                        incidents["caseorigincode"] = new OptionSetValue(1);
                        incidents["smp_createdfrom"] = new OptionSetValue(1);
                        incident["smp_portalsubmit"] = true;
                        incidents["smp_problembuilding"] = new EntityReference(string.Empty, Guid.NewGuid());
                        incidents["smp_problemclassid"] = new EntityReference(string.Empty, Guid.NewGuid());
                        incidents["smp_problemtypeid"] = new EntityReference(string.Empty, Guid.NewGuid());

                        incidents.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                        return incidents;
                    }
                    else if (entity == "smp_servicerequestproblemtypedesc")
                    {
                        Entity dpnEntity = new Entity(entity);
                        dpnEntity.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
                        dpnEntity["statecode"] = 1;
                        dpnEntity["statuscode"] = 2;
                    }

                    return null;
                };

                PostUpdateSRUpdateDynNotes srUpdateDynNotes = new PostUpdateSRUpdateDynNotes();
                srUpdateDynNotes.Execute(this.serviceProvider);
            }
        }