public void TestSuccessfullyGetTopHundred()
        {
            FakeGameResultRepository fakeGameResultRepository = new FakeGameResultRepository();
            List <GameResultDTO>     allGames = new List <GameResultDTO>();
            Random random = new Random();

            for (int i = 0; i < 140; i++)
            {
                GameResultDTO FakeGame = new GameResultDTO()
                {
                    GameID    = random.Next(1, 140),
                    PlayerID  = random.Next(1, 140),
                    Timestamp = DateTime.Now,
                    Win       = random.Next(1, 200)
                };
                allGames.Add(FakeGame);
                fakeGameResultRepository.Add(FakeGame);
            }

            IEnumerable <GameResultDTO> top100 = (from games in allGames
                                                  orderby games.Win descending
                                                  select new GameResultDTO
            {
                GameID = games.GameID,
                PlayerID = games.PlayerID,
                Win = games.Win,
                Timestamp = games.Timestamp
            }).ToList().Take(100);

            int total     = top100.ToList().Count;
            int totalFake = fakeGameResultRepository.GetTopHundred().ToList().Count;

            Assert.AreEqual(total, 100);
            Assert.AreEqual(total, totalFake);
        }
Beispiel #2
0
 public QuizResultModel(GameResultDTO result)
 {
     TotalNrQuestions = result.TotalNrQuestions;
     NrCorrectAnswers = result.CorrectNrAnswers;
     Verdict          = result.ScoreMessage;
     GameId           = result.GameId;
 }
        public bool Update(GameResultDTO gameResultDTO)
        {
            GameResult game = db.GameResults.Single(e => e.GameID == gameResultDTO.GameID && e.PlayerID == gameResultDTO.PlayerID);

            game.Win      += gameResultDTO.Win;
            game.Timestamp = gameResultDTO.Timestamp;
            return(db.SaveChanges() > 0);
        }
        public bool Update(GameResultDTO gameResultDTO)
        {
            GameResult newGame = Create(gameResultDTO);
            GameResult game    = gameResults[gameResults.FindIndex(e => e.GameID == newGame.GameID && e.PlayerID == newGame.PlayerID)];

            game.Win += newGame.Win;
            return(true);
        }
 private GameResult Create(GameResultDTO gameResultDTO)
 {
     return(new GameResult()
     {
         GameID = gameResultDTO.GameID,
         PlayerID = gameResultDTO.PlayerID,
         Timestamp = gameResultDTO.Timestamp,
         Win = gameResultDTO.Win
     });
 }
 public WalletViewModel(WalletDTO wallet, GameResultDTO gameResult, string gridSize)
 {
     this.Win            = gameResult.WonAmount;
     this.Balance        = wallet.Balance;
     this.Currency       = wallet.Currency;
     this.CurrencySymbol = wallet.CurrencySymbol;
     this.WinningRows    = gameResult.WinningRows == null ? new bool[gameResult.Grid.GetLength(0)] : gameResult.WinningRows.ToArray();
     this.Grid           = GridToString(gameResult.Grid);
     this.GridSize       = gridSize;
 }
