private string CreateCsvLine(CrmEntityStore record, List <string> header)
        {
            if (record != null)
            {
                string[] items = new string[header.Count];
                items[0] = record.Id.ToString();
                foreach (var item in record.Attributes)
                {
                    int position = header.IndexOf(item.AttributeName);

                    if (position >= 0)
                    {
                        object attrValue = EntityConverterHelper.GetAttributeValueForCsv(item);
                        if (item.AttributeType == "System.String")
                        {
                            string atVal = attrValue?.ToString().Replace("\"", "\"\"");
                            items[position] = $"\"{atVal}\"";
                        }
                        else
                        {
                            items[position] = attrValue?.ToString();
                        }
                    }
                }

                return(string.Join(delimiter, items));
            }

            return(null);
        }
Exemple #2
0
        public void GetAttributeValueForCsvAliasedValue()
        {
            var input     = new AliasedValue("contact", "contactid", Guid.NewGuid().ToString());
            var attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.AliasedValue"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.Should().Be(input.Value);
        }
Exemple #3
0
        public void GetAttributeValueForCsvByte()
        {
            byte[] input     = new byte[5];
            var    attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "System.Byte[]"
            };

            FluentActions.Invoking(() => EntityConverterHelper.GetAttributeValueForCsv(attribute))
            .Should()
            .Throw <ConfigurationException>();
        }
Exemple #4
0
        public void GetAttributeValueForCsvMoney()
        {
            var input     = new Money(new decimal(12.00));
            var attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.Money"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.Should().Be(input.Value);
        }
Exemple #5
0
        public void GetAttributeValueForCsvOptionSetValue()
        {
            var input = new OptionSetValue(12);
            CrmAttributeStore attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.OptionSetValue"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.ToString().Should().Be(input.Value.ToString(CultureInfo.InvariantCulture));
        }
Exemple #6
0
        public void GetAttributeValueForCsvEntityReference()
        {
            var input = new EntityReference("contact", Guid.NewGuid());
            CrmAttributeStore attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.EntityReference"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.ToString().Should().Be(input.Id.ToString());
        }
Exemple #7
0
        public void GetAttributeValueForCsvEntityCollection()
        {
            var list = new List <Entity>
            {
                new Entity("account", Guid.NewGuid())
            };
            EntityCollection input = new EntityCollection(list);
            var attribute          = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.EntityCollection"
            };

            FluentActions.Invoking(() => EntityConverterHelper.GetAttributeValueForCsv(attribute))
            .Should()
            .Throw <ConfigurationException>();
        }
Exemple #8
0
        public void GetAttributeValueForCsvOptionSetValueCollection()
        {
            var list = new List <OptionSetValue>
            {
                new OptionSetValue(12),
                new OptionSetValue(3)
            };
            var input     = new OptionSetValueCollection(list);
            var attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.OptionSetValueCollection"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.Should().Be("12|3");
        }