Exemplo n.º 1
0
        protected void ConvertToNexusId <TMapping>()
            where TMapping : EntityMapping, new()
        {
            var container = new UnityContainer();

            // Self-register and set up service location
            container.RegisterInstance <IUnityContainer>(container);
            var locator = new UnityServiceLocator(container);

            Global.ServiceLocator = locator;

            var task = new SimpleMappingEngineConfiguration(container);

            task.Configure();

            var start    = new DateTime(2000, 12, 31);
            var expected = new EnergyTrading.Mdm.Contracts.MdmId
            {
                MappingId              = 34,
                SystemName             = "Test",
                Identifier             = "1",
                SourceSystemOriginated = true,
                StartDate              = start,
                EndDate = DateUtility.MaxDate
            };
            var s1 = new SourceSystem {
                Name = "Test"
            };
            var m1 = new TMapping
            {
                Id           = 34,
                System       = s1,
                MappingValue = "1",
                IsMaster     = true,
                Validity     = new DateRange(start, DateUtility.MaxDate)
            };

            var mappingEngine = container.Resolve <IMappingEngine>();

            var candidate = mappingEngine.Map <IEntityMapping, EnergyTrading.Mdm.Contracts.MdmId>(m1);

            Check(expected, candidate);
        }
Exemplo n.º 2
0
        public TMapping GetOrCreateMappings <TMapping>() where TMapping : IXbimMappings <TSourceRepository, TTargetRepository>, new()
        {
            var mappings = new TMapping {
                Exchanger = this
            };
            ConcurrentDictionary <Type, IXbimMappings <TSourceRepository, TTargetRepository> > toMappings;

            if (_mappings.TryGetValue(mappings.MapFromType, out toMappings))
            {
                IXbimMappings <TSourceRepository, TTargetRepository> imappings;
                if (toMappings.TryGetValue(mappings.MapToType, out imappings))
                {
                    return((TMapping)imappings);
                }
                toMappings.TryAdd(mappings.MapToType, mappings);
                return(mappings);
            }
            toMappings = new ConcurrentDictionary <Type, IXbimMappings <TSourceRepository, TTargetRepository> >();
            toMappings.TryAdd(mappings.MapToType, mappings);
            _mappings.TryAdd(mappings.MapFromType, toMappings);
            return(mappings);
        }
Exemplo n.º 3
0
        public void Map <TMapping>()
            where TMapping : class, IEntityMapping, new()
        {
            // Arrange
            var system = new SourceSystem {
                Name = "Test"
            };
            var systemList = new System.Collections.Generic.List <SourceSystem> {
                system
            };
            var repository = new Mock <IRepository>();

            repository.Setup(x => x.Queryable <SourceSystem>()).Returns(systemList.AsQueryable());

            var start  = new DateTime(2010, 1, 1);
            var end    = new DateTime(2012, 12, 31);
            var source = new EnergyTrading.Mdm.Contracts.MdmId {
                MappingId = 1, SystemName = "Test", Identifier = "1", StartDate = start, EndDate = end
            };

            var expected = new TMapping
            {
                System       = system,
                MappingValue = "1",
                Validity     = new DateRange(start, end)
            };

            expected.MappingId = 1;

            var mapper = new MappingMapper <TMapping>(repository.Object);

            // Act
            var candidate = mapper.Map(source);

            // Assert
            Check(expected, candidate);
        }