public void ProcessEntityObfuscateMultipleIntegerFields()
        {
            // Arrange
            CrmGenericImporterConfig config = GetCrmConfigWithFieldsToObfuscate();

            InitializeEntityMetadata();
            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "age"))
            .Returns(new IntegerAttributeMetadata());

            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "idnumber"))
            .Returns(new IntegerAttributeMetadata());

            int ageBefore      = 25;
            int idNumberBefore = 25;

            Entity entity = new Entity("contact");

            entity.Attributes.Add("age", ageBefore);
            entity.Attributes.Add("idnumber", idNumberBefore);
            EntityWrapper entityWrapper = new EntityWrapper(entity);
            List <FieldToBeObfuscated> fiedlsToBeObfuscated = new List <FieldToBeObfuscated>
            {
                new FieldToBeObfuscated()
                {
                    FieldName = "age"
                },
                new FieldToBeObfuscated()
                {
                    FieldName = "idnumber"
                }
            };

            EntityToBeObfuscated entityToBeObfuscated = new EntityToBeObfuscated()
            {
                EntityName = "contact"
            };

            entityToBeObfuscated.FieldsToBeObfuscated.AddRange(fiedlsToBeObfuscated);

            var fieldToBeObfuscated = new List <EntityToBeObfuscated>
            {
                entityToBeObfuscated
            };

            config.FieldsToObfuscate.AddRange(fieldToBeObfuscated);

            // Act
            ObfuscateFieldsProcessor processor = new ObfuscateFieldsProcessor(MockEntityMetadataCache.Object, config.FieldsToObfuscate);

            processor.ProcessEntity(entityWrapper, 1, 1);

            int ageAfter      = (int)entity["age"];
            int idNumberAfter = (int)entity["idnumber"];

            // Assert
            Assert.AreNotEqual(ageBefore, ageAfter);
            Assert.AreNotEqual(idNumberBefore, idNumberAfter);
        }
Beispiel #2
0
        public void ProcessEntityOrganizationEnity()
        {
            var entity = new Entity()
            {
                LogicalName = "organization"
            };
            EntityWrapper entityWrapper  = new EntityWrapper(entity);
            var           entityMetadata = new EntityMetadata();

            MockEntityRepo.SetupGet(a => a.GetEntityMetadataCache).Returns(MockEntityMetadataCache.Object);
            MockEntityRepo.Setup(a => a.GetParentBuId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.GetOrganizationId()).Returns(Guid.NewGuid());

            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(entityMetadata);

            var values = new Dictionary <Guid, Guid>
            {
                { Guid.NewGuid(), Guid.NewGuid() },
                { Guid.NewGuid(), Guid.NewGuid() }
            };

            mappingConfig.Mappings.Add("buId", values);

            systemUnderTest = new MapEntityProcessor(mappingConfig, MockLogger.Object, MockEntityRepo.Object, passOneReferences);

            FluentActions.Invoking(() => systemUnderTest.ProcessEntity(entityWrapper, passNumber, maxPassNumber))
            .Should()
            .NotThrow();

            MockEntityRepo.VerifyAll();
            MockEntityMetadataCache.Verify(a => a.GetEntityMetadata(It.IsAny <string>()));
        }
Beispiel #3
0
        public void AssociateManyToManyEntity()
        {
            ManyToManyDetails details = new ManyToManyDetails
            {
                Entity1IntersectAttribute = "contactid",
                Entity2IntersectAttribute = "accountid",
                IsManyToMany = true,
                SchemaName   = "accountcontact"
            };

            MockEntityMetadataCache.Setup(a => a.GetManyToManyEntityDetails(It.IsAny <string>()))
            .Returns(details);

            testOrgService.ExecutionResponse = new AssociateResponse();

            systemUnderTest = new EntityRepositorySingle(MockOrganizationService.Object, MockRetryExecutor.Object, MockEntityMetadataCache.Object);

            var response = new UpdateResponse();

            MockOrganizationService.Setup(a => a.Execute(It.IsAny <OrganizationRequest>()))
            .Returns(response);

            FluentActions.Invoking(() => systemUnderTest.AssociateManyToManyEntity(entities))
            .Should()
            .NotThrow();

            MockOrganizationService.VerifyAll();
        }
        public void FindEntitiesByName()
        {
            string nameValue      = "Joe";
            var    entityMetaData = new EntityMetadata();

            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(entityMetaData);

            FluentActions.Invoking(() => systemUnderTest.FindEntitiesByName(entityName, nameValue))
            .Should()
            .NotThrow();
        }
