Exemple #1
0
        public List <DTO.Horse> Convert(WolferhamptonDataSource source, List <DTO.Horse> destination, ResolutionContext context)
        {
            var selections = source.RawData.Markets.FirstOrDefault()?.Selections.Select(s => new { ParticipantId = int.Parse(s.Tags.Participant), Price = s.Price });

            var participants = source.RawData.Participants
                               .Select(p => new { ParticipantId = p.Id, HorseName = p.Name });

            if (selections == null)
            {
                return(null);
            }
            else
            {
                var horseData = participants
                                .Join(selections,
                                      participant => participant.ParticipantId,
                                      selection => selection.ParticipantId,
                                      (participant, selection) => new DTO.Horse()
                {
                    HorseID   = participant.ParticipantId,
                    HorseName = participant.HorseName,
                    Price     = selection.Price
                });

                return(horseData.ToList());
            }
        }
Exemple #2
0
        public void HorseDataMapperWolferHampton_Mapper_Test()
        {
            var config = new MapperConfiguration(opts => { opts.AddProfile(new RaceDataMapper()); });
            var mapper = config.CreateMapper();


            var source = new WolferhamptonDataSource()
            {
                RawData = new RaceDetails()
                {
                    Markets = new List <Market>()
                    {
                        new Market()
                        {
                            Id         = "NbSeMfzhDCHT_HdtAYZF_7zjFkI",
                            Selections = new[]
                            {
                                new Selection()
                                {
                                    Id = "1asdasd", Price = 2.2f, Tags = new SectionTag()
                                    {
                                        Participant = "1",
                                        Name        = "John"
                                    }
                                },

                                new Selection()
                                {
                                    Id = "3asdasd", Price = 1.2f, Tags = new SectionTag()
                                    {
                                        Participant = "3",
                                        Name        = "Eldho"
                                    }
                                },

                                new Selection()
                                {
                                    Id = "2asdasd", Price = 5.2f, Tags = new SectionTag()
                                    {
                                        Participant = "2",
                                        Name        = "Sam"
                                    }
                                }
                            },
                        }
                    },
                    Participants = new[]
                    {
                        new Participant()
                        {
                            Id = 1, Name = "John", Tags = new ParticipantsTags()
                            {
                                Drawn = "abc"
                            }
                        },
                        new Participant()
                        {
                            Id = 3, Name = "Eldho", Tags = new ParticipantsTags()
                            {
                                Drawn = "bcd"
                            }
                        },
                        new Participant()
                        {
                            Id = 2, Name = "Sam", Tags = new ParticipantsTags()
                            {
                                Drawn = "cde"
                            }
                        },
                    }
                }
            };

            var houseList = mapper.Map <List <Challenge.DataLayer.DTO.Horse> >(source);

            Assert.NotNull(houseList);
            Assert.Equal(2.2f, houseList.First()?.Price);
        }