public void FormatValueTemplateParseTest() { var customerId = Guid.NewGuid(); var service = new Mock <IOrganizationService>(); service.Setup(s => s.Execute(It.IsAny <RetrieveAllEntitiesRequest>())) .Returns(new [] { _contactMetadata }.AsResponse()); service.Setup(s => s.Execute(It.IsAny <RetrieveEntityRequest>())) .Returns(_contactMetadata.AsResponse()); var startDate = new DateTime(2019, 05, 20, 20, 30, 00, DateTimeKind.Utc); service.Setup(s => s.RetrieveMultiple(It.Is <QueryExpression>(e => e.Criteria.Conditions.Any(c => c.AttributeName == "contactid" && c.Values.Contains(customerId))))) .Returns(new EntityCollection(new List <Entity> { new Entity("contact", customerId) { ["startdate"] = startDate } })); var template = "Recieve it at ${Customer.contact.startdate?t} Return at ${Customer.contact.enddate?t!Whenever}"; var parser = new FreeMarkerParser(service.Object, template); var result = parser.Produce(new Dictionary <string, EntityReference> { ["Customer"] = new EntityReference("contact", customerId) }); Assert.AreEqual($"Recieve it at {startDate.ToLocalTime().ToString("t")} Return at Whenever", result); }
public void HrefFormatValueTemplateParseTest() { var customerId = Guid.NewGuid(); var service = new Mock <IOrganizationService>(); service.Setup(s => s.Execute(It.IsAny <RetrieveAllEntitiesRequest>())) .Returns(new[] { _contactMetadata }.AsResponse()); service.Setup(s => s.Execute(It.IsAny <RetrieveEntityRequest>())) .Returns(_contactMetadata.AsResponse()); var contact = new Entity("contact", customerId) { ["fullname"] = "Brunhilde Semel" }; service.Setup(s => s.RetrieveMultiple(It.Is <QueryExpression>(e => e.Criteria.Conditions.Any(c => c.AttributeName == "contactid" && c.Values.Contains(customerId))))) .Returns(new EntityCollection(new List <Entity> { contact })); var template = "Follow the link <a href='https://mysite.com?user=${Customer.contact.fullname?href}'>${Customer.contact.fullname}</a>"; var parser = new FreeMarkerParser(service.Object, template); var result = parser.Produce(new Dictionary <string, EntityReference> { ["Customer"] = new EntityReference("contact", customerId) }); Assert.AreEqual("Follow the link <a href='https://mysite.com?user=Brunhilde%20Semel'>Brunhilde Semel</a>", result); }
public void Execute(IServiceProvider serviceProvider) { var pluginExecutionContext = serviceProvider.GetService <IPluginExecutionContext>(); var tracingService = serviceProvider.GetService <ITracingService>(); var serviceFactory = serviceProvider.GetService <IOrganizationServiceFactory>(); var sms = GetTarget(pluginExecutionContext); var service = serviceFactory.CreateOrganizationService(pluginExecutionContext.UserId); var templateReference = sms.GetAttributeValue <EntityReference>("zed_templateid"); var template = service.Retrieve("zed_messagetemplate", templateReference.Id, new ColumnSet("zed_template")); var parser = new FreeMarkerParser(service, template.GetAttributeValue <string>("zed_template")); var toUpdate = new Entity(sms.LogicalName, sms.Id) { ["description"] = parser.Produce(new Dictionary <string, EntityReference> { ["Recipient"] = sms.GetAttributeValue <EntityCollection>("to")?.Entities? .FirstOrDefault()?.GetAttributeValue <EntityReference>("partyid"), ["Context"] = sms.ToEntityReference() }) }; service.Update(toUpdate); }