/// <summary> /// Initializes a new instance of the <see cref="CuteContext"/> class. /// </summary> public CuteContext() { InputParameters = new ParameterCollection(); OutputParameters = new ParameterCollection(); PreEntityImages = new EntityImageCollection(); PostEntityImages = new EntityImageCollection(); }
public FakeExecutionContext() { InputParameters = new ParameterCollection(); OutputParameters = new ParameterCollection(); SharedVariables = new ParameterCollection(); PreEntityImages = new EntityImageCollection(); PostEntityImages = new EntityImageCollection(); UserId = new Guid("eb96c0b5-93cc-4a82-bf9d-f8f5880f4772"); }
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 PipelineBase(IOrganizationService service = null) { if (service == null) { FakeService = new FakeOrganzationService(); Service = FakeService; } else { Service = service; } CorrelationId = Guid.NewGuid(); RequestId = Guid.NewGuid(); OperationId = Guid.NewGuid(); OperationCreatedOn = DateTime.UtcNow; PreImages = new EntityImageCollection(); PostImages = new EntityImageCollection(); InputParameters = new ParameterCollection(); OutputParameters = new ParameterCollection(); PluginExecutionContext = A.Fake <IPluginExecutionContext>(a => a.Strict()); A.CallTo(() => PluginExecutionContext.PreEntityImages).Returns(PreImages); A.CallTo(() => PluginExecutionContext.PostEntityImages).Returns(PostImages); A.CallTo(() => PluginExecutionContext.InputParameters).Returns(InputParameters); A.CallTo(() => PluginExecutionContext.OutputParameters).Returns(OutputParameters); // ITracingService TracingService = A.Fake <ITracingService>((a) => a.Strict()); A.CallTo(() => TracingService.Trace(A <string> .Ignored, A <object[]> .Ignored)) .Invokes((string format, object[] args) => { if (args != null && args.Length > 0) { Trace.WriteLine(string.Format(format, args)); } else { Trace.WriteLine(format); } }); // IOrganizationServiceFactory Factory = A.Fake <IOrganizationServiceFactory>((a) => a.Strict()); A.CallTo(() => Factory.CreateOrganizationService(A <Guid?> .Ignored)).Returns(Service); // IServiceProvider ServiceProvider = A.Fake <IServiceProvider>((a) => a.Strict()); A.CallTo(() => ServiceProvider.GetService(A <Type> .Ignored)) .ReturnsLazily((objectcall) => { var type = (Type)objectcall.Arguments[0]; if (type == typeof(IPluginExecutionContext)) { return(PluginExecutionContext); } else if (type == typeof(ITracingService)) { return(TracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(Factory); } return(null); }); }
private Mock<IPluginExecutionContext> MockPluginExecutionContext() { var mock = new Mock<IPluginExecutionContext>(); mock.SetupGet(x => x.UserId).Returns(TestId); mock.SetupGet(x => x.InputParameters).Returns(TestParameterCollection); var testEntityImageCollection = new EntityImageCollection() { new KeyValuePair<string, Entity>(PluginContext.ImageEntityAlias, TestEntity) }; mock.SetupGet(x => x.PreEntityImages).Returns(testEntityImageCollection); mock.SetupGet(x => x.PostEntityImages).Returns(testEntityImageCollection); return mock; }
public IPlugin ExecutePluginWith <T>(ParameterCollection inputParameters, ParameterCollection outputParameters, EntityImageCollection preEntityImages, EntityImageCollection postEntityImages) where T : IPlugin, new() { var ctx = GetDefaultPluginContext(); ctx.InputParameters.AddRange(inputParameters); ctx.OutputParameters.AddRange(outputParameters); ctx.PreEntityImages.AddRange(preEntityImages); ctx.PostEntityImages.AddRange(postEntityImages); var fakedServiceProvider = GetFakedServiceProvider(ctx); var fakedPlugin = A.Fake <IPlugin>(); A.CallTo(() => fakedPlugin.Execute(A <IServiceProvider> ._)) .Invokes((IServiceProvider provider) => { var plugin = new T(); plugin.Execute(fakedServiceProvider); }); fakedPlugin.Execute(fakedServiceProvider); //Execute the plugin return(fakedPlugin); }
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 FSPostUpdateOfServiceRequestStatusTestMethod() { using (ShimsContext.Create()) { FSPostUpdateOfServiceRequestStatus fspostUpdateOfServiceRequestStatus = new StubFSPostUpdateOfServiceRequestStatus(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "incident"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity targetIncident = new Entity("incident"); targetIncident.Id = new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); targetIncident.Attributes["statuscode"] = new OptionSetValue(180620002); paramCollection.Add("Target", targetIncident); pluginContext.InputParametersGet = () => paramCollection; Entity incidentImage = new Entity("incident"); incidentImage.Id = new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); incidentImage.Attributes["statuscode"] = new OptionSetValue(180620002); incidentImage.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0468-E711-80F5-3863BB3C0660")); incidentImage.Attributes["smp_problembuilding"] = new EntityReference("building", new Guid("884A078B-0458-E711-80F5-3863BB3C0660")); incidentImage.Attributes["smp_workorderwithind365"] = true; incidentImage.Attributes["transactioncurrencyid"] = new EntityReference("transactioncurrency", new Guid("884A078B-0468-E721-80F5-3863BB3C0660")); var postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", incidentImage)) }; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Update", postImage); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("FetchExpression")) { if (((Microsoft.Xrm.Sdk.Query.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 == "msdyn_workorder") { Entity workorder = new Entity("msdyn_workorder"); workorder.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); workorder.Attributes["msdyn_servicerequest"] = new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); collection.Entities.Add(workorder); } if (entityName == "pricelevel") { Entity pricelevel = new Entity("pricelevel"); pricelevel.Id = new Guid("884A078B-0468-E712-80F5-3863BB3C0560"); pricelevel.Attributes["name"] = "US"; collection.Entities.Add(pricelevel); } if (entityName == "account") { Entity pricelevel = new Entity("account"); pricelevel.Id = new Guid("884A078B-0468-E712-80F8-3863BB3C0560"); pricelevel.Attributes["name"] = "BuildingName"; collection.Entities.Add(pricelevel); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "account") { Entity incident = new Entity("account"); incident.Id = new Guid("884A078B-0468-E711-80F5-3863BB3C0660"); incident.Attributes["smp_workorderwithind365"] = true; incident.Attributes["msdyn_servicerequest"] = new EntityReference("account", new Guid("884A078B-0468-E711-80F5-3863BB3C0660")); incident.Attributes["msdyn_pricelist"] = new EntityReference("pricelevel", new Guid("884A078B-0468-E712-80F5-3863BB3C0560")); return(incident); } if (entity == "incident") { Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0468-E721-80F5-3863BB3C0660"); incident.Attributes["smp_reclassifiedfromworkorder"] = false; return(incident); } return(null); }; fspostUpdateOfServiceRequestStatus.Execute(serviceProvider); } }
public void ContactPreCreateTest() { string resultEntityName = string.Empty; using (ShimsContext.Create()) { CCRM.REF.DataMallSync.CreateUpdateContactDataMallSync contactPreCreate = new CreateUpdateContactDataMallSync(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "contact"; pluginContext.PrimaryEntityIdGet = () => new Guid("BF4A4DA6-2204-E911-A964-000D3A3406C4"); ParameterCollection paramCollection = new ParameterCollection(); Entity contact = new Entity("contact"); contact.Id = new Guid("801BD880-6A5F-E911-A981-000D3A30DC0A"); contact.Attributes["smp_buildingnumber"] = "20"; contact.Attributes["smp_roomno"] = "12754253"; contact.Attributes["smp_mgrpersonalnumber"] = "1331341"; contact.Attributes["smp_companyid"] = "Microsoft"; paramCollection.Add("Target", contact); pluginContext.InputParametersGet = () => paramCollection; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", contact)) }; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Update"); 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_building'>")) { entityName = "smp_building"; } if (((FetchExpression)query).Query.Contains("<entity name='smp_room'>")) { entityName = "smp_room"; } if (((FetchExpression)query).Query.Contains("<entity name='contact'>")) { entityName = "contact"; } if (((FetchExpression)query).Query.Contains("<entity name='smp_company'>")) { entityName = "smp_company"; } } else if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "smp_room") { Entity room = new Entity(entityName); room.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0679"); room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679"); room["smp_feedstoreid"] = "12754253"; room["smp_roomno"] = new EntityReference("room", new Guid("735AA200-B954-E911-A985-000D3A30DC28")); collection.Entities.Add(room); } if (entityName == "smp_building") { Entity building = new Entity(entityName); building.Id = new Guid("F06E8975-7AF4-E711-8100-3863BB2E0660"); building["smp_buildingid"] = new Guid("F06E8975-7AF4-E711-8100-3863BB2E0660"); building["smp_feedstoreid"] = "20"; building["smp_buildingnumber"] = new EntityReference("building", new Guid("735AA200-B954-E911-A985-000D3A30DC28")); collection.Entities.Add(building); } if (entityName == "contact") { Entity managerpersonalnumber = new Entity(entityName); managerpersonalnumber.Id = new Guid("801BD880-6A5F-E911-A981-000D3A30DC0A"); managerpersonalnumber["smp_personalnumber"] = "1331341"; collection.Entities.Add(managerpersonalnumber); } if (entityName == "smp_company") { Entity company = new Entity(entityName); company.Id = new Guid("801BD880-6A5F-E911-A981-000D3A30DB0A"); company["smp_name"] = "Microsoft"; collection.Entities.Add(company); } return(collection); }; organizationService.UpdateEntity = (ent) => { resultEntityName = ent.LogicalName; }; contactPreCreate.Execute(serviceProvider); Assert.AreEqual("contact", resultEntityName); } }
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); }
static IExecutionContext CreatePluginExecutionContext( Object target = null, String messageName = null, Entity preImage = null, Entity postImage = null, ExecutionMode stepMode = ExecutionMode.Synchronous, PipelineStage stage = PipelineStage.PostOperation) { var userId = Guid.NewGuid(); var executionContext = new Mock <IPluginExecutionContext>(); var input = new ParameterCollection(); if (target != null) { input.Add("Target", target); } executionContext .Setup(o => o.UserId) .Returns(userId); executionContext .Setup(o => o.InputParameters) .Returns(input); executionContext .Setup(o => o.MessageName) .Returns(messageName); var preImages = new EntityImageCollection(); var postImages = new EntityImageCollection(); if (preImage != null) { preImages.Add(EntityImageType.PreImage.ToString(), preImage); } if (postImage != null) { postImages.Add(EntityImageType.PostImage.ToString(), postImage); } executionContext .Setup(o => o.PreEntityImages) .Returns(preImages); executionContext .Setup(o => o.PostEntityImages) .Returns(postImages); executionContext .Setup(o => o.Mode) .Returns((Int32)stepMode); executionContext .Setup(o => o.Stage) .Returns((Int32)stage); var primaryEntityName = target is Entity ? ((Entity)(target)).LogicalName : target is EntityReference ? ((EntityReference)(target)).LogicalName : null; executionContext .Setup(o => o.PrimaryEntityName) .Returns(primaryEntityName); return(executionContext.Object); }
/// <summary> /// Flattens a collection into a delimited string. /// </summary> /// <param name="entityImageCollection">The collection to flatten.</param> /// <returns>A string representation of the collection.</returns> private static string SerializeEntityImageCollection(EntityImageCollection entityImageCollection) { StringBuilder sb = new StringBuilder(); foreach (KeyValuePair<string, Entity> entityImage in entityImageCollection) { sb.AppendFormat("{0}{1}: {2}", Environment.NewLine, entityImage.Key, SerializeEntity(entityImage.Value)); } return sb.ToString(); }
public void UpdateCompletionDate() { 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(); ParameterCollection paramCollectionPostImage = new 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"] = "2018-01-08"; incident["createdon"] = "2018-01-08"; incident["modifiedon"] = "2018-01-08"; incident["smp_problemoccureddatetime"] = "2018-01-08"; 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")); incident.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); paramCollection.Add("Target", incident); Entity preIncident = new Entity("incident"); preIncident["incidentid"] = Guid.NewGuid(); preIncident["statuscode"] = new OptionSetValue(1); 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, "Update", postImage, preImage); 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_auditconfiguration") { Entity auditConfiguration = new Entity(entityName); auditConfiguration["smp_entityname"] = "incident"; auditConfiguration.Attributes["statuscode"] = new OptionSetValue(1); auditConfiguration["smp_attributename"] = "smp_contact"; collection.Entities.Add(auditConfiguration); Entity auditConfiguration1 = new Entity(entityName); auditConfiguration1["smp_entityname"] = "incident"; auditConfiguration1.Attributes["statuscode"] = new OptionSetValue(1); auditConfiguration1["smp_attributename"] = "smp_csr"; collection.Entities.Add(auditConfiguration1); Entity auditConfiguration2 = new Entity(entityName); auditConfiguration2["smp_entityname"] = "incident"; auditConfiguration2.Attributes["statuscode"] = new OptionSetValue(1); auditConfiguration2["smp_attributename"] = "smp_duedate"; collection.Entities.Add(auditConfiguration2); } 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); }; organizationService.ExecuteOrganizationRequest = QueryBase => { if (QueryBase.RequestName == "RetrieveAttribute") { PicklistAttributeMetadata picklistAttributeMetadata = new PicklistAttributeMetadata(); picklistAttributeMetadata.OptionSet = new OptionSetMetadata(); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label("Option1", 1), null)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label("Option2", 2), null)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label("Option3", 3), null)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label("Option4", 4), null)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label("Option5", 5), null)); RetrieveAttributeResponse response = new RetrieveAttributeResponse(); response.Results.Add("AttributeMetadata", picklistAttributeMetadata); return(response); } return(null); }; PostServiceRequestUpdateCreateAudit postServiceRequestUpdateCreateAudit = new PostServiceRequestUpdateCreateAudit(); postServiceRequestUpdateCreateAudit.Execute(serviceProvider); }
public void SRUpdate4() { this.pluginContext.PrimaryEntityNameGet = () => "incident"; this.pluginContext.PrimaryEntityIdGet = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); ParameterCollection paramCollection = new ParameterCollection(); ParameterCollection paramCollectionPostImage = new ParameterCollection(); Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident["smp_createdfrom"] = new OptionSetValue(3); incident.Attributes["caseorigincode"] = new OptionSetValue(1); 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; Entity postIncident = new Entity("incident"); postIncident["incidentid"] = Guid.NewGuid(); postIncident["statuscode"] = new OptionSetValue(1); postIncident["smp_createdfrom"] = new OptionSetValue(3); postIncident["smp_portalsubmit"] = true; postIncident.Attributes["caseorigincode"] = new OptionSetValue(1); postIncident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")) { Name = "building" }; postIncident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560")) { Name = "problemClass" }; postIncident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")) { Name = "problemType" }; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair<string, Entity>("PostImage", postIncident)) }; 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")); servicerequestproblemtype["statecode"] = "Acive"; 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); 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()); incident["smp_portalsubmit"] = true; 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); }
public void UpdateCompletionDate4() { 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(); ParameterCollection paramCollectionPostImage = new ParameterCollection(); Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident.Attributes["statuscode"] = new OptionSetValue(180620011); incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C0652")) { 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["modifiedon"] = "2018-01-08"; incident["smp_problemoccureddatetime"] = "2018-01-08"; 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")); incident.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); paramCollection.Add("Target", incident); Entity preIncident = new Entity("incident"); preIncident["incidentid"] = Guid.NewGuid(); preIncident["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")) { Name = "P1" }; preIncident.Attributes["statuscode"] = new OptionSetValue(2); preIncident["smp_issurveyservicerequest"] = false; preIncident.Attributes["smp_duedate"] = new DateTime(2018, 1, 8); preIncident.Attributes["caseorigincode"] = new OptionSetValue(1); preIncident.Attributes["smp_duedate"] = new DateTime(2018, 1, 8); preIncident.Attributes["smp_portalsubmit"] = false; preIncident.Attributes["smp_duedatebybuildingtimezone"] = "2018-01-08"; preIncident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08"; preIncident["smp_submitteddatetime"] = "2018-01-08"; preIncident["createdon"] = "2018-01-08"; preIncident["smp_problemoccureddatetime"] = "2018-01-08"; preIncident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C0652")) { Name = "building" }; pluginContext.InputParametersGet = () => paramCollection; EntityImageCollection preImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PreImage", preIncident)) }; Helper.Helper.PreImagePluginVariables(serviceProvider, pluginContext, organizationService, 20, "Update", preImage); 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_timezone") { Entity timeZone = new Entity(entityName); timeZone["smp_timezonename"] = "test timezone"; timeZone["smp_offset"] = new OptionSetValue(2); collection.Entities.Add(timeZone); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "smp_timezone") { Entity timeZone = new Entity(entity); timeZone["smp_timezonename"] = "test timezone"; timeZone["smp_offset"] = new OptionSetValue(2); return(timeZone); } return(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", 1033) })), 0)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("+03:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("-03", 1033) })), 1)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("+04:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("-04", 1033) })), 2)); RetrieveAttributeResponse response = new RetrieveAttributeResponse(); response.Results.Add("AttributeMetadata", picklistAttributeMetadata); return(response); } return(null); }; PreServiceRequestUpdateCompletedDate completionDate = new PreServiceRequestUpdateCompletedDate(); completionDate.Execute(serviceProvider); }
public void UpdateCompletionDate() { 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(); ParameterCollection paramCollectionPostImage = new 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"] = "2018-01-08"; incident["createdon"] = "2018-01-08"; incident["modifiedon"] = "2018-01-08"; incident["smp_problemoccureddatetime"] = "2018-01-08"; 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")); incident.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); incident.Attributes["smp_priorityescalationpopupnotes"] = "Test Notes"; paramCollection.Add("Target", incident); pluginContext.InputParametersGet = () => paramCollection; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", incident)) }; Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Update", 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 == "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); } 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); } return(null); }; PreSRUpdatePriorityEscalationNotes escalationNotes = new PreSRUpdatePriorityEscalationNotes(); escalationNotes.Execute(serviceProvider); }
public PipelineBase(IOrganizationService service = null) { _shimContext = ShimsContext.Create(); { if (service == null) { FakeService = new FakeOrganzationService(); Service = FakeService; } else { Service = service; } PreImages = new EntityImageCollection(); PostImages = new EntityImageCollection(); InputParameters = new ParameterCollection(); OutputParameters = new ParameterCollection(); PluginExecutionContext = new StubIPluginExecutionContext(); PluginExecutionContext.PreEntityImagesGet = () => { return(PreImages); }; PluginExecutionContext.PostEntityImagesGet = () => { return(PreImages); }; PluginExecutionContext.InputParametersGet = () => { return(InputParameters); }; PluginExecutionContext.OutputParametersGet = () => { return(OutputParameters); }; // ITracingService TracingService = new StubITracingService(); TracingService.TraceStringObjectArray = (format, values) => { if (values != null && values.Length > 0) { Trace.WriteLine(string.Format(format, values)); } else { Trace.WriteLine(format); } }; // IOrganizationServiceFactory Factory = new StubIOrganizationServiceFactory { CreateOrganizationServiceNullableOfGuid = id => { return(Service); } }; // IServiceProvider ServiceProvider = new System.Fakes.StubIServiceProvider { GetServiceType = type => { if (type == typeof(IPluginExecutionContext)) { return(PluginExecutionContext); } else if (type == typeof(ITracingService)) { return(TracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(Factory); } return(null); } }; } }
/// <summary> /// triggerred event as if Dynamics CRM /// </summary> /// <param name="entity"> Entity lick filling fields in CRM UI</param> /// <param name="stepName">Full Name of Step - you can get it from PlugIn Registration tool easily - Look at Event Handler section</param> /// <param name="preImage"> Entity shot before database operation </param> /// <param name="postImage"> Entity shot after database operation </param> /// <param name="inputParameters"> The parameters of the request message that triggered the event that caused the plug-in to execute. We send Entity</param> /// <param name="outputParameters">The parameters of the response message after the core platform operation has completed. It is entity for us</param> public EntityCollection Execute(Entity entity, string stepName, EntityImageCollection preImage = null, EntityImageCollection postImage = null, ParameterCollection inputParameters = null, ParameterCollection outputParameters = null) { Assembly assembly = Assembly.LoadFrom("TourismPlugins.dll"); Type type = assembly.GetType(stepName); if (type != null) { MethodInfo methodInfo = type.GetMethod("Execute"); if (methodInfo != null) { object result = null; object classInstance = Activator.CreateInstance(type, new object[] { "", "" }); BnBTechnologies.Xrm.MemoryService.Provider serviceProvider = new BnBTechnologies.Xrm.MemoryService.Provider(entity); MemoryPluginExecutionContext executionContext = (MemoryPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (preImage != null) { executionContext.PreEntityImages = preImage; } if (postImage != null) { executionContext.PostEntityImages = postImage; } if (inputParameters != null) { executionContext.InputParameters = inputParameters; } if (outputParameters != null) { executionContext.OutputParameters = outputParameters; } // Obtain the organization factory service from the service provider. IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); //load initial data ((OrganizationService)factory.CreateOrganizationService(null)).MockMemoryDatabase = memoryDatabaseData; object[] parametersArray = new object[] { serviceProvider }; result = methodInfo.Invoke(classInstance, parametersArray); // Obtain the organization service reference which you will need for web service calls. return(new EntityCollection(((OrganizationService)factory.CreateOrganizationService(null)).MockMemoryDatabase)); } } return(null); }
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 AssignToFieldServiceTeamTestMethod() { using (ShimsContext.Create()) { AssignToFieldServiceTeam assignToFieldServiceTeam = new StubAssignToFieldServiceTeam(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "msdyn_workorder"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity workOrder = new Entity("msdyn_workorder"); workOrder.Attributes["msdyn_servicerequest"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); paramCollection.Add("Target", workOrder); pluginContext.InputParametersGet = () => paramCollection; Entity incidentImage = new Entity("msdyn_workorder"); incidentImage.Attributes["msdyn_servicerequest"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); var postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", incidentImage)) }; 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='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 annotation = new Entity("smp_providermatrix"); annotation.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); annotation.Attributes["smp_buildingid"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")) { Name = "building" }; annotation.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560")) { Name = "problemClass" }; annotation.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")) { Name = "problemType" }; annotation.Attributes["smp_fieldserviceteam"] = new EntityReference("team", new Guid("884A078B-0469-E711-80E5-3863BB3C0560")) { Name = "Team1" }; annotation.Attributes["statecode"] = new OptionSetValue(0); annotation.Attributes["statuscode"] = new OptionSetValue(1); collection.Entities.Add(annotation); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "incident") { Entity incident = new Entity("incident"); incident.Id = 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(915240000); incident.Attributes["smp_duedate"] = new DateTime(2018, 1, 8); 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" }; return(incident); } return(null); }; assignToFieldServiceTeam.Execute(serviceProvider); } }
public static void PluginVariables(StubIServiceProvider serviceProvider, StubIPluginExecutionContext pluginContext, StubIOrganizationService organizationService, int stageNumber, string messageName, EntityImageCollection postImage) { var serviceFactory = new StubIOrganizationServiceFactory(); var tracingService = new StubITracingService(); if (serviceProvider != null) { serviceProvider.GetServiceType = type => { if (type == typeof(IPluginExecutionContext)) { return(pluginContext); } else if (type == typeof(ITracingService)) { return(tracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(serviceFactory); } return(null); }; } pluginContext.DepthGet = () => 1; pluginContext.UserIdGet = () => new Guid(); pluginContext.MessageNameGet = () => messageName; pluginContext.StageGet = () => stageNumber; pluginContext.InitiatingUserIdGet = () => Guid.Parse("F83DA6A6-748E-E412-9412-00155D614A70"); pluginContext.CorrelationIdGet = () => new Guid(); pluginContext.PrimaryEntityIdGet = () => { return(Guid.NewGuid()); }; pluginContext.PostEntityImagesGet = () => { return(postImage); }; pluginContext.PreEntityImagesGet = () => { return(postImage); }; serviceFactory.CreateOrganizationServiceNullableOfGuid = t1 => organizationService; tracingService.TraceStringObjectArray = Trace; }
internal static void PluginVariables(StubIServiceProvider serviceProvider, StubIPluginExecutionContext pluginContext, StubIOrganizationService organizationService, int stageNumber, string messageName, EntityImageCollection postImage, EntityImageCollection preImage) { pluginContext.PreEntityImagesGet = () => { return(preImage); }; PluginVariables(serviceProvider, pluginContext, organizationService, 40, messageName, postImage); }
public static T GetImage <T>(this EntityImageCollection images, string key) where T : Entity => GetImage(images, key).ToEntity <T>();
public static Entity GetImage(this EntityImageCollection images, string key) { return(images.TryGetValue(key, out var image) ? image : null); }
public void ServiceRequestsmp_CopySR() { var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "incident"; pluginContext.PrimaryEntityIdGet = () => new Guid("AE6226C5-4AB7-E811-A842-000D3A37C8E1"); ParameterCollection paramCollection = new ParameterCollection(); ParameterCollection paramCollectionPostImage = new ParameterCollection(); EntityReference incident = new EntityReference("incident", new Guid("AE6226C5-4AB7-E811-A842-000D3A37C8E1")); Entity inc = new Entity("incident"); inc["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); inc["caseorigincode"] = new OptionSetValue(1); inc["smp_flag"] = false; inc["smp_createdfrom"] = new OptionSetValue(3); inc["smp_problemoccureddatetime"] = Convert.ToDateTime(DateTime.UtcNow); inc["smp_portalsubmit"] = false; paramCollection.Add("Target", incident); pluginContext.InputParametersGet = () => paramCollection; pluginContext.OutputParametersGet = () => paramCollection; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", inc)) }; Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "smp_CopySR", 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 == "account") { Entity account = new Entity("account"); account["accountid"] = new Guid("884A078B-0467-E711-80F5-3863BB3C0652"); account.Id = new Guid("884A078B-0469-E711-80F5-3863BB3C0560"); 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")); collection.Entities.Add(account); } if (entityName == "smp_servicerequestproblemtypedesc") { Entity servicerequestproblemtypedesc = new Entity("smp_servicerequestproblemtypedesc"); servicerequestproblemtypedesc.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); servicerequestproblemtypedesc["smp_problemtypedescriptionid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); servicerequestproblemtypedesc["smp_answer"] = "8/8RoutingPriorities"; servicerequestproblemtypedesc["smp_value"] = "P1,P2,PS1,PS2"; collection.Entities.Add(servicerequestproblemtypedesc); Entity servicerequest = new Entity("smp_servicerequest"); servicerequest.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); collection.Entities.Add(servicerequest); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "incident") { inc["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); inc["caseorigincode"] = new OptionSetValue(1); inc["smp_flag"] = false; inc["smp_createdfrom"] = new OptionSetValue(3); inc["smp_problemoccureddatetime"] = Convert.ToDateTime(DateTime.UtcNow); inc["smp_portalsubmit"] = false; return(inc); } if (entity == "smp_servicerequestproblemtypedesc") { Entity servicerequestproblemtypedesc = new Entity("smp_servicerequestproblemtypedesc"); servicerequestproblemtypedesc.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); servicerequestproblemtypedesc["smp_answer"] = "8/8RoutingPriorities"; servicerequestproblemtypedesc["smp_value"] = "P1,P2,PS1,PS2"; return(servicerequestproblemtypedesc); } return(null); }; Guid expected = Guid.NewGuid(); Entity clonedEntity = null; organizationService.CreateEntity = e => { clonedEntity = e; return(expected); }; PostServiceRequestsmp_CopySR CopySR = new PostServiceRequestsmp_CopySR(); CopySR.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); }
private static string SerializeEntityImageCollection(EntityImageCollection entityImageCollection) { StringBuilder sb = new StringBuilder(); foreach (KeyValuePair<string, Entity> entityImage in entityImageCollection) { sb.Append(Environment.NewLine); sb.Append(entityImage.Key + ": " + SerializeEntity(entityImage.Value)); } return sb.ToString(); }
public void CreateDynNotes() { var workflowUserId = Guid.NewGuid(); var workflowCorrelationId = Guid.NewGuid(); var workflowInitiatingUserId = Guid.NewGuid(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); this.Service = new StubIOrganizationService(); this.IWorKFlowContext = new StubIWorkflowContext(); this.Factory = new StubIOrganizationServiceFactory(); this.TracingService = new StubITracingService(); this.IWorKFlowContext.UserIdGet = () => { return(workflowUserId); }; this.Factory.CreateOrganizationServiceNullableOfGuid = id => { return(Service); }; PostCreateSRCreateDynNotes updateDeviceRequestEmployeeDetails = new PostCreateSRCreateDynNotes(); var invoker = new WorkflowInvoker(updateDeviceRequestEmployeeDetails); invoker.Extensions.Add <ITracingService>(() => this.TracingService); invoker.Extensions.Add <IWorkflowContext>(() => this.IWorKFlowContext); invoker.Extensions.Add <IOrganizationServiceFactory>(() => this.Factory); pluginContext.PrimaryEntityNameGet = () => "incident"; pluginContext.PrimaryEntityIdGet = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); ParameterCollection paramCollection = new ParameterCollection(); ParameterCollection paramCollectionPostImage = new ParameterCollection(); Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); paramCollection.Add("Target", incident); pluginContext.InputParametersGet = () => paramCollection; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", incident)) }; Helper.Helper.PluginVariables(serviceProvider, pluginContext, this.Service, 40, "Create", postImage); this.Service.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); } return(collection); }; this.Service.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); 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.Attributes["statecode"] = new OptionSetValue(1); incidents.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); return(incidents); } return(null); }; IDictionary <string, object> inputs = new Dictionary <string, object>(); EntityReference newIncident = new EntityReference(incident.LogicalName, incident.Id); inputs["ServiceRequest"] = newIncident; var output = invoker.Invoke(inputs); }