public void IsAwayForfeit_IsForfeitFalse_ReturnsFalse()
        {
            Fixture fixture = new Fixture(homeTeamLeague, awayTeamLeague, fixtureDate, user) { IsPlayed = "Y" };
            fixture.IsForfeit = false;

            Assert.That(fixture.IsAwayForfeit(), Is.False);
        }
        public FixtureViewModel()
        {
            Fixture = new Fixture();
            Fixture.FixtureDate = DateTime.Now;

            SetCupRoundNames();
        }
        public void IsAwayForfeit_IsForfeitTrueAwayIdDoesNotMatch_ReturnsFalse()
        {
            Fixture fixture = new Fixture(homeTeamLeague, awayTeamLeague, fixtureDate, user) { IsPlayed = "Y" };
            fixture.IsForfeit = true;
            fixture.ForfeitingTeam = homeTeamLeague.Team;

            Assert.That(fixture.IsAwayForfeit(), Is.False);
        }
        public MatchResultDto(Fixture fixture, List<PlayerFixture> homePlayerStats, List<PlayerFixture> awayPlayerStats)
        {
            this.Fixture = new FixtureDto(fixture, true);

            this.HomePlayerStats = new List<PlayerFixtureDto>();
            homePlayerStats.ForEach(x => this.HomePlayerStats.Add(new PlayerFixtureDto(x)));

            this.AwayPlayerStats = new List<PlayerFixtureDto>();
            awayPlayerStats.ForEach(x => this.AwayPlayerStats.Add(new PlayerFixtureDto(x)));
        }
        public static Fixture CreateFixture(int id)
        {
            Season season = CreateSeason();
            EntityIdSetter.SetIdOf(season, 1);
            Team team = new Team("teamName", "teamNameLong");
            League league = new League(season, "league desc", 1, 1);
            EntityIdSetter.SetIdOf(league, 1);
            TeamLeague teamLeague = new TeamLeague(league, team, "teamName", "teamNameLong");

            Fixture fixture = new Fixture(teamLeague, teamLeague, DateTime.Today, CreateUser());
            fixture.IsCupFixture = false;
            EntityIdSetter.SetIdOf(fixture, id);
            return fixture;
        }
        public PlayerFixture(TeamLeague teamLeague, Fixture fixture, Player player, int pointsScored, int fouls)
            : this()
        {
            Check.Require(teamLeague != null, "teamLeague cannot be null");
            Check.Require(fixture != null, "teamLeague cannot be null");
            Check.Require(player != null, "player cannot be null");
            Check.Require(pointsScored >= 0, "pointsScored must be greater than or equal to zero");
            Check.Require(fouls >= 0, "fouls must be greater than or equal to zero");

            this.TeamLeague = teamLeague;
            this.Fixture = fixture;
            this.Player = player;
            this.PointsScored = pointsScored;
            this.Fouls = fouls;
        }
        public void SaveMatchResult_GameNotCancelled_Success()
        {
            Fixture fixture = new Fixture() { IsCancelled = "N" };
            User user = new User() { UserName = "******"};

            matchResultService.SaveMatchResult(fixture, user);

            Assert.That(fixture.IsCancelled, Is.EqualTo("N"));
            Assert.That(fixture.ResultAddedDate, Is.Not.Null);
            Assert.That(fixture.LastUpdated, Is.Not.Null);
            Assert.That(fixture.LastUpdatedBy.UserName, Is.EqualTo(user.UserName));

            mockFixtureService.Received().Update(fixture);
            mockFixtureService.Received().Commit();
        }
        public void CanCreateFixture()
        {
            Fixture fixture = new Fixture(homeTeamLeague, awayTeamLeague, fixtureDate, user);

            Assert.IsNotNull(fixture);
            Assert.That(fixture.IsPlayed, Is.EqualTo("N"));
            Assert.That(fixture.IsCancelled, Is.EqualTo("N"));
            Assert.That(fixture.HomeTeamLeague == homeTeamLeague);
            Assert.That(fixture.HomeTeamLeague.TeamName == homeTeamLeague.TeamName);
            Assert.That(fixture.HomeTeamLeague.TeamNameLong == homeTeamLeague.TeamNameLong);
            Assert.That(fixture.AwayTeamLeague == awayTeamLeague);
            Assert.That(fixture.AwayTeamLeague.TeamName == awayTeamLeague.TeamName);
            Assert.That(fixture.AwayTeamLeague.TeamNameLong == awayTeamLeague.TeamNameLong);
            Assert.That(fixture.FixtureDate == fixtureDate);
            Assert.That(fixture.HasPlayerStats, Is.EqualTo("Y"));
            Assert.That(fixture.IsPenaltyAllowed, Is.True);
            Assert.That(fixture.LastUpdated, Is.Not.Null);
        }
        public FixtureDto(Fixture fixture, bool includeReport)
        {
            this.FixtureId     = fixture.Id;
            this.HomeTeamName  = fixture.HomeTeamLeague.TeamName;
            this.AwayTeamName  = fixture.AwayTeamLeague.TeamName;
            this.HomeTeamScore = fixture.HomeTeamScore.ToString();
            this.AwayTeamScore = fixture.AwayTeamScore.ToString();
            this.IsPlayed      = fixture.IsPlayed.YesNoToBool();
            this.IsCancelled   = fixture.IsCancelled.YesNoToBool();
            this.FixtureDate   = fixture.FixtureDate;

            if (!string.IsNullOrEmpty(fixture.TipOffTime))
                this.TipOffTime = fixture.TipOffTime;
            else if (fixture.HomeTeamLeague.Team != null) // I've not idea why but sometimes this returns null in which case just ignore it
                this.TipOffTime = fixture.HomeTeamLeague.Team.TipOffTime;

            if (includeReport) this.Report = Html.ConvertToPlainText(fixture.Report);
        }
        /// <param name="playerFixture"></param>
        /// <param name="fixture">Required because EF won't load all the required information to look up the opposing team in a list of PlayerFixtures</param>
        public PlayerSeasonFixtureStatsDto(PlayerFixture playerFixture, Fixture fixture)
        {
            this.FixtureDate = playerFixture.Fixture.FixtureDate;
            this.CurrentTeam = playerFixture.TeamLeague.TeamName;
            // Sucky code alert. Because of the WCF/EF lazy loading problems only entities one level deep
            // from PlayerFixture are loaded. I.e. Fixture is loaded but Fixture.HomeTeamLeague isn't.
            // However PlayerFixture.TeamLeague will always be populated which means either
            // PlayerFixture.Fixture.HomeTeamLeague or PlayerFixture.Fixture.AwayTeamLeague is populated,
            // I'm not entirely sure why. So the opposing team will be null
            if(fixture.HomeTeamLeague.Team != null) // Very odd. This seems to work because a Player's team as already been loaded
                OpponentName = fixture.AwayTeamLeague.TeamName;
            else
               OpponentName = fixture.HomeTeamLeague.TeamName;

            this.IsMvp = playerFixture.IsMvp.YesNoToBool();
            this.Fouls = playerFixture.Fouls.ToString();
            this.Points = playerFixture.PointsScored.ToString();
        }
 public void MapToModel(Fixture fixture)
 {
     LeagueOrCupId         = fixture.IsCupFixture ? fixture.Cup.Id : fixture.HomeTeamLeague.League.Id;
     HomeTeamId            = fixture.HomeTeamLeague.Team.Id;
     AwayTeamId            = fixture.AwayTeamLeague.Team.Id;
     Referee1Id            = fixture.Referee1 != null ? fixture.Referee1.Id : (int?)null;
     Referee2Id            = fixture.Referee2 != null ? fixture.Referee2.Id : (int?)null;
     OneOffVenueId         = fixture.OneOffVenue != null ? fixture.OneOffVenue.Id : (int?)null;
 }
        public Fixture MapToFixture(Fixture fixture, TeamLeague homeTeamLeague, TeamLeague awayTeamLeague, Referee referee1, Referee referee2, User lastUpdatedBy, OneOffVenue oneOffVenue)
        {
            fixture.HomeTeamLeague = homeTeamLeague;
            fixture.AwayTeamLeague = awayTeamLeague;
            fixture.LastUpdatedBy  = lastUpdatedBy;
            fixture.LastUpdated    = DateTime.Now;

            // If you remove the few lines below accessing the referee objects you cannot reliably
            // set the properties to null. The assignment seems to be ignored.
            // By best guess is that the properties aren't lazy loaded until accessed so if you assign
            // a value to the property then read from it, the value gets loaded from the database. F****d up.
            fixture.Referee1.Touch();
            fixture.Referee2.Touch();

            fixture.Referee1 = referee1;
            fixture.Referee2 = referee2;

            fixture.OneOffVenue.Touch();
            fixture.OneOffVenue = oneOffVenue;

            return fixture;
        }
 public void Teardown()
 {
     season         = null;
     homeTeam       = null;
     homeTeam       = null;
     league         = null;
     teamLeagueHome = null;
     teamLeagueAway = null;
     fixture        = null;
 }
 public void Setup()
 {
     user           = new User();
     season         = new Season(2008, 2009);
     homeTeam       = new Team("home", "homeTeam");
     awayTeam       = new Team("away", "awayTeam");
     league         = new League(season, "league desc", 1, 1);
     teamLeagueHome = new TeamLeague(league, homeTeam, "home", "homeTeam");
     teamLeagueAway = new TeamLeague(league, awayTeam, "away", "awayTeam");
     player         = new Player("Phil", "Hale");
     fixtureDate    = DateTime.Today;
     fixture        = new Fixture(teamLeagueHome, teamLeagueAway, fixtureDate, user);
 }
        /// <summary>
        /// Returns a complete list of PlayerFixtureStats representing an entire team for 
        /// a fixture, regardless of whether the player has played in the fixture
        /// </summary>
        /// <param name="existingPlayerFixtures"></param>
        /// <param name="allPlayersInTeam"></param>
        /// <param name="teamLeague"></param>
        /// <param name="fixture"></param>
        /// <returns></returns>
        public List<PlayerFixtureStats> MapToPlayerFixtureStats(List<PlayerFixture> existingPlayerFixtures, 
            List<Player> allPlayersInTeam,
            TeamLeague teamLeague,
            Fixture fixture)
        {
            List<PlayerFixtureStats> playerFixturesScreen = new List<PlayerFixtureStats>();
            PlayerFixture existingPlayerFixture;

            foreach (Player player in allPlayersInTeam)
            {
                // Select PF record if exists
                existingPlayerFixture = existingPlayerFixtures.Where(x => x.Player.Id == player.Id).SingleOrDefault();

                // If a PF record exists, add it. If not, add a blank record
                if (existingPlayerFixture != null)
                    playerFixturesScreen.Add(new PlayerFixtureStats(existingPlayerFixture, true));
                else
                    playerFixturesScreen.Add(new PlayerFixtureStats(new PlayerFixture(teamLeague, fixture, player, 0, 0), false));

            }

            return playerFixturesScreen;
        }
        public void MapToModel(Fixture fixture)
        {
            this.FixtureId = fixture.Id;

            this.HomeTeamId = fixture.HomeTeamLeague.Team.Id;
            this.AwayTeamId = fixture.AwayTeamLeague.Team.Id;

            this.HomeTeamName = fixture.HomeTeamLeague.TeamNameLong;
            this.AwayTeamName = fixture.AwayTeamLeague.TeamNameLong;

            this.HomeTeamScore = fixture.HomeTeamScore;
            this.AwayTeamScore = fixture.AwayTeamScore;

            this.HasPlayerStats = fixture.HasPlayerStats.YesNoToBool();

            this.Report = fixture.Report;

            this.IsPenaltyAllowed = fixture.IsPenaltyAllowed;

            this.IsForfeit = fixture.IsForfeit;
        }
        public void IsHomeWin_NoForfeitHomeTeamScoreGreater_ReturnsTrue()
        {
            Fixture fixture = new Fixture(homeTeamLeague, awayTeamLeague, fixtureDate, user) { IsPlayed = "Y" };
            fixture.IsForfeit = false;
            fixture.HomeTeamScore = 20;
            fixture.AwayTeamScore = 10;

            Assert.That(fixture.IsHomeWin(), Is.True);
        }
 public void IsHomeTeam_NullTeamLeague_ThrowsArgumentException()
 {
     Fixture f = new Fixture();
     Assert.Throws<ArgumentException>(() => f.IsHomeTeam(null));
 }
        public void IsHomeTeam_PassHomeTeam_True()
        {
            TeamLeague homeTeamLeague = new TeamLeague() { Id = 1 };
            TeamLeague awayTeamLeague = new TeamLeague() { Id = 2 };
            Fixture f = new Fixture() { HomeTeamLeague = homeTeamLeague, AwayTeamLeague = awayTeamLeague};

            Assert.That(f.IsHomeTeam(homeTeamLeague), Is.True);
        }
        //public void AddTeamLeaguePenalty(int teamLeagueId, int penaltyPoints)
        //{
        //    TeamLeague teamLeague = teamLeagueRepository.Get(teamLeagueId);
        //    teamLeague.PointsPenalty = penaltyPoints;
        //    //teamLeague = teamLeagueRepository.SaveOrUpdate(teamLeague);
        //    //FlushSessionAndEvict(teamLeague);
        //}
        private Fixture AddFixture(TeamLeague home, TeamLeague away, string fixtureDate, User lastUpdatedBy)
        {
            Fixture fixture = new Fixture(home, away, DateTime.Parse(fixtureDate), lastUpdatedBy);

            fixture.IsCupFixture = false;
            //fixture = fixtureRepository.SaveOrUpdate(fixture);
            //FlushSessionAndEvict(fixture);

            CurrentSeasonFixtures.Add(fixture);

            return fixture;
        }
        public void IsCancelled_IsYFixtureDateChanged_SetToN()
        {
            Fixture f = new Fixture();
            DateTime myDate = DateTime.Now;
            f.FixtureDate = myDate;
            f.IsCancelled = "Y";

            f.FixtureDate = myDate.AddDays(1);
            Assert.That(f.IsCancelled, Is.EqualTo("N"));
        }
        public void IsCancelled_IsYFixtureDateNotChanged_RemainsY()
        {
            Fixture f = new Fixture();
            DateTime myDate = DateTime.Now;
            f.FixtureDate = myDate;
            f.IsCancelled = "Y";

            f.FixtureDate = myDate;
            Assert.That(f.IsCancelled, Is.EqualTo("Y"));
        }
        public void IsHomeWin_NotPlayed_ReturnsFalse()
        {
            Fixture fixture = new Fixture() { IsPlayed = "N"};

            Assert.That(fixture.IsHomeWin(), Is.False);
        }
        public Fixture MapToFixture(Fixture fixture)
        {
            fixture.HomeTeamScore = this.HomeTeamScore;
            fixture.AwayTeamScore = this.AwayTeamScore;

            fixture.HasPlayerStats = this.HasPlayerStats.BoolToYesNo();

            fixture.Report = this.Report;

            fixture.IsPenaltyAllowed = this.IsPenaltyAllowed;

            fixture.IsForfeit = this.IsForfeit;

            return fixture;
        }
 public FixtureViewModel(Fixture fixture)
 {
     Fixture = fixture;
     SetCupRoundNames();
 }
        public void IsHomeWin_HomeForfeits_ReturnsFalse()
        {
            Fixture fixture = new Fixture(homeTeamLeague, awayTeamLeague, fixtureDate, user) { IsPlayed = "Y" };
            fixture.IsForfeit = true;
            fixture.ForfeitingTeam = homeTeamLeague.Team;

            Assert.That(fixture.IsHomeWin(), Is.False);
        }
        public void IsAwayForfeit_NotPlayed_ReturnsFalse()
        {
            Fixture fixture = new Fixture() { IsPlayed = "N" };
            fixture.IsForfeit = true;

            Assert.That(fixture.IsAwayForfeit(), Is.False);
        }
        public void IsHomeForfeit_IsForfeitTrueHomeIdMatches_ReturnsTrue()
        {
            Fixture fixture = new Fixture(homeTeamLeague, awayTeamLeague, fixtureDate, user) { IsPlayed = "Y" };
            fixture.IsForfeit = true;
            fixture.ForfeitingTeam = homeTeamLeague.Team;

            Assert.That(fixture.IsHomeForfeit(), Is.True);
        }
        //protected Player SavePlayer(Player player)
        //{
        //    playerRepository.SaveOrUpdate(player);
        //    FlushSessionAndEvict(player);
        //    return player;
        //}
        private PlayerFixture AddPlayerFixture(TeamLeague teamLeague, Fixture fixture, Player player, int points, int fouls, bool isMvp)
        {
            PlayerFixture playerFixture = new PlayerFixture(teamLeague, fixture, player, points, fouls);

            if (isMvp)
                playerFixture.IsMvp = "Y";
            else
                playerFixture.IsMvp = "N";

            //statsRepository.SaveOrUpdatePlayerFixture(playerFixture);
            //FlushSessionAndEvict(playerFixture);
            return playerFixture;
        }
        private Fixture GetFixture(TeamLeague homeTeamLeague, TeamLeague awayTeameLeague, bool isHomeWin, bool isPlayed = true)
        {
            var fixture = new Fixture() { HomeTeamLeague = homeTeamLeague, AwayTeamLeague = awayTeameLeague };

            fixture.IsPlayed = isPlayed ? "Y" : "N";

            if(isHomeWin)
            {
                fixture.HomeTeamScore = 30;
                fixture.AwayTeamScore = 10;
            }
            else
            {
                fixture.HomeTeamScore = 10;
                fixture.AwayTeamScore = 30;
            }

            return fixture;
        }