Example #1
0
        public void GetExternalRef_Null_ReturnsNull()
        {
            var sut = new CrmReference();

            var actual = sut.NumericValue();

            Assert.That(actual, Is.Null.Or.Empty);
        }
Example #2
0
        public void CrmReferenceIsInequal(
            [Values(1, 2, 3)] int x,
            [Values("", "12")] string s)
        {
            var numCrmReference = new CrmReference(x);

            var stringCrmReference = new CrmReference(s);

            var actual = numCrmReference != stringCrmReference;

            Assert.That(actual, Is.True);
        }
Example #3
0
        public void NumericValue_InvalidNumber(
            [Values("a1234a", "ab",
                    "£$%^7_")]
            string crmReference)
        {
            var sut = new CrmReference(crmReference);

            var actual = sut.NumericValue();

            Assert.That(actual, Is.Not.Null);

            Assert.That(actual, Is.EqualTo(string.Empty));
        }
Example #4
0
        public void CrmReferenceIsNotEqual(
            [Values(1, 2, 3)] int x,
            [Values("", "12")] string s)
        {
            var numCrmReference = new CrmReference(x);

            var stringCrmReference = new CrmReference(s);

            var actual = numCrmReference == stringCrmReference;

            Assert.That(actual, Is.False);

            Assert.That(numCrmReference, Is.Not.EqualTo(stringCrmReference));
        }
Example #5
0
        public void NumericValue_ExtractsNumber(
            [Values("1234", "ab123",
                    "£$%^7")]
            string crmReference,
            [Values("1234", "123", "7")] string expected)
        {
            var sut = new CrmReference(crmReference);

            var actual = sut.NumericValue();

            Assert.That(actual, Is.Not.Null);

            Assert.That(actual, Is.EqualTo(expected));
        }
Example #6
0
        public void NumericValue_KeepsLeadingZero()
        {
            var crmNumber  = "012345678901234";
            var crmPrefix  = "AF";
            var crmPostFix = "567";


            var crmRef = new CrmReference(crmPrefix + crmNumber + crmPostFix);

            var expected = crmNumber + crmPostFix;

            var actual = crmRef.NumericValue();

            Assert.That(actual, Is.Not.Null);

            Assert.That(actual, Is.EqualTo(expected));
        }
Example #7
0
        private DynamicEntity RemoveInvalidReferences(DynamicEntity input)
        {
            DynamicEntity invalidReferenceEntity = null;

            IEnumerable <Property> referenceProperties =
                (from p in input.Properties
                 where p.GetType() == typeof(LookupProperty) ||
                 p.GetType() == typeof(CustomerProperty) ||
                 p.GetType() == typeof(OwnerProperty)
                 select p).ToList();

            foreach (Property prop in referenceProperties)
            {
                CrmReference reference      = (CrmReference)prop.GetType().GetProperty("Value").GetValue(prop, null);
                Guid         newReferenceId = Guid.Empty;

                int matchingRecordCount = GetMatchingRecordCount(reference.type, reference.Value, reference.name, ref newReferenceId);
                switch (matchingRecordCount)
                {
                case 0:
                    if (invalidReferenceEntity == null)
                    {
                        invalidReferenceEntity = new DynamicEntity(input.Name);
                        invalidReferenceEntity.Properties.Add(input.Properties.OfType <KeyProperty>().First());
                    }

                    invalidReferenceEntity.Properties.Add(prop);
                    input.Properties.Remove(prop.Name);
                    break;

                case 1:
                    if (newReferenceId != Guid.Empty)
                    {
                        reference.Value = newReferenceId;
                    }
                    break;

                default:
                    ReportError(String.Format("Cannot import attribute {0} on {1} with id {2} because the value matches more than one record in the target system.", prop.Name, input.Name, input.Properties.OfType <KeyProperty>().First().Value.Value));
                    input.Properties.Remove(prop.Name);
                    break;
                }
            }

            return(invalidReferenceEntity);
        }
Example #8
0
        /// <summary>
        /// </summary>
        /// <param name="CRMReference"></param>
        /// <returns></returns>
        public bool ValidCrmReference(string CRMReference)
        {
            var crmReference = new CrmReference();

            return(crmReference.IsValid());
        }