Exemple #1
0
            public void UpdatesAnExistingMatch()
            {
                //Arrange
                this.matches   = new List <E.Match>();
                this.matchDate = new DateTime(2013, 02, 02);

                var matchToCheck = new E.Match()
                {
                    TeamsPlayerA = new E.TeamPlayer {
                        Name = "QPR"
                    },
                    TeamsPlayerB = new E.TeamPlayer {
                        Name = "Norwich"
                    },
                    MatchDate = this.matchDate.AddHours(15) //wrong time
                };

                matches.Add(matchToCheck);

                this.webRepositoryProvider = new ManifestWebRepositoryProvider();

                this.mockFixtureRepository = BuildFixtureRepository.Create()
                                             .HasTheSkySportsURL(this.matchDate)
                                             .HasGetAliasWhichReturnsItself()
                                             .CanAddOrUpdateMatches(matches)
                                             .HasFootballTournamentEvents();

                this.mockStoredProcRepository = new Mock <ISqlLinqStoredProceduresRepository>();

                var footballFixtureStrategy = new TestableFootballFixtureStrategy(this.mockFixtureRepository,
                                                                                  this.mockStoredProcRepository, this.webRepositoryProvider);

                //Act
                footballFixtureStrategy.UpdateFixtures(this.matchDate);

                //Assert
                //Hasn't been added twice
                Assert.AreEqual(1, this.matches.Count(x => x.TeamsPlayerA.Name == "QPR" && x.TeamsPlayerB.Name == "Norwich"));
                //Time has been updated
                Assert.AreEqual(this.matchDate.AddHours(12.75), this.matches.First(x => x.TeamsPlayerA.Name == "QPR" && x.TeamsPlayerB.Name == "Norwich").MatchDate);
            }
      public void UpdatesAnExistingMatch()
      {
        //Arrange
        this.matches = new List<E.Match>();
        this.matchDate = new DateTime(2013, 02, 02);

        var matchToCheck = new E.Match()
        {
          TeamsPlayerA = new E.TeamPlayer { Name = "QPR" },
          TeamsPlayerB = new E.TeamPlayer { Name = "Norwich" },
          MatchDate = this.matchDate.AddHours(15) //wrong time
        };

        matches.Add(matchToCheck);

        this.webRepositoryProvider = new ManifestWebRepositoryProvider();

        this.mockFixtureRepository = BuildFixtureRepository.Create()
          .HasTheSkySportsURL(this.matchDate)
          .HasGetAliasWhichReturnsItself()
          .CanAddOrUpdateMatches(matches)
          .HasFootballTournamentEvents();

        this.mockStoredProcRepository = new Mock<ISqlLinqStoredProceduresRepository>();

        var footballFixtureStrategy = new TestableFootballFixtureStrategy(this.mockFixtureRepository,
          this.mockStoredProcRepository, this.webRepositoryProvider);

        //Act
        footballFixtureStrategy.UpdateFixtures(this.matchDate);

        //Assert
        //Hasn't been added twice
        Assert.AreEqual(1, this.matches.Count(x => x.TeamsPlayerA.Name == "QPR" && x.TeamsPlayerB.Name == "Norwich"));
        //Time has been updated
        Assert.AreEqual(this.matchDate.AddHours(12.75), this.matches.First(x => x.TeamsPlayerA.Name == "QPR" && x.TeamsPlayerB.Name == "Norwich").MatchDate);
      }
