Exemple #1
0
 public void TestPatchElementMapFieldTypeOptionSet()
 {
     var patch            = new PatchElement();
     var expectedOperator = "op";
     var expectedPath     = "path";
     var expectedValue    = new OptionSet {
         Value = 1000
     };
     var field = new Field
     {
         Type  = FieldType.OptionSet,
         Name  = "fieldName",
         Value = expectedValue
     };
     var mapped = FieldMapHelper.TryMapField("fieldName", field, expectedOperator, expectedPath, (op, path, value) =>
     {
         patch.Operator = op;
         patch.Path     = path;
         patch.Value    = value;
     });
     //Assert.IsTrue(mapped);
     //Assert.IsNotNull(patch);
     //Assert.AreEqual(expectedOperator, patch.Operator);
     //Assert.AreEqual(expectedPath, patch.Path);
     //Assert.AreEqual(expectedValue, patch.Value);
 }
Exemple #2
0
        public void TestPatchElementMapFieldMatchFieldName()
        {
            var patch            = new PatchElement();
            var expectedOperator = "op";
            var expectedPath     = "path";
            var expectedValue    = "fieldValue";
            var field            = new Field
            {
                Name  = "fieldName",
                Type  = FieldType.String,
                Value = expectedValue
            };
            var mapped = FieldMapHelper.TryMapField("fieldName", field, expectedOperator, expectedPath, (op, path, value) =>
            {
                patch.Operator = op;
                patch.Path     = path;
                patch.Value    = value;
            });

            Assert.IsTrue(mapped);
            Assert.IsNotNull(patch);
            Assert.AreEqual(expectedOperator, patch.Operator);
            Assert.AreEqual(expectedPath, patch.Path);
            Assert.AreEqual(expectedValue, patch.Value);
            mapped = FieldMapHelper.TryMapField("fieldName1", field, expectedOperator, expectedPath, (op, path, value) =>
            {
                patch.Operator = op;
                patch.Path     = path;
                patch.Value    = value;
            });
            Assert.IsFalse(mapped);
        }
Exemple #3
0
 public void TestMapFieldTypeDecimal()
 {
     string property = null;
     var    field    = new Field
     {
         Type  = FieldType.Decimal,
         Name  = "fieldName",
         Value = "fieldValue"
     };
     var mapped = FieldMapHelper.TryMapField("fieldName", field, value => property = value);
     //Assert.AreEqual(true, mapped);
     //Assert.AreEqual("fieldValue", property);
 }
Exemple #4
0
        public void TestMapFieldTypeDateTime()
        {
            string property = null;
            var    field    = new Field
            {
                Type  = FieldType.DateTime,
                Name  = "fieldName",
                Value = DateTime.Now.Date
            };
            var mapped = FieldMapHelper.TryMapField("fieldName", field, value => property = value);

            Assert.AreEqual(true, mapped);
            Assert.AreEqual(DateTime.Now.Date.ToShortDateString(), property);
        }
Exemple #5
0
        public void TestMapFieldTypeOptionSet()
        {
            string property = null;
            var    field    = new Field
            {
                Type  = FieldType.OptionSet,
                Name  = "fieldName",
                Value = JsonConvert.SerializeObject(new OptionSetValue(1000))
            };
            var mapped = FieldMapHelper.TryMapField("fieldName", field, value => property = value);

            Assert.IsTrue(mapped);
            Assert.AreEqual("1000", property);
        }
Exemple #6
0
        public void TestMapFieldTypeGuid()
        {
            var    guid     = Guid.NewGuid();
            string property = null;
            var    field    = new Field
            {
                Name  = "fieldName",
                Type  = FieldType.Guid,
                Value = guid
            };
            var mapped = FieldMapHelper.TryMapField("fieldName", field, value => property = value);

            Assert.AreEqual(true, mapped);
            Assert.AreEqual(guid.ToString(), property);
        }
Exemple #7
0
        public void TestMapFieldTypeOptionSet()
        {
            string property = null;
            var    field    = new Field
            {
                Type  = FieldType.OptionSet,
                Name  = "fieldName",
                Value = new OptionSet {
                    Value = 1000
                }
            };
            var mapped = FieldMapHelper.TryMapField("fieldName", field, value => property = value);

            Assert.IsTrue(mapped);
            Assert.AreEqual("1000", property);
        }
