Exemplo n.º 1
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());
        }
        public void Get()
        {
            //arrange
            //Todo: Use Autofacs config for this initialization
            AutoMapperConfig.RegisterMappings();
            var db          = new EntityMapperDbContext();
            var authAdapter = new IdentityAuthAdapter();
            var repo        = new EfRepository <EntityMapping>(db, authAdapter);
            var _logger     = new InMemoryLogger();
            EfRepository <MappingOrigin> originRepo        = new EfRepository <MappingOrigin>(db, authAdapter);
            EfRepository <Entity>        entityRepo        = new EfRepository <Entity>(db, authAdapter);
            IMappingRepository           mappingRepository = new EntityMappingRepository(repo, _logger, null, null);
            var sut           = new EntityMappingsController(repo, originRepo, entityRepo, mappingRepository);
            var dbRecordCount = db.EntityMappings.Count();

            //act
            var actionResult = sut.Get();
            var result       = actionResult as OkNegotiatedContentResult <List <EntityMappingViewModel> >;

            //assert
            Assert.NotNull(result);
            var content = result.Content;

            Assert.AreEqual(dbRecordCount, content.Count);
        }
        public void AddEntities(int record, List <int> mappingPercentiles, List <int> numMappings)
        {
            try
            {
                _db = new EntityMapperDbContext();
                var testData        = _db.TestDatas.Take(record).ToList();
                var learningSession = new LearningSession(new UntrainedData
                {
                    Sources      = testData.Select(t => t.Source).ToList(),
                    Destinations = testData.Select(t => t.Destination).ToList()
                });
                var result     = learningSession.StartLearning().Select(t => t.Mapping).ToList();
                var resultText = string.Join(@"\n", result.Select(t => t.Source + " - " + t.Destination).ToList());

                var correctMappings = 0;
                foreach (var correctMapping in testData)
                {
                    var calculatedMappings = result.First(t => t.Source.Equals(correctMapping.Source));
                    //var correctMapping = testData.Single(t => t.Source.Equals(calculatedMappings.Source));
                    if (calculatedMappings.Destination.Equals(correctMapping.Destination))
                    {
                        correctMappings++;
                    }
                }
                var percentage = ((decimal)correctMappings / (decimal)testData.Count) * 100.0M;

                mappingPercentiles.Add(Convert.ToInt32(percentage));
                numMappings.Add(result.Count());

                Assert.AreEqual(record, result.Count());
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 4
0
        //[SetUp]
        public void SetUp(int record)
        {
            _db = new EntityMapperDbContext();
            var testData = _db.TestDatas.Take(record).ToList();

            _authAdapter    = new IdentityAuthAdapter();
            _sourceIds      = new List <int>();
            _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   = "QualityControl",
                Active = true
            });

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

            _sourceSystemId      = sourceSystem.Id;
            _destinationSystemId = destinationSystem.Id;
            foreach (var source in testData.Select(t => t.Source))
            {
                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 testData.Select(t => t.Destination))
            {
                var entityCrud = new EfRepository <Entity>(_db, _authAdapter);
                var entity     = entityCrud.Add(new Entity
                {
                    SystemId = _destinationSystemId,
                    Name     = destination.Trim(),
                    Active   = true
                });
                _destinationIds.Add(entity.Id);
            }
        }
        public void Setup()
        {
            //Prefill
            _authAdapter = new IdentityAuthAdapter();
            _db          = new EntityMapperDbContext();

            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   = "Export",
                Active = true
            });

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

            _sourceSystemId      = sourceSystem.Id;
            _destinationSystemId = destinationSystem.Id;



            var entityCrud = new EfRepository <Entity>(_db, _authAdapter);

            entityCrud.Add(new Entity
            {
                SystemId = _sourceSystemId,
                Name     = "Commodity",
                Active   = true
            });

            entityCrud.Add(new Entity
            {
                SystemId = _destinationSystemId,
                Name     = "commodity",
                Active   = true
            });
        }
Exemplo n.º 6
0
        public void AddSystem()
        {
            var context     = new EntityMapperDbContext();
            var authAdapter = new IdentityAuthAdapter();
            var sut         = new EfRepository <global::Data.Models.System>(context, authAdapter);

            var result = sut.Add(new global::Data.Models.System
            {
                DomainId = 1,
                Active   = true,
                Name     = "First System"
            });

            Assert.NotNull(result);
            Assert.Greater(result.Id, 0);
            var systems = context.Domains.Find(1).Systems.ToList();

            Assert.Greater(systems.Count, 0);
            Assert.NotNull(result.Domain);
            context.Systems.Remove(result);
            context.SaveChanges();
        }
Exemplo n.º 7
0
        public void AddASingleEntity()
        {
            var context     = new EntityMapperDbContext();
            var authAdapter = new IdentityAuthAdapter();
            var sut         = new EfRepository <Entity>(context, authAdapter);

            var result = sut.Add(new Entity
            {
                SystemId = 1,
                Active   = true,
                Name     = "First Entity"
            });

            Assert.NotNull(result);
            Assert.Greater(result.Id, 0);
            var entities = context.Systems.Find(1).Entities.ToList();

            Assert.Greater(entities.Count, 0);
            Assert.NotNull(result.System);
            context.Entities.Remove(result);
            context.SaveChanges();
        }
        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);
        }