Exemple #3
0
            public void AddScoresToAnExistingFixture()
            {
                //Arrange
                this.matches   = new List <E.Match>();
                this.matchDate = new DateTime(2013, 02, 02);

                var matchToCheck = new E.Match()
                {
                    TeamsPlayerA = new E.TeamPlayer {
                        Name = "QPR"
                    },
                    TeamsPlayerB = new E.TeamPlayer {
                        Name = "Norwich"
                    },
                    MatchDate       = this.matchDate.AddHours(15), //wrong time
                    TournamentEvent = new E.TournamentEvent {
                        Id = 1
                    }
                };

                matches.Add(matchToCheck);

                this.webRepositoryProvider = new ManifestWebRepositoryProvider();

                this.mockFixtureRepository = BuildFixtureRepository.Create()
                                             .HasTheSkySportsURL(this.matchDate)
                                             .HasGetAliasWhichReturnsItself()
                                             .CanAddOrUpdateMatches(matches)
                                             .HasPersistedMatches(matches)
                                             .HasFootballTournamentEvents()
                                             .CanReturnScoreOutcome();

                this.mockStoredProcRepository = new Mock <ISqlLinqStoredProceduresRepository>();

                var footballFixtureStrategy = new TestableFootballFixtureStrategy(this.mockFixtureRepository,
                                                                                  this.mockStoredProcRepository, this.webRepositoryProvider);

                //Act
                footballFixtureStrategy.UpdateResults(this.matchDate);

                //Assert
                //We have the right number of matches
                Assert.AreEqual(8, this.matches.Count(x => x.TournamentEvent.Id == 1));  //Prem
                Assert.AreEqual(11, this.matches.Count(x => x.TournamentEvent.Id == 2)); //Champ
                Assert.AreEqual(11, this.matches.Count(x => x.TournamentEvent.Id == 3)); //League 1
                Assert.AreEqual(10, this.matches.Count(x => x.TournamentEvent.Id == 4)); //League 2
                //We have collected the correct dates
                Assert.AreEqual(1, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(12.75)));
                Assert.AreEqual(1, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(17.5)));
                Assert.AreEqual(1, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(17).AddMinutes(20)));
                Assert.AreEqual(37, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(15)));
                //Spot check a few matches
                var qprNowich         = this.matches.Where(x => x.TeamsPlayerA.Name == "QPR" && x.TeamsPlayerB.Name == "Norwich");
                var yeovilBrentford   = this.matches.Where(x => x.TeamsPlayerA.Name == "Yeovil" && x.TeamsPlayerB.Name == "Brentford");
                var cheltenhamTorquay = this.matches.Where(x => x.TeamsPlayerA.Name == "Cheltenham" && x.TeamsPlayerB.Name == "Torquay");

                Assert.AreEqual(1, qprNowich.Count());
                Assert.AreEqual(1, yeovilBrentford.Count());
                Assert.AreEqual(1, cheltenhamTorquay.Count());

                Assert.AreEqual("0-0", qprNowich.FirstOrDefault().ObservedOutcomes.First().ScoreOutcome.ToString());
                Assert.AreEqual("3-0", yeovilBrentford.FirstOrDefault().ObservedOutcomes.First().ScoreOutcome.ToString());
                Assert.AreEqual("2-1", cheltenhamTorquay.FirstOrDefault().ObservedOutcomes.First().ScoreOutcome.ToString());
            }
      public void AddScoresToAnExistingFixture()
      {
        //Arrange
        this.matches = new List<E.Match>();
        this.matchDate = new DateTime(2013, 02, 02);

        var matchToCheck = new E.Match()
        {
          TeamsPlayerA = new E.TeamPlayer { Name = "QPR" },
          TeamsPlayerB = new E.TeamPlayer { Name = "Norwich" },
          MatchDate = this.matchDate.AddHours(15), //wrong time
          TournamentEvent = new E.TournamentEvent { Id = 1 }
        };

        matches.Add(matchToCheck);

        this.webRepositoryProvider = new ManifestWebRepositoryProvider();

        this.mockFixtureRepository = BuildFixtureRepository.Create()
          .HasTheSkySportsURL(this.matchDate)
          .HasGetAliasWhichReturnsItself()
          .CanAddOrUpdateMatches(matches)
          .HasPersistedMatches(matches)
          .HasFootballTournamentEvents()
          .CanReturnScoreOutcome();

        this.mockStoredProcRepository = new Mock<ISqlLinqStoredProceduresRepository>();

        var footballFixtureStrategy = new TestableFootballFixtureStrategy(this.mockFixtureRepository,
          this.mockStoredProcRepository, this.webRepositoryProvider);

        //Act
        footballFixtureStrategy.UpdateResults(this.matchDate);

        //Assert
        //We have the right number of matches
        Assert.AreEqual(8, this.matches.Count(x => x.TournamentEvent.Id == 1)); //Prem
        Assert.AreEqual(11, this.matches.Count(x => x.TournamentEvent.Id == 2)); //Champ
        Assert.AreEqual(11, this.matches.Count(x => x.TournamentEvent.Id == 3)); //League 1
        Assert.AreEqual(10, this.matches.Count(x => x.TournamentEvent.Id == 4)); //League 2
        //We have collected the correct dates
        Assert.AreEqual(1, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(12.75)));
        Assert.AreEqual(1, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(17.5)));
        Assert.AreEqual(1, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(17).AddMinutes(20)));
        Assert.AreEqual(37, this.matches.Count(x => x.MatchDate == this.matchDate.AddHours(15)));
        //Spot check a few matches
        var qprNowich = this.matches.Where(x => x.TeamsPlayerA.Name == "QPR" && x.TeamsPlayerB.Name == "Norwich");
        var yeovilBrentford = this.matches.Where(x => x.TeamsPlayerA.Name == "Yeovil" && x.TeamsPlayerB.Name == "Brentford");
        var cheltenhamTorquay = this.matches.Where(x => x.TeamsPlayerA.Name == "Cheltenham" && x.TeamsPlayerB.Name == "Torquay");

        Assert.AreEqual(1, qprNowich.Count());
        Assert.AreEqual(1, yeovilBrentford.Count());
        Assert.AreEqual(1, cheltenhamTorquay.Count());

        Assert.AreEqual("0-0", qprNowich.FirstOrDefault().ObservedOutcomes.First().ScoreOutcome.ToString());
        Assert.AreEqual("3-0", yeovilBrentford.FirstOrDefault().ObservedOutcomes.First().ScoreOutcome.ToString());
        Assert.AreEqual("2-1", cheltenhamTorquay.FirstOrDefault().ObservedOutcomes.First().ScoreOutcome.ToString());
      }
    private IEnumerable<Match> ConvertFixtures(DateTime fixtureDate, IEnumerable<ISkySportsFixture> fixtureTokens)
    {
      var returnMatches = new List<Match>();
      var skySportsSource = this.fixtureRepository.GetExternalSource("Sky Sports");
      var valueSamuraiSource = this.fixtureRepository.GetExternalSource("Value Samurai");
      var sport = this.fixtureRepository.GetSport("Football");

      foreach (var fixture in fixtureTokens)
      {
        var homeTeam = this.fixtureRepository.GetAlias(fixture.HomeTeam, skySportsSource, valueSamuraiSource, sport);
        var awayTeam = this.fixtureRepository.GetAlias(fixture.AwayTeam, skySportsSource, valueSamuraiSource, sport);

        if (homeTeam == null) throw new ArgumentNullException("homeTeam");
        if (awayTeam == null) throw new ArgumentNullException("awayTeam");

        var persistedMatch = this.fixtureRepository.GetMatchFromTeamSelections(homeTeam, awayTeam, fixtureDate);
        if (persistedMatch == null)
        {
          var tournamentEvent = this.fixtureRepository.GetFootballTournamentEvent((int)fixture.LeagueEnum, fixtureDate);
          var newMatch = new Match()
          {
            TournamentEvent = tournamentEvent,
            MatchDate = fixtureDate.AddHours(fixture.KickOffHours).AddMinutes(fixture.KickOffMintutes),
            TeamsPlayerA = homeTeam,
            TeamsPlayerB = awayTeam,
            EligibleForBetting = true
          };

          returnMatches.Add(newMatch);
          this.fixtureRepository.AddMatch(newMatch);
        }
        else
        {
          //only field we're likley to need to update
          persistedMatch.MatchDate = fixtureDate.AddHours(fixture.KickOffHours).AddMinutes(fixture.KickOffMintutes);
          returnMatches.Add(persistedMatch);
        }
      }
      return returnMatches;
    }
    public IEnumerable<GenericMatchDetailQuery> UpdateResults(DateTime fixtureDate)
    {
      this.excelMatches.Where(x =>
                            x.Field<DateTime>("DateToTake").Date == fixtureDate.Date)
                              .ToList()
                              .ForEach(x =>
                              {
                                var player1 = this.fixtureRepository.GetTeamOrPlayerFromNameAndMaybeFirstName(x.Field<string>("Player1Surname"), x.Field<string>("Player1FirstName"));
                                var player2 = this.fixtureRepository.GetTeamOrPlayerFromNameAndMaybeFirstName(x.Field<string>("Player2Surname"), x.Field<string>("Player2FirstName"));
                                var matchDate = x.Field<DateTime>("DateToTake");
                                var persistedMatch = this.fixtureRepository.GetTennisMatch(player1.Slug, player2.Slug, matchDate);
                                if (persistedMatch == null)
                                {
                                  var tournamentEvent = this.fixtureRepository.GetTournamentEventFromTournamentAndDate(matchDate, x.Field<string>("WebName"));
                                  var newMatch = new Match()
                                  {
                                    TournamentEvent = tournamentEvent,
                                    MatchDate = matchDate,
                                    TeamsPlayerA = player1,
                                    TeamsPlayerB = player2,
                                    EligibleForBetting = true,
                                  };

                                  int[] scores = new int[] 
                                  { 
                                    (int)x.Field<double>("FirstSet"), 
                                    (int)x.Field<double>("SecondSet"),
                                    (int)x.Field<double>("ThirdSet"),
                                    (int)x.Field<double>("FourthSet"),
                                    (int)x.Field<double>("FifthSet")
                                  };

                                  newMatch.ObservedOutcomes.Add(new ObservedOutcome()
                                  {
                                    Match = newMatch,
                                    ScoreOutcome = this.fixtureRepository.GetScoreOutcome(scores.Count(s => s == 1), scores.Count(s => s == -1)) //TODO <- this is bullshit, retirie's will get a null returned
                                  });
                                  this.fixtureRepository.AddMatch(newMatch);
                                }
                              });

      this.fixtureRepository.SaveChanges();

      return this.storedProcRepository
                 .GetGenericMatchDetails(fixtureDate, "Tennis");
    }
 public IEnumerable<GenericMatchDetailQuery> UpdateResults(DateTime fixtureDate)
 {
   FixturesCouponsOdds.Where(x => 
                             x.Field<DateTime>("Date").Date == fixtureDate.Date)
                              .ToList()
                              .ForEach(x =>
                              {
                                var homeTeam = this.fixtureRepository.GetTeamOrPlayerFromName(x.Field<string>("HomeTeam"));
                                var awayTeam = this.fixtureRepository.GetTeamOrPlayerFromName(x.Field<string>("AwayTeam"));
                                var matchDate = x.Field<DateTime>("Date");
                                var persistedMatch = this.fixtureRepository.GetMatchFromTeamSelections(homeTeam, awayTeam, matchDate);
                                if (persistedMatch == null)
                                {
                                  var tournamentEvent = this.fixtureRepository.GetFootballTournamentEvent(1, fixtureDate);
                                  var newMatch = new Match()
                                  {
                                    TournamentEvent = tournamentEvent,
                                    MatchDate = matchDate,
                                    TeamsPlayerA = homeTeam,
                                    TeamsPlayerB = awayTeam,
                                    EligibleForBetting = true,
                                  };
                                  newMatch.ObservedOutcomes.Add(new ObservedOutcome()
                                  {
                                    Match = newMatch,
                                    ScoreOutcome = this.fixtureRepository.GetScoreOutcome((int)x.Field<double>("FTHG"), (int)x.Field<double>("FTAG"))
                                  });
                                  this.fixtureRepository.AddMatch(newMatch);
                                }
                              });
   
   this.fixtureRepository.SaveChanges();
   return this.storedProcRepository.GetGenericMatchDetails(fixtureDate, "Football");
 }