Exemple #1
0
        public void CreateAutomatedMappings()
        {
            //Arrange
            var crudRepo = new EfRepository <EntityMapping>(_db, _authAdapter);
            var logger   = new InMemoryLogger();
            var repo     = new EntityMappingRepository(crudRepo, logger, null, null);



            var trainingData = new List <Mapping>
            {
                new Mapping
                {
                    Source      = "Commodity",
                    Destination = "commodity"
                }
            };


            repo.CreateMapping(new ManualMapping
            {
                Mappings      = trainingData,
                SourceId      = _sourceSystemId,
                DestinationId = _destinationSystemId
            });

            var learntMappings = new List <LearntMapping>
            {
                new LearntMapping {
                    Mapping = new Mapping
                    {
                        Source      = "Variety",
                        Destination = "variety"
                    }
                },
                new LearntMapping
                {
                    Mapping = new Mapping
                    {
                        Source      = "Farm",
                        Destination = "farm"
                    }
                }
            };

            var learningResult = new LearningResult(learntMappings);

            //Act
            var result = repo.CreateMapping(new AutomatedMapping
            {
                LearningResult = learningResult,
                SourceId       = _sourceSystemId,
                DestinationId  = _destinationSystemId
            });

            //Assert
            Assert.AreEqual(learntMappings.Count, result);
        }
        public void CreateManualMappings()
        {
            //Arrange
            var crudRepo = new EfRepository <EntityMapping>(_db, _authAdapter);
            var logger   = new InMemoryLogger();
            var repo     = new EntityMappingRepository(crudRepo, logger, null, null);



            var trainingData = new List <Mapping>
            {
                new Mapping
                {
                    Source      = "Commodity",
                    Destination = "commodity"
                }
            };



            //Act
            var result = repo.CreateMapping(new ManualMapping
            {
                Mappings      = trainingData,
                SourceId      = _sourceSystemId,
                DestinationId = _destinationSystemId
            });

            //Assert
            Assert.AreEqual(trainingData.Count, result);
        }
Exemple #3
0
        public void AutomatedMapping()
        {
            var db               = new EntityMapperDbContext();
            var auth             = new IdentityAuthAdapter();
            var repository       = new EfRepository <EntityMapping>(db, auth);
            var logger           = new InMemoryLogger();
            var sut              = new EntityMappingRepository(repository, logger, null, null);
            var automatedMapping = new AutomatedMapping
            {
                DestinationId  = 177,
                SourceId       = 176,
                LearningResult = new LearningResult(new List <LearntMapping>
                {
                    new LearntMapping
                    {
                        Mapping = new Mapping
                        {
                            Source      = "qmob_commodity",
                            Destination = "qcommodity"
                        }
                    }
                })
            };

            //act
            var result = sut.CreateMapping(automatedMapping);

            //assert
            Assert.AreEqual(1, result.Count());
        }
Exemple #4
0
        public void AddEntities(int record, List <long> times)
        {
            SetUp(record);
            try
            {
                var timer = new Stopwatch();
                timer.Start();


                var learningSession = new LearningSession(new UntrainedData
                {
                    Sources      = _db.Entities.Where(t => _sourceIds.Contains(t.Id)).Select(t => t.Name).ToList(),
                    Destinations = _db.Entities.Where(t => _destinationIds.Contains(t.Id)).Select(t => t.Name).ToList()
                });
                var result = learningSession.StartLearning();



                _repo.CreateMapping(new AutomatedMapping
                {
                    LearningResult = result,
                    SourceId       = _sourceSystemId,
                    DestinationId  = _destinationSystemId
                });
                timer.Stop();
                times.Add(timer.ElapsedMilliseconds);
                var mappings = _db.EntityMappings.Take(record).ToList();
                Assert.AreEqual(record, mappings.Count);
            }
            catch (Exception)
            {
            }
            TearDown();
        }
        public void KristalTest()
        {
            _db = new EntityMapperDbContext();
            _db = new EntityMapperDbContext();
            var sources         = _db.TestDatas.Where(t => t.Source.Trim() != "").Select(t => t.Source).ToList();
            var destinations    = _db.TestDatas.Where(t => t.Destination.Trim() != "").Select(t => t.Destination).ToList();
            var _authAdapter    = new IdentityAuthAdapter();
            var _sourceIds      = new List <int>();
            var _destinationIds = new List <int>();

            var domainCrud = new EfRepository <Domain>(_db, _authAdapter);
            var domain     = domainCrud.Add(new Domain
            {
                Name   = "Fruit",
                Active = true
            });



            var systemCrud   = new EfRepository <global::Data.Models.System>(_db, _authAdapter);
            var sourceSystem = systemCrud.Add(new global::Data.Models.System
            {
                Domain = domain,
                Name   = "Functions",
                Active = true
            });

            var destinationSystem = systemCrud.Add(new global::Data.Models.System
            {
                Domain = domain,
                Name   = "Tables",
                Active = true
            });
            var _sourceSystemId      = sourceSystem.Id;
            var _destinationSystemId = destinationSystem.Id;

            foreach (var source in sources)
            {
                var entityCrud = new EfRepository <Entity>(_db, _authAdapter);
                var entity     = entityCrud.Add(new Entity
                {
                    SystemId = _sourceSystemId,
                    Name     = source.Trim(),
                    Active   = true
                });
                _sourceIds.Add(entity.Id);
            }
            foreach (var destination in destinations)
            {
                var entityCrud = new EfRepository <Entity>(_db, _authAdapter);
                var entity     = entityCrud.Add(new Entity
                {
                    SystemId = _destinationSystemId,
                    Name     = destination.Trim(),
                    Active   = true
                });
                _destinationIds.Add(entity.Id);
            }
            var _logger            = new InMemoryLogger();
            var _entityMappingCrud = new EfRepository <EntityMapping>(_db, _authAdapter);
            var _repo = new EntityMappingRepository(_entityMappingCrud, _logger, null, null);

            var learningSession = new LearningSession(new UntrainedData
            {
                Sources      = _db.Entities.Where(t => _sourceIds.Contains(t.Id)).Select(t => t.Name).ToList(),
                Destinations = _db.Entities.Where(t => _destinationIds.Contains(t.Id)).Select(t => t.Name).ToList()
            });
            var result = learningSession.StartLearning();



            _repo.CreateMapping(new AutomatedMapping
            {
                LearningResult = result,
                SourceId       = _sourceSystemId,
                DestinationId  = _destinationSystemId
            });

            //var learningSession = new LearningSession(new UntrainedData
            //{
            //    Sources = sources,
            //    Destinations = destinations
            //});
            //var result = learningSession.StartLearning().Select(t => t.Mapping).ToList();
            var resultText = string.Join(@"\n", result.Select(t => t.Mapping).ToList().Select(t => t.Source + " - " + t.Destination).ToList());


            Assert.NotNull(resultText);
        }