Esempio n. 1
0
        public void Should_retrieve_traces_from_a_code_activity()
        {
            var fakedContext = new XrmFakedContext();

            //Inputs
            var inputs = new Dictionary <string, object>()
            {
                { "firstSummand", 2 },
                { "secondSummand", 3 }
            };

            var result = fakedContext.ExecuteCodeActivity <AddActivity>(inputs);

            //Get tracing service
            var fakeTracingService = fakedContext.GetFakeTracingService();
            var log = fakeTracingService.DumpTrace();

            //Assert that the target contains a new attribute
            Assert.Equal(log, "{ title: \"Complex message\", description: \"That could brake Formatter if not treated carefully\" }" + System.Environment.NewLine);
        }
Esempio n. 2
0
        public void Example_about_retrieving_traces_written_by_plugin()
        {
            var fakedContext = new XrmFakedContext();

            var guid1  = Guid.NewGuid();
            var target = new Entity("account")
            {
                Id = guid1
            };

            //Execute our plugin against a target that doesn't contains the accountnumber attribute
            var fakedPlugin = fakedContext.ExecutePluginWithTarget <AccountNumberPlugin>(target);

            //Get tracing service
            var fakeTracingService = fakedContext.GetFakeTracingService();
            var log = fakeTracingService.DumpTrace();

            //Assert that the target contains a new attribute
            Assert.Equal(log, "Contains target\r\nIs Account\r\n");
        }
Esempio n. 3
0
        public void Should_retrieve_traces_from_a_code_activity()
        {
            var fakedContext = new XrmFakedContext();

            //Inputs
            var inputs = new Dictionary <string, object>()
            {
                { "firstSummand", 2 },
                { "secondSummand", 3 }
            };

            var result = fakedContext.ExecuteCodeActivity <AddActivity>(inputs);

            //Get tracing service
            var fakeTracingService = fakedContext.GetFakeTracingService();
            var log = fakeTracingService.DumpTrace();

            //Assert that the target contains a new attribute
            Assert.Equal(log, "Some trace written" + System.Environment.NewLine);
        }
        public void It_Should_Throw_If_Not_Enough_Params()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "firstname", "Frodo" }
                }
            };

            var formula = "Substring ( Value ( \"firstname\" ) )";

            Assert.That(() => new XTLInterpreter(formula, contact, null, service, tracing).Produce(), Throws.TypeOf <InvalidPluginExecutionException>());
        }
        public void Strings_Should_Also_Be_Possible_With_Single_Quotes()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            var formula = "Concat(Value ('subject'), '\"', Value(\"subject\"), \"'\")";
            var result  = new XTLInterpreter(formula, email, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("TestSubject\"TestSubject'"));
        }
        public void It_Should_Execute_Lambdas_On_Map()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            var formula = "Join(\" \", Map([\"Lord\", \"of\", \"the\", \"Rings\"], (e) => Substring(e, 0, 1)))";
            var result  = new XTLInterpreter(formula, email, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("L o t R"));
        }
        public void It_Should_Get_LogicalName_From_Entity()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = new Guid("a99b0170-d463-4f70-8db9-e2d8ee348f5f"),
                Attributes  = new AttributeCollection
                {
                    { "name", "newName" }
                }
            };

            var formula = "RecordLogicalName (PrimaryRecord())";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("contact"));
        }
        public void It_Should_Apply_Regex()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "firstname", "Frodo" }
                }
            };

            var formula = "Replace ( Value ( \"firstname\" ), \"o\", \"a\" )";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("Frada"));
        }
        public void It_Should_Return_Correct_Index()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "firstname", "Frodo Beutlin" }
                }
            };

            var formula = "IndexOf ( Value ( \"firstname\" ), \"Beutlin\")";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("6"));
        }
        public void It_Should_Union_Arrays()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            var formula = "Join(\" \", Union ([\"Lord\"], [\"of\", \"the\"], [\"Rings\"]))";
            var result  = new XTLInterpreter(formula, email, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("Lord of the Rings"));
        }
Esempio n. 11
0
        public void It_Should_Recognize_Matching_OptionSet_Values()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "gendercode", new OptionSetValue(1) }
                }
            };

            var formula = "If ( IsEqual ( Value ( \"gendercode\" ), 1 ), \"true\", \"false\" )";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("true"));
        }
Esempio n. 12
0
        public void It_Should_Not_Fail_On_Null_Valued_Formula()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            string result = null;

            Assert.That(() => result = new XTLInterpreter(null, email, null, service, tracing).Produce(), Throws.Nothing);
            Assert.That(result, Is.EqualTo(string.Empty));
        }
