Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Age,Contact,Experience,ProExperience,Availability")] Umpire umpire)
        {
            if (id != umpire.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(umpire);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UmpireExists(umpire.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(umpire));
        }
Example #2
0
        public void DecideOutcome_GivenEmptyBoard_ReturnsOpenOutcome()
        {
            var umpire = new Umpire();
            var result = umpire.DecideOutcome(new Board());

            Assert.That(result, Is.EqualTo(GameOutcome.OpenOutcome));
        }
Example #3
0
        public void DecideOutcome_WhenPlayer_o_MadMove_4_ReturnsOpenOutcome()
        {
            var umpire = new Umpire();
            var board  = SimulateGame(new[] { 4 });
            var result = umpire.DecideOutcome(board);

            Assert.That(result, Is.EqualTo(GameOutcome.OpenOutcome));
        }
Example #4
0
        public void DecideOutcome_GivenFilledBoard_WhenNoOneHasWon_ReturnsDraw()
        {
            var umpire = new Umpire();
            var board  = SimulateGame(new [] { 0, 1, 2, 4, 3, 5, 7, 6, 8 });
            var result = umpire.DecideOutcome(board);

            Assert.That(result, Is.EqualTo(GameOutcome.Draw));
        }
Example #5
0
        public void DecideOutcome_WhenPlayer_x_FilledThirdRow_ReturnsXHasWon()
        {
            var umpire = new Umpire();
            var board  = SimulateGame(new[] { 3, 6, 4, 7, 1, 8 });
            var result = umpire.DecideOutcome(board);

            Assert.That(result, Is.EqualTo(GameOutcome.XHasWon));
        }
Example #6
0
        public void DecideOutcome_WhenPlayer_x_FilledSecondColumn_ReturnsXHasWon()
        {
            var umpire = new Umpire();
            var board  = SimulateGame(new[] { 0, 1, 2, 4, 5, 7 });
            var result = umpire.DecideOutcome(board);

            Assert.That(result, Is.EqualTo(GameOutcome.XHasWon));
        }
Example #7
0
        public void DecideOutcome_WhenPlayer_o_FilledDiagonalRow_ReturnsOHasWon()
        {
            var umpire = new Umpire();
            var board  = SimulateGame(new[] { 0, 1, 4, 2, 8 });
            var result = umpire.DecideOutcome(board);

            Assert.That(result, Is.EqualTo(GameOutcome.OHasWon));
        }
Example #8
0
        public IActionResult Play()
        {
            // Play Game
            IRandomNumberGenerator randomNumGen = new GetRandomNumber();
            Scorekeeper            keeper       = new Scorekeeper(ONE_DAY);
            Game game = new Game(randomNumGen);

            string[] team1 = new string[] { "Ian Botham", "Mike Gatting", "David Gower", "Joe Root", "Jos Buttler", "Ben Stokes",
                                            "Johnny Bairstow", "Stuart Broad", "Graham Swann", "Jofra Archer", "Jimmy Anderson" };
            string[] team2 = new string[] { "Michael Vaughan", "Alistair Cook", "Viv Richards", "Freddie Flintoff", "Geoff Miller", "Nasser Hussain",
                                            "Alex Stewart", "Darren Gough", "Bob Willis", "Phil Tuffnell", "Mike Hendrick" };

            keeper.ChangeBowler("Malcolm Marshall");
            keeper.SubmitTeam(0, team1);
            keeper.SubmitTeam(1, team2);

            Umpire umpey = new Umpire(game, keeper);

            umpey.playInnings();
            keeper.StartInnings(1);
            keeper.ChangeBowler("Ian Botham");
            umpey.playInnings();


            //// Map Scores to View Model
            PlayViewModel pvm = new PlayViewModel();

            var(r1, w1, b1, e1) = keeper.GetInningsScore(0);
            var(r2, w2, b2, e2) = keeper.GetInningsScore(1);


            pvm.runs = new int[2] {
                r1, r2
            };
            pvm.wickets = new int[2] {
                w1, w2
            };
            pvm.overs = new int[2] {
                b1, b2
            };
            pvm.extras = new int[2] {
                e1, e2
            };

            pvm.team1 = team1;
            pvm.team2 = team2;

            pvm.scores1 = new int[11];
            pvm.scores2 = new int[11];

            for (int i = 0; i < 11; i++)
            {
                pvm.scores1[i] = keeper.GetBatsmanScore(0, team1[i]);
                pvm.scores2[i] = keeper.GetBatsmanScore(1, team2[i]);
            }

            return(View(pvm));
        }
        public string AddUmpire(Umpire newumpire)
        {
            if (newumpire == null)
            {
                throw new ArgumentNullException($"Umpire is null");
            }
            var umpireAddKey = _umpireRepository.Create(newumpire);

            return(umpireAddKey);
        }
Example #10
0
        public void ShouldCompareTwoHandsCardsAndReturnTheHighestCard(List <string> hardCards_1, List <string> hardCards_2, string expected)
        {
            var umpire = new Umpire();

            umpire.ReadWhiteCards(hardCards_1);
            umpire.ReadBlackCards(hardCards_2);
            var theHighestCard = umpire.CompareCards();

            Assert.Equal(expected, theHighestCard);
        }
Example #11
0
        public async Task <IActionResult> Create([Bind("Id,Name,Age,Contact,Experience,ProExperience,Availability")] Umpire umpire)
        {
            if (ModelState.IsValid)
            {
                _context.Add(umpire);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(umpire));
        }
Example #12
0
        private static void Main(string[] args)
        {
            var cleverUmpire = new Umpire();

            cleverUmpire.SaySomething();

            cleverUmpire.ReadWhiteCards();

            cleverUmpire.ReadBlackCards();

            cleverUmpire.AnnounceTheWinner();
        }
 public void UpdateUmpire(string umpireId, Umpire updateumpire)
 {
     if (updateumpire == null)
     {
         throw new ArgumentNullException($"UserUmpire is null");
     }
     if (string.IsNullOrEmpty(umpireId))
     {
         throw new ArgumentException($"Umpire ID is null");
     }
     _umpireRepository.CreateWithId(umpireId, updateumpire);
 }
        public static void ClassInit(TestContext context)
        {
            //Arrange
            Umpire = new Umpire {
                Id = "ID"
            };
            var matches = new List <Umpire> {
                Umpire
            };
            var mockRepo = new Mock <IRepository <Models.Umpire> >();

            mockRepo.Setup(x => x.Create(It.IsAny <Models.Umpire>())).Returns("UmpireId");
            mockRepo.Setup(x => x.GetList()).Returns(matches);
            mockRepo.Setup((IRepository <Umpire> x) => x.GetItem(It.IsAny <string>())).Returns((Umpire)Umpire);
            UmpireService = new UmpireService(mockRepo.Object);
        }
Example #15
0
        void test_play_ball()
        {
            // Arrange
            Mock <Game>        thisGame        = new Mock <Game>();
            Mock <Scorekeeper> thisScorekeeper = new Mock <Scorekeeper>(ONE_DAY);

            thisGame.Setup(x => x.Play()).Returns(TWO_RUNS);
            thisScorekeeper.Setup(x => x.HandleEvent(It.IsAny <outcomes>())).Returns(true);  // end of innings - true

            // Act
            Umpire thisUmpire = new Umpire(thisGame.Object, thisScorekeeper.Object);

            thisUmpire.playInnings();

            // Assertions
            thisGame.Verify(x => x.Play(), Times.Exactly(1));
            thisScorekeeper.Verify(x => x.HandleEvent(It.IsAny <outcomes>()), Times.Exactly(1));
            thisScorekeeper.Verify(x => x.EndOfOver(), Times.Never());
        }
Example #16
0
        void test_play_full_over()
        {
            // need to enqueue six returns from Play (called six times)
            // Arrange
            Mock <Game>        thisGame        = new Mock <Game>();
            Mock <Scorekeeper> thisScorekeeper = new Mock <Scorekeeper>(ONE_DAY);

            thisGame.Setup(x => x.Play()).Returns(TWO_RUNS);
            Queue <bool> results = new Queue <bool>(new bool[] { false, false, false, false, false, true });

            thisScorekeeper.Setup(x => x.HandleEvent(It.IsAny <outcomes>())).Returns(() => results.Dequeue());  // end of innings - true

            // Act
            Umpire thisUmpire = new Umpire(thisGame.Object, thisScorekeeper.Object);

            thisUmpire.playInnings();

            // Assertions
            thisGame.Verify(x => x.Play(), Times.Exactly(6));
            thisScorekeeper.Verify(x => x.HandleEvent(It.IsAny <outcomes>()), Times.Exactly(6));
            thisScorekeeper.Verify(x => x.EndOfOver(), Times.Exactly(1));
        }
        private void ProcessUmpires(MlbStatsContext context, Game dbGame, List <Feeds.BoxscoreFeed.OfficialElement> feedUmpires)
        {
            var officialIds         = feedUmpires.Select(x => x.Official?.Id).Where(x => x.HasValue).ToList();
            var dbUmpires           = context.Umpires.Where(x => officialIds.Contains(x.UmpireID)).ToList();
            var dbUmpireAssignments = context.UmpireAssignments.Where(x => x.GameID == this.GameId).ToList();

            foreach (var feedOfficial in feedUmpires)
            {
                var dbUmpire = dbUmpires.SingleOrDefault(x => x.UmpireID == feedOfficial.Official.Id);
                if (dbUmpire == null)
                {
                    dbUmpire = new Umpire
                    {
                        UmpireID   = feedOfficial.Official.Id,
                        UmpireName = feedOfficial.Official.FullName,
                        UmpireLink = feedOfficial.Official.Link
                    };
                    context.Umpires.Add(dbUmpire);
                    dbUmpires.Add(dbUmpire);
                }

                var dbUmpireAssignment = dbUmpireAssignments.SingleOrDefault(x => x.UmpireID == feedOfficial.Official.Id);
                if (dbUmpireAssignment == null)
                {
                    dbUmpireAssignment = new UmpireAssignment
                    {
                        Umpire     = dbUmpire,
                        Game       = dbGame,
                        UmpireType = UmpireType.Unknown
                    };
                    context.UmpireAssignments.Add(dbUmpireAssignment);
                    dbUmpireAssignments.Add(dbUmpireAssignment);
                }

                UmpireType umpireType = GetUmpireType(feedOfficial.OfficialType);
                dbUmpireAssignment.UmpireType = umpireType;
            }
        }