private static async Task TestGameRepositorySpecificOperations() { var userId = "U1"; IGameRepository repo = new GameRepository(_tableName); for (int i = 0; i < 5; i++) { var g = new Game { Id = "GA" + i, Name = "Game A" + i }; Console.WriteLine($"Adding {g.Id}"); await repo.AddGame(userId, g); } Console.ReadKey(); var games = await repo.GetGameList(userId); foreach (var item in games) { Console.WriteLine(JsonSerializer.Serialize(item)); } Console.ReadKey(); for (int i = 0; i < 5; i++) { var gameId = "GA" + i; Console.WriteLine($"Deleting {gameId}"); await repo.DeleteGame(userId, gameId); } }
public Game AddGame(CreateGameDto game) { Game g = gameRepo.AddGame(game); g.GameGenres = gameGenreService.AddGameGenres(game.GameGenres, g.ID); return(g); }
public void GamesCanBeAdded() { Game game = new Game(); Assert.AreEqual(3, repository.GetGames().Count); repository.AddGame(game); Assert.AreEqual(4, repository.GetGames().Count); }
public void AddGame_CallsAddGameInRepository() { var dataContext = new DataContext(); var game = new Game { GameId = 1, GameLevel = 1, BoardDimension = 3, IsGameOver = false, IsGameWon = false, TurnChoice = 1 }; var gameRepository = new GameRepository(dataContext); gameRepository.AddGame(game); Assert.Equal(1, dataContext.Games.Count()); }
public async void TestRepo_GameRepository() { IGameRepository repo = new GameRepository(_tableName, _serviceUrl); var userId = "U1"; var list0 = await repo.GetGameList(userId); Assert.Equal(0, list0.Count); var g = new Game { Id = "GA", Name = "Game A" }; await repo.AddGame(userId, g); var list1 = await repo.GetGameList(userId); Assert.Equal(1, list1.Count); var item0 = list1[0]; Assert.NotNull(item0); Assert.Equal("GA", item0.Id); Assert.Equal("Game A", item0.Name); var found = await repo.GetGame(userId, g.Id); Assert.NotNull(found); Assert.Equal("GA", found.Id); Assert.Equal("Game A", found.Name); found.Name = "Game AA"; await repo.UpdateGame(userId, found); var updated = await repo.GetGame(userId, g.Id); Assert.NotNull(found); Assert.Equal("Game AA", found.Name); await repo.DeleteGame(userId, g.Id); var deleted = await repo.GetGame(userId, g.Id); Assert.Null(deleted); var emptyList = await repo.GetGameList(userId); Assert.Equal(0, emptyList.Count); }
public void CreateGame(string name, DateTime scheduleTime) { List <Contest> contest = new List <Contest> { new Contest { Name = "Full House", Winner = null } }; _gameRepository.AddGame( new Game { Name = name, ScduledDateTime = scheduleTime, Status = Status.NotStarted, Contests = contest }); }
private async void SaveGame() { ContentDialogResult result = await _dialogService.ShowContentDialogAsync(new ConfirmDialogViewModel("End Game", "Are you sure you want to quit the game and log the stats?")); if (result == ContentDialogResult.Secondary) { return; } CalculateScores(); AchievementService achievementService = new AchievementService(game); achievementService.CheckForPersonalScores(); achievementService.CheckForEverScores(); try { _gameRepo.AddGame(game); int multiScore = colours.SingleOrDefault(c => c.name == "Multi")?.score ?? 0; foreach (Player player in game.players) { _playerGameRepo.AddPlayerGame(player, game, colours.SingleOrDefault(c => c.name == "Red").score, colours.SingleOrDefault(c => c.name == "White").score, colours.SingleOrDefault(c => c.name == "Blue").score, colours.SingleOrDefault(c => c.name == "Yellow").score, colours.SingleOrDefault(c => c.name == "Green").score, multiScore); } achievementService.CheckForFirsts(); achievementService.CheckForMileStones(); achievementService.AddAchievements(); ((App)Application.Current).rootFrame.Navigate(typeof(StandingsView), game); } catch (SQLiteException) { await _dialogService.ShowContentDialogAsync(new MessageDialogViewModel("Error", "Something went wrong, please try again")); } }
static void Seed() { var GameRepo = new GameRepository(); var UserRepo = new UserProfileRepository(); var WordRepo = new WordBankRepository(); var RoleRepo = new RoleRepository(); var DicRepo = new DictionaryRepository(); DicRepo.AddDictionary(DictionaryList.OrderBy(d => d.Word).Distinct().ToList()); foreach (var item in Roles) { RoleRepo.AddRole(item); } UserRepo.AddUserProfile(UserProfile); Console.WriteLine("User Added"); GameRepo.AddGame(Game); Console.WriteLine("Game Added"); WordRepo.AddWordBank(WordBank); Console.WriteLine("Word Added"); }
public void AddGame() { Game game = new Game(); var homeSelector = (ComboBoxItem)_addGame.HomeTeamComboBox.SelectedItem; Team homeTeam = _teamRepository.GetTeamById((long)homeSelector.Tag); game.HomeTeam = homeTeam; var awaySelector = (ComboBoxItem)_addGame.AwayTeamComboBox.SelectedItem; Team awayTeam = _teamRepository.GetTeamById((long)awaySelector.Tag); game.AwayTeam = awayTeam; var citySelector = (ComboBoxItem)_addGame.CityComboBox.SelectedItem; City city = _cityRepository.GetCityById((long)citySelector.Tag); game.City = city; List <Referee> referees = new List <Referee>(); foreach (ListBoxItem item in _addGame.RefereeListBox.Items) { referees.Add(_refereeRepository.GetRefereeById((long)item.Tag)); } game.Referees = referees; game.NoOfReferees = (int)_addGame.numberOfReferee.Value.Value; var licenceSelector = (ComboBoxItem)_addGame.LicenceComboBox.SelectedItem; Licence licence = _licenceRepository.GetLicenceById((long)licenceSelector.Tag); game.MinimalLicence = licence; game.Address = _addGame.AddressTextBox.Text; game.StartTime = _addGame.DatePicker.SelectedDate.Value; _gameRepository.AddGame(game); _addGame.Close(); ReloadListOfGames(); }
public void AddGame() { using (ApplicationContext context = new ApplicationContext()) { CreateGameDto game = new CreateGameDto() { AgeRatingID = 2, Description = "test description", GamePlatformID = 3, Name = "test game", Price = 10, ProductionID = 1, ReleaseDate = DateTime.Now }; GameRepository gameRepository = new GameRepository(context); Game gameDb = gameRepository.AddGame(game); Assert.AreEqual(gameDb.Name, gameDb.Name); }; }
private async void SaveGame() { if (!CheckForEndOfGame()) { ContentDialogResult result = await _dialogService.ShowContentDialogAsync(new ConfirmDialogViewModel("End Game", "You are about to quit an unfinished game. Are you sure you want to quit the game and log the stats?")); if (result == ContentDialogResult.Secondary) { return; } } CalculateScores(); AchievementService achievementService = new AchievementService(game); achievementService.CheckForPersonalScores(); achievementService.CheckForEverScores(); try { _gameRepo.AddGame(game); foreach (Player player in game.players) { _playerGameRepo.AddPlayerGame(player, game.id); } achievementService.CheckForFirsts(); achievementService.CheckForMileStones(); achievementService.AddAchievements(); ((App)Application.Current).rootFrame.Navigate(typeof(StandingsView), game); } catch (SQLiteException) { await _dialogService.ShowContentDialogAsync(new MessageDialogViewModel("Error", "Something went wrong, please try again")); } }
private static void Main() { WriteLine("What's your name?"); var name = ReadLine(); while (true) { Clear(); var game = new Game(name); WriteLine($"Hello, {name}!"); WriteLine("Use the up and down keys to guess whether the next number will be higher or lower."); WriteLine("Press (h) to view the high-scores, or any other key to continue."); var input = ReadKey(); if (input.Key == ConsoleKey.H) { PrintHighScores(); } Clear(); while (!game.IsFinished) { WriteLine($"The current number is {game.CurrentNumber}."); WriteLine("Will the next be higher or lower?."); Guess?guess = null; while (guess == null) { input = ReadKey(); guess = input.Key switch { ConsoleKey.UpArrow => Guess.Higher, ConsoleKey.DownArrow => Guess.Lower, _ => null }; } var success = game.GuessNext(guess.Value); if (success) { WriteLine($"Nice! You guessed {guess.Value.ToString().ToLowerInvariant()} and the next number is {game.CurrentNumber}"); } else { WriteLine($"Oh no! You guessed {guess.Value.ToString().ToLowerInvariant()} and the next number is {game.CurrentNumber}"); } if (game.IsFinished) { if (game.IsComplete) { WriteLine($"You completed the game in {game.RunningTime.TotalSeconds} seconds"); } else { WriteLine($"You lost the game in {game.RunningTime.Seconds} seconds with a score of {game.Score}"); } var newHighScore = HighScores.AddGame(game); if (newHighScore) { WriteLine("That was a NEW HIGH SCORE!"); ReadKey(); WriteLine(); PrintHighScores(); } WriteLine("Press any key to play again or ESC to quit."); var key = ReadKey().Key; if (key == ConsoleKey.Escape) { return; } game = new Game(name); } } } }
public void AddGame(Game game) { _repo.AddGame(game); }