Exemplo n.º 1
0
        public IActionResult PostWinningPlayer(WinnerDTO winner)
        {
            GameResult gameResult = GameHolder.RetrieveGame(winner.GameID);

            if (!gameResult.ValidGameID)
            {
                return(BadRequest());
            }

            Game game = gameResult.GameObj;

            if (!game.WinState || game.WinRecorded)
            {
                return(BadRequest());
            }

            int time = game.GameTime.GetTotalTime();

            if (game.SeedMode == false)
            {
                long completionTime = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();
                repository.UpdateScores(winner.PlayerName, time, completionTime, game.SeedValue);
            }
            game.WinRecorded = true;

            return(Ok(new WinStateDTO
            {
                GameID = winner.GameID,
                PlayerName = winner.PlayerName,
                GameTime = time,
                TopScores = repository.GetTopScores().ToList(),
                WeeklyScores = repository.GetWeeklyScores(new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds()).ToList()
            }));
        }
Exemplo n.º 2
0
 public void Insert_ShouldAddARow_ToThe_Winner_Table_WithTheSuppliedValues()
 {
     using (new TransactionScope()) {
         //Arrange
         long attendeeID;
         long sponsorID;
         long swagID;
         string name = "Joe Smith";
         using (var dc = new DayOfDotNetDataContext()) {
             attendeeID = (from x in dc.Attendees where x.IsEligible && !x.HasWon select x.AttendeeID).First();
             sponsorID = (from x in dc.Sponsors where x.ProvidedSwag select x.SponsorID).First();
             swagID = (from x in dc.Swags where x.SponsorID == sponsorID select x.SwagID).First();
         }
         WinnerDTO winner = new WinnerDTO {AttendeeID = attendeeID, SponsorID = sponsorID, SwagID = swagID, Name = name};
         //Act
         IWinnerRepository repo = new WinnerRepository();
         bool success = repo.Insert(winner);
         //Assert
         success.ShouldBeTrue("Expected Success To Be True");
         Winner retrievedWinner;
         using (var dc = new DayOfDotNetDataContext()) {
             retrievedWinner = (from x in dc.Winners where x.AttendeeID == attendeeID select x).First();
         }
         retrievedWinner.AttendeeID.ShouldEqual(attendeeID, "Wrong AttendeeID");
         retrievedWinner.SponsorID.ShouldEqual(sponsorID, "Wrong SponsorID");
         retrievedWinner.SwagID.ShouldEqual(swagID, "Wrong SwagID");
         retrievedWinner.Name.ShouldEqual(name, "Wrong Name");
     }
 }
Exemplo n.º 3
0
 public bool Insert(WinnerDTO winner)
 {
     Winner w = new Winner {AttendeeID = winner.AttendeeID, SponsorID = winner.SponsorID, SwagID = winner.SwagID, Name = winner.Name};
     using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()) {
         dc.Winners.InsertOnSubmit(w);
         dc.SubmitChanges();
     }
     return true;
 }
Exemplo n.º 4
0
        public async Task <IActionResult> GetWinnerById(Guid userId)
        {
            WinnerDTO winner = await _winnerService.GetWinnerByIdAsync(userId);

            if (winner != null)
            {
                return(Ok(winner));
            }

            return(BadRequest("Sorry, you haven't won anything. More luck next time."));
        }
Exemplo n.º 5
0
        public async Task Test400CodeForEarlyEndAttempt()
        {
            WinnerDTO fakedWin = new WinnerDTO {
                GameID = gameDTO.GameID, PlayerName = "anonymous"
            };
            StringContent winContent = TestUtilities.ObjToStringContent(fakedWin);

            HttpClient          client   = TestUtilities.GetHttpClient();
            HttpResponseMessage response = await client.PostAsync("postwin", winContent);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Exemplo n.º 6
0
        public async Task TestRepeatRequestToEndResultsIn400()
        {
            HttpClient client = TestUtilities.GetHttpClient();
            WinnerDTO  win    = new WinnerDTO {
                GameID = gameDTO.GameID, PlayerName = "test"
            };
            StringContent winContent = TestUtilities.ObjToStringContent(win);

            HttpResponseMessage postResponse1 = await client.PostAsync("postwin", winContent);

            HttpResponseMessage postResponse2 = await client.PostAsync("postwin", winContent);

            Assert.AreEqual(HttpStatusCode.BadRequest, postResponse2.StatusCode);
        }
Exemplo n.º 7
0
        private async Task CreateWinnerAsync(int numberOfHits, Ticket ticket, IEnumerable <int> matchings, Draw lastDraw)
        {
            Prize prize = await Task.Run(() => _prizeRepository.GetAll().FirstOrDefault(p => p.NumberOfHits == numberOfHits));

            WinnerDTO winner = new WinnerDTO
            {
                NumberOfHits   = numberOfHits,
                PrizeId        = prize.PrizeId,
                WinningNumbers = String.Join(", ", matchings),
                UserId         = ticket.UserId,
                TicketId       = ticket.TicketId,
                SessionId      = lastDraw.SessionId
            };

            await Task.Run(() => _winnerRepository.Add(_mapper.Map <Winner>(winner)));
        }
Exemplo n.º 8
0
        public async Task TestWinState()
        {
            HttpClient client = TestUtilities.GetHttpClient();
            WinnerDTO  win    = new WinnerDTO {
                GameID = gameDTO.GameID, PlayerName = "test"
            };
            StringContent winContent = TestUtilities.ObjToStringContent(win);

            HttpResponseMessage postResponse = await client.PostAsync("postwin", winContent);

            string responseContent = await postResponse.Content.ReadAsStringAsync();

            winStateDTO = JsonConvert.DeserializeObject <WinStateDTO>(responseContent);

            Assert.IsTrue(gameDTO.WinState, "Win state is not true");
            Assert.NotZero(winStateDTO.GameTime, "Expected a game time above zero");
            Assert.AreEqual(gameDTO.CardsRemaining, 9, "Expected 9 cards remaining");
        }
Exemplo n.º 9
0
        public IActionResult GetWinner()
        {
            WinnerDTO winner = PokerService.GetWinner();

            return(Ok(winner));
        }
Exemplo n.º 10
0
 public bool Insert(WinnerDTO winner)
 {
     return true;
 }
Exemplo n.º 11
0
 public bool Insert(WinnerDTO winner)
 {
     return _winner.Insert(winner);
 }
Exemplo n.º 12
0
 public bool Insert(WinnerDTO winner)
 {
     return _repository.Insert(winner);
 }