Esempio n. 1
0
        public void ResolveNamingNegativeTest()
        {
            IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext);

            SportType football = new SportType {
                Name = "Football"
            };
            SportType sport = unit.GetRepository <SportType>()
                              .Get(x => x.Name.ToUpper() == football.Name.ToUpper())
                              .FirstOrDefault();

            Team negativeTeam = new Team
            {
                Name      = "Металлист",
                SportType = sport,
                Names     = new List <TeamName>()
            };

            NamingMatcher matcher = new NamingMatcher(unit);

            List <Conformity> negativeConformities = matcher.ResolveNaming(negativeTeam);

            Assert.IsNull(negativeConformities);

            Team team = unit.GetRepository <Team>()
                        .Get((x) => x.Id == negativeTeam.Id)
                        .FirstOrDefault();

            Assert.AreEqual(negativeTeam, team);
        }
Esempio n. 2
0
        public void ResolveNamingNeutralTest()
        {
            IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext);

            SportType football = new SportType {
                Name = "Football"
            };
            SportType sport = unit.GetRepository <SportType>()
                              .Get(x => x.Name.ToUpper() == football.Name.ToUpper())
                              .FirstOrDefault();

            Conformity expConf = new Conformity
            {
                InputName   = "Ст. Этьен",
                ExistedName = "Сент-Этьен"
            };

            Team neutralTeam = new Team
            {
                Name      = "Ст. Этьен",
                SportType = sport
            };

            NamingMatcher matcher = new NamingMatcher(unit);

            List <Conformity> neutralConformities = matcher.ResolveNaming(neutralTeam);

            Conformity newConf = neutralConformities.FirstOrDefault();

            Assert.AreEqual(expConf.InputName, newConf.InputName);
            Assert.AreEqual(expConf.ExistedName, newConf.ExistedName);
        }
Esempio n. 3
0
        public void ResolveNamingPositiveTest()
        {
            IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext);

            SportType football = new SportType {
                Name = "Football"
            };
            SportType sport = unit.GetRepository <SportType>()
                              .Get(x => x.Name.ToUpper() == football.Name.ToUpper())
                              .FirstOrDefault();

            Team positiveTeam = new Team
            {
                Name      = "Краснодар ФК",
                SportType = sport,
                Names     = new List <TeamName> {
                    new TeamName {
                        Name = "Краснодар ФК"
                    }
                }
            };

            NamingMatcher matcher = new NamingMatcher(unit);

            List <Conformity> positiveConformities = matcher.ResolveNaming(positiveTeam);

            Assert.IsNull(positiveConformities);

            Team team = unit.GetRepository <Team>()
                        .Get((x) => x.Names.Select(n => n.Name)
                             .Contains(positiveTeam.Name))
                        .FirstOrDefault();

            Assert.IsTrue(team.Names.Select(t => t.Name).Contains("Краснодар"));
            Assert.IsTrue(team.Names.Select(t => t.Name).Contains("Краснодар ФК"));
        }
Esempio n. 4
0
        public bool SaveSportEvents(ICollection <SportEventDTO> eventDTOs)
        {
            Log.Info("Writing transferred data...");
            try
            {
                NamingMatcher matcher = new NamingMatcher(this.dataUnit);

                IEnumerable <SportType> sportTypes = this.dataUnit.GetRepository <SportType>().Get();

                foreach (SportEventDTO eventDTO in eventDTOs)
                {
                    SportType sportType = sportTypes.FirstOrDefault(st => st.Name == eventDTO.SportType)
                                          ?? new SportType {
                        Name = eventDTO.SportType
                    };

                    SportEvent sportEvent = new SportEvent
                    {
                        SportType = sportType, Date = this.ConvertAndTrimDate(eventDTO.Date), Results = new List <Result>()
                    };
                    TempSportEvent tempEvent = new TempSportEvent()
                    {
                        SportType = sportType, Date = this.ConvertAndTrimDate(eventDTO.Date), TempResults = new List <TempResult>()
                    };

                    foreach (ResultDTO resultDTO in eventDTO.Results)
                    {
                        Team team = new Team
                        {
                            Name      = resultDTO.TeamName,
                            SportType = sportType,
                            Names     = new List <TeamName> {
                                new TeamName {
                                    Name = resultDTO.TeamName
                                }
                            }
                        };

                        List <Conformity> conformities = matcher.ResolveNaming(team);

                        if (conformities == null)
                        {
                            team = this.dataUnit.GetRepository <TeamName>()
                                   .Get((x) => x.Name == team.Name).Select(x => x.Team).FirstOrDefault();

                            Result result = new Result {
                                Team = team, Score = resultDTO.Score ?? -1, IsHome = resultDTO.IsHome
                            };
                            sportEvent.Results.Add(result);
                        }
                        else
                        {
                            TempResult result = new TempResult
                            {
                                Score        = resultDTO.Score ?? -1,
                                Conformities = new List <Conformity>(),
                                IsHome       = resultDTO.IsHome
                            };

                            if (team.Names.FirstOrDefault().Id != 0)
                            {
                                result.Team = team;
                            }

                            foreach (Conformity conformity in conformities)
                            {
                                result.Conformities.Add(conformity);
                            }
                            conformities.Clear();
                            tempEvent.TempResults.Add(result);
                        }
                    }

                    this.Save(tempEvent, sportEvent);
                }
                this.dataUnit.SaveChanges();

                this.predictionSender.SendPredictionRequest();
            }
            catch (Exception ex)
            {
                Log.Error("Exception when trying to save transferred data to DB", ex);
                return(false);
            }
            Log.Info("Transferred data sucessfully saved");
            return(true);
        }