Exemple #8
0
        public void TestMapFieldMatchFieldName()
        {
            string property = null;
            var    field    = new Field
            {
                Name = "fieldName", Type = FieldType.String, Value = "fieldValue"
            };
            var mapped = FieldMapHelper.TryMapField("fieldName", field, value => property = value);

            Assert.AreEqual(true, mapped);
            Assert.AreEqual("fieldValue", property);
            mapped = FieldMapHelper.TryMapField("fieldName1", field, value => property = value);
            Assert.AreEqual(false, mapped);
            Assert.AreEqual("fieldValue", property);
            property = null;
            mapped   = FieldMapHelper.TryMapField("fieldName1", field, value => property = value);
            Assert.AreEqual(false, mapped);
            Assert.IsNull(property);
        }
        /// <summary>
        /// Creates Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer class and fills properties required to create request
        /// </summary>
        /// <param name="model">Customer record entity model</param>
        /// <returns>mapped Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer</returns>
        public object Map(EntityModel model)
        {
            const int fieldsToMapCount  = 6;
            var       mappedFieldsCount = 0;
            var       customer          = new Customer();

            customer.CustomerIdentifier = new CustomerIdentifier();
            customer.CustomerIdentity   = new CustomerIdentity();
            foreach (var field in model.Fields)
            {
                var mapped = FieldMapHelper.TryMapField("tc_sourcesystemid", field, value => customer.CustomerIdentifier.CustomerId = value) ||
                             FieldMapHelper.TryMapField(Attributes.Customer.Salutation, field, value => customer.CustomerIdentity.Salutation = value) ||
                             FieldMapHelper.TryMapField(Attributes.Customer.FirstName, field, value => customer.CustomerIdentity.FirstName   = value) ||
                             FieldMapHelper.TryMapField(Attributes.Customer.LastName, field, value => customer.CustomerIdentity.LastName     = value) ||
                             FieldMapHelper.TryMapField(Attributes.Customer.Language, field, value => customer.CustomerIdentity.Language     = value) ||
                             FieldMapHelper.TryMapField(Attributes.Customer.Birthdate, field, value => customer.CustomerIdentity.Birthdate   = value);
                if (mapped && ++mappedFieldsCount == fieldsToMapCount)
                {
                    break;
                }
            }
            return(customer);
        }