Beispiel #5
0
        public void ProcessEntity_ObfuscateIntegerFields()
        {
            // Arrange
            CrmGenericImporterConfig config = GetCrmConfigWithFieldsToObfuscate();

            InitializeEntityMetadata();
            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "age"))
            .Returns(new IntegerAttributeMetadata());

            int    ageBefore     = 25;
            string surnameBefore = "Tester";

            Entity entity = new Entity("contact");

            entity.Attributes.Add("age", ageBefore);
            entity.Attributes.Add("surname", surnameBefore);
            EntityWrapper entityWrapper = new EntityWrapper(entity);


            List <FieldToBeObfuscated> fiedlsToBeObfuscated = new List <FieldToBeObfuscated>();

            fiedlsToBeObfuscated.Add(new FieldToBeObfuscated()
            {
                FieldName = "age"
            });

            EntityToBeObfuscated entityToBeObfuscated = new EntityToBeObfuscated()
            {
                EntityName = "contact", FieldsToBeObfuscated = fiedlsToBeObfuscated
            };

            var fieldToBeObfuscated = new List <EntityToBeObfuscated>();

            fieldToBeObfuscated.Add(entityToBeObfuscated);

            config.FieldsToObfuscate = fieldToBeObfuscated;

            // Act
            ObfuscateFieldsProcessor processor = new ObfuscateFieldsProcessor(MockEntityMetadataCache.Object, config.FieldsToObfuscate);

            processor.ProcessEntity(entityWrapper, 1, 1);

            int    ageAfter     = (int)entity["age"];
            string surnameAfter = (string)entity["surname"];

            // Assert
            Assert.AreNotEqual(ageBefore, ageAfter);
            Assert.AreEqual(surnameBefore, surnameAfter);
        }
        public void ProcessEntityObfuscateDoubleFields()
        {
            // Arrange
            CrmGenericImporterConfig config = GetCrmConfigWithFieldsToObfuscate();

            InitializeEntityMetadata();
            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "address1_latitude"))
            .Returns(new DoubleAttributeMetadata());

            double latitudeBefore = 51.5178737;

            Entity entity = new Entity("contact");

            entity.Attributes.Add("address1_latitude", latitudeBefore);
            EntityWrapper entityWrapper = new EntityWrapper(entity);

            List <FieldToBeObfuscated> fieldsToBeObfuscated = new List <FieldToBeObfuscated>
            {
                new FieldToBeObfuscated()
                {
                    FieldName = "address1_latitude"
                }
            };

            EntityToBeObfuscated entityToBeObfuscated = new EntityToBeObfuscated()
            {
                EntityName = "contact"
            };

            entityToBeObfuscated.FieldsToBeObfuscated.AddRange(fieldsToBeObfuscated);

            var fieldToBeObfuscated = new List <EntityToBeObfuscated>
            {
                entityToBeObfuscated
            };

            config.FieldsToObfuscate.AddRange(fieldToBeObfuscated);

            // Act
            ObfuscateFieldsProcessor processor = new ObfuscateFieldsProcessor(MockEntityMetadataCache.Object, config.FieldsToObfuscate);

            processor.ProcessEntity(entityWrapper, 1, 1);

            double latitudeAfter = (double)entity["address1_latitude"];

            // Assert
            Assert.AreNotEqual(latitudeBefore, latitudeAfter);
        }