Esempio n. 13
0
        public void It_Should_Format_Money()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "revenue", new Money(123456789.2m) }
                }
            };

            var formula = "Format ( Value(\"revenue\"),  { format: \"{0:0,0.0}\" } )";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("123,456,789.2"));
        }
        public void It_Should_Take_Everything_From_Start_Without_Length()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "firstname", "Frodo" }
                }
            };

            var formula = "Substring ( Value ( \"firstname\" ), 1 )";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("rodo"));
        }
Esempio n. 15
0
        public void It_Should_Join_Values_And_Remove_Empty_Entries_With_Native_Array()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            string result = null;

            Assert.That(() => result = new XTLInterpreter(@"Join ( "","", [ Value(""subject""), Value(""none""), Value(""subject"") ], true)", email, null, service, tracing).Produce(), Throws.Nothing);
            Assert.That(result, Is.EqualTo("TestSubject,TestSubject"));
        }
Esempio n. 16
0
        public void It_Should_Concatenate_Strings()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            var formula = "Concat(Value (\"subject\"), \" \", Value (\"subject\"))";
            var result  = new XTLInterpreter(formula, email, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("TestSubject TestSubject"));
        }
Esempio n. 17
0
        public void It_Should_Recognize_Not_Matching_Bool_Values()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "donotsendbulkemails", true }
                }
            };

            var formula = "If ( IsEqual ( Value ( \"donotsendbulkemails\" ), false ), \"true\", \"false\" )";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("false"));
        }
Esempio n. 18
0
        public void It_Should_Recognize_Not_Matching_Integers()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "int", 2 }
                }
            };

            var formula = "If ( IsEqual ( Value ( \"int\" ), 1 ), \"true\", \"false\" )";
            var result  = new XTLInterpreter(formula, email, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("false"));
        }
Esempio n. 19
0
        public void It_Should_Ignore_Whitespace()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "account",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "name", "TestSubject" }
                }
            };

            var formula = "\nValue\n(\n\"name\"\n)\n";
            var result  = new XTLInterpreter(formula, email, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("TestSubject"));
        }
Esempio n. 20
0
        public void It_Should_Concatenate_Array_Values_For_String_Representation()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var email = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" }
                }
            };

            string result = null;

            Assert.That(() => result = new XTLInterpreter("Array(\"This\", null, \"is\", \"a\", \"test\")", email, null, service, tracing).Produce(), Throws.Nothing);
            Assert.That(result, Is.EqualTo("This, , is, a, test"));
        }
        public void It_Should_Not_Wrap_Automatically_If_Contains_Plain_Text()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "firstname", "Frodo" }
                }
            };

            var snippetEs = new Entity
            {
                LogicalName  = "oss_xtlsnippet",
                Id           = Guid.NewGuid(),
                ["oss_name"] = "salutation es"
            };

            var snippetDe = new Entity
            {
                LogicalName               = "oss_xtlsnippet",
                Id                        = Guid.NewGuid(),
                ["oss_name"]              = "salutation de",
                ["oss_xtlexpression"]     = "This contains text: ${{Value('firstname')}}",
                ["oss_containsplaintext"] = true
            };

            context.Initialize(new Entity[] { snippetEs, snippetDe });

            var formula = "Snippet ('salutation de')";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("This contains text: Frodo"));
        }
        public void It_Should_Fetch_Simple_Snippet_By_Unique_Name()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "firstname", "Frodo" }
                }
            };

            var snippetEs = new Entity
            {
                LogicalName  = "oss_xtlsnippet",
                Id           = Guid.NewGuid(),
                ["oss_name"] = "salutation es"
            };

            var snippetDe = new Entity
            {
                LogicalName           = "oss_xtlsnippet",
                Id                    = Guid.NewGuid(),
                ["oss_uniquename"]    = "salutation de",
                ["oss_xtlexpression"] = "Value('firstname')"
            };

            context.Initialize(new Entity[] { snippetEs, snippetDe });

            var formula = "Snippet ('salutation de')";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("Frodo"));
        }
Esempio n. 23
0
        public void When_UsingFilteringAttributes_And_TheyDontMatch_Expect_PluginDoesNotTriggers()
        {
            // Arange
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            var id = Guid.NewGuid();

            var entities = new List <Entity>
            {
                new Contact
                {
                    Id = id
                }
            };

            context.Initialize(entities);

            // Act
            context.RegisterPluginStep <ValidatePipelinePlugin, Contact>("Update", ProcessingStepStage.Preoperation, ProcessingStepMode.Synchronous, filteringAttributes: new string[] { "address1_city" });

            var updatedEntity = new Contact
            {
                Id = id
            };

            var service = context.GetOrganizationService();

            service.Update(updatedEntity);

            // Assert
            var trace = context.GetFakeTracingService().DumpTrace().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.Equal(0, trace.Length);
        }
