public void TestTextProcessor_ToLocalDateTimeFunctionSingleQuotes() { using (ShimsContext.Create()) { DateTime createdOnAttributeESTServer = new DateTime(2015, 04, 27, 11, 01, 00); string easternZoneId = "Eastern Standard Time"; TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById(easternZoneId); //In UTC that EST Time = 15:01 DateTime createdOnAttribute = TimeZoneInfo.ConvertTimeToUtc(createdOnAttributeESTServer, easternZone); Entity recordContext = new Entity("dxtools_payment"); recordContext["createdon"] = createdOnAttribute; recordContext.Id = Guid.NewGuid(); IOrganizationService stubOrganisationService = StubOrganizationServiceFactory.SetupIOrganisationService(recordContext, "createdon", AttributeTypeCode.DateTime); ITextProcessor dynTextProcessor = new DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing.TextProcessor(stubOrganisationService); string inputText = "Your payment was created on {ToString(ToLocalDateTime(createdon,'GMT Standard Time'),'dd/MM/yyyy HH:mm')} or {createdon}, thanks. "; string expected = "Your payment was created on " + "27/04/2015 16:01" + " or " + createdOnAttribute + ", thanks. "; string resultOuput = dynTextProcessor.Process(inputText, recordContext.ToEntityReference()); Assert.AreEqual(expected, resultOuput); } }
public void TestTextProcessor_EntityReference() { Entity contact = new Entity("contact"); contact["fullname"] = "Test Contact"; contact.Id = Guid.NewGuid(); Entity recordContext = new Entity("dxtools_payment"); recordContext.Id = Guid.NewGuid(); recordContext["dxtools_contactid"] = contact.ToEntityReference(); recordContext["dxtools_paymentreference"] = "182929"; IOrganizationService stubOrganisationService = SetupIOrganisationService(recordContext, contact); ITextProcessor dynTextProcessor = new DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing.TextProcessor(stubOrganisationService); string inputText = "{dxtools_contactid.fullname} is the owner of the payment {dxtools_paymentreference}"; string expected = contact["fullname"].ToString() + " is the owner of the payment " + recordContext["dxtools_paymentreference"].ToString(); string resultOuput = dynTextProcessor.Process(inputText, recordContext.ToEntityReference()); Assert.AreEqual(expected, resultOuput); }
public void TestTextProcessor_ToStringFunction_Currency() { using (ShimsContext.Create()) { Entity parentPayment = new Entity("dxtools_payment"); parentPayment["dxtools_amount"] = new Money(150); parentPayment.Id = Guid.NewGuid(); StubData parentRecord = new StubData(); parentRecord.Record = parentPayment; parentRecord.AttributesMetadata = new AttributeMetadata[] { new StubAttributeMetadata(AttributeTypeCode.Money) { LogicalName = "dxtools_amount" } }; Entity childPayment = new Entity("dxtools_payment"); childPayment["dxtools_parentpaymentid"] = parentPayment.ToEntityReference(); childPayment["dxtools_amount"] = new Decimal(85); childPayment.Id = Guid.NewGuid(); StubData childRecord = new StubData(); childRecord.Record = childPayment; childRecord.AttributesMetadata = new AttributeMetadata[] { new StubAttributeMetadata(AttributeTypeCode.Money) { LogicalName = "dxtools_amount" }, new StubAttributeMetadata(AttributeTypeCode.Lookup) { LogicalName = "dxtools_parentpaymentid" } }; List <StubData> stubData = new List <StubData>(); stubData.Add(parentRecord); stubData.Add(childRecord); IOrganizationService stubOrganisationService = StubOrganizationServiceFactory.SetupIOrganisationService(stubData); ITextProcessor dynTextProcessor = new DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing.TextProcessor(stubOrganisationService); string inputText = "Parent Payment amount: {ToString(dxtools_parentpaymentid.dxtools_amount,'0.00')}"; string expected = "Parent Payment amount: " + ((Money)parentPayment["dxtools_amount"]).Value.ToString("0.00"); string resultOuput = dynTextProcessor.Process(inputText, childPayment.ToEntityReference()); Assert.AreEqual(expected, resultOuput); } }
public void TestTextProcessor_OptionSet() { using (ShimsContext.Create()) { Entity recordContext = new Entity("dxtools_payment"); recordContext.Id = Guid.NewGuid(); recordContext["dxtools_paymentdirection"] = new OptionSetValue(503530000); IOrganizationService stubOrganisationService = SetupIOrganisationService(recordContext, 503530000); ISyntacticParser syntacticParser = new SyntacticParser(new LexicalParser()); ITextProcessor dynTextProcessor = new DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing.TextProcessor(stubOrganisationService); string inputText = "Payment direction is {dxtools_PaymentDirection}. Other option to get the same is {dxtools_paymentdirection.Label}, and the value is {dxtools_paymentdirection.Value}"; string expected = "Payment direction is IN. Other option to get the same is IN, and the value is 503530000"; string resultOuput = dynTextProcessor.Process(inputText, recordContext.ToEntityReference()); Assert.AreEqual(expected, resultOuput); } }
public void TestTextProcessor_ToStringFunctionSingleQuotes() { using (ShimsContext.Create()) { DateTime createdOnAttribute = DateTime.Now; Entity recordContext = new Entity("dxtools_payment"); recordContext["createdon"] = createdOnAttribute; recordContext.Id = Guid.NewGuid(); IOrganizationService stubOrganisationService = StubOrganizationServiceFactory.SetupIOrganisationService(recordContext, "createdon", AttributeTypeCode.DateTime); ITextProcessor dynTextProcessor = new DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing.TextProcessor(stubOrganisationService); string inputText = "Your payment was created on {ToString(createdon,'dd/MM/yyyy')} or {createdon}, thanks. "; string expected = "Your payment was created on " + DateTime.Now.ToString("dd/MM/yyyy") + " or " + createdOnAttribute + ", thanks. "; string resultOuput = dynTextProcessor.Process(inputText, recordContext.ToEntityReference()); Assert.AreEqual(expected, resultOuput); } }