Exemple #10
0
        /// <inheritdoc />
        /// <summary>
        /// Creates Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer class and fills properties required to update request
        /// </summary>
        /// <param name="model">Customer record entity model</param>
        /// <returns>mapped Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer</returns>
        public object Map(EntityModel model)
        {
            List <PatchElement> elements = null;

            foreach (var field in model.Fields)
            {
                var element = new PatchElement();

                var mapped =
                    ////////////////////////////////////////CustomerIdentity//////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.Salutation, field, $"{Replace}", $"{Identity}/salutation", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.FirstName, field, $"{Replace}", $"{Identity}/firstName", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.LastName, field, $"{Replace}", $"{Identity}/lastName", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Language, field, $"{Replace}", $"{Identity}/language", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Birthdate, field, $"{Replace}", $"{Identity}/birthdate", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.AcademicTitle, field, $"{Replace}", $"{Identity}/academicTitle", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.MiddleName, field, $"{Replace}", $"{Identity}/middleName", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Gender, field, $"{Replace}", $"{Identity}/gender", UpdateElement(element, typeof(Model.Schema.Gender))) ||
                    ////////////////////////////////////////CustomerIdentifier///////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.SourceMarket, field, $"{Replace}", $"{Identifier}/sourceMarket", UpdateElement(element)) ||
                    ////////////////////////////////////////CustomerGeneral///////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.StatusCode, field, $"{Replace}", $"{General}/customerStatus", UpdateElement(element, typeof(Model.Schema.CustomerStatus))) ||
                    ////////////////////////////////////////Company//////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.Name, field, $"{Replace}", $"{Company}/companyName", UpdateElement(element)) ||
                    ////////////////////////////////////////Additional///////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.Segment, field, $"{Replace}", $"{Company}/segmentadditional", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.DateOfDeath, field, $"{Replace}", $"{Additional}/dateOfDeath", UpdateElement(element)) ||
                    ////////////////////////////////////////Address1/////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1AdditionaInformation, field, $"{Replace}", $"{Address1}/additionalAddressInfo", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1FlatOrUnitNumber, field, $"{Replace}", $"{Address1}/flatNumberUnit", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1Street, field, $"{Replace}", $"{Address1}/street", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1Town, field, $"{Replace}", $"{Address1}/town", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1County, field, $"{Replace}", $"{Address1}/county", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1CountryId, field, $"{Replace}", $"{Address1}/country", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1PostalCode, field, $"{Replace}", $"{Address1}/postalCode", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address1HouseNumberOrBuilding, field, $"{Replace}", $"{Address1}/houseNumberBuilding", UpdateElement(element)) ||
                    ////////////////////////////////////////Address2/////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2AdditionaInformation, field, $"{Replace}", $"{Address2}/additionalAddressInfo", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2FlatOrUnitNumber, field, $"{Replace}", $"{Address2}/flatNumberUnit", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2Street, field, $"{Replace}", $"{Address2}/street", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2Town, field, $"{Replace}", $"{Address2}/town", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2County, field, $"{Replace}", $"{Address2}/county", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2CountryId, field, $"{Replace}", $"{Address2}/country", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2PostalCode, field, $"{Replace}", $"{Address2}/postalCode", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Address2HouseNumberOrBuilding, field, $"{Replace}", $"{Address2}/houseNumberBuilding", UpdateElement(element)) ||
                    //////////////////////////////////////////Phone////////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.Telephone1, field, $"{Replace}", $"{Phone1}/number", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Telephone1Type, field, $"{Replace}", $"{Phone1}/type", UpdateElement(element, typeof(Model.Schema.PhoneType))) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Telephone2, field, $"{Replace}", $"{Phone2}/number", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Telephone2Type, field, $"{Replace}", $"{Phone2}/type", UpdateElement(element, typeof(Model.Schema.PhoneType))) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Telephone3, field, $"{Replace}", $"{Phone3}/number", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.Telephone3Type, field, $"{Replace}", $"{Phone3}/type", UpdateElement(element, typeof(Model.Schema.PhoneType))) ||
                    ////////////////////////////////////////Email////////////////////////////////////////////////////
                    FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress1, field, $"{Replace}", $"{Email1}/number", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress1Type, field, $"{Replace}", $"{Email1}/type", UpdateElement(element, typeof(Model.Schema.EmailType))) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress2, field, $"{Replace}", $"{Email2}/number", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress2Type, field, $"{Replace}", $"{Email2}/type", UpdateElement(element, typeof(Model.Schema.EmailType))) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress3, field, $"{Replace}", $"{Email3}/number", UpdateElement(element)) ||
                    FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress3Type, field, $"{Replace}", $"{Email3}/type", UpdateElement(element, typeof(Model.Schema.EmailType)));
                if (mapped)
                {
                    if (elements == null)
                    {
                        elements = new List <PatchElement> {
                            element
                        }
                    }
                    ;
                    else
                    {
                        elements.Add(element);
                    }
                }
            }
            return(elements);
        }