Esempio n. 24
0
        public void It_Should_Not_Fail_On_Empty_Table()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "firstname", "Frodo" }
                }
            };

            SetupContext(context);
            context.Initialize(new Entity[] { contact });

            var formula = "RecordTable(Fetch(\"<fetch no-lock='true'><entity name='task'><attribute name='description' /><attribute name='subject' /><filter><condition attribute='regardingobjectid' operator='eq' value='{0}' /></filter></entity></fetch>\"), \"task\", false, \"subject\", \"description\")";

            var expected = @"<table>
<tr><th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">Subject Label</th>
<th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">Description Label</th>
<tr />
<tr>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Task 1</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Description 1</td>
<tr />
<tr>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Task 2</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Description 2</td>
<tr />
</table>".Replace("\r", "").Replace("\n", "");

            Assert.That(() => new XTLInterpreter(formula, contact, null, service, tracing).Produce(), Throws.Nothing);
        }
Esempio n. 25
0
        public void When_PluginStepRegisteredAsDeletePreOperationSyncronous_Expect_CorrectValues()
        {
            // Arange
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            var id = Guid.NewGuid();

            var entities = new List <Entity>
            {
                new Contact
                {
                    Id = id
                }
            };

            context.Initialize(entities);

            // Act
            context.RegisterPluginStep <ValidatePipelinePlugin, Contact>("Delete", ProcessingStepStage.Preoperation, ProcessingStepMode.Synchronous);

            var service = context.GetOrganizationService();

            service.Delete(Contact.EntityLogicalName, id);

            // Assert
            var trace = context.GetFakeTracingService().DumpTrace().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.Equal(5, trace.Length);
            Assert.Contains("Message Name: Delete", trace);
            Assert.Contains("Stage: 20", trace);
            Assert.Contains("Mode: 0", trace);
            Assert.Contains($"Entity Reference Logical Name: {Contact.EntityLogicalName}", trace);
            Assert.Contains($"Entity Reference ID: {id}", trace);
        }
        public void It_Should_Resolve_Link_Text_Formulas()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = new Guid("a99b0170-d463-4f70-8db9-e2d8ee348f5f"),
                Attributes  =
                {
                    { "firstname", "Frodo" }
                }
            };

            var emailWithSubject = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" },
                    { "regardingobjectid", contact.ToEntityReference() }
                }
            };

            context.Initialize(new Entity[] { contact, emailWithSubject });

            var formula = "RecordUrl ( Value(\"regardingobjectid\"), { linkText: Value(\"regardingobjectid.firstname\") })";

            var result1 = new XTLInterpreter(formula, emailWithSubject, new OrganizationConfig {
                OrganizationUrl = "https://test.local"
            }, service, tracing).Produce();

            Assert.That(result1, Is.EqualTo("<a href=\"https://test.local/main.aspx?etn=contact&id=a99b0170-d463-4f70-8db9-e2d8ee348f5f&newWindow=true&pagetype=entityrecord\">Frodo</a>"));
        }
Esempio n. 27
0
        public void It_Should_Directly_Apply_Format_If_Set()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var createdOn = new DateTime(2019, 3, 17, 12, 0, 0, DateTimeKind.Utc);

            var target = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "createdon", createdOn }
                }
            };

            var expected = TimeZoneInfo.ConvertTimeFromUtc(createdOn, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).ToString("yyyyMMdd hh:mm", CultureInfo.InvariantCulture);

            var formula = "ConvertDateTime(Value(\"createdon\"), { timeZoneId: \"Eastern Standard Time\", format: \"yyyyMMdd hh:mm\" })";

            Assert.That(() => new XTLInterpreter(formula, target, null, service, tracing).Produce(), Is.EqualTo(expected));
        }
Esempio n. 28
0
        public void It_Should_Only_Execute_Relevant_SubTree()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "firstname", "Frodo" }
                }
            };

            var emailWithSubject = new Entity
            {
                LogicalName = "email",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "subject", "TestSubject" },
                    { "directioncode", true },
                    { "regardingobjectid", contact.ToEntityReference() }
                }
            };

            context.Initialize(new Entity[] { contact, emailWithSubject });

            var formula = "If ( IsEqual ( Value(\"directioncode\"), true ), Value(\"regardingobjectid.firstname\"), Value(\"regardingobjectid.lastname\") )";
            var result1 = new XTLInterpreter(formula, emailWithSubject, null, service, tracing).Produce();

            Assert.That(result1, Is.EqualTo("Frodo"));
            A.CallTo(() => service.Retrieve(A <string> ._, A <Guid> ._, A <ColumnSet> ._)).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 29
