public static StubIServiceProvider StubIServiceProvider(StubIOrganizationService service, StubIPluginExecutionContext pluginExecutionContext) { // ITracingService var tracingService = new StubITracingService { TraceStringObjectArray = (f, o) => { Debug.WriteLine(f, o); } }; // IOrganizationServiceFactory var factory = new StubIOrganizationServiceFactory { CreateOrganizationServiceNullableOfGuid = id => service }; // IServiceProvider var serviceProvider = new StubIServiceProvider { GetServiceType = t => { if (t == typeof(IPluginExecutionContext)) { return(pluginExecutionContext); } if (t == typeof(ITracingService)) { return(tracingService); } return(t == typeof(IOrganizationServiceFactory) ? factory : null); } }; return(serviceProvider); }
public void WhenOrganizationSeviceIsNullThenAnExceptionIsThrown() { var postChangeOrderDetailsCreate = new PostChangeOrderDetailsCreate(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); PluginTestsHelper.MolePluginVariables(serviceProvider, pluginContext, null, 40, "Create"); var entityAttributes = new Dictionary <string, object>(); Entity changeOrderDetailsEntity = new Entity(); changeOrderDetailsEntity.Attributes.Add("name", "Test"); pluginContext.InputParametersGet = delegate { ParameterCollection parameterCollection = new ParameterCollection(); parameterCollection.Add("Target", changeOrderDetailsEntity); return(parameterCollection); }; postChangeOrderDetailsCreate.Execute(serviceProvider); // This should get executed only if an exception is not thrown by the above line Assert.Fail(); }
public void CreateInspectionResponseTestMethod() { using (ShimsContext.Create()) { CreateInspectionResponse createInspectionResponse = new StubCreateInspectionResponse(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "smp_inspection"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E512-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity inspection = new Entity("smp_inspection"); inspection.Attributes["smp_inspectiontype"] = new EntityReference("smp_inspectiontype", new Guid("884A078B-0467-E721-80F5-3863BB3C0660")); inspection.Attributes["ownerid"] = new EntityReference("systemuser", new Guid("884A078B-0467-E721-80F5-3863BB3C0668")); paramCollection.Add("Target", inspection); 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", null); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("FetchExpression")) { if (((FetchExpression)query).Query.Contains("<entity name='smp_inspectionquestion'>")) { entityName = "smp_inspectionquestion"; } } else if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "smp_inspectionquestion") { Entity question = new Entity("smp_inspectionquestion"); question.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); question.Attributes["smp_questiontext"] = "unittest1"; collection.Entities.Add(question); } return(collection); }; createInspectionResponse.Execute(serviceProvider); } }
public void EscalationDuplicate() { var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "smp_escalation"; pluginContext.PrimaryEntityIdGet = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection(); Entity escalation = new Entity("smp_escalation"); escalation.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); escalation["smp_name"] = "test escalation"; paramCollection.Add("Target", escalation); pluginContext.InputParametersGet = () => paramCollection; Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "smp_escalation") { Entity escaltionCollection = new Entity("smp_escalation"); escaltionCollection.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); escaltionCollection["smp_name"] = "test escalation"; collection.Entities.Add(escaltionCollection); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "incident") { Entity building = new Entity(entity); building.Id = Guid.NewGuid(); building["smp_issurveyservicerequest"] = true; building["smp_cancelledforreclassification"] = true; return(building); } return(null); }; PreEscalationCreateDuplicateDetection escaltionDetect = new PreEscalationCreateDuplicateDetection(); escaltionDetect.Execute(serviceProvider); }
public void AssociateKBArticlesToWOTestMethod() { using (ShimsContext.Create()) { AssociateProceduresToWO associateProceedureToWO = new StubAssociateProceduresToWO(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "msdyn_agreementbookingdate"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity bookingDate = new Entity("msdyn_agreementbookingdate"); bookingDate.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); bookingDate.Attributes["msdyn_workorder"] = new EntityReference("msdyn_workorder", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); paramCollection.Add("Target", bookingDate); pluginContext.InputParametersGet = () => paramCollection; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Update", null); organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "msdyn_agreementbookingdate") { Entity bookingdate = new Entity("msdyn_workorder"); bookingdate.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); bookingdate.Attributes["smp_reclassificationreason"] = new OptionSetValue(180620002); bookingdate.Attributes["msdyn_workorder"] = new EntityReference("msdyn_workorder", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); bookingdate.Attributes["msdyn_bookingsetup"] = new EntityReference("msdyn_bookingsetup", new Guid("884A078B-0467-E711-80F5-3863BB3C0661")); bookingdate.Attributes["smp_comment"] = "2018-01-08"; return(bookingdate); } if (entity == "msdyn_workorder") { Entity workorder = new Entity("msdyn_workorder"); workorder.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); return(workorder); } if (entity == "msdyn_bookingsetup") { Entity bookingsetup = new Entity("msdyn_bookingsetup"); bookingsetup.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0661"); bookingsetup.Attributes["smp_procedureid"] = new EntityReference("smp_knowledgearticle", new Guid("884A078B-0467-E711-80F5-3863BB3C0661")); return(bookingsetup); } return(null); }; associateProceedureToWO.Execute(serviceProvider); } }
public void ServiceRequestOnUpdateofProblemDescription() { using (ShimsContext.Create()) { ServiceRequestOnUpdate serviceRequestOnUpdate = new StubServiceRequestOnUpdate(); 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["smp_problemtypedescription"] = "updating the problem description"; paramCollection.Add("Target", targetIncident); pluginContext.InputParametersGet = () => paramCollection; 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='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"); collection.Entities.Add(workorder); } return(collection); }; serviceRequestOnUpdate.Execute(serviceProvider); } }
public void ExecuteTest() { ContactParentPlugin target = new ContactParentPlugin(); var accountId = Guid.NewGuid(); var previousNumber = 3; var expected = 4; var actual = 0; // IOrganizationService var service = new StubIOrganizationService(); service.RetrieveStringGuidColumnSet = (entityName, id, columns) => { return(new Entity("account") { Id = accountId, Attributes = { { "numberofemployees", previousNumber } } }); }; service.UpdateEntity = (entity) => { actual = entity.GetAttributeValue <int>("numberofemployees"); }; // IPluginExecutionContext var pluginExecutionContext = new StubIPluginExecutionContext(); pluginExecutionContext.StageGet = () => { return(40); }; pluginExecutionContext.MessageNameGet = () => { return("Create"); }; pluginExecutionContext.PrimaryEntityNameGet = () => { return("contact"); }; pluginExecutionContext.PostEntityImagesGet = () => { return(new EntityImageCollection { { "PostCreateImage", new Entity("contact") { Attributes = { { "parentcustomerid", new EntityReference("account", accountId) } } } } }); }; var serviceProvider = PluginsFakes.StubIServiceProvider(service, pluginExecutionContext); // Act // target.Execute(serviceProvider); // // Assert // Assert.AreEqual(expected, actual); }
/// <summary> /// Generic helper function to set up the Organisation service for several records and attributes /// </summary> /// <param name="stubData"></param> /// <returns></returns> public static IOrganizationService SetupIOrganisationService(List <StubData> stubData) { StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) => { var record = from r in stubData where r.Record.LogicalName.Equals(entityLogicalName, StringComparison.InvariantCultureIgnoreCase) && r.Record.Id.Equals(recordId) select r.Record; if (record != null) { return(record.FirstOrDefault()); } else { return(null); } }; stubIOrganisationService.ExecuteOrganizationRequest = (request) => { if (request.RequestName == "RetrieveEntity") { RetrieveEntityResponse retrieveEntityResponse = new RetrieveEntityResponse(); EntityMetadata entityMetadata = new EntityMetadata(); retrieveEntityResponse["EntityMetadata"] = entityMetadata; return(retrieveEntityResponse); } return(null); }; Microsoft.Xrm.Sdk.Metadata.Fakes.ShimEntityMetadata.AllInstances.AttributesGet = (item) => { var attributesMetadata = from r in stubData where r.Record.LogicalName.Equals(item.LogicalName, StringComparison.InvariantCultureIgnoreCase) select r.AttributesMetadata; if (attributesMetadata != null) { return(attributesMetadata.FirstOrDefault()); } else { return(null); } }; return(stubIOrganisationService); }
public void SetDefaultPriceList() { using (ShimsContext.Create()) { PreCreateofProduct precreateofproduct = new StubPreCreateofProduct(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "product"; pluginContext.PrimaryEntityIdGet = () => new Guid("74D94FC2-52AD-E511-8158-1458D04DB6D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity targetProduct = new Entity("product"); targetProduct.Id = new Guid("74D94FC2-52AD-E511-8158-1458D04DB6D1"); paramCollection.Add("Target", targetProduct); pluginContext.InputParametersGet = () => paramCollection; PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create"); 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 == "pricelevel") { Entity pricelist = new Entity("pricelevel"); pricelist.Id = new Guid("74D94FC2-52AD-E511-8158-1458D04DB6D1"); pricelist.Attributes["name"] = "US"; pricelist.Attributes["pricelevelid"] = new EntityReference("product", new Guid("74D94FC2-52AD-E511-8158-1458D04DB6D1")); collection.Entities.Add(pricelist); } return(collection); }; precreateofproduct.Execute(serviceProvider); } }
public void PluginMethodTest() { using (ShimsContext.Create()) { Plugin baseplugin = new StubPlugin(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); 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(); ////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", null); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("FetchExpression")) { if (((FetchExpression)query).Query.Contains("<entity name='ava_keyvaluepair'>")) { entityName = "ava_keyvaluepair"; } } else if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { return(null); }; baseplugin.Execute(serviceProvider); } }
private IOrganizationService SetupIOrganisationService(Entity recordContext) { StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) => { return(recordContext); }; return(stubIOrganisationService); }
public void ExecuteUpdateWithAllAttributes() { var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "account"; pluginContext.PrimaryEntityIdGet = () => new Guid(); pluginContext.BusinessUnitIdGet = () => new Guid(); pluginContext.DepthGet = () => - 1; var entity = new Entity(); entity.LogicalName = "account"; ////entity.Attributes.Add("accountid", new Guid()); entity.Attributes.Add("name", "Mock Account Name"); ParameterCollection paramCollection = new ParameterCollection(); paramCollection.Add("Target", entity); pluginContext.InputParametersGet = () => paramCollection; //// Mole the basic Plugin objects Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null); organizationService.RetrieveMultipleQueryBase = query => { var entityCollection = new EntityCollection(); var entity1 = new Entity(); switch (((QueryExpression)query).EntityName) { ////case "team": //// entityCollection.Entities.Add(entity1); //// break; //case "account": // entity1.Attributes.Add("name", string.Empty); // entityCollection.Entities.Add(entity1); // break; } return(entityCollection); }; ////organizationService.UpdateEntity = param => { }; ////organizationService.CreateEntity = parameter => ////{ //// return new Guid(); ////}; var pluginClass = new PreProviderCreateDuplicateDetection(); pluginClass.Execute(serviceProvider); }
private IOrganizationService SetupIOrganisationService(Entity recordContext, int optionSetValue) { StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) => { if (entityLogicalName == "dxtools_payment") { return(recordContext); } else { return(null); } }; stubIOrganisationService.ExecuteOrganizationRequest = (request) => { if (request.RequestName == "RetrieveAttribute") { RetrieveAttributeResponse response = new RetrieveAttributeResponse(); return(response); } else { return(null); } }; Microsoft.Xrm.Sdk.Messages.Fakes.ShimRetrieveAttributeResponse.AllInstances.AttributeMetadataGet = (i) => { OptionMetadataCollection optionMetadataCollection = new OptionMetadataCollection(); OptionMetadata optionMetadata = new OptionMetadata(new Label(), optionSetValue); optionMetadata.Label.UserLocalizedLabel = new LocalizedLabel("IN", 1033); optionMetadataCollection.Add(optionMetadata); PicklistAttributeMetadata picklistAttributeMetadata = new PicklistAttributeMetadata(); picklistAttributeMetadata.OptionSet = new OptionSetMetadata(optionMetadataCollection); return(picklistAttributeMetadata); }; return(stubIOrganisationService); }
public void TestTextProcessor_StaticParameters() { IOrganizationService stubIOrganizationService = new StubIOrganizationService(); Dictionary <string, string> contextDicitonary = new Dictionary <string, string>(); contextDicitonary.Add("fullname", "John Smith"); contextDicitonary.Add("lastname", "Lock"); contextDicitonary.Add("LASTNAME", "Smith"); ITextProcessor crmTextProcessor = new TextProcessor(stubIOrganizationService); string textToBeProcessed = "Hello dear {fullname}. My lastname is {LASTNAME}"; string expected = "Hello dear John Smith. My lastname is Lock"; string actualResult = crmTextProcessor.Process(textToBeProcessed, contextDicitonary); Assert.AreEqual(expected, actualResult); }
/// <summary> /// Moles the plugin variables. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="pluginContext">The plugin context.</param> /// <param name="organizationService">The organization service.</param> /// <param name="stageNumber">The stage number.</param> /// <param name="messageName">Name of the message.</param> public static void MolePluginVariables( StubIServiceProvider serviceProvider, StubIPluginExecutionContext pluginContext, StubIOrganizationService organizationService, int stageNumber, string messageName) { var serviceFactory = new StubIOrganizationServiceFactory(); var tracingService = new StubITracingService(); if (serviceProvider != null) { serviceProvider.GetServiceType = type => { if (type == typeof(IPluginExecutionContext)) { return(pluginContext); } else if (type == typeof(ITracingService)) { return(tracingService); } else if (type == typeof(IOrganizationServiceFactory)) { return(serviceFactory); } return(null); }; } pluginContext.DepthGet = () => 1; pluginContext.UserIdGet = () => new Guid(); pluginContext.MessageNameGet = () => messageName; pluginContext.StageGet = () => stageNumber; pluginContext.InitiatingUserIdGet = () => new Guid(); pluginContext.CorrelationIdGet = () => new Guid(); pluginContext.PrimaryEntityIdGet = Guid.NewGuid; pluginContext.IsInTransactionGet = () => true; serviceFactory.CreateOrganizationServiceNullableOfGuid = t1 => organizationService; tracingService.TraceStringObjectArray = Trace; }
private IOrganizationService SetupIOrganisationService(Entity recordContext, Entity contact) { StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) => { if (entityLogicalName == "dxtools_payment") { return(recordContext); } else if (entityLogicalName == "contact") { return(contact); } else { return(null); } }; return(stubIOrganisationService); }
/// <summary> /// Simple helper method to set up Organisation Service /// </summary> /// <param name="recordContext"></param> /// <param name="attributeName"></param> /// <param name="attributeType"></param> /// <returns></returns> public static IOrganizationService SetupIOrganisationService(Entity recordContext, string attributeName, AttributeTypeCode attributeType) { StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) => { return(recordContext); }; stubIOrganisationService.ExecuteOrganizationRequest = (request) => { if (request.RequestName == "RetrieveEntity") { RetrieveEntityResponse retrieveEntityResponse = new RetrieveEntityResponse(); EntityMetadata entityMetadata = new EntityMetadata(); retrieveEntityResponse["EntityMetadata"] = entityMetadata; return(retrieveEntityResponse); } return(null); }; Microsoft.Xrm.Sdk.Metadata.Fakes.ShimEntityMetadata.AllInstances.AttributesGet = (item) => { return(new AttributeMetadata[] { new StubAttributeMetadata(attributeType) { LogicalName = attributeName } }); }; return(stubIOrganisationService); }
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, "Create"); 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_name"] = "1001"; room["status"] = 0; room["smp_buildingnumber"] = new EntityReference("building", new Guid("F06E8975-7AF4-E711-8100-3863BB2E0660")); 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 SetDueDateonWOTestMethod() { using (ShimsContext.Create()) { SetDueDateonWO setDueDateon = new StubSetDueDateonWO(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "msdyn_agreementbookingdate"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E512-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity agreementBooking = new Entity("msdyn_agreementbookingdate"); agreementBooking.Id = new Guid("54D94FC2-52AD-E512-8148-1458D04DB4D1"); agreementBooking.Attributes["msdyn_workorder"] = new EntityReference("msdyn_workorder", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); paramCollection.Add("Target", agreementBooking); pluginContext.InputParametersGet = () => paramCollection; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Update", null); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("FetchExpression")) { if (((FetchExpression)query).Query.Contains("<entity name='msdyn_workorder'>")) { entityName = "msdyn_workorder"; } } else if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "msdyn_workorder") { Entity workoOrder = new Entity("msdyn_workorder"); workoOrder.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); collection.Entities.Add(workoOrder); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "msdyn_agreementbookingdate") { Entity agreementBooking1 = new Entity("msdyn_agreementbookingdate"); agreementBooking1.Id = new Guid("54D94FC2-52AD-E512-8148-1458D04DB4D1"); agreementBooking1.Attributes["msdyn_bookingdate"] = DateTime.Now; agreementBooking1.Attributes["msdyn_workorder"] = new EntityReference("msdyn_workorder", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); return(agreementBooking1); } if (entity == "msdyn_workorder") { Entity workorder = new Entity("msdyn_workorder"); workorder.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); workorder.Attributes["smp_reclassificationreason"] = new OptionSetValue(180620002); workorder.Attributes["smp_comment"] = "2018-01-08"; return(workorder); } return(null); }; setDueDateon.Execute(serviceProvider); } }
public void SendStatusChangeEmail() { var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "incident"; pluginContext.PrimaryEntityIdGet = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection(); Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection(); Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident.Attributes["statuscode"] = new OptionSetValue(2); incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")) { Name = "building" }; incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560")) { Name = "room" }; incident.Attributes["caseorigincode"] = new OptionSetValue(1); incident.Attributes["smp_duedate"] = new DateTime(2018, 1, 8); incident.Attributes["smp_portalsubmit"] = false; incident.Attributes["smp_duedatebybuildingtimezone"] = "2018-01-08"; incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08"; incident["smp_submitteddatetime"] = new DateTime(2018, 1, 8); incident["createdon"] = new DateTime(2018, 1, 8); incident["smp_problemoccureddatetime"] = new DateTime(2018, 1, 8); incident["smp_createdfrom"] = new OptionSetValue(1); incident["smp_integrationstatus"] = true; incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08"; incident.Attributes["smp_createddatetimebybuildingtimezone"] = "2018-01-08"; incident["smp_contact"] = new EntityReference("contact", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")) { Name = "contact" }; incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")) { Name = "priority" }; incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")) { Name = "roomtype" }; incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560")) { Name = "problemClass" }; incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")) { Name = "problemType" }; incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")) { Name = "TestName" }; incident.Attributes["customerid"] = new EntityReference("contact", new Guid()); incident.Attributes["smp_allowemailnotification"] = true; incident["caseorigincode"] = new OptionSetValue(180620001); ////Entity preIncident = new Entity("incident"); ////preIncident["incidentid"] = Guid.NewGuid(); incident["statuscode"] = new OptionSetValue(2); incident["smp_requestorid"] = new EntityReference("contact", Guid.NewGuid()); incident["smp_cc"] = new EntityReference("contact", Guid.NewGuid()); incident["smp_approver"] = new EntityReference("contact", Guid.NewGuid()); paramCollection.Add("Target", incident); pluginContext.InputParametersGet = () => paramCollection; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", incident)) }; ////pluginContext.PostEntityImagesGet = () => { return postImage; }; Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", postImage); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "smp_configuration") { Entity configuration = new Entity("smp_configuration"); configuration.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration["smp_title"] = "8/8RoutingPriorities"; configuration["smp_value"] = "P1,P2,PS1,PS2"; collection.Entities.Add(configuration); Entity configuration1 = new Entity("smp_configuration"); configuration1.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration1["smp_title"] = "EmailSenderDomainName"; configuration1["smp_value"] = "*****@*****.**"; collection.Entities.Add(configuration1); Entity configuration2 = new Entity("smp_configuration"); configuration2.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration2["smp_title"] = "PendingDispatchStatusCode"; configuration2["smp_value"] = "2"; collection.Entities.Add(configuration2); Entity configuration3 = new Entity("smp_configuration"); configuration3.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration3["smp_title"] = "DefaultProviderName"; configuration3["smp_value"] = "NotAssigned"; collection.Entities.Add(configuration3); Entity configuration4 = new Entity("smp_configuration"); configuration4.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration4["smp_title"] = "NoCmmsIntegrationActionCodes"; configuration4["smp_value"] = "Draft"; collection.Entities.Add(configuration4); Entity configuration5 = new Entity("smp_configuration"); configuration5.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration5["smp_title"] = "StatusChangeOnCodes"; configuration5["smp_value"] = "Draft"; collection.Entities.Add(configuration5); Entity configuration9 = new Entity("smp_configuration"); configuration9.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); configuration9["smp_title"] = "Sample One"; configuration9["smp_value"] = "*****@*****.**"; collection.Entities.Add(configuration9); Entity configuration10 = new Entity("smp_configuration"); configuration10.Id = new Guid(); configuration10["smp_title"] = "sample name"; configuration10["smp_value"] = "04/10/2018"; collection.Entities.Add(configuration10); Entity configuration11 = new Entity("smp_configuration"); configuration11.Id = new Guid(); configuration11["smp_title"] = "en-us"; configuration11["smp_value"] = "2018-09-09"; collection.Entities.Add(configuration11); Entity configuration12 = new Entity("smp_configuration"); configuration12.Id = new Guid(); configuration12["smp_title"] = "ServiceRequestConfirmation/ToBeScheduled"; configuration12["smp_value"] = "2018-09-09"; collection.Entities.Add(configuration12); Entity configuration13 = new Entity("smp_configuration"); configuration13.Id = new Guid(); configuration13["smp_title"] = "ServiceRequestPortalLink"; configuration13["smp_value"] = "https://test.microsofotcrmportals.com"; collection.Entities.Add(configuration13); Entity configuration14 = new Entity("smp_configuration"); configuration14.Id = new Guid(); configuration14["smp_title"] = "ServiceRequestSurveyLink"; configuration14["smp_value"] = "https://[email protected]"; collection.Entities.Add(configuration14); Entity configuration15 = new Entity("smp_configuration"); configuration15.Id = new Guid(); configuration15["smp_title"] = "Seemoreinformationaboutyourservicerequest"; configuration15["smp_value"] = "seemoreinformation"; collection.Entities.Add(configuration15); Entity configuration16 = new Entity("smp_configuration"); ////configuration16["smp_entityname"] = "incident"; ////configuration16.Attributes["statuscode"] = new OptionSetValue(2); ////configuration16["smp_attributename"] = "smp_duedate"; configuration16["smp_title"] = "PrioritiesToDisplayTheDueDate"; configuration16["smp_value"] = "2018-09-09"; collection.Entities.Add(configuration16); } if (entityName == "systemuser") { Entity systemUser = new Entity(entityName); systemUser.Id = Guid.NewGuid(); systemUser["systemuserid"] = systemUser.Id; collection.Entities.Add(systemUser); } else if (entityName == "smp_servicerequeststatuscode") { Entity srStatusCode = new Entity(entityName); srStatusCode.Id = Guid.NewGuid(); srStatusCode["smp_name"] = "test1"; srStatusCode["smp_servicerequeststatus"] = new OptionSetValue(2); collection.Entities.Add(srStatusCode); } else if (entityName == "smp_servicerequestproblemtypedesc") { Entity servicerequestproblemtype = new Entity(entityName); servicerequestproblemtype.Id = Guid.NewGuid(); servicerequestproblemtype["smp_servicerequestproblemtypedescid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")); servicerequestproblemtype["smp_problemtypedescriptionid"] = new EntityReference("smp_problemtypedescription", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")); servicerequestproblemtype["smp_answer"] = "Sample Answer"; collection.Entities.Add(servicerequestproblemtype); } else if (entityName == "annotation") { Entity annotation = new Entity(entityName); annotation.Id = Guid.NewGuid(); annotation["annotationid"] = annotation.Id; annotation["subject"] = "Sample subject"; annotation["notetext"] = "Sample text"; annotation["filename"] = "Sample filename4"; annotation["isdocument"] = true; annotation["documentbody"] = "Sample body"; annotation["createdon"] = DateTime.Now.AddDays(-10); collection.Entities.Add(annotation); } else if (entityName == "template") { Entity annotation = new Entity(entityName); annotation.Id = Guid.NewGuid(); annotation["templateid"] = annotation.Id; annotation["subject"] = "<?xml version=\"1.0\" ?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"text\" indent=\"no\" /><xsl:template match=\"/data\"><![CDATA[We haven't heard from you...]]></xsl:template></xsl:stylesheet>"; annotation["body"] = "<?xml version=\"1.0\" ?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"text\" indent=\"no\"/><xsl:template match=\"/data\"><![CDATA[<P>Dear ]]><xsl:choose><xsl:when test=\"account/name\"><xsl:value-of select=\"account/name\" /></xsl:when><xsl:otherwise>Valued Customer</xsl:otherwise></xsl:choose><![CDATA[,</P> <P>We have not heard from you for a while. We wanted to check in and make sure that you are still having a great experience using our product(s). We have asked ]]><xsl:choose><xsl:when test=\"account/ownerid/@name\"><xsl:value-of select=\"account/ownerid/@name\" /></xsl:when><xsl:otherwise>a customer service representative</xsl:otherwise></xsl:choose><![CDATA[ to contact you next week to get your feedback on the product(s) you are currently using and to give you details about our upcoming products.</P> <P>Thank you.</P>]]></xsl:template></xsl:stylesheet>"; collection.Entities.Add(annotation); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "incident") { Entity incident1 = new Entity(entity); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident1["smp_issurveyservicerequest"] = true; incident1["smp_cancelledforreclassification"] = true; return(incident1); } if (entity == "account") { Entity account = new Entity(entity); account.Id = new Guid("58d19398-b350-490a-9e2d-6b30391304a0"); account["name"] = "test"; account["smp_iscmmsintegrationenabled"] = true; account["smp_cmmsurl"] = "https://testurl/cmmsservicerequestmanagerAAD.svc"; account["smp_hostedonazure"] = false; account["smp_providerteam"] = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652")); return(account); } else if (entity == "contact") { Entity contact = new Entity(entity); contact.Id = Guid.NewGuid(); contact["smp_preferredlanguage"] = "en-us"; contact["smp_isprovideruser"] = false; contact["smp_costcenter"] = "11110"; contact["smp_allowemailnotification"] = false; contact["smp_alias"] = "testalias"; contact["firstname"] = "first"; contact["lastname"] = "last"; contact["funllname"] = "last"; contact["emailaddress1"] = "*****@*****.**"; return(contact); } else if (entity == "smp_building") { Entity building = new Entity(entity); building.Id = Guid.NewGuid(); building["smp_timezoneid"] = new EntityReference("smp_timezone", new Guid("884A078B-0467-E711-80F5-3863BB3C0652")); building["smp_isfinancialstatecampus"] = true; building["smp_buildinglevelemailnotification"] = true; building["smp_feedstoreid"] = "Sample StoreId"; building["smp_buildingname"] = "sample building"; return(building); } else if (entity == "smp_problemclass") { Entity problemClass = new Entity(entity); problemClass.Id = Guid.NewGuid(); problemClass["smp_donotallowsurvey"] = true; problemClass["smp_allowemailnotification"] = true; return(problemClass); } else if (entity == "smp_problemtype") { Entity problemType = new Entity(entity); problemType.Id = Guid.NewGuid(); problemType["smp_donotallowsurvey"] = true; problemType["smp_allowemailnotification"] = true; return(problemType); } else if (entity == "smp_problemtypedescription") { Entity problemType = new Entity(entity); problemType.Id = Guid.NewGuid(); problemType["smp_problemtypedescriptionname"] = "sample description"; return(problemType); } else if (entity == "smp_priority") { Entity priority = new Entity(entity); priority.Id = Guid.NewGuid(); priority["smp_name"] = "sample name"; return(priority); } else if (entity == "smp_roomtype") { Entity problemclass = new Entity(entity); problemclass.Id = Guid.NewGuid(); problemclass["smp_roomtype"] = "sample room"; return(problemclass); } return(null); }; PostServiceRequestCreateEmailNotification pluginClass = new PostServiceRequestCreateEmailNotification(); pluginClass.Execute(serviceProvider); }
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 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 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; }
public void AttachmentURLUpdateOnNoteDeleteTestMethod() { using (ShimsContext.Create()) { AttachmentURLUpdateOnNoteDelete attachmentURLUpdateOnNoteDelete = new StubAttachmentURLUpdateOnNoteDelete(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "annotation"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); EntityReference annotation = new EntityReference("annotation"); annotation.Id = new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); paramCollection.Add("Target", annotation); pluginContext.InputParametersGet = () => paramCollection; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Delete", null); 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_customerasset") { Entity question = new Entity { LogicalName = "msdyn_customerasset", Id = new Guid("884A078c-0467-E711-80E5-3863BB3C0660") }; //// question.Attributes["smp_questiontext"] = "unittest1"; collection.Entities.Add(question); } if (entityName == "smp_attachmentsurl") { Entity attachmentUrl = new Entity("smp_attachmentsurl"); attachmentUrl.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); attachmentUrl.Attributes["smp_objectid"] = "54D94FC2-52AD-E511-8158-1458D04DB4D1"; attachmentUrl.Attributes["smp_name"] = "Test"; collection.Entities.Add(attachmentUrl); } return(collection); }; attachmentURLUpdateOnNoteDelete.Execute(serviceProvider); } }
public void PostServiceRequestsmp_ReclassifyTestMethod() { var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "incident"; pluginContext.PrimaryEntityIdGet = () => new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); ParameterCollection paramCollection = new ParameterCollection(); Microsoft.Xrm.Sdk.ParameterCollection paramCollectionPostImage = new Microsoft.Xrm.Sdk.ParameterCollection(); Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident.Attributes["smp_incidentid"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); incident.Attributes["incidentid"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); incident.Attributes["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); incident.Attributes["smp_createdfrom"] = new OptionSetValue(3); incident.Attributes["smp_referencesr"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); incident.Attributes["smp_flag"] = false; incident.Attributes["smp_problemoccureddatetime"] = "2018-01-08"; incident.Attributes["smp_portalsubmit"] = false; paramCollection.Add("Target", new EntityReference(incident.LogicalName, incident.Id)); pluginContext.InputParametersGet = () => paramCollection; pluginContext.OutputParametersGet = () => paramCollection; EntityImageCollection postImage = new EntityImageCollection { (new KeyValuePair <string, Entity>("PostImage", incident)) }; Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 40, "smp_Reclassify", postImage); organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("FetchExpression")) { if (((FetchExpression)query).Query.Contains("<entity name='annotation'>")) { entityName = "annotation"; } } else if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "smp_servicerequestproblemtypedesc") { Entity servicerequestproblemtype = new Entity(entityName); servicerequestproblemtype.Id = Guid.NewGuid(); servicerequestproblemtype["smp_servicerequestproblemtypedescid"] = new EntityReference("smp_servicerequestproblemtypedesc", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")); servicerequestproblemtype["smp_problemtypedescriptionid"] = new EntityReference("smp_problemtypedescription", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")); servicerequestproblemtype["smp_answer"] = "Sample Answer"; servicerequestproblemtype["smp_servicerequestid"] = new EntityReference("incident", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")); collection.Entities.Add(servicerequestproblemtype); } else if (entityName == "annotation") { Entity annotation = new Entity(entityName); annotation.Id = Guid.NewGuid(); annotation["annotationid"] = annotation.Id; annotation["subject"] = "Sample subject"; annotation["notetext"] = "Sample text"; annotation["filename"] = "Sample filename4"; annotation["isdocument"] = true; annotation["documentbody"] = "Sample body"; annotation["createdon"] = DateTime.Now.AddDays(-10); annotation["objectid"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); annotation["objecttypecode"] = "incident"; collection.Entities.Add(annotation); } else if (entityName == "account") { Entity account = new Entity(entityName); account.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); account["accountid"] = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); account["name"] = "test"; account["smp_iscmmsintegrationenabled"] = true; account["smp_cmmsurl"] = "https://testurl/cmmsservicerequestmanagerAAD.svc"; account["smp_hostedonazure"] = false; account["smp_providerteam"] = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652")); collection.Entities.Add(account); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "incident") { Entity incident2 = new Entity(entity); incident2.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident2["incidentid"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); incident2["customerid"] = new EntityReference("account", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")); incident2["smp_createdfrom"] = new OptionSetValue(3); incident2["smp_referencesr"] = new EntityReference("incident", new Guid("884A078B-0467-E711-80F5-3863BB3C0660")); incident2["smp_flag"] = false; incident2["smp_problemoccureddatetime"] = "2018-01-08"; incident2["smp_portalsubmit"] = false; return(incident2); } if (entity == "account") { Entity account = new Entity(entity); account.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); account["name"] = "test"; account["smp_iscmmsintegrationenabled"] = true; account["smp_cmmsurl"] = "https://testurl/cmmsservicerequestmanagerAAD.svc"; account["smp_hostedonazure"] = false; account["smp_providerteam"] = new EntityReference("team", new Guid("884A078B-0467-E711-80F5-3863BB3C0652")); return(account); } return(null); }; Guid expected = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); Entity clonedEntity = null; organizationService.CreateEntity = e => { clonedEntity = e; return(expected); }; PostServiceRequestsmp_Reclassify reclassify = new PostServiceRequestsmp_Reclassify(); reclassify.Execute(serviceProvider); }
public void SetPriority3() { var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "incident"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); Microsoft.Xrm.Sdk.ParameterCollection paramCollection = new Microsoft.Xrm.Sdk.ParameterCollection(); Entity incident = new Entity("incident"); incident.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); incident.Attributes["statuscode"] = new OptionSetValue(2); incident.Attributes["smp_problembuilding"] = new EntityReference("smp_building", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")) { Name = "building" }; incident.Attributes["new_problemroomnumber"] = new EntityReference("smp_room", new Guid("884A078B-0467-E711-80F5-3863BB3C0560")) { Name = "room" }; incident.Attributes["caseorigincode"] = new OptionSetValue(3); incident.Attributes["smp_duedate"] = "2018-01-08";////Convert.ToDateTime(null, CultureInfo.CurrentCulture); incident.Attributes["smp_portalsubmit"] = false; incident.Attributes["smp_duedatebybuildingtimezone"] = "2018-01-08"; ////incident.Attributes["smp_occureddatetimebybuildingtimezone"] = "2018-01-08"; //// incident["smp_submitteddatetime"] = Convert.ToDateTime(null, CultureInfo.CurrentCulture);//new DateTime(2018, 1, 8); incident["createdon"] = "2018-01-08"; incident["smp_problemoccureddatetime"] = "2018-01-08"; ////incident.Attributes["smp_submitteddatetimebybuildingtimezone"] = "2018-01-08"; ////incident.Attributes["smp_createddatetimebybuildingtimezone"] = "2018-01-08"; incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", Guid.Empty) { Name = "priority" }; incident.Attributes["smp_problemroomtype"] = new EntityReference("smp_roomtype", new Guid("884A078B-0466-E711-80F5-3863BB3C0560")) { Name = "roomtype" }; incident.Attributes["smp_problemclassid"] = new EntityReference("smp_problemclass", new Guid("884A078B-0468-E711-80F5-3863BB3C0560")) { Name = "problemClass" }; incident.Attributes["smp_problemtypeid"] = new EntityReference("smp_problemtype", new Guid("884A078B-0469-E711-80F5-3863BB3C0560")) { Name = "problemType" }; incident.Attributes["smp_priorityid"] = new EntityReference("smp_priority", Guid.Empty); incident.Attributes["smp_contact"] = new EntityReference("contact", Guid.NewGuid()); paramCollection.Add("Target", incident); pluginContext.InputParametersGet = () => paramCollection; Helper.Helper.PluginVariables(serviceProvider, pluginContext, organizationService, 20, "Create", null); organizationService.ExecuteOrganizationRequest = QueryBase => { if (QueryBase.RequestName == "RetrieveAttribute") { PicklistAttributeMetadata picklistAttributeMetadata = new PicklistAttributeMetadata(); picklistAttributeMetadata.OptionSet = new OptionSetMetadata(); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("+02:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("+02:30", 1033) })), 0)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("+03:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("+03:30", 1033) })), 1)); picklistAttributeMetadata.OptionSet.Options.Add(new OptionMetadata(new Label(new LocalizedLabel("-04:30", 1033), (new LocalizedLabel[] { new LocalizedLabel("-04:30", 1033) })), 2)); RetrieveAttributeResponse response = new RetrieveAttributeResponse(); response.Results.Add("AttributeMetadata", picklistAttributeMetadata); return(response); } else if (QueryBase.RequestName == "LocalTimeFromUtcTime") { LocalTimeFromUtcTimeResponse localTimeResponse = new LocalTimeFromUtcTimeResponse(); ////localTimeResponse.Results.Add("", value); DateTime dateTime = Convert.ToDateTime(QueryBase.Parameters["UtcTime"]).AddMinutes(Convert.ToInt32(QueryBase.Parameters["TimeZoneCode"])); localTimeResponse.Results.Add("LocalTime", dateTime); return(localTimeResponse); } else if (QueryBase.RequestName == "UtcTimeFromLocalTime") { UtcTimeFromLocalTimeResponse utcTimeResponse = new UtcTimeFromLocalTimeResponse(); DateTime dateTime = Convert.ToDateTime(QueryBase.Parameters["LocalTime"]).AddMinutes(-Convert.ToInt32(QueryBase.Parameters["TimeZoneCode"])); utcTimeResponse.Results.Add("UtcTime", dateTime); return(utcTimeResponse); } return(null); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "smp_building") { Entity building = new Entity(entity); building.Id = Guid.NewGuid(); building["smp_timezoneid"] = new EntityReference("smp_timezone", Guid.NewGuid()); building["smp_isfinancialstatecampus"] = true; return(building); } else if (entity == "smp_timezone") { Entity timeZone = new Entity(entity); timeZone["smp_timezonename"] = "test timezone"; timeZone["smp_offset"] = new OptionSetValue(2); return(timeZone); } else if (entity == "smp_priority") { Entity priority = new Entity(entity); priority["smp_noofminutes"] = 100; return(priority); } else if (entity == "smp_roomtype") { Entity roomType = new Entity(entity); roomType["smp_zone"] = new OptionSetValue(1); return(roomType); } return(null); }; organizationService.RetrieveMultipleQueryBase = (query) => { EntityCollection collection = new EntityCollection(); string entityName = string.Empty; if (query.GetType().Name.Equals("FetchExpression")) { if (((FetchExpression)query).Query.Contains("<entity name='ava_keyvaluepair'>")) { entityName = "ava_keyvaluepair"; } } else if (query.GetType().Name.Equals("QueryExpression")) { entityName = ((QueryExpression)query).EntityName; } else { entityName = ((QueryByAttribute)query).EntityName; } if (entityName == "smp_providermatrix") { Entity matrix = new Entity("smp_providermatrix"); matrix.Id = new Guid("884A078B-0466-E711-80F5-3863BB3C0560"); matrix["smp_primaryproviderid"] = new EntityReference("account", new Guid("884A078B-0467-E711-80F5-3863BB3C1560")); collection.Entities.Add(matrix); } else if (entityName == "smp_room") { Entity room = new Entity(entityName); room["smp_name"] = "test room"; room["smp_roomid"] = new Guid("884A078B-0466-E711-80F5-3863BB3C0679"); collection.Entities.Add(room); } else if (entityName == "account") { Entity account = new Entity(entityName); account["accountid"] = new Guid("884A078B-0467-E711-80F5-3863BB3C1560"); account["statuscode"] = 1; collection.Entities.Add(account); } else if (entityName == "smp_slamatrix") { Entity slaMatrix = new Entity(entityName); slaMatrix["smp_priorityid"] = new EntityReference("smp_priority", new Guid("884A078B-0467-E711-80F5-3863BB3C1489")); slaMatrix["smp_starthours"] = 2; slaMatrix["smp_endhours"] = 1; collection.Entities.Add(slaMatrix); } else if (entityName == "smp_buildingworkhours") { ////Entity buildWorkHours = new Entity(entityName); ////buildWorkHours["smp_starthours"] = new OptionSetValue(1); ////buildWorkHours["smp_endhours"] = new OptionSetValue(2); ////buildWorkHours.FormattedValues["smp_starthours"] = "08:30"; ////buildWorkHours.FormattedValues["smp_endhours"] = "08:30"; ////collection.Entities.Add(buildWorkHours); } else if (entityName == "smp_weekdays") { Entity weekdays = new Entity(entityName); weekdays["smp_name"] = Convert.ToDateTime("09-03-2017 02:30 AM"); collection.Entities.Add(weekdays); } else if (entityName == "smp_configuration") { Entity configuration = new Entity(entityName); configuration["smp_value"] = "Production"; collection.Entities.Add(configuration); } else if (entityName == "systemuser") { Entity systemuser = new Entity(entityName); systemuser.Id = Guid.NewGuid(); systemuser["systemuserid"] = systemuser.Id; collection.Entities.Add(systemuser); } else if (entityName == "usersettings") { Entity usersettings = new Entity(entityName); usersettings["timezonecode"] = 85; collection.Entities.Add(usersettings); } return(collection); }; PreServiceRequestCreateSetPriority prioritySet = new PreServiceRequestCreateSetPriority(); prioritySet.Execute(serviceProvider); }
public void WhenAllChangeOrderDetailsCreationDetailsArePresentChangeOrderDetailsAreCreated() { var postChangeOrderDetailsCreate = new PostChangeOrderDetailsCreate(); var serviceProvider = new StubIServiceProvider(); var tracingService = new StubITracingService(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); PluginTestsHelper.MolePluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create"); var entityAttributes = new Dictionary <string, object>(); Entity changeOrderDetailsEntity = new Entity(); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.IsCreatedFromInstalledBaseLine, true); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.SelectedInstalledBaseLineGuids, "\"B344FF0E - 2567 - E711 - 81A5 - 000D3A275BAD\",\"BB5F3570 - 1466 - E711 - 81A3 - 000D3A275BAD\""); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.Operation, new OptionSetValue(10000)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.OrderType, new OptionSetValue(10000)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.Product, new EntityReference("product", Guid.NewGuid())); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.OldCustomer, new EntityReference("contact", Guid.NewGuid())); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.OldBranch, new EntityReference("account", Guid.NewGuid())); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.NewBranch, new EntityReference("account", Guid.NewGuid())); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.ScheduleTerminationDuration, 6453); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.ScheduleUnits, false); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.SalesTerminationReason, new OptionSetValue(10000)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.BillingTerminationReason, new OptionSetValue(10001)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.HardwareTerminationReason, new OptionSetValue(10002)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.AddOnTerminationReason, new OptionSetValue(10003)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.SalesSuspensionReason, new OptionSetValue(10004)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.BillingSuspensionReason, new OptionSetValue(10005)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.SalesReactivationReason, new OptionSetValue(10004)); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.BillingReactivationReason, new OptionSetValue(10002)); pluginContext.InputParametersGet = delegate { ParameterCollection parameterCollection = new ParameterCollection(); parameterCollection.Add("Target", changeOrderDetailsEntity); return(parameterCollection); }; // Installed Base Line and Account organizationService.RetrieveStringGuidColumnSet = (entityName, recordId, columns) => { if (string.Compare(entityName, InstalledBaseLineEntity.EntitySchemaName, StringComparison.CurrentCultureIgnoreCase) == 0) { var installedBaseLineEntity = new Entity(); installedBaseLineEntity.Id = Guid.NewGuid(); installedBaseLineEntity.Attributes.Add(InstalledBaseLineEntity.BillingModel, new OptionSetValue(4256364)); installedBaseLineEntity.Attributes.Add(InstalledBaseLineEntity.PriceList, new EntityReference("pricelevel", Guid.NewGuid())); return(installedBaseLineEntity); } else if (string.Compare(entityName, InstalledBaseEntity.EntitySchemaName, StringComparison.CurrentCultureIgnoreCase) == 0) { var installedBaseEntity = new Entity(); installedBaseEntity.Id = Guid.NewGuid(); installedBaseEntity.Attributes.Add(InstalledBaseEntity.ContractId, "ContractABC"); installedBaseEntity.Attributes.Add(InstalledBaseEntity.Customer, new EntityReference(AccountEntity.EntitySchemaName, Guid.NewGuid())); installedBaseEntity.Attributes.Add(InstalledBaseEntity.Currency, new EntityReference("transactioncurrencyid", Guid.NewGuid())); return(installedBaseEntity); } else if (string.Compare(entityName, AccountEntity.EntitySchemaName, StringComparison.CurrentCultureIgnoreCase) == 0) { var accountEntity = new Entity(); accountEntity.Id = Guid.NewGuid(); accountEntity.Attributes.Add(AccountEntity.AccountManager, new EntityReference("systemuser", Guid.NewGuid())); accountEntity.Attributes.Add(AccountEntity.TechnicalContact, new EntityReference("contact", Guid.NewGuid())); accountEntity.Attributes.Add(AccountEntity.BillingContact, new EntityReference("contact", Guid.NewGuid())); return(accountEntity); } return(null); }; organizationService.CreateEntity = (e) => { return(Guid.NewGuid()); }; Entity commercialOrderEntity = new Entity(); commercialOrderEntity.Id = Guid.NewGuid(); commercialOrderEntity.Attributes.Add(CommercialOrderEntity.Customer, new EntityReference("account", Guid.NewGuid())); commercialOrderEntity.Attributes.Add(CommercialOrderEntity.PriceList, new EntityReference("pricelevel", Guid.NewGuid())); commercialOrderEntity.Attributes.Add(CommercialOrderEntity.Currency, new EntityReference("transactioncurrencyid", Guid.NewGuid())); commercialOrderEntity.Attributes.Add(CommercialOrderEntity.BillingModel, new OptionSetValue(7464)); var selectedInstalledBaseLinesCount = 5; var selectedInstalledBaseLineEntities = TestDataCreator.GetSelectedInstalledBaseLineRecords(selectedInstalledBaseLinesCount); var newlyCreatedChangeOrderRecordGuids = PostChangeOrderDetailsCreate.CreateChangeOrderDetailsFromAvailableDetails(organizationService, tracingService, new Models.ChangeOrderDetailsCreationDetails() { NewlyCreatedChangeOrderDetailsRecord = changeOrderDetailsEntity, CommercialOrderRecord = commercialOrderEntity, SelectedInstalledBaseLineRecords = selectedInstalledBaseLineEntities }); Assert.AreEqual(selectedInstalledBaseLinesCount, newlyCreatedChangeOrderRecordGuids.Count); }
public void PostUpdateofNoteIdAttachmentURLTestMethod() { using (ShimsContext.Create()) { PostUpdateofNoteIdAttachmentURL attachmentURLOnUpdate = new PostUpdateofNoteIdAttachmentURL(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "smp_attachmentsurl"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity attachmentUrl = new Entity("smp_attachmentsurl"); attachmentUrl.Id = new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); attachmentUrl["smp_isdelete"] = true; attachmentUrl["smp_notesid"] = "884A078B-0467-E711-80F5-3863BB3C0660"; attachmentUrl["smp_source"] = new OptionSetValue(180620000); paramCollection.Add("Target", attachmentUrl); pluginContext.InputParametersGet = () => paramCollection; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Update", null); 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 == "smp_attachmentsurl") { Entity attachmentUrlentity = new Entity("smp_attachmentsurl"); attachmentUrlentity.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); attachmentUrlentity.Attributes["smp_objectid"] = "54D94FC2-52AD-E511-8158-1458D04DB4D1"; attachmentUrlentity.Attributes["smp_name"] = "Test"; attachmentUrlentity.Attributes["smp_source"] = new OptionSetValue(180620000); attachmentUrlentity.Attributes["smp_notesid"] = "884A078B-0467-E711-80F5-3863BB3C0660"; collection.Entities.Add(attachmentUrlentity); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "smp_attachmentsurl") { Entity attachmentUrlentity = new Entity("smp_attachmentsurl"); attachmentUrlentity.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); attachmentUrlentity.Attributes["smp_objectid"] = "54D94FC2-52AD-E511-8158-1458D04DB4D1"; attachmentUrlentity.Attributes["smp_name"] = "Test"; attachmentUrlentity.Attributes["smp_source"] = new OptionSetValue(180620000); attachmentUrlentity.Attributes["smp_notesid"] = "884A078B-0467-E711-80F5-3863BB3C0660"; return(attachmentUrlentity); } return(null); }; attachmentURLOnUpdate.Execute(serviceProvider); } }
public void WhenChangeOrderIsCreatedFromInstalledBaseLineAndCustomerDetailsArePresentThenACommercialOrderIsCreated() { var postChangeOrderDetailsCreate = new PostChangeOrderDetailsCreate(); var serviceProvider = new StubIServiceProvider(); var tracingService = new StubITracingService(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); PluginTestsHelper.MolePluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create"); var entityAttributes = new Dictionary <string, object>(); Entity changeOrderDetailsEntity = new Entity(); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.IsCreatedFromInstalledBaseLine, true); changeOrderDetailsEntity.Attributes.Add(ChangeOrderDetailsEntity.SelectedInstalledBaseLineGuids, "\"B344FF0E - 2567 - E711 - 81A5 - 000D3A275BAD\",\"BB5F3570 - 1466 - E711 - 81A3 - 000D3A275BAD\""); pluginContext.InputParametersGet = delegate { ParameterCollection parameterCollection = new ParameterCollection(); parameterCollection.Add("Target", changeOrderDetailsEntity); return(parameterCollection); }; // Installed Base Line and Account organizationService.RetrieveStringGuidColumnSet = (entityName, recordId, columns) => { if (string.Compare(entityName, InstalledBaseLineEntity.EntitySchemaName, StringComparison.CurrentCultureIgnoreCase) == 0) { var installedBaseLineEntity = new Entity(); installedBaseLineEntity.Id = Guid.NewGuid(); installedBaseLineEntity.Attributes.Add(InstalledBaseLineEntity.BillingModel, new OptionSetValue(4256364)); installedBaseLineEntity.Attributes.Add(InstalledBaseLineEntity.PriceList, new EntityReference("pricelevel", Guid.NewGuid())); return(installedBaseLineEntity); } else if (string.Compare(entityName, InstalledBaseEntity.EntitySchemaName, StringComparison.CurrentCultureIgnoreCase) == 0) { var installedBaseEntity = new Entity(); installedBaseEntity.Id = Guid.NewGuid(); installedBaseEntity.Attributes.Add(InstalledBaseEntity.ContractId, "ContractABC"); installedBaseEntity.Attributes.Add(InstalledBaseEntity.Customer, new EntityReference(AccountEntity.EntitySchemaName, Guid.NewGuid())); installedBaseEntity.Attributes.Add(InstalledBaseEntity.Currency, new EntityReference("transactioncurrencyid", Guid.NewGuid())); return(installedBaseEntity); } else if (string.Compare(entityName, AccountEntity.EntitySchemaName, StringComparison.CurrentCultureIgnoreCase) == 0) { var accountEntity = new Entity(); accountEntity.Id = Guid.NewGuid(); accountEntity.Attributes.Add(AccountEntity.AccountManager, new EntityReference("systemuser", Guid.NewGuid())); accountEntity.Attributes.Add(AccountEntity.TechnicalContact, new EntityReference("contact", Guid.NewGuid())); accountEntity.Attributes.Add(AccountEntity.BillingContact, new EntityReference("contact", Guid.NewGuid())); return(accountEntity); } return(null); }; organizationService.CreateEntity = (e) => { return(Guid.NewGuid()); }; var selectedInstalledBaseLineEntities = TestDataCreator.GetSelectedInstalledBaseLineRecords(5); var commercialOrderRecord = PostChangeOrderDetailsCreate.GetDetailsToCreateAndCreateCommercialOrderRecordFromDetailsInInstalledBaseAndCustomer(organizationService, tracingService, selectedInstalledBaseLineEntities, changeOrderDetailsEntity); Assert.IsNotNull(commercialOrderRecord); Assert.IsTrue(commercialOrderRecord.Id != Guid.Empty); }
public void AttachmentURLOnCreationTestMethodforWorkOrder() { using (ShimsContext.Create()) { AttachmentURLOnCreation attachmentURLOnCreate = new AttachmentURLOnCreation(); var serviceProvider = new StubIServiceProvider(); var pluginContext = new StubIPluginExecutionContext(); var organizationService = new StubIOrganizationService(); pluginContext.PrimaryEntityNameGet = () => "smp_attachmentsurl"; pluginContext.PrimaryEntityIdGet = () => new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); ParameterCollection paramCollection = new ParameterCollection(); Entity attachmentUrl = new Entity("smp_attachmentsurl"); attachmentUrl.Id = new Guid("54D94FC2-52AD-E511-8158-1458D04DB4D1"); attachmentUrl["smp_isdelete"] = false; attachmentUrl["smp_source"] = new OptionSetValue(Constants.SourceAX); attachmentUrl["smp_name"] = "testfile"; attachmentUrl["smp_objectid"] = "884A078B-0467-E711-80F5-3863BB3C0660"; attachmentUrl["smp_objecttypecode"] = "10266"; attachmentUrl["smp_mimetype"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; ////attachmentUrl["smp_bloburl"] = this.bloburl; paramCollection.Add("Target", attachmentUrl); pluginContext.InputParametersGet = () => paramCollection; PluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create", null); 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 == "annotation") { Entity note = new Entity("annotation"); note.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); note.Attributes["smp_name"] = "Test"; collection.Entities.Add(note); } return(collection); }; organizationService.RetrieveStringGuidColumnSet = delegate(string entity, Guid guid, ColumnSet secondaryUserColumnSet) { if (entity == "smp_attachmentsurl") { Entity attachmentUrlentity = new Entity("smp_attachmentsurl"); attachmentUrlentity.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); attachmentUrlentity.Attributes["smp_objectid"] = "54D94FC2-52AD-E511-8158-1458D04DB4D1"; attachmentUrlentity.Attributes["smp_name"] = "Test"; attachmentUrlentity.Attributes["smp_source"] = new OptionSetValue(180620001); attachmentUrlentity.Attributes["smp_notesid"] = "884A078B-0467-E711-80F5-3863BB3C0660"; return(attachmentUrlentity); } if (entity == "annotation") { Entity note = new Entity("annotation"); note.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660"); note.Attributes["smp_name"] = "Test"; return(note); } if (entity == "msdyn_workorder") { Entity workorder = new Entity { LogicalName = "msdyn_workorder", Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0680") }; return(workorder); } return(null); }; attachmentURLOnCreate.Execute(serviceProvider); } }