public void CarNumbersObjectToCarNumberDataEntitiesMapper_WhenInvokingMapMethodWithPopulatedEntity_ExpectPopulatedList()
        {
            var factory = new IntegerIdentityFactory <CarNumberDataEntity>(() => new CarNumberDataEntity()); // TODO: Mock it
            var mapper  = new Application.Maps.Manual.CarNumbersObjectToCarNumberDataEntitiesMapper(factory);

            var carNumbersObjectFactory = new CarNumbersObjectFactory(() => new CarNumbersObject()); // TODO: Mock it

            const int carNumbersObjectId = 1;
            var       carNumbersObject   = carNumbersObjectFactory.Create(carNumbersObjectId);

            carNumbersObject.CarNumberDriver1 = 3;
            carNumbersObject.CarNumberDriver2 = 4;

            var sut = mapper.Map(carNumbersObject).ToList();

            sut.Should().NotBeNull();
            sut.Count.Should().Be(2);

            var carNumberDataEntity1 = sut.Single(x => x.PositionId == 0);

            carNumberDataEntity1.Should().NotBeNull();
            carNumberDataEntity1.Id.Should().Be(2);
            carNumberDataEntity1.ValueA.Should().Be(carNumbersObject.CarNumberDriver1);
            carNumberDataEntity1.ValueB.Should().Be(carNumbersObject.CarNumberDriver1);

            var carNumberDataEntity2 = sut.Single(x => x.PositionId == 1);

            carNumberDataEntity2.Should().NotBeNull();
            carNumberDataEntity2.Id.Should().Be(3);
            carNumberDataEntity2.ValueA.Should().Be(carNumbersObject.CarNumberDriver2);
            carNumberDataEntity2.ValueB.Should().Be(carNumbersObject.CarNumberDriver2);
        }
예제 #2
0
        public void TeamDataEntityOnTeamEntityProfile_WhenMappingFromPopulatedCarNumbersObject_ExpectPopulatedTeamEntity()
        {
            var carNumbersObjectFactory = new CarNumbersObjectFactory(() => new CarNumbersObject());       // TODO: Mock it
            var teamEntityFactory       = new IntegerIdentityFactory <TeamEntity>(() => new TeamEntity()); // TODO: Mock it

            var assembly            = Assembly.GetAssembly(typeof(ApplicationMaps));
            var mapperConfiguration = new MapperConfiguration(c => c.AddProfiles(assembly));
            var mapper        = mapperConfiguration.CreateMapper();
            var mapperService = new AutoMapperMapperService(mapper);

            const int teamDataEntityId = 1;
            var       carNumbersObject = carNumbersObjectFactory.Create(teamDataEntityId);

            carNumbersObject.CarNumberDriver1 = 23;
            carNumbersObject.CarNumberDriver2 = 24;

            const int teamEntityId = 1;
            var       sut          = teamEntityFactory.Create(teamEntityId);

            mapperService.Map(carNumbersObject, sut);

            sut.Should().NotBeNull();
            sut.CarNumberDriver1.Should().Be(carNumbersObject.CarNumberDriver1);
            sut.CarNumberDriver2.Should().Be(carNumbersObject.CarNumberDriver2);
        }
예제 #3
0
        public CarNumbersObject Map(IEnumerable <CarNumberDataEntity> items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            var list = items as IList <CarNumberDataEntity> ?? items.ToList();

            if (list.Count != 2)
            {
                throw new ArgumentOutOfRangeException();
            }

            var result = _factory.Create(list.Single(x => x.PositionId == 0).Id / 2);

            result.CarNumberDriver1 = list.Single(x => x.PositionId == 0).ValueA;
            result.CarNumberDriver2 = list.Single(x => x.PositionId == 1).ValueA;
            return(result);
        }
        public void Export()
        {
            var teams = _domainService.GetTeams();

            foreach (var team in teams)
            {
                // Map one into three
                var teamDataEntity = _teamDataEntityFactory.Create(team.Id);
                _mapperService.Map(team, teamDataEntity);

                var chassisHandlingDataEntity = _chassisHandlingDataEntityFactory.Create(team.Id);
                _mapperService.Map(team, chassisHandlingDataEntity);

                var carNumbersObject      = _carNumbersObjectFactory.Create(team.Id);
                var carNumberDataEntities = _carNumbersMapper.Map(_mapperService.Map(team, carNumbersObject));

                _dataService.Teams.SetById(teamDataEntity);
                _dataService.ChassisHandlings.SetById(chassisHandlingDataEntity);
                foreach (var item in carNumberDataEntities)
                {
                    _dataService.CarNumbers.SetById(item);
                }
            }
        }