Beispiel #7
0
 public IHttpActionResult Post(GameResultDTO gameResult)
 {
     try
     {
         return(Ok(service.Add(gameResult)));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Beispiel #8
0
 public bool Add(GameResultDTO gameResultDTO)
 {
     if (repository.ExistGameResultWithSameGameIdAndPlayerId(gameResultDTO))
     {
         return(repository.Update(gameResultDTO));
     }
     else
     {
         return(repository.Add(gameResultDTO));
     }
 }
 public bool Add(GameResultDTO gameResultDTO)
 {
     db.GameResults.Add(new GameResult()
     {
         GameID    = gameResultDTO.GameID,
         PlayerID  = gameResultDTO.PlayerID,
         Win       = gameResultDTO.Win,
         Timestamp = gameResultDTO.Timestamp
     });
     return(db.SaveChanges() > 0);
 }
        public void TestInitialize()
        {
            //Arrange
            testWalletDTO = new WalletDTO();
            gameResultDTO = new GameResultDTO()
            {
                Grid        = new GameResults[0, 0],
                WinningRows = new bool[0],
                WonAmount   = 0
            };
            testUser = new User()
            {
                FirstName = testUserFirstname,
                LastName  = testUserLastname,
                Email     = testUserEmail,
                UserName  = testUserUsername,
                IsDeleted = false,
                WalletId  = wallteId,
                Role      = UserRole.None
            };
            mockContext = new Mock <HttpContext>();

            mockUserManager = new Mock <UserManager <User> >(
                new Mock <IUserStore <User> >().Object,
                new Mock <IOptions <IdentityOptions> >().Object,
                new Mock <IPasswordHasher <User> >().Object,
                new IUserValidator <User> [0],
                new IPasswordValidator <User> [0],
                new Mock <ILookupNormalizer>().Object,
                new Mock <IdentityErrorDescriber>().Object,
                new Mock <IServiceProvider>().Object,
                new Mock <ILogger <UserManager <User> > >().Object);
            mockUserManager.Setup(manager => manager.GetUserAsync(It.IsAny <ClaimsPrincipal>()))
            .ReturnsAsync(testUser);

            gameMock = new Mock <IGame>();
            gameMock
            .Setup(game => game.Play(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(gameResultDTO);
            gameMock
            .Setup(game => game.GenerateGrid(It.IsAny <string>()))
            .Returns(gameResultDTO);

            walletServiceMock = new Mock <IWalletService>();
            walletServiceMock
            .Setup(wallet => wallet.GetUserWallet(It.IsAny <User>()))
            .ReturnsAsync(testWalletDTO);
            walletServiceMock
            .Setup(wallet => wallet.UpdateUserWallet(It.IsAny <User>(), It.IsAny <decimal>()))
            .ReturnsAsync(testWalletDTO);
            transactionServiceMock = new Mock <ITransactionService>();
        }
Beispiel #11
0
        public void ShouldBeAbleToAddNewGameResult()
        {
            GameResultService service = new GameResultService(new FakeGameResultRepository());
            GameResultDTO     dto     = new GameResultDTO()
            {
                GameID    = 1,
                PlayerID  = 1,
                Timestamp = DateTime.Now,
                Win       = 2
            };

            Assert.IsTrue(service.Add(dto));
        }
        public void TestSuccessfullyAddNewGameResult()
        {
            FakeGameResultRepository fakeGameResultRepository = new FakeGameResultRepository();
            GameResultDTO            FakeGame = new GameResultDTO()
            {
                GameID    = 1,
                PlayerID  = 1,
                Timestamp = DateTime.Now,
                Win       = 2
            };

            Assert.IsTrue(fakeGameResultRepository.Add(FakeGame));
        }
Beispiel #13
0
        public async Task SaveGameResultAsync(GameResultDTO result)
        {
            using var uow = UnitOfWorkProvider.Create();
            var game = await gameRepository.GetByIdAsync(result.GameId, nameof(Game.GameParticipation));

            game.TurnCount = result.TurnCount;

            var winner = game.GameParticipation?.FirstOrDefault(g => g.Id == result.WinnerId);

            if (winner != default)
            {
                winner.IsWinner = true;
            }

            await uow.CommitAsync();
        }
        public GameResultDTO Finish(int gameId)
        {
            using (var ctx = new QuizBoxContext())
            {
                var game             = ctx.Game.Include(g => g.GameQuestion).ThenInclude(g => g.Answer).First(g => g.Id == gameId);
                int totalNrQuestions = game.GameQuestion.Count();
                int nrCorrectAnswers = game.GameQuestion.Count(q => q.Answer.IsCorrect);

                var result = new GameResultDTO()
                {
                    GameId           = gameId,
                    CategoryId       = game.CategoryId,
                    TotalNrQuestions = totalNrQuestions,
                    CorrectNrAnswers = nrCorrectAnswers,
                    StartTime        = game.Start
                };
                result.ScoreMessage = GetScoreMessage((float)result.CorrectNrAnswers / (float)result.TotalNrQuestions);
                return(result);
            }
        }
        public ActionResult AtualizarPontuacao(GameResultDTO result)
        {
            if (!ModelState.IsValid)
            {
                return(View(result));
            }
            else
            {
                try
                {
                    GameOperationServiceClient service = new GameOperationServiceClient();
                    service.InserirResultado(result.playerId, result.gameId, result.win);
                    ViewBag.InfoServico = "";

                    return(Redirect("/"));
                }
                catch
                {
                    ViewBag.InfoServico = "* Serviço temporariamento indisponível";
                }

                return(AtualizarPontuacao());
            }
        }
Beispiel #16
0
        public GameResultDTO GenerateGrid(string gridDimensions)
        {
            string[] dimensions = gridDimensions.Split('x');

            int rows = int.Parse(dimensions[0]);

            int cows = int.Parse(dimensions[1]);

            var grid = new GameResults[rows, cows];

            for (int row = 0; row < grid.GetLength(0); row++)
            {
                for (int col = 0; col < grid.GetLength(1); col++)
                {
                    grid[row, col] = GenerateValue();
                }
            }

            var result = new GameResultDTO();

            result.Grid = grid;

            return(result);
        }
 public bool ExistGameResultWithSameGameIdAndPlayerId(GameResultDTO gameResultDTO)
 {
     return(gameResults.Any(e => e.GameID == gameResultDTO.GameID && e.PlayerID == gameResultDTO.PlayerID));
 }
 public bool Add(GameResultDTO gameResultDTO)
 {
     gameResults.Add(Create(gameResultDTO));
     return(true);
 }