Exemple #11
0
        /// <summary>
        /// Creates Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer class and fills properties required to create request
        /// </summary>
        /// <param name="model">Customer record entity model</param>
        /// <returns>mapped Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer</returns>
        public object Map(EntityModel model)
        {
            var customer = new Customer
            {
                CustomerIdentifier = new CustomerIdentifier(),
                CustomerGeneral    = new CustomerGeneral(),
                CustomerIdentity   = new CustomerIdentity(),
                Company            = new Company(),
                Additional         = new Additional(),
                Address            = new[] { new Address(), new Address() },
                Phone  = new[] { new Phone(), new Phone(), new Phone() },
                Email  = new[] { new Email(), new Email(), new Email() },
                Social = new Social[1]
            };

            foreach (var field in model.Fields)
            {
                ////////////////////////////////////////CustomerIdentifier////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.SourceMarket, field, value => customer.CustomerIdentifier.SourceMarket = value);
                ////////////////////////////////////////CustomerGeneral///////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.StatusCode, field, value => customer.CustomerGeneral.CustomerStatus = (CustomerStatus)EnumHelper.MapOptionSet(value, typeof(CustomerStatus)));
                customer.CustomerGeneral.CustomerType = CustomerType.Person;
                ////////////////////////////////////////CustomerIdentity//////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.Salutation, field, value => customer.CustomerIdentity.Salutation       = value);
                FieldMapHelper.TryMapField(Attributes.Customer.AcademicTitle, field, value => customer.CustomerIdentity.AcademicTitle = value);
                FieldMapHelper.TryMapField(Attributes.Customer.FirstName, field, value => customer.CustomerIdentity.FirstName         = value);
                FieldMapHelper.TryMapField(Attributes.Customer.LastName, field, value => customer.CustomerIdentity.LastName           = value);
                FieldMapHelper.TryMapField(Attributes.Customer.MiddleName, field, value => customer.CustomerIdentity.MiddleName       = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Language, field, value => customer.CustomerIdentity.Language           = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Gender, field, value => customer.CustomerIdentity.Gender       = (Gender)EnumHelper.MapOptionSet(value, typeof(Gender)) /*GetGender(value)*/);
                FieldMapHelper.TryMapField(Attributes.Customer.Birthdate, field, value => customer.CustomerIdentity.Birthdate = value);
                ////////////////////////////////////////Company//////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.Name, field, value => customer.Company.CompanyName = value);
                ////////////////////////////////////////Additional///////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.Segment, field, value => customer.Additional.Segment         = value);
                FieldMapHelper.TryMapField(Attributes.Customer.DateOfDeath, field, value => customer.Additional.DateOfDeath = value);
                ////////////////////////////////////////Address1/////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.Address1AdditionaInformation, field, value => customer.Address[0].AdditionalAddressInfo = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1FlatOrUnitNumber, field, value => customer.Address[0].FlatNumberUnit            = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1HouseNumberOrBuilding, field, value => customer.Address[0].HouseNumberBuilding  = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1Street, field, value => customer.Address[0].Street         = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1Town, field, value => customer.Address[0].Town             = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1CountryId, field, value => customer.Address[0].Country     = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1County, field, value => customer.Address[0].County         = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address1PostalCode, field, value => customer.Address[0].PostalCode = value);
                customer.Address[0].AddressType = AddressType.Main;
                ////////////////////////////////////////Address2/////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.Address2AdditionaInformation, field, value => customer.Address[1].AdditionalAddressInfo = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2FlatOrUnitNumber, field, value => customer.Address[1].FlatNumberUnit            = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2HouseNumberOrBuilding, field, value => customer.Address[1].HouseNumberBuilding  = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2Street, field, value => customer.Address[1].Street         = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2Town, field, value => customer.Address[1].Town             = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2CountryId, field, value => customer.Address[1].Country     = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2County, field, value => customer.Address[1].County         = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Address2PostalCode, field, value => customer.Address[1].PostalCode = value);
                customer.Address[1].AddressType = AddressType.NotSpecified;
                //////////////////////////////////////////Phone////////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.Telephone1Type, field, value => customer.Phone[0].PhoneType = (PhoneType)EnumHelper.MapOptionSet(value, typeof(PhoneType)));
                FieldMapHelper.TryMapField(Attributes.Customer.Telephone1, field, value => customer.Phone[0].Number        = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Telephone2Type, field, value => customer.Phone[1].PhoneType = (PhoneType)EnumHelper.MapOptionSet(value, typeof(PhoneType)));
                FieldMapHelper.TryMapField(Attributes.Customer.Telephone2, field, value => customer.Phone[1].Number        = value);
                FieldMapHelper.TryMapField(Attributes.Customer.Telephone3Type, field, value => customer.Phone[2].PhoneType = (PhoneType)EnumHelper.MapOptionSet(value, typeof(PhoneType)));
                FieldMapHelper.TryMapField(Attributes.Customer.Telephone3, field, value => customer.Phone[2].Number        = value);
                ////////////////////////////////////////Email////////////////////////////////////////////////////
                FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress1Type, field, value => customer.Email[0].EmailType = (EmailType)EnumHelper.MapOptionSet(value, typeof(EmailType)));
                FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress1, field, value => customer.Email[0].Address       = value);
                FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress2Type, field, value => customer.Email[1].EmailType = (EmailType)EnumHelper.MapOptionSet(value, typeof(EmailType)));
                FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress2, field, value => customer.Email[1].Address       = value);
                FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress3Type, field, value => customer.Email[2].EmailType = (EmailType)EnumHelper.MapOptionSet(value, typeof(EmailType)));
                FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress3, field, value => customer.Email[2].Address       = value);
            }
            return(customer);
        }