0
        public void It_Should_Create_Sub_Record_Table_With_Url()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "firstname", "Frodo" }
                }
            };

            var task = new Entity
            {
                LogicalName = "task",
                Id          = new Guid("76f167d6-35b3-44ae-b2a0-9373dee13e82"),
                Attributes  =
                {
                    { "subject",           "Task 1"                    },
                    { "description",       "Description 1"             },
                    { "regardingobjectid", contact.ToEntityReference() }
                }
            };

            var task2 = new Entity
            {
                LogicalName = "task",
                Id          = new Guid("5c0370f2-9b79-4abc-86d6-09260d5bbfed"),
                Attributes  =
                {
                    { "subject",           "Task 2"                    },
                    { "description",       "Description 2"             },
                    { "regardingobjectid", contact.ToEntityReference() }
                }
            };

            SetupContext(context);
            context.Initialize(new Entity[] { contact, task, task2 });

            var formula = "RecordTable(Fetch(\"<fetch no-lock='true'><entity name='task'><attribute name='description' /><attribute name='subject' /><filter><condition attribute='regardingobjectid' operator='eq' value='{0}' /></filter></entity></fetch>\"), \"task\", true, \"subject\", \"description\")";

            var expected = @"<table>
<tr><th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">Subject Label</th>
<th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">Description Label</th>
<th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">URL</th>
<tr />
<tr>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Task 1</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Description 1</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px""><a href=""https://test.local/main.aspx?etn=task&id=76f167d6-35b3-44ae-b2a0-9373dee13e82&newWindow=true&pagetype=entityrecord"">https://test.local/main.aspx?etn=task&id=76f167d6-35b3-44ae-b2a0-9373dee13e82&newWindow=true&pagetype=entityrecord</a></td>
<tr />
<tr>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Task 2</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Description 2</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px""><a href=""https://test.local/main.aspx?etn=task&id=5c0370f2-9b79-4abc-86d6-09260d5bbfed&newWindow=true&pagetype=entityrecord"">https://test.local/main.aspx?etn=task&id=5c0370f2-9b79-4abc-86d6-09260d5bbfed&newWindow=true&pagetype=entityrecord</a></td>
<tr />
</table>".Replace("\r", "").Replace("\n", "");

            var result = new XTLInterpreter(formula, contact, new OrganizationConfig {
                OrganizationUrl = "https://test.local"
            }, service, tracing).Produce();

            Assert.That(result.Replace("\r", "").Replace("\n", ""), Is.EqualTo(expected));
        }
Esempio n. 30
0
        public void It_Should_Create_Sub_Record_Table_Without_Url()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "firstname", "Frodo" }
                }
            };

            var task = new Entity
            {
                LogicalName = "task",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "subject",           "Task 1"                    },
                    { "description",       "Description 1"             },
                    { "regardingobjectid", contact.ToEntityReference() }
                }
            };

            var task2 = new Entity
            {
                LogicalName = "task",
                Id          = Guid.NewGuid(),
                Attributes  =
                {
                    { "subject",           "Task 2"                    },
                    { "description",       "Description 2"             },
                    { "regardingobjectid", contact.ToEntityReference() }
                }
            };

            SetupContext(context);
            context.Initialize(new Entity[] { contact, task, task2 });

            var formula = "RecordTable(Fetch(\"<fetch no-lock='true'><entity name='task'><attribute name='description' /><attribute name='subject' /><filter><condition attribute='regardingobjectid' operator='eq' value='{0}' /></filter></entity></fetch>\"), \"task\", false, \"subject\", \"description\")";

            var expected = @"<table>
<tr><th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">Subject Label</th>
<th style=""border:1px solid black;text-align:left;padding:1px 15px 1px 5px"">Description Label</th>
<tr />
<tr>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Task 1</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Description 1</td>
<tr />
<tr>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Task 2</td>
<td style=""border:1px solid black;padding:1px 15px 1px 5px"">Description 2</td>
<tr />
</table>".Replace("\r", "").Replace("\n", "");

            var result = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result.Replace("\r", "").Replace("\n", ""), Is.EqualTo(expected));
        }