예제 #5
0
        public void TeamDataEntityOnTeamEntityProfile_WhenMappingFromPopulatedTeamEntity_ExpectPopulatedCarNumbersObject()
        {
            var teamDataEntityFactory            = new IntegerIdentityFactory <TeamDataEntity>(() => new TeamDataEntity(new LanguageCatalogueValue())); // TODO: Mock it
            var chassisHandlingDataEntityFactory = new IntegerIdentityFactory <ChassisHandlingDataEntity>(() => new ChassisHandlingDataEntity());       // TODO: Mock it
            var carNumbersObjectFactory          = new CarNumbersObjectFactory(() => new CarNumbersObject());                                           // TODO: Mock it
            var teamEntityFactory = new IntegerIdentityFactory <TeamEntity>(() => new TeamEntity());                                                    // TODO: Mock it

            var assembly            = Assembly.GetAssembly(typeof(ApplicationMaps));
            var mapperConfiguration = new MapperConfiguration(c => c.AddProfiles(assembly));
            var mapper        = mapperConfiguration.CreateMapper();
            var mapperService = new AutoMapperMapperService(mapper);

            // Initialise data entities using unique non-default dummy values to verify mappings
            const int teamDataEntityId = 1;
            var       teamDataEntity   = teamDataEntityFactory.Create(teamDataEntityId);

            teamDataEntity.Name.Shared      = "UnitTest";
            teamDataEntity.LastPosition     = 11;
            teamDataEntity.LastPoints       = 12;
            teamDataEntity.FirstGpTrack     = 13;
            teamDataEntity.FirstGpYear      = 14;
            teamDataEntity.Wins             = 15;
            teamDataEntity.YearlyBudget     = 16;
            teamDataEntity.UnknownA         = 17;
            teamDataEntity.CountryMapId     = 18;
            teamDataEntity.LocationPointerX = 19;
            teamDataEntity.LocationPointerY = 20;
            teamDataEntity.TyreSupplierId   = 21;

            const int chassisHandlingDataEntityId = 2;
            var       chassisHandlingDataEntity   = chassisHandlingDataEntityFactory.Create(chassisHandlingDataEntityId);

            chassisHandlingDataEntity.Value = 22;

            var carNumbersObject = carNumbersObjectFactory.Create(teamDataEntityId);

            carNumbersObject.CarNumberDriver1 = 23;
            carNumbersObject.CarNumberDriver2 = 24;

            // Initialise using values used in earlier initialisation to verify reverse mappings
            var teamEntity = teamEntityFactory.Create(teamDataEntity.Id);

            teamEntity.TeamId           = teamDataEntity.Id + 1;
            teamEntity.Name             = teamDataEntity.Name.Shared;
            teamEntity.LastPosition     = teamDataEntity.LastPosition;
            teamEntity.LastPoints       = teamDataEntity.LastPoints;
            teamEntity.FirstGpTrack     = teamDataEntity.FirstGpTrack;
            teamEntity.FirstGpYear      = teamDataEntity.FirstGpYear;
            teamEntity.Wins             = teamDataEntity.Wins;
            teamEntity.YearlyBudget     = teamDataEntity.YearlyBudget;
            teamEntity.CountryMapId     = teamDataEntity.CountryMapId;
            teamEntity.LocationPointerX = teamDataEntity.LocationPointerX;
            teamEntity.LocationPointerY = teamDataEntity.LocationPointerY;
            teamEntity.TyreSupplierId   = teamDataEntity.TyreSupplierId;
            teamEntity.ChassisHandling  = chassisHandlingDataEntity.Value;
            teamEntity.CarNumberDriver1 = carNumbersObject.CarNumberDriver1;
            teamEntity.CarNumberDriver2 = carNumbersObject.CarNumberDriver2;

            var newCarNumbersObject = carNumbersObjectFactory.Create(teamEntity.Id);
            var sut = mapperService.Map(teamEntity, newCarNumbersObject);

            sut.Should().NotBeNull();
            sut.CarNumberDriver1.Should().Be(teamEntity.CarNumberDriver1);
            sut.CarNumberDriver2.Should().Be(teamEntity.CarNumberDriver2);
        }