Beispiel #7
0
        public void ReturnAFormattedValue()
        {
            // Arrange
            var mockFormattingClient = new Mock <IObfuscationFormattingType <string> >();

            mockFormattingClient.Setup(a => a.CreateFormattedValue(It.IsAny <string>(), It.IsAny <FieldToBeObfuscated>(), It.IsAny <Dictionary <string, object> >()))
            .Returns("126 New Close");
            var systemUnderTest = new CrmObfuscateStringHandler(mockFormattingClient.Object);

            InitializeEntityMetadata();
            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "address1_line1"))
            .Returns(new StringAttributeMetadata()
            {
                MaxLength = 200
            });

            string originalValue = "1 Main Road";

            Entity entity = new Entity("contact");

            entity.Attributes.Add("address1_line1", originalValue);

            List <ObfuscationFormatOption> arguments       = new List <ObfuscationFormatOption>();
            Dictionary <string, string>    argumentsParams = new Dictionary <string, string>
            {
                { "filename", "test.csv" },
                { "columnname", "street" }
            };

            arguments.Add(new ObfuscationFormatOption(ObfuscationFormatType.Lookup, argumentsParams));

            var fieldToBeObfuscated = new FieldToBeObfuscated()
            {
                FieldName         = "address1_line1",
                ObfuscationFormat = "{0}"
            };

            fieldToBeObfuscated.ObfuscationFormatArgs.AddRange(arguments);

            // Act
            systemUnderTest.HandleObfuscation(entity, fieldToBeObfuscated, MockEntityMetadataCache.Object);

            string newValue = entity["address1_line1"].ToString();

            newValue.Should().NotBe(originalValue);
        }
Beispiel #8
0
        public void ProcessEntity_ObfuscateDecimalFields()
        {
            // Arrange
            CrmGenericImporterConfig config = GetCrmConfigWithFieldsToObfuscate();

            InitializeEntityMetadata();
            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "creditlimit"))
            .Returns(new DecimalAttributeMetadata());

            decimal creditLimitBefore = 1000M;

            Entity entity = new Entity("contact");

            entity.Attributes.Add("creditlimit", creditLimitBefore);
            EntityWrapper entityWrapper = new EntityWrapper(entity);


            List <FieldToBeObfuscated> fiedlsToBeObfuscated = new List <FieldToBeObfuscated>();

            fiedlsToBeObfuscated.Add(new FieldToBeObfuscated()
            {
                FieldName = "creditlimit"
            });

            EntityToBeObfuscated entityToBeObfuscated = new EntityToBeObfuscated()
            {
                EntityName = "contact", FieldsToBeObfuscated = fiedlsToBeObfuscated
            };

            var fieldToBeObfuscated = new List <EntityToBeObfuscated>();

            fieldToBeObfuscated.Add(entityToBeObfuscated);

            config.FieldsToObfuscate = fieldToBeObfuscated;

            // Act
            ObfuscateFieldsProcessor processor = new ObfuscateFieldsProcessor(MockEntityMetadataCache.Object, config.FieldsToObfuscate);

            processor.ProcessEntity(entityWrapper, 1, 1);

            decimal creditLimitAfter = (decimal)entity["creditlimit"];

            // Assert
            Assert.AreNotEqual(creditLimitBefore, creditLimitAfter);
        }
        public void ProcessZeroEntitiesFirst()
        {
            MockEntityRepo.SetupGet(p => p.GetEntityMetadataCache).Returns(MockEntityMetadataCache.Object);
            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(new EntityMetadata());
            MockEntityMetadataCache.Setup(a => a.GetIdAliasKey(It.IsAny <string>())).Returns("testvalue");

            DataCrmStoreWriter dsw = new DataCrmStoreWriter(MockLogger.Object, MockEntityRepo.Object, 200, null);
            var storeReader        = new Mock <IDataStoreReader <Entity, EntityWrapper> >();
            var config             = new Mock <ICrmGenericImporterConfig>();

            // setup pass zero entities
            config.SetupGet(c => c.PassOneReferences).Returns(new List <string> {
                "businessunit", "uom", "uomschedule", "queue"
            });

            // handle data store reader - after rested put entities back into queue
            Queue <List <EntityWrapper> > queue = GetMockedData();

            storeReader.Setup(sr => sr.ReadBatchDataFromStore()).Returns(queue.Dequeue);
            storeReader.Setup(sr => sr.Reset()).Callback(() => GetMockedData().All(data =>
            {
                queue.Enqueue(data);
                return(true);
            })); // reset the queue!

            // record order of saving entites
            List <EntityWrapper> actual = new List <EntityWrapper>();

            MockEntityRepo.Setup(repo => repo.CreateUpdateEntities(It.IsAny <List <EntityWrapper> >())).Callback <List <EntityWrapper> >(list => actual.AddRange(list));

            // execute test
            TestCrmGenericImporter importer = new TestCrmGenericImporter(MockLogger.Object, storeReader.Object, dsw, config.Object);

            importer.MigrateData();

            // 3 batches - 3 calls!
            MockEntityRepo.Verify(repo => repo.CreateUpdateEntities(It.IsAny <List <EntityWrapper> >()), Times.Exactly(3));

            MockEntityMetadataCache.Verify(a => a.GetEntityMetadata(It.IsAny <string>()));
            MockEntityMetadataCache.Verify(a => a.GetIdAliasKey(It.IsAny <string>()));

            // queue should be added first
            Assert.AreEqual("queue", actual[0].OriginalEntity.LogicalName);
            Assert.AreEqual("queue", actual[1].OriginalEntity.LogicalName);
        }
        public void ReturnAFormattedValue()
        {
            // Arrange
            var mockFormattingClient = new Mock <IObfuscationFormattingType <double> >();

            mockFormattingClient.Setup(a => a.CreateFormattedValue(It.IsAny <double>(), It.IsAny <FieldToBeObfuscated>(), It.IsAny <Dictionary <string, object> >()))
            .Returns(49.123);
            CrmObfuscateDoubleHandler systemUnderTest = new CrmObfuscateDoubleHandler(mockFormattingClient.Object);

            InitializeEntityMetadata();
            MockEntityMetadataCache
            .Setup(cache => cache.GetAttribute("contact", "address1_latitude"))
            .Returns(new DoubleAttributeMetadata());

            double latitudeBefore = 51.5178737;

            Entity entity = new Entity("contact");

            entity.Attributes.Add("address1_latitude", latitudeBefore);

            List <ObfuscationFormatOption> arguments       = new List <ObfuscationFormatOption>();
            Dictionary <string, string>    argumentsParams = new Dictionary <string, string>
            {
                { "filename", "FirstnameAndSurnames.csv" },
                { "columnname", "latitude" }
            };

            arguments.Add(new ObfuscationFormatOption(ObfuscationFormatType.Lookup, argumentsParams));

            var fieldToBeObfuscated = new FieldToBeObfuscated()
            {
                FieldName         = "address1_latitude",
                ObfuscationFormat = "{0}"
            };

            fieldToBeObfuscated.ObfuscationFormatArgs.AddRange(arguments);

            // Act
            systemUnderTest.HandleObfuscation(entity, fieldToBeObfuscated, MockEntityMetadataCache.Object);

            double latitudeAfter = (double)entity["address1_latitude"];

            latitudeAfter.Should().NotBe(latitudeBefore);
        }
Beispiel #11
0
        public void ProcessEntityManyToManyEnity()
        {
            var id1    = Guid.NewGuid();
            var id2    = Guid.NewGuid();
            var entity = new Entity()
            {
                LogicalName = "accountcontact"
            };

            entity.Attributes["accountid"] = id1;
            entity.Attributes["contactid"] = id2;
            var entityWrapper = new EntityWrapper(entity, true);

            var entityMetadata = new EntityMetadata();

            MockEntityRepo.SetupGet(a => a.GetEntityMetadataCache).Returns(MockEntityMetadataCache.Object);
            MockEntityRepo.Setup(a => a.GetParentBuId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.GetOrganizationId()).Returns(Guid.NewGuid());

            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(entityMetadata);

            var values = new Dictionary <Guid, Guid>
            {
                { id1, Guid.NewGuid() },
                { id2, Guid.NewGuid() }
            };

            mappingConfig.Mappings.Add("accountcontact", values);

            systemUnderTest = new MapEntityProcessor(mappingConfig, MockLogger.Object, MockEntityRepo.Object, passOneReferences);

            FluentActions.Invoking(() => systemUnderTest.ProcessEntity(entityWrapper, passNumber, maxPassNumber))
            .Should()
            .NotThrow();

            MockEntityRepo.VerifyAll();
            MockEntityMetadataCache.Verify(a => a.GetEntityMetadata(It.IsAny <string>()));
        }
Beispiel #12
0
        public void ProcessEntity()
        {
            EntityWrapper entity = new EntityWrapper(new Entity()
            {
                LogicalName = "testentity"
            });
            var entityMetadata = new EntityMetadata();

            MockEntityRepo.SetupGet(a => a.GetEntityMetadataCache).Returns(MockEntityMetadataCache.Object);
            MockEntityRepo.Setup(a => a.GetParentBuId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.GetOrganizationId()).Returns(Guid.NewGuid());

            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(entityMetadata);

            systemUnderTest = new MapEntityProcessor(mappingConfig, MockLogger.Object, MockEntityRepo.Object, passOneReferences);

            FluentActions.Invoking(() => systemUnderTest.ProcessEntity(entity, passNumber, maxPassNumber))
            .Should()
            .NotThrow();

            MockEntityRepo.VerifyAll();
            MockEntityMetadataCache.Verify(a => a.GetEntityMetadata(It.IsAny <string>()));
        }
        public void AssociateManyToManyEntity()
        {
            testOrgService.ExecutionResponse = new RetrieveEntityResponse();

            MockRetryExecutor.Setup(a => a.Execute(It.IsAny <Func <ExecuteMultipleResponse> >()))
            .Returns(requestResult);
            ManyToManyDetails details = new ManyToManyDetails
            {
                Entity1IntersectAttribute = "contactid",
                Entity2IntersectAttribute = "accountid",
                IsManyToMany = true,
                SchemaName   = "accountcontact"
            };

            MockEntityMetadataCache.Setup(a => a.GetManyToManyEntityDetails(It.IsAny <string>()))
            .Returns(details);

            FluentActions.Invoking(() => systemUnderTest.AssociateManyToManyEntity(entities))
            .Should()
            .NotThrow();

            MockRetryExecutor.VerifyAll();
            MockEntityMetadataCache.VerifyAll();
        }
Beispiel #14
0
        public void ProcessEntityApplyAliasMapping()
        {
            entityName = "ProcessEntityApplyAliasMapping";
            string lookUpName    = "contact";
            string attributeName = "c.contactid";
            var    testEntity    = new Entity("contact", Guid.NewGuid());
            var    listOfEntity  = new List <Entity> {
                testEntity
            };

            var attributeMetaDataItem = new AttributeMetadata {
                LogicalName = attributeName
            };

            SetFieldValue(attributeMetaDataItem, "_attributeType", AttributeTypeCode.Uniqueidentifier);

            var attributes = new List <AttributeMetadata> {
                attributeMetaDataItem
            };

            var oneToManyRelationshipMetadata = new OneToManyRelationshipMetadata
            {
                ReferencingAttribute = attributeName
            };
            var oneToManyRelationships = new List <OneToManyRelationshipMetadata>
            {
                oneToManyRelationshipMetadata
            };

            var entityMetaData = InitializeEntityMetadata(attributes, oneToManyRelationships);

            SetFieldValue(entityMetaData, "_primaryIdAttribute", attributeName);

            mappingConfig.ApplyAliasMapping = true;
            EntityWrapper entityWraper = new EntityWrapper(new Entity()
            {
                LogicalName = entityName
            });

            entityWraper.OriginalEntity.Attributes[attributeName] = new AliasedValue("contact", "contactid", testEntity.Id.ToString());

            MockEntityRepo.SetupGet(a => a.GetEntityMetadataCache).Returns(MockEntityMetadataCache.Object);
            MockEntityRepo.Setup(a => a.GetParentBuId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.GetOrganizationId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.FindEntitiesByName(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(listOfEntity);

            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(entityMetaData);
            MockEntityMetadataCache.Setup(a => a.GetIdAliasKey(It.IsAny <string>())).Returns(attributeName);
            MockEntityMetadataCache.Setup(a => a.GetLookUpEntityName(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(lookUpName);

            systemUnderTest = new MapEntityProcessor(mappingConfig, MockLogger.Object, MockEntityRepo.Object, passOneReferences);

            FluentActions.Invoking(() => systemUnderTest.ProcessEntity(entityWraper, passNumber, maxPassNumber))
            .Should()
            .NotThrow();

            MockEntityRepo.VerifyAll();
            MockEntityMetadataCache.VerifyAll();
        }