Exemple #1
0
        public async Task ProcessGame_WhenGameDecoratorArgIsNotNull_ShouldProcessGame()
        {
            // Arrange
            var strategy = new ProcessGameStrategyBase(_teamSeasonRepository);

            var gameDecorator = A.Fake <IGameDecorator>();

            gameDecorator.GuestName = "Guest";
            gameDecorator.HostName  = "Host";

            // Act
            try
            {
                await strategy.ProcessGameAsync(gameDecorator);
            }
            catch (NotImplementedException)
            {
                // This test case calls a base class method that is implemented only in subclasses, thereby throwing a
                // NotImplementedException. The exception has no impact on what I expect to happen here, so it can be
                // ignored.
            }

            // Assert
            var seasonYear = gameDecorator.SeasonYear;

            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.GuestName, seasonYear))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.HostName, seasonYear))
            .MustHaveHappenedOnceExactly();
        }
        /// <summary>
        /// Processes a <see cref="Game"/> entity into the Teams data store asynchronously.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public virtual async Task ProcessGameAsync(IGameDecorator gameDecorator)
        {
            Guard.ThrowIfNull(gameDecorator, $"{GetType()}.{nameof(ProcessGameAsync)}: {nameof(gameDecorator)}");

            var seasonYear = gameDecorator.SeasonYear;

            var guestSeason =
                await _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.GuestName, seasonYear);

            TeamSeasonDecorator?guestSeasonDecorator = null;

            if (!(guestSeason is null))
            {
                guestSeasonDecorator = new TeamSeasonDecorator(guestSeason);
            }

            var hostSeason =
                await _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.HostName, seasonYear);

            TeamSeasonDecorator?hostSeasonDecorator = null;

            if (!(hostSeason is null))
            {
                hostSeasonDecorator = new TeamSeasonDecorator(hostSeason);
            }

            await EditWinLossDataAsync(guestSeasonDecorator, hostSeasonDecorator, gameDecorator);

            EditScoringData(guestSeasonDecorator, hostSeasonDecorator, gameDecorator.GuestScore,
                            gameDecorator.HostScore);
        }
Exemple #3
0
        public async Task ProcessGame_WhenGameIsATie_ShouldUpdateTiesForTeamSeasons()
        {
            // Arrange
            var strategy = new AddGameStrategy(_teamSeasonRepository);

            var gameDecorator = A.Fake <IGameDecorator>();

            gameDecorator.GuestName  = "Guest";
            gameDecorator.HostName   = "Host";
            gameDecorator.WinnerName = "Winner";
            gameDecorator.LoserName  = "Loser";
            gameDecorator.SeasonYear = 1920;
            A.CallTo(() => gameDecorator.IsTie()).Returns(true);

            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(A <string> .Ignored, A <int> .Ignored))
            .Returns <TeamSeason?>(null);

            // Act
            await strategy.ProcessGameAsync(gameDecorator);

            // Assert
            var seasonYear = gameDecorator.SeasonYear;

            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.GuestName, seasonYear))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.HostName, seasonYear))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.WinnerName, seasonYear))
            .MustNotHaveHappened();
            A.CallTo(() => _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(gameDecorator.LoserName, seasonYear))
            .MustNotHaveHappened();
        }
Exemple #4
0
        public async Task <IActionResult> PredictGame([Bind("GuestSeasonYear,GuestName,GuestScore,HostSeasonYear,HostName,HostScore")] GamePrediction prediction)
        {
            var seasons = (await _seasonRepository.GetSeasonsAsync()).OrderByDescending(s => s.Year);


            GuestSeasonYear = prediction.GuestSeasonYear;

            ViewBag.GuestSeasons = new SelectList(seasons, "Year", "Year", GuestSeasonYear);

            var guests = await _teamSeasonRepository.GetTeamSeasonsBySeasonAsync(GuestSeasonYear);

            var guest = await _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(prediction.GuestName,
                                                                                      GuestSeasonYear);

            if (guest is null)
            {
                ViewBag.Guests = new SelectList(guests, "TeamName", "TeamName");
            }
            else
            {
                ViewBag.Guests = new SelectList(guests, "TeamName", "TeamName", guest.TeamName);
            }


            HostSeasonYear = prediction.HostSeasonYear;

            ViewBag.HostSeasons = new SelectList(seasons, "Year", "Year", HostSeasonYear);

            var hosts = await _teamSeasonRepository.GetTeamSeasonsBySeasonAsync(HostSeasonYear);

            var host = await _teamSeasonRepository.GetTeamSeasonByTeamAndSeasonAsync(
                prediction.HostName, HostSeasonYear);

            if (host is null)
            {
                ViewBag.Hosts = new SelectList(hosts, "TeamName", "TeamName");
            }
            else
            {
                ViewBag.Hosts = new SelectList(hosts, "TeamName", "TeamName", host.TeamName);
            }

            return(View(prediction));
        }