Ejemplo n.º 1
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>()));
        }
        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);
        }
Ejemplo n.º 3
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>()));
        }
Ejemplo n.º 4
